I need help with a student's game!


#1

I have a student who is working on his game and trying to code a sprite so that whichever direction the sprite is facing, it can fire a projectile in that direction. I have no clue what he should do. I’ve tried a couple things that haven’t worked, so I thought I’d put it out to the CSD community. Can someone help me? Here is his current project: https://studio.code.org/projects/gamelab/5stCjFjG46hARHnnsmloi-kcuOc1jKWc6yBjfrXNPec

Thanks!


#2

There are a couple of ways that he can do this, and it looks like he’s chosen to check the visibility property of one of the sprites in a conditional, then set the velocity of the shot accordingly (lines 56-60).

The main problem is in lines 61-63. Right now they are always run, so even though the if statement sets the velocity to -5 when the player is visible (and the space bar is pressed), lines 61-63 will always set it back to 5. Instead, lines 61-63 should only run when the condition in line 56 is not true. Your student can fix this either by using an else in the conditional and putting those lines inside, or by creating a new conditional that checks whether the other sprite is visible.

Elizabeth


#3

Thank you, Elizabeth! We are starting a long Easter weekend break today, so I will touch base with him when the students return with your idea.


#4

I had a related issue with a “space-invaders-style” game. I could create a projectile, but had trouble creating multiples and having each of them behave independently. I came up with a solution using groups and FOR loops to handle the issue.

See particularly 73-107.

I hope it helps!!!

-dave


#5

I need help with my student’s game ASAP as it’s due tomorrow. Anything she puts in Line 144 keeps saying it’s not a function. ANY IDEAS???


#6

There seems to be something wrong with the singer for me. I’ll try and work on it some more here.


#7

found it
line 139.
The student was setting the velocityY of the singer to the singer
singer = singer.velocityY + 0.1;

this breaks the singer.

should be

singer.velocityY = singer.velocityY + 0.1;