View Single Post
Old 28-11-2010, 03:56 PM   #4
_r.u.s.s.
I'm not Russ
but an ex-alektorophobic
 
_r.u.s.s.'s Avatar


 
Join Date: May 2005
Location: Nitra, Slovakia
Posts: 6,533
Default

that's a nice start

however, i see you already noticed the most common problem when people start programing with keyboard events. for example, when you hold one key the dot moves a bit at first, then pauses and then continues moving. you can solve this by remembering states of the keyboard rather than relying on keyboard events directly

example, we have a boolean variable "pressed_left" which is false by default, when a user presses left key you set this variable to true. later in the cycle you check this variable for true or false and move the circle accordingly. when user releases the key you would set the variable to false. that way you can move in more directions at once too.

with this you'd probably notice that you have a lot of variables and it gets kind of big (lines-wise). then you could use arrays. arrays are very useful in programming, you should definitely check them out. for example you could have only one variable which could hold all the key states

also, the code will eventually grow and it's a good to make a clean difference between the action code, calculations and rendering. you can for example try creating a procedure which will register key events and modify positions of the circle (1 up 1 left for example), then a procedure for enemy movement, a procedure which would calculate if something hit something else ... and then, a procedure which will simply draw all this into the scene. the main loop will be cleaner, simpler and much easier to navigate in. ideally, you would use objects and classes, but i don't think that this is a topic for beginner yet, just stick to your procedures and functions for now. and i'm not even sure if pascal supports them anyways
__________________
_r.u.s.s. is offline                         Send a private message to _r.u.s.s.
Reply With Quote