posted 12 years ago
I started writing a game 2 days ago. It is a simple platform game. There are 3 platforms total : a "floor" and 2 "floating ramps". On the ground, between the "floating ramps", there is a "coin". On the second floating ramp, there is another "coin". You can pick up the coins. On the first floating ramp, there is a "gun". If you pick up the "gun", you can "shoot" "bullets". Only one "bullet" by the user is allowed to be shot at one time. The user can physically control the object (cube, box, etc) with the arrow buttons. Up physically moves the object up a certain distance. Moving to the right causes the world to move left. Moving to the left causes the world to move right. You may destroy 2 "targets" with the "bullets" if you have picked up the "gun". If the "targets" are "destroyed", an AI "character" (box, cube, etc) comes running at a constant speed to the left. It spits out a stream of "bullets". If the user destroys the AI "character", the character disappears along with its bullets. The only issue is when the character moves while the AI character is still "alive" and shooting "bullets". The character's location algorithm is composed of this :
When a user pushes the left or right arrow on their keyboard, a timer starts :
These continue until the user stops holding down the key.
This is what happens when the AI "walks" (it walks if it is still "alive") :
I have marked what I believe to be the problem line above. I have tried changing the timer on the "enemyShoot" timer and it doesn't affect the problem. If a user is "running" full to the left, the "bullets" go out as far as they should. If a user is stopped, the "bullet's" path is shorter. If a user is "running" full to the right, the "bullets" start moving to the right at lower timer intervals (around 20 it is noticeably going to the left). I was wondering how to fix this problem. To me, it just seems like the lag of the repaint and the refreshing of the bullets. I would like the bullets to be consistently going to the right.
Here is the keyEvent info for left and right arrows :
Here is the release key code :
The AI's bullet display system is the same as the character's bullet display system :
Thanks,
John Price
EDIT : So, to restate my question... I would like a solution or help to finding a solution to fix the problem of the movement of the user causing the AI's "bullets" to not be consistent.
EDIT(2) : Please note that the AI movement isn't lagging. It is the "bullets" that the AI shoots.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” (Mosher's Law of Software Engineering)
“If debugging is the process of removing bugs, then programming must be the process of putting them in.” (Edsger Dijkstra)