I am currently working on a project in Code.org's Game Lab. In this game, if the object(bee) collides with another object, it's velocity should increase permanently. Is there any way to do this? Here is a link:
https://studio.code.org/projects/gamelab/bObYvRkfcSN938ptuiIyH0ZdF1de4jhaiOYZLgfTTwM/edit
Here is a code snippet:
//Making the bee
var bee = createSprite(200, 200);
//Set animation for 'bee' as bee_1
bee.setAnimation("bee_1");
//Scaling the bee tp 0.5x
bee.scale = 0.5;
var velocity = 2;
bee.velocityY = velocity;
//Making the walls
function draw() {
background("white");
createEdgeSprites();
bee.bounceOff(edges);
if (bee.isTouching(edges)) {
velocity = velocity * 1.25;
}
/*
if (keyDown("up")) {
bee.velocityX = 0;
bee.velocityY = velocity * -1;
}
else if (keyDown("down")) {
bee.velocityX = 0;
bee.velocityY = velocity;
}
else if (keyDown("right")) {
bee.velocityX = velocit;
bee.velocityY = 0;
}
else if (keyDown("left")) {
bee.velocityX = -2;
bee.velocityY = 0;
}
if (velocity>15) {
velocity = 10;
}
else if (velocity<-15) {
velocity = -10;
}*/
drawSprites();
}
Unfortunately, the snippet cannot be run as I don't have access to the HTML and CSS code. I have tried using the isTouching() method, but that method only works as long as the bee is touching the walls. I need a way to make it so that when the bee collides with any object (I plan on adding more sprites which will function as walls), the velocity
variable is set to 1.25 times itself. i.e.
if (<insert condition here>) {
velocity = velocity * 1.25;
}
I would appreciate any other tips on how to improve my code also.