• entries
455
639
• views
424748

# The game continues to be formed...

73 views

I'm still as yet to work out if my way of doing things is remotely sane, I've less than 48h until this has to be handed in (infact at this point on monday I'll be on route to get drunk...) and I haven't done a great deal of 'graphics' stuff.

Infact, I spent most of yesterday arsing aroung with Luajava trying to get it to call a proxy function to my player object. Which, needless to say I couldn't get working. Of course, 4h into all this I realise that it doesn't matter as I can handle it all Lua side; insert swearing and cursing here.

So, I skeleton'd the code last night in Lua for the game;
It's split over 3 lua files.

j3su_startup.lua
This holds the functions which are called from Java to perform setup, update and render. It then hands off to the current state's functions for processing.

Handles the menu state. Waits for the famous 'anykey' to be pressed at which point the state is swapped to the game.

j3su_game.lua
This handles the game logic, which pretty much requires that it updates all the game elements, performs collision detection (with the aid of a new engine function) and handles rendering order.

j3su_player.lua
Handles all player related logic.
Requests keystate from a keyhandler class (Java side) and process accordingly. Also controls player rendering, health and lives

j3su_enemies.lua
A simple enemy class; fires randomly and moves in some sin/cos type pattern on the screen (or will when I've written it).

j3su_bullet.lua
Bullet logic; which is basically 'move in a straight line until we fall off the screen' as the removal for collision is handled in the game script.

There are a still a few things I need to handle but I'm pretty happy with the basic game logic; this is infact the first 'real' Lua programming I've done; previous to this I've only really used it as a massive switching table.

I have to say I like it more now I've worked with it for a while, although being able to only use Lua5.0 instead of 5.1 is slightly bothersome, but that's the Java binding problem for you.

There is still one area I'm not 100% sure is going to work and thats the state system.

Basically, the menu and game are tables, in these tables is a 'currentstate' table which holds a bunch of function objects and an instance var which points to the 'current' table instance we want to call the function on.

The idea is to extract the instance and the function and then call the function on the instance;
local instance = currentstate.instancelocal func = currentstate.initFuncinstance:func()

Now, I don't see why this wouldn't work, as instance is a table and func is a function, so it's basically the same as doing instance:init() directly, or even init(instance) as the former is just syntatic sugar for the later.. as to if Lua will let me do it like this however remains to be seen.

I've sat here and consider it; we have a table and function, just like a statically written call, the only difference is the table and function can be change before the call.

So, I don't see why it won't work... however, rest assured if it doesn't you'll probably hear the scream [grin]

I need to wrap this up quickly tonight and get all the graphics sorted out so that I can spend tomorrow doing finishing touches and the write up to hand in before 5pm monday (yay for non-before 10am hand in times). I've got about 6h tonight if I want to try and get 8h sleep before I get up tomorrow, so I should have plenty of time... heh, famous last words [grin]

On Java 3...
Now, related to the above;
Quote:
 Original post by MARS_999So what is your thoughts on Java so far!! I myself when I did code in it, back in college, I liked it but was already using C++. If I wasn't using C++ I would probably use Java. I like most things about Java. But again this is personal opinions again! :) Back to bed again!

I'm on record at college as saying I think Java is the devil. OK, a bit extreme but there are just things about it I don't like and probably never will.

Can I use it? Yes, apprently quite well it seems, so I've got the skills, I just don't like how it's designed (and for all my looking I've not found anything like an 'out' or reference method of passing vars into functions, this is a major dislike of mine as there are a number of cases when I've considered this the best way to do thing).

I wouldn't be using Java if I had the choice; for grades I'd go with C++ simply because it's the language I know the best thus I know I can get the code working.
If I had time to learn then I'd probably go with C#, it fixes so many of the programs I think Java has.

End of the day, I can use it, I just wouldn't by choice.
Oh, and for the record I first used it back in the 1.0 days, pretty soon after it started to do the rounds online publically... I even recall having some trouble getting my head around the call back system for events in 1.1 *chuckles* that's gotta be about 10 years ago now...

Amazing how time flies isn't it?

Anyways, back to Lua!

There are no comments to display.

## Create an account

Register a new account