Please help me with this students code-Unit 3 Lesson 22

csd-unit-3-lesson-22
#1
#2

Stefanie,

What is this supposed to do/ how can we help. Right now when the user either presses the “1” or “2” a bunch of objects move vertically or horizontally across the screen, which is what the code directs the objects to do. Let us know what the final product is supposed to be and let’s figure this out together!

Brad

#3

The number key 1 and 2 trigger two different games. Each time the numbers are pressed, it should reset the game so that the other is not running as well. Game number one is a simple vertical scroller game in which the spaceship “eb” collects a point when touching any cow c1 through c9. The player loses 10 points when touching the “crazy” cow c10. That is as far as it goes. The second game is an extremely simple side scroller in which the dinosaur avoids the cacti obstacle “ob(number)” at all costs using only the x and y axes. It is basically a slightly different version of the dinosaur game that you can play when you do not have internet service on Google. (On a mobile device, I believe.) -Caidan Bevacqua

Stefanie Morrison

Business/Computer Teacher

Yearbook Advisor

Johnsonburg Area Junior/Senior High School

315 High School Road, Johnsonburg PA 15845

814-965-2556

#4

Hi @stefaniem,
I was just checking in to see if you need further help with this project. As it is right now, it looks like it is switching between games very well. Please let us know if you need more help.

#5

I do need help, did you remix it? I would appreciate help so much.

Stefanie Morrison

Business/Computer Teacher

Yearbook Advisor

Johnsonburg Area Junior/Senior High School

315 High School Road, Johnsonburg PA 15845

814-965-2556

#6

It only switches I am not able to actually play the game. Can you please help me.

Stefanie Morrison

Business/Computer Teacher

Yearbook Advisor

Johnsonburg Area Junior/Senior High School

315 High School Road, Johnsonburg PA 15845

814-965-2556

#7

It’s a bit difficult to understand the intent of the code without comments, but it looks like the functions that run each came are only being called a single time becaues they are in keyWentDown conditionals (which are only true immediately after you press down the key). A different approach to this problem would be to use a variable to track which game mode you are in. For example

var game_mode = 0;

if (keyWentDown(1)) {
  game_mode = 1;
}

if (keyWentDown(2)) {
  game_mode = 2;
}

if (game_mode == 1) {
  //do game 1 stuff
} else if (game_mode == 2) {
  //do game 2 stuff
}
#8

I made the student add comments, would you be able to look at the code again. We appreciate the help https://studio.code.org/projects/gamelab/Zi_qIDza5ZTjBnyHOL3uzJEV-gvPy-rGROcTkt7AZQU
Thank you so much for your time.

#9

I think one of the problems is in the keyWentDown to select the games.
You only press the 1 or 2 key once. After that you need those branches of code to be executed every time through the game but you can’t keep pressing the 1 or 2 key.
So I made some variables to control what game you play. When the 1 key goes does it sets the gameOne variable to true and then every time through the draw loop the code for game one get executed. Same for game 2. Check out the structure.

I edited it a bit to get the controls working.
I’m not sure what the variables x,y, and z control. I commented some of that out.

Check it out.

Let us know how it goes.