xxxxxxxxxx
290
let state = "intro"
let map1 = {}
let map2 = {}
let map3 = {}
let hero = {}
let img1;
let img2;
let img3;
function setup() {
createCanvas(1000, 700);
textSize(35);
textAlign(CENTER);
img1 = loadImage('assets/mink.png');
imageMode(CORNER);
img2 = loadImage('assets/burfix2.png');
img3 = loadImage('assets/bane.png');
// Lost
img4 = loadImage('assets/gameover.png');
img5 = loadImage('assets/gameover1.png');
img6 = loadImage('assets/skull.png');
img7 = loadImage('assets/skull2.png');
img8 = loadImage('assets/win.png');
img9 = loadImage('assets/start.png');
map1.x = 850
map1.y = 300
map1.w = 700
map1.h = 50
map2.x = 400
map2.y = 400
map2.w = 200
map2.h = 50
map3.x = 100
map3.y = 600
map3.w = 200
map3.h = 50
hero.x = 250
hero.y = 500
hero.w = 40
hero.h = -100
hero.vy = 5
hero.acx = 0.3
}
function draw() {
background(252);
if (state == "intro") {
introState();
} else if (state == "game1") {
gameState();
} else if (state == "gameover")
{gameoverState();
} else if (state == "winning")
{winningState();}
}
function introState() {
image(img9, 0, 0, 1000, 700);
if (keyIsDown(32)) {
state = "game1";
}
}
function gameState() {
background(135, 206, 235)
image(img3, 0, 0, 1000, 700);
// SIMPLE MAP OJECT
image(img2,map1.x, map1.y, map1.w, map1.h);
image(img2,map2.x, map2.y, map2.w, map2.h, 000, 000, 100, 100);
image(img2,map3.x, map3.y, map3.w, map3.h, 00, 0, 100, 100);
// THE HERO
image(img1,hero.x, hero.y, hero.w, hero.h);
// HERO FALLING OFF EGDE //
//////////////////////GRAVITY/////////////////////////
hero.y += hero.vy
hero.vy += hero.acx
////////////////////ANTI GRAVITY////////////////////////
// Canvas control
if (hero.x > width-40){
hero.x = width-40
}
if (hero.x < 0){
hero.x = 0
}
// MAP1..CONTACT RULES
if (hero.y > map1.y &&
hero.y < map1.y + map1.h &&
hero.x > map1.x - 40 &&
hero.x < map1.x + map1.w
) {
hero.vy = 0
hero.y = map1.y
}
if (hero.x + 40 >= map1.x && hero.y > map1.y && hero.y < map1.y - map1.h) {
hero.x = map1.x - 40
} else hero.x = hero.x
// MAP2..CONTACT RULES NEW
if (hero.y > map2.y &&
hero.y < map2.y + map2.h &&
hero.x > map2.x - 40 &&
hero.x < map2.x + map2.w
) {
hero.vy = 0
hero.y = map2.y
}
if (hero.x + 40 >= map2.x && hero.y > map2.y && hero.y < map2.y - map2.h) {
hero.x = map2.x - 40
} else hero.x = hero.x
// MAP3..CONTACT RULES
if (hero.y > map3.y &&
hero.y < map3.y + map3.h &&
hero.x > map3.x - 40 &&
hero.x < map3.x + map3.w
) {
hero.vy = 0
hero.y = map3.y
}
if (hero.x + 40 >= map3.x && hero.y > map3.y && hero.y < map3.y - map3.h) {
hero.x = map3.x - 40
} else hero.x = hero.x
//print(hero.y)
//print(hero.x)
// CONTROL
if (keyIsDown(68)) {
hero.x = hero.x + 4;
}
if (keyIsDown(65)) {
hero.x = hero.x - 4;
}
if (keyIsDown(RIGHT_ARROW)) {
hero.x = hero.x + 4;
}
if (keyIsDown(LEFT_ARROW)) {
hero.x = hero.x - 4;
}
if (keyIsDown(87)) {
if (hero.vy == 0) hero.vy = + -10
}
// RESPAWN
if (hero.y > 1000) {
state = "gameover";
hero.y = 100;
hero.x = 100;
}
if (hero.x > 959) {
state = "winning";
}
}
function gameoverState() {
background(0);
image(img4, 0, 0, 1000, 700);
image(img5, 0, 0, 1000, 700);
image(img6, 30, 60,300, 300);
image(img7, 700, 60,300, 300);
if (keyIsDown(69)) {
state = "game1";
}
}
function winningState(){
background(255);
image(img8, 0, 0, 1000, 700);
if (keyIsDown(69)) {
state = "game1";
hero.x = map3.x;
}}