Game Idea 2

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

// Variables

var score;
var platform=createSprite(100,-40);
var platform2=createSprite(300,100);
var coin=createSprite(randomNumber(0,400),randomNumber(0,400));
var coin2=createSprite(randomNumber(0,400),randomNumber(0,400));
var alien=createSprite(200,200);
// Create Sprites
score=0;
alien.scale=1.2;
platform.setAnimation("platform");
platform2.setAnimation("platform");
coin.setAnimation("coin1");
coin2.setAnimation("coin1");
coin.scale=0.5;
coin2.scale=0.5;
alien.setAnimation("alien");
function draw() {
// draw the background
if(score>49){
background2();
}
else{
background1();
}
controlPlayer();
showScore();
playerLands();
collectItems();
gameOver();
// update the sprites
platform.velocityY=0.5;
if(platform.y>400){
platform.y=0;
}
platform2.velocityY=0.5;
if(platform2.y>400){
platform2.y=0;
}
coin.velocityY=5;
if(coin.y>399){
coin.y=0;
coin.x=randomNumber(0,400);
}
coin2.velocityY=5;
if(coin2.y>399){
coin2.y=0;
coin2.x=randomNumber(0,400);
}
alien.velocityY=alien.velocityY+0.1;

drawSprites();
}
// Functions
function background1() {
background("darkBlue");
noStroke();
fill("white");
ellipse(randomNumber(0, 400), randomNumber(0, 400), 3, 3);
ellipse(randomNumber(0, 400), randomNumber(0, 400), 3, 3);
ellipse(340, 50, 60, 60);
fill("darkBlue");
ellipse(320, 30, 60, 60);
}
function background2() {
background("DeepSkyBlue");
noStroke();
fill("yellow");
ellipse(randomNumber(0, 400), randomNumber(0, 400), 3, 3);
ellipse(randomNumber(0, 400), randomNumber(0, 400), 3, 3);
ellipse(340, 50, 60, 60);
}
function showScore() {
fill("white");
textSize(20);
text("Score: "+score,10, 20);
}
function controlPlayer() {
if(keyDown("left")){
alien.velocityX=-2;
}
if(keyDown("up")){
alien.velocityY=-2;
}
if(keyDown("right")){
alien.velocityX=2;
}
}
function playerLands() {
alien.collide(platform);
alien.collide(platform2);
}
function collectItems(){
if(alien.isTouching(coin)){
coin.y=0;
coin.x=randomNumber(0,400);
score=score+1;
}
if(alien.isTouching(coin2)){
coin2.y=0;
coin2.x=randomNumber(0,400);
score=score+1;
}
}
function gameOver(){
if(alien.y>399){
background("black");
fill("green");
textSize(50);
textFont("Arial");
platform.visible=false;
platform2.visible=false;
coin.visible=false;
coin2.visible=false;
alien.visible=false;
text("Game Over!",50,180);

}
}

You might also like