In this game you try to keep the penguin alive. If the penguin touches the water you lose. the penguin has to jump between ice cubes floating across the screen. the ice cubes are objects stored in an array. the penguin can jump when it is touching the ice cube. two challenges appear while playing. one makes the ice cubes smaller, and one makes the ice cubes move faster. if you navigate through these challenges you can get to safety and win the game. I attached a video of me completing the game because it might not be a game you can complete first try.
I wanted to create a fun game that had a relation to climate change. since climate change is melting ice which might cause harm to wildlife, I made this game where the ice is melting. If I had more time I might add more challenges and make the movement of the ice cubes look more realistic, like they are actually in water.
var ice = []
var penguinY = 0;
var penguinX = 300;
var penguinDy = 0;
var count = 0
var menu = 0
function setup() {
createCanvas(600,600)
//creating the 4 icecubes
for (i = 0; i < 4; i++) {
iceX = random(width)
iceY = 440
size = 70
ice[i] = makeIce(iceX, iceY, size)
}
}
function draw() {
//menu page
if (menu < 1) {
fill("lightgreen")
rect(0,0,800,600)
textAlign(CENTER)
textFont('Helvetica')
textSize(18)
fill("black")
text("The ice is melting!", 400,220)
text("get to safety!", 400,370)
fill("red")
text("use the arrow keys to move left and right", 400,280)
text("spacebar to jump", 400,310)
text("press spacebar to begin", 400, 450)
}
//win page
else if (count >= 3200){
fill(220)
noStroke()
background("lightblue")
ellipse(400,650,1200,400)
textSize(18)
fill(0)
text("you made it to safety!",400,300)
translate(400,420)
drawPenguin(0,0)
noLoop()
}
else {
//scenary
background("lightblue")
fill("blue")
rect(0, height - 100, width, 100)
//sun that rotates
push()
translate(100,100)
rotate(radians(count))
drawSun()
pop()
stroke(0)
//checking if penguin is on any icecube or above the icecubes
if (penguinY <= 440 &
(penguinX >= ice[0].fx && penguinX <= ice[0].fx+75) ||
(penguinX >= ice[1].fx && penguinX <= ice[1].fx+75) ||
(penguinX >= ice[2].fx && penguinX <= ice[2].fx+75) ||
(penguinX >= ice[3].fx && penguinX <= ice[3].fx+75)
) {
penguinY = min(395, penguinY + penguinDy);
//checking if penguin is below the icecubes
} else {
penguinY = min(height, penguinY + penguinDy);
}
//showing the penguin and ice
drawPenguin(penguinX,penguinY)
showIce()
//penguin gravity
penguinDy = penguinDy + .25;
//penguin left/right movement
if (keyIsDown(LEFT_ARROW)){
penguinX-=5
}
if (keyIsDown(RIGHT_ARROW)){
penguinX+=5
}
// if you touch the water "you lose"
if (penguinY >= 550) {
textSize(18)
text("You Lose",400,300)
fill(255)
drawDeadPenguin(penguinX,penguinY)
noLoop()
}
//use this count to initate challenges levels
count+=1
//challenge level 1
countdown(900)
if (count >= 1100 & count <= 1500){
ice[0].icesize = 30
ice[1].icesize = 30
ice[2].icesize = 30
ice[3].icesize = 30
}
if (count >= 1500 && count <= 2000){
ice[0].icesize = 70
ice[1].icesize = 70
ice[2].icesize = 70
ice[3].icesize = 70
}
//challenge level 2
countdown(1800)
if (count >= 2000 && count <= 2400){
ice[0].icespeed = -4
ice[1].icespeed = -5
ice[2].icespeed = -6
ice[3].icespeed = -7
}
if (count >= 2400 && count <= 2401){
ice[0].icespeed = random(-1.5,-3)
ice[1].icespeed = random(-1.5,-3)
ice[2].icespeed = random(-1.5,-3)
ice[3].icespeed = random(-1.5,-3)
}
//approaching the end text
if (count >= 2600 && count <= 2800){
textSize(22)
text("you are approaching the end",400,300)
}
}
}
//penguin jump
function keyPressed() {
if (keyCode === 32) {
if (penguinY >= 360 && (
(penguinX >= ice[0].fx && penguinX <= ice[0].fx+75) ||
(penguinX >= ice[1].fx && penguinX <= ice[1].fx+75) ||
(penguinX >= ice[2].fx && penguinX <= ice[2].fx+75) ||
(penguinX >= ice[3].fx && penguinX <= ice[3].fx+75)
)) {
penguinDy = -10;
}
menu = 1
}
}
//two functions for alive penguin and dead penguin
function drawPenguin(x,y){
fill(0);
noStroke();
ellipse(x, y+2, 46, 81);
fill(255);
ellipse(x, y+10, 31, 56);
ellipse(x-5, y-20, 21, 21);
ellipse(x+5, y-20, 21, 21);
fill(255,150,40);
triangle(x-7, y-15, x+7, y-15, x,y-3);
ellipse(x+8, y+42, 15, 8);
ellipse(x-8, y+42, 15, 8);
fill(0);
ellipse(x-8, y-21, 8, 8);
ellipse(x+8, y-21, 8, 8);
ellipse(x-21, y+10, 12, 40);
ellipse(x+21, y+10, 12, 40);
}
function drawDeadPenguin(x,y){
fill(0);
noStroke();
ellipse(x, y+2, 46, 81);
fill(255);
ellipse(x, y+10, 31, 56);
ellipse(x-5, y-20, 21, 21);
ellipse(x+5, y-20, 21, 21);
fill(255,150,40);
triangle(x-7, y-15, x+7, y-15, x,y-3);
ellipse(x+8, y+42, 15, 8);
ellipse(x-8, y+42, 15, 8);
fill(0);
textSize(12)
text("x",x-9, y-20);
text("x",x+6, y-20);
ellipse(x-21, y+10, 12, 40);
ellipse(x+21, y+10, 12, 40);
}
// function creates the sun
function drawSun(){
fill("gold")
stroke("gold")
line(0,0,60,60)
line(0,0,-60,60)
line(0,0,-60,-60)
line(0,0,60,-60)
line(0,0,35,80)
line(0,0,-35,80)
line(0,0,35,-80)
line(0,0,-35,-80)
line(0,0,80,0)
line(0,0,-80,0)
line(0,0,0,80)
line(0,0,0,-80)
line(0,0,75,35)
line(0,0,-75,-35)
line(0,0,75,-35)
line(0,0,-75,35)
circle(0,0,100)
}
//function for the countdown for a challenge
function countdown(x){
if (count >= x & count <= x+200 ){
textSize(30)
text("Challenge in",350,200)
}
if (count >= x+16 && count = x+70 && count <=x+140 ){
textSize(50)
text("2",350,300)
}
if (count >= x+140 && count <=x+200 ){
textSize(50)
text("1",350,300)
}
}
//functions for the creation/movement of the ice
function makeIce(iceX, iceY, size) {
var ice = {
fx: iceX,
fy: iceY,
icesize: size,
icespeed: random(-1.5, -3),
icemove: moveIce,
icecolor: color(random(50, 100), random(100, 200), 255),
icedraw: drawIce
}
return ice
}
function moveIce() {
this.fx += this.icespeed
if (this.fx <= -10) {
this.fx += width
}
}
function drawIce() {
stroke(0)
fill(this.icecolor);
rect(this.fx, this.fy, this.icesize, 70)
}
function showIce() {
for (i = 0; i < ice.length; i++) {
ice[i].icemove()
ice[i].icedraw()
}
}