Unit 3 Lesson 22


#1

students are trying to use two mouseovers in an if statement to proceed, but their && statement proceeds after the first mouseover. Is there better logic for evaluating two user choices on a screen? In #give cutomers their orders. Here is the code.

// Create your variables here
var startgamescreen = true;
var randnum = 0;

// Create your sprites here
var pic = createSprite(200, 100);
pic.setAnimation(“picture”);
pic.scale = 0.75;
var start = createSprite(200, 300);
start.setAnimation(“start”);
start.scale = 1.5;

var hamburger = createSprite(70, 350);
hamburger.setAnimation(“burger”);
hamburger.visible = false;
hamburger.scale = 0.20;

var pizza = createSprite(200, 350);
pizza.setAnimation(“pizza”);
pizza.visible = false;
pizza.scale = 0.30;

var salad = createSprite(335, 350);
salad.setAnimation(“salad”);
salad.visible = false;
salad.scale = 0.15;

var soda = createSprite(145, 270);
soda.setAnimation(“soda”);
soda.visible = false;
soda.scale = 0.20;

var water = createSprite(270, 270);
water.setAnimation(“water_bottle”);
water.visible = false;
water.scale = 0.16;

var Anabelle = createSprite(100, 150);
Anabelle.setAnimation(“kid1”);
Anabelle.visible = false;
Anabelle.scale = 0.75;

var Mia = createSprite(100, 158);
Mia.setAnimation(“kid2”);
Mia.visible = false;

var Lena = createSprite(100, 160);
Lena.setAnimation(“kid3”);
Lena.visible = false;

var orderB = createSprite(300, 90);
orderB.setAnimation(“burger_order”);
orderB.visible = false;
orderB.scale = 0.40;

var orderPW = createSprite(300, 90);
orderPW.setAnimation(“pizza/water_order”);
orderPW.visible = false;
orderPW.scale = 0.2;

var orderSS = createSprite(320, 90);
orderSS.setAnimation(“Salad/soda_order”);
orderSS.visible = false;
orderSS.scale = 0.18;

//Draw Loop
function draw() {
// draw background
if (mousePressedOver(start)) {
startgamescreen = false;
}
if (startgamescreen) {
StartBackground();
} else {
GameBackground();
}

// update customers
randnum = randomNumber(0, 1000);
if (randnum > 999 && startgamescreen===false) {
Anabelle.visible = true;
orderPW.visible = true;
} else if (randnum<1 && startgamescreen===false){
Mia.visible = true;
orderB.visible = true;
} else if (randnum==50 && startgamescreen===false){
Lena.visible = true;
orderSS.visible = true;
}

//Give the coustomers their orders
if (randnum < 1 && mousePressedOver(hamburger)) {

}
drawSprites();
}

// Create your functions here
function StartBackground() {
background(“lightyellow”);
textFont(“Arial”);
textSize(20);
textAlign(CENTER);
text(“Give the correct order to each customer! Press Start to play!”, 70, 180, 270, 400);
}
function GameBackground() {
background(rgb(168, 198, 189));
fill(rgb(55, 24, 13));
noStroke();
rect(0, 230, 700, 700);
//get the game start screen sprites
pic.visible = false;
start.visible = false;
hamburger.visible = true;
pizza.visible = true;
salad.visible = true;
soda.visible = true;
water.visible = true;
}


#2

Hi, I’m not sure I understand what the students are trying to do. What exactly is the program supposed to do? I’m also not sure what you mean when you say that the && statement proceeds after the first mouseover. I tried to look at the part of the code you referenced, but it looks to be checking for the value of a random number and then looking at a mouseover, so I still didn’t understand.

Maybe if you linked the project and explained the behavior that the students wanted, it might be easier to help out.

Thanks,
Elizabeth