Professional Documents
Culture Documents
Bounce Game in
Bounce Game in
org
var lives;
var score;
var xSpeed;
var ySpeed;
var ballX;
var ballY;
var paddleSpeed;
var paddleX;
var coinX;
var moveLeft;
var moveRight;
var isReset;
var canBounce;
setScreen("game");
lives = 2;
score = 0;
reset();
timedLoop(17, update);
});
if (event.key == "Left") {
moveLeft = true;
moveRight = true;
});
if (event.key == "Left") {
moveLeft = false;
moveRight = false;
});
startGame();
});
setScreen("start");
});
function update() {
movePaddle();
checkBounce();
collectCoin();
ballX += xSpeed;
ballY += ySpeed;
paddleX += paddleSpeed;
setText("score", score);
setText("lives", lives);
function checkBounce() {
xSpeed = -xSpeed;
ySpeed = -ySpeed;
canBounce = true;
canBounce = false;
ySpeed = -ySpeed;
reset();
function movePaddle() {
paddleSpeed = -5;
paddleSpeed = 5;
else {
paddleSpeed = 0;
function collectCoin() {
score++;
playSound("hitsound.mp3", false);
coinX = 500; // move the coin off screen for a while once it gets hit
ySpeed--;
xSpeed--;
xSpeed++;
setTimeout(function() {
}, 1500);
function reset() {
xSpeed = 0;
ySpeed = 0;
paddleSpeed = 0;
moveLeft = false;
moveRight = false;
isReset = true;
showElement("startText");
ballX = 147;
ballY = 212;
paddleX = 115;
coinX = 135;
canBounce = true;
if (lives == -1) {
endGame();
function startGame() {
hideElement("startText");
xSpeed = randomNumber(-5,5);
isReset = false;
function endGame() {
stopTimedLoop();
setText("finalscore", score);
setScreen("gameover");
}
Sprite Lab
var Score = 0;
World.frameRate = 200;
drawWorld();
movingYoda();
lilyoda.setAnimation("51N+0bihAKL.jpg_1");
lilyoda.scale = 0.2;
sun.setAnimation("sun_2");
cloud.setAnimation("cloud_1");
cloud.scale = 0.4;
cloudagain.setAnimation("cloud_1_copy_1");
cloudagain.scale = 0.4;
bonebroth.setAnimation("bone broth.jpg_1");
bonebroth.scale = 0.2;
function draw() {
background(rgb (135,206,235));
textSize(9);
fill(rgb(0, 0, 0, 0));
text("Collect the Bone Broth to make Baby Yoda stronger!", 115, 175);
barrier.setAnimation("reee.jpg_1");
barrier.visible = 0;
barrieragain.setAnimation("reee.jpg_1_copy_1");
barrieragain.height = 0.1;
barrieragain.visible = 0;
if (lilyoda.isTouching(barrier)) {
lilyoda.velocityY = lilyoda.velocityY + 2;
lilyoda.y = lilyoda.y + 2;
if (lilyoda.isTouching(barrieragain)) {
lilyoda.bounce(barrieragain);
drawWorld();
movingYoda();
scores();
enemies();
drawSprites();
}
function drawWorld() {
// draw background
// update sprites
function movingYoda() {
if (keyDown("a")) {
lilyoda.x = lilyoda.x - 2;
if (keyDown("d")) {
lilyoda.x = lilyoda.x + 2;
if (keyDown("w")) {
lilyoda.y = lilyoda.y - 2;
if (keyDown("space")) {
lilyoda.y = lilyoda.y - 2;
if (keyDown("s")) {
lilyoda.y = lilyoda.y + 2;
}
function scores() {
if (lilyoda.isTouching(bonebroth)) {
if (lilyoda.isTouching(bonebroth)) {
Score = Score + 1;
function enemies() {
lilyoda.setAnimation("1_copy_1");
sun.visible = 0;
cloud.visible = 0;
cloudagain.visible = 0;
bonebroth.visible = 0;
background("white");
textSize(20);
text("Baby Yoda has grown up!", 160, 220);
lilyoda.setAnimation("ausitmn");
drawSprites();
setScreen("screen1");
});
drawImageURL("http://www.charlierestivo.com/images/NiGHTS/JoD/mydream_n_003_nc.png");
image("bug", "http://www.wpclipart.com/cartoon/animals/mouse_rat/rodent/mole_cartoon.svg");
var clicks = 0;
console.log(getTime());
var startTime=getTime();
var elapsedTime=((getTime()-startTime)/1000);
textLabel("winner", elapsedTime + " seconds to smash 10 moles.");
hideElement("winner");
var fastestTime=startTime;
hideElement("highscore");
clicks = clicks + 1;
if (clicks==10) {
hideElement("bug");
var elapsedTime=((getTime()-startTime)/1000);
showElement("winner");
console.log((getTime()-startTime)/1000);
showElement("restart");
hideElement("canvas");
});
if (elapsedTime<fastestTime) {
fastestTime=elapsedTime;
showElement("highscore");
console.log('new winner');
setKeyValue("highscoreTime", fastestTime, function () {
});
});
hideElement("restart");
hideElement("restart");
hideElement("highscore");
hideElement("winner");
showElement("bug");
showElement("canvas");
clicks=0;
startTime=getTime();
});
//screen 2
setScreen("screen2");
drawImageURL("");
setScreen("screen1");
newRecord.name=getText("text_input2");
});
setText("instructions", "Press WASD or Arrow Keys to move\n\nPress Spacebar or click Play Again to
play again\n\n\nPress Spacebar to start the game");
var snake = {
x: 0,
y: 0,
w: 10,
h: 10,
velX: 0,
velY: 0,
IDandLength: 1,
moves: [],
didCrash: false
};
var fruit = {
x: 0,
y: 0,
w: 10,
h: 10
};
var ai = {
b: false,
o: false,
t: false,
access: false,
};
var points = {
x: [],
y: []
};
points.x.push(a);
points.y.push(a);
var doGameOver = 0;
var highscore = 0;
function snakeObj() {
if (ai.access)
aiBot();
if (snake.x > 300 || snake.x < 10 || snake.y > 430 || snake.y < 20)
deathAction();
if (!snake.didCrash) {
if (snake.moves.length == snake.IDandLength + 1)
snake.moves.pop();
addNewBlock();
var y = parseInt(coords[1]);
deathAction();
snake.x += snake.velX;
snake.y += snake.velY;
function deathAction() {
stopTimedLoop();
snake.didCrash = true;
if (doGameOver == 0) {
doGameOver++;
gameOver();
return x1 < snake.x + snake.w && x1 + w1 > snake.x && y1 < snake.y + snake.h && h1 + y1 > snake.y;
function addNewBlock() {
var x = parseInt(coords[0]);
var y = parseInt(coords[1]);
snake.IDandLength++;
function xyIsSame(x, y) {
function gameOver() {
highscore = snake.IDandLength;
deleteElement("gameOverLabel");
deleteElement("endScoreLabel");
deleteElement("playagainButt");
hideElement("snake");
hideElement("fruit");
hideElement("" + a);
reset();
});
deleteElement("gameOverLabel");
deleteElement("endScoreLabel");
deleteElement("playagainButt");
hideElement("snake");
hideElement("fruit");
reset();
resetOnce = false;
deleteElement("gameOverLabel");
deleteElement("endScoreLabel");
deleteElement("playagainButt");
hideElement("snake");
hideElement("fruit");
hideElement("" + a);
reset();
resetOnce = false;
startUp = true;
ai.access = false;
ai.b = false;
ai.o = false;
ai.t = false;
highscore = 0;
showElement("instructions");
setText("scorelabel", "");
setText("highscorelabel", "");
deleteElement("gameOverLabel");
deleteElement("endScoreLabel");
deleteElement("playagainButt");
hideElement("snake");
hideElement("fruit");
hideElement("" + a);
resetOnce = false;
});
function reset() {
setScreen("game");
for (var a = 1; a < snake.IDandLength; a++)
deleteElement("" + a);
snake.IDandLength = 1;
doGameOver = 0;
snake.didCrash = false;
giveDirection();
showElement("snake");
showElement("fruit");
timedLoop(50, snakeObj);
function giveDirection() {
if (randomNumber(0, 1) == 0)
down();
else
right();
if (randomNumber(0, 1) == 0)
up();
else
right();
if (randomNumber(0, 1) == 0)
down();
else
left();
else // quadrant 4
if (randomNumber(0, 1) == 0)
up();
else
left();
function aiBot() {
if (snake.y != fruit.y) {
if (isDown() || isUp())
if (snake.x == 10)
right();
left();
else
if (randomNumber(0, 1) == 0)
left();
else
right();
if (isRight() || isLeft())
up();
down();
} else {
if (snake.x == fruit.x)
if (snake.y > 200)
up();
else
down();
left();
right();
if (snake.x != fruit.x) {
if (isRight() || isLeft())
if (snake.y == 20)
down();
up();
else
if (randomNumber(0, 1) == 0)
down();
else
up();
if (isDown() || isUp())
right();
} else {
if (snake.y == fruit.y)
left();
else
right();
up();
down();
} else {
up();
left();
down();
else if (isUp() && snake.y < fruit.y + 10)
left();
if (snake.y == fruit.y)
left();
up();
right();
down();
right();
if (snake.y == fruit.y)
right();
if (snake.x == fruit.x) {
up();
if (snake.x == 10)
right();
down();
if (snake.x == 10)
right();
left();
if (startUp) {
startUp = false;
hideElement("instructions");
reset();
} else {
ai.b = false;
ai.o = false;
ai.t = false;
ai.access = false;
if (key == "b")
ai.b = true;
ai.o = true;
if (key == "t")
if (ai.o)
ai.t = true;
else
ai.b = false;
ai.access = true;
} else {
up();
down();
left();
if (!isLeft() && (key == "d" || key == "Right"))
right();
stopTimedLoop();
startUp = true;
ai.access = false;
ai.b = false;
ai.o = false;
ai.t = false;
highscore = 0;
showElement("instructions");
setText("scorelabel", "");
setText("highscorelabel", "");
hideElement("snake");
hideElement("fruit");
hideElement("" + a);
});
// these are functions for to set velX and velY variables to indicate movement of the snake
function up() {
snake.velY = -10;
snake.velX = 0;
function down() {
snake.velY = 10;
snake.velX = 0;
function left() {
snake.velX = -10;
snake.velY = 0;
function right() {
snake.velX = 10;
snake.velY = 0;
// these are functions to check if the snake is currently going in a certain direction
function isUp() {
function isDown() {
return snake.velY == 10 && snake.velX == 0;
function isLeft() {
function isRight() {
Applab coding
var currentIndex=0;
var icecream="http://www.akerufeed.com/wp-content/uploads/2016/07/allice.jpg";
var padThai="http://www.circulaire-en-ligne.ca/wp-content/uploads/recette-pad-thai-facile-
300x200.jpg";
var panda="https://upload.wikimedia.org/wikipedia/commons/6/62/Panda_(PSF).png";
var myFavoriteThings=[icecream,padThai,panda];
updateScreen();
nextImage();
updateScreen();
});
previousImage();
updateScreen();
});
appendItem(myFavoriteThings,getText("inputBox"));
updateScreen();
setText("inputBox","");
});
if (event.key=="Up") {
nextImage();
} else if ((event.key=="Down")) {
previousImage();
updateScreen();
});
//functions
currentIndex++;
if (currentIndex> myFavoriteThings.length-1){
currentIndex= currentIndex-1;
console.log("Up");
playSound("https://studio.code.org/v3/assets/R3xt1BXO0VuQve0HdwClFg/cartoonButton.mp3");
function previousImage(){
currentIndex--;
if (currentIndex< 0) {
currentIndex = currentIndex+1;
console.log("Down");
playSound("https://studio.code.org/v3/assets/13v2AdelOqxDhJ32C1fnAw/DownSound.mp3");
function updateScreen() {
setImageURL("myImage", myFavoriteThings[currentIndex]);
if (currentIndex>=myFavoriteThings.length) {
currentIndex = 0;
setImageURL("myImage","http://greatwallpapers.online/halloween-iphone-wallpaper-
pinterest/wallpaper-tumblr-halloween-iphone-wallpaper-pinterest-wallpaper-tumblr-7.jpeg");
}else {
hideElement("instruction");
removeItem(myFavoriteThings, currentIndex);
if (currentIndex>=myFavoriteThings.length) {
currentIndex = 0;
setImageURL("myImage","http://greatwallpapers.online/halloween-iphone-wallpaper-
pinterest/wallpaper-tumblr-halloween-iphone-wallpaper-pinterest-wallpaper-tumblr-7.jpeg");
} else {
updateScreen();
console.log("removeButton clicked!");}
});
Link : https://studio.code.org/projects/applab/17S9dUeJd7GnhTW7VSvjhA/view
Banana Game
var score = 0;
var lives = 3;
setScreen("game_screen");
});
score = score + 1;
setText("total_score", score);
if (score == 20) {
setScreen("win_screen");
});
lives = lives - 1;
setText("number_lives", lives);
if (lives == 0) {
setScreen("lose_screen");
}
});
lives = 3;
setText("number_lives", lives);
score = 0;
setText("total_score", score);
setScreen("welcome_screen");
});
score = 0;
setText("total_score", score);
lives = 3;
setText("number_lives", lives);
setScreen("welcome_screen");
});
https://studio.code.org/projects/applab/TOSgYoamr2c7_8_V7T1Y8VaP7nSQ2V8Qbp5TuXCBk1k/view