//GAME SETUP
// Create the sprites
var mario = createSprite(200, 350);
mario.setAnimation("mario");
mario.scale = 3;
var bb = createSprite(200, 200);
bb.setAnimation("bb");
bb.scale = 0.25;
bb.velocityX = -5;
mario.debug = false;
bb.debug = false;
// set velocity for the obstacle and the target
//create the variables
var score = 0;
var health = 100;
function draw() {
if (bb.x < 0) {
bb.velocityX = 5;
bb.setAnimation("bb3");
}
if (bb.x > 400) {
bb.velocityX = -5;
bb.setAnimation("bb");
}
// BACKGROUND
background("cyan");
// draw the ground and other background
// SPRITE INTERACTIONS
// if the player touches the obstacle
// the health goes down, and the obstacle turns
if (mario.y > 350) {
mario.velocityY = 0;
}
if (keyDown("up")) {
mario.velocityY = -20;
}
if (mario.y < 100) {
mario.velocityY = 20;
}
if (keyDown("down")) {
if (bb.isTouching(mario)) {
mario.y = 260;
mario.velocityY = 20;
mario.rotation = 0;
}
}
if (keyDown("left")) {
mario.velocityX = -10;
}
if (keyDown("right")) {
mario.velocityX = 10;
}
// if the player touches the target
// the score goes up, the target resets
if (bb.isTouching(mario)) {
mario.velocityY = 0;
mario.x = bb.x;
mario.rotation = randomNumber(-30, 30);
}
// JUMPING
// if the player has reached the ground
// stop moving down
// if the player presses the up arrow
// start moving up
// if the player reaches the top of the jump
// start moving down
// LOOPING
// if the obstacle has gone off the left hand side of the screen,
// move it to the right hand side of the screen
// if the target has gone off the left hand side of the screen,
// move it to the right hand side of the screen
// DRAW SPRITES
drawSprites();
// SCOREBOARD
// add scoreboard and health meter
fill("black");
textSize(20);
text("Health:", 280, 30);
text (health, 350, 30);
// GAME OVER
// if health runs out
// show Game over
if (health < 0) {
background("black");
fill("green");
textSize(50);
text("Game Over!" , 40, 200);
}
}
// Create the sprites
var mario = createSprite(200, 350);
mario.setAnimation("mario");
mario.scale = 3;
var bb = createSprite(200, 200);
bb.setAnimation("bb");
bb.scale = 0.25;
bb.velocityX = -5;
mario.debug = false;
bb.debug = false;
// set velocity for the obstacle and the target
//create the variables
var score = 0;
var health = 100;
function draw() {
if (bb.x < 0) {
bb.velocityX = 5;
bb.setAnimation("bb3");
}
if (bb.x > 400) {
bb.velocityX = -5;
bb.setAnimation("bb");
}
// BACKGROUND
background("cyan");
// draw the ground and other background
// SPRITE INTERACTIONS
// if the player touches the obstacle
// the health goes down, and the obstacle turns
if (mario.y > 350) {
mario.velocityY = 0;
}
if (keyDown("up")) {
mario.velocityY = -20;
}
if (mario.y < 100) {
mario.velocityY = 20;
}
if (keyDown("down")) {
if (bb.isTouching(mario)) {
mario.y = 260;
mario.velocityY = 20;
mario.rotation = 0;
}
}
if (keyDown("left")) {
mario.velocityX = -10;
}
if (keyDown("right")) {
mario.velocityX = 10;
}
// if the player touches the target
// the score goes up, the target resets
if (bb.isTouching(mario)) {
mario.velocityY = 0;
mario.x = bb.x;
mario.rotation = randomNumber(-30, 30);
}
// JUMPING
// if the player has reached the ground
// stop moving down
// if the player presses the up arrow
// start moving up
// if the player reaches the top of the jump
// start moving down
// LOOPING
// if the obstacle has gone off the left hand side of the screen,
// move it to the right hand side of the screen
// if the target has gone off the left hand side of the screen,
// move it to the right hand side of the screen
// DRAW SPRITES
drawSprites();
// SCOREBOARD
// add scoreboard and health meter
fill("black");
textSize(20);
text("Health:", 280, 30);
text (health, 350, 30);
// GAME OVER
// if health runs out
// show Game over
if (health < 0) {
background("black");
fill("green");
textSize(50);
text("Game Over!" , 40, 200);
}
}
|
|
<iframe src="https://docs.google.com/presentation/d/e/2PACX-1vRGny4ESo4j7KGQZ5X4CoH0eYNG9dAB--1_Qrw-C6Q9QaGj31PaISe4I0I71uFyIv_fa4cfmt_Van1o/embed?start=false&loop=false&delayms=3000" frameborder="0" width="960" height="569" allowfullscreen="true" mozallowfullscreen="true" webkitallowfullscreen="true"></iframe>
<iframe width="725" height="453" src="https://www.tinkercad.com/embed/1OGPtyZ5w94?editbtn=1" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>