Help me help this student!

csd-unit-3
csd-unit-3-lesson-22

#1

My student is trying to touch the watermelon with the giraffe and have the watermelon move after being “eaten”/touched. The watermelon just moves super fast and we can’t seem to slow it down or get it to do what he wants when the giraffe touches it. Here is the code:

// Create your variables here
var character = createSprite(200, 200);
character.setAnimation(“giraffe”);
character.scale = 0.3;
var watermelon = createSprite(200, 200);
watermelon.setAnimation(“watermelon”);
watermelon.scale = 0.2;

// Create your sprites here

function draw() {
// draw background
background(“green”);
text(“Space to jump, Arrows to move,get the watermelon”, 0, 15);
moveCharacter();
resetwatermelon();
gravity();
drawSprites();
}

function moveCharacter(){
if(keyWentDown(“space”)){
character.velocityY -= 5;
}
if(keyDown(“LEFT_ARROW”)){
character.velocityX -= 0.2;
}
if(keyDown(“RIGHT_ARROW”)){
character.velocityX += 0.2;
}
}

function resetwatermelon(){
if(character.isTouching(watermelon)){
watermelon.x = randomNumber(0,400);
watermelon.y = randomNumber(0,400);
}
}

function gravity(){
character.velocityY += 0.2;
}


#2

Could you post the link to the project here? It’s nice to be able to go in and just make it run to see what it’s doing. Thanks!


#5

Hatif

Jan 21, 23:37 PST

Hi,
One of my stduents is not able to proceed with her project on AppLab. Everytime, she enters the code , the screen goes blank and nothing happens. I am sharing the link to her project below. Please help her out. Thanks


Sorry, I didn’t know where exactly to enter this post.


#6

https://studio.code.org/projects/gamelab/K8YHgyeqfBywowFiuOh3ibrohNVW4jss7lDcSJ-wr_A


#7

Hello Mindy!
The problem this student is experiencing is in the animation tab. It appears the student attempted to scale the giraffe and watermelon sprites down using the animation tools instead of adjusting the size in the code. This caused the collider (or hitbox) for both sprites to be the size they were before they were scaled down, which was very large, which caused the sprites to constantly collide.
An easy fix for this is to remove both sprites, and create new ones without scaling them down in the animation tab, and remember that the problem is not with the code.
Hope this solves your issue!
Thanks, have a great day! :slight_smile:


#9

Hello Hatif! To answer your question, your app is starting on the blank screen “boy13”. To fix this you would have to set the starting screen to “Homescreen” or whichever starting screen is needed.
Hope this helps, have a great day! :smiley: