Code viewer for World:
Game
let fullwidth = ABWorld.fullwidth();
let fullheight = ABWorld.fullheight();
let img;
let enemy;
let imgsize = fullwidth/8;
let x = fullwidth/2 - fullwidth/16;
let speed = fullwidth/15;
let enemy_speed = fullwidth/140;
var game = false;
var dead = false;
var y = 100;
var locals = [fullwidth/4-imgsize/2, fullwidth/2-imgsize/2, 3*fullwidth/4-imgsize/2];
var x2;
function setup() {
createCanvas(fullwidth, fullheight);
img = loadImage('uploads/alexmurphy1996/mator.png');
enemy = loadImage('uploads/alexmurphy1996/fire.png');
}
function draw() {
if (dead===true){
die();
return;
}
background(0);
fill('green');
triangle(0, 0, fullwidth/4, 0, 0, fullheight);
triangle(fullwidth, 0, fullwidth - fullwidth/4, 0, fullwidth, fullheight);
fill('white');
rect(fullwidth/2-fullwidth/100, 0, fullwidth/50, fullheight/6);
rect(fullwidth/2-fullwidth/100, fullheight/2, fullwidth/50, fullheight/4);
image(img, x, fullheight-imgsize, imgsize, imgsize);
if (game === false) {
game=true;
x2 = locals[getRandomInt(3)];
}
move_enemy(x2);
}
function keyPressed() {
if (keyCode === LEFT_ARROW) {
x -= speed;
}
else if (keyCode === RIGHT_ARROW) {
x += speed;
}
}
function move_enemy(enemy_pos) {
image(enemy, enemy_pos, y, imgsize, imgsize);
//console.log('sdhbfi');
y+=enemy_speed;
if (y >= fullheight) {
y=0;
game=false;
enemy_speed+=0.5;
return;
}
if (x > enemy_pos - imgsize/2 && x < enemy_pos + imgsize/2 && y+imgsize >= fullheight-imgsize) {
die();
}
}
function die() {
background(0);
fill('red');
text('YOU DIED', fullwidth/2, fullheight/2);
dead = true;
}
function getRandomInt(max) {
return Math.floor(Math.random() * Math.floor(max));
}