I want the enemy ships to move back and forth

When I click “playbuttonlevelscreen” I want the game to start, the ship slowly moves up, and the enemy ships to move back and forth. I have the code for it, and it works, but the ships quickly move and disappear, and I don’t know how to fix it. The code for this is lines 531 - 773.

When I ran it, it did as you described. The ships only disappeared when the timer countdown stopped … is it supposed to do something different?


Yes, when I press the play button the ships are supposed to not move until the player ship is done moving slowly up, then they would flash and move left to right slowly until the farthest ship on each side touches it, and they go the other directions. Also, the laser on the ship is supposed to shoot when I hit space, and when it hits an enemy it is supposed to make the enemy flash and disappear and change the enemy remaining.

Well, that’s quite a list of things you want to implement which is great! Some of them already work, like firing with the space bar. some may be best implemented with a conditional statement … such as the ships can only start moving IF the y value of your player ship reaches a certain point.

Since you have several hundred lines of code, it would take quite a long time for me to figure out how to solve all of the issues you bring up. My suggestion would be for you to pick one you want to work on first, try writing the code for that one element and then if you get stuck, reach back out for help on that one item.

We are happy to help, but we can’t debug as complex a game as you have coded all at once. You may consider further breaking it into functions so when something works, you have it all in one spot. This is called decomposition and is used by programmers everywhere when they break a program down into smaller chunks and work on one at a time.

Let us know!


I have fixed the movement code, and the enemy ships. The only problem now is when space is pressed and goes past y = 300, the laser will slow down extremely. The other problem is the time, I have tried changing the variable total, but it still just stays at 20 and counts down very fast.

I want to focus on the laser, the problem is when space is first pressed it will shoot right above the ship, but when it is pressed again it will move to the right side of the ship. I just want the laser to always shoot above the ship and move at the same speed.

Here is the updated code: Code.org


It looks like you are using timed Loops. those aren’t correlated directly with seconds, so you will have to adjust for that. You may want to tie it to the World.seconds variable somehow.

Also, GameLab is designed as a training platform for 7th - 12th grade students and it may not be as robust as you need to create a fully functioning game that doesn’t have any lag. You can certainly work on cleaning up the code and optimizing it, but some of the lag may not go away due to it not being a robust gaming environment.