A space clicking game where you press the spacebar repeatedly that lets out spaceships that evacuate people from the Earth in the wake of the expanding sun.
The showcase player uses a modified version of Processing.js in combination with jsweet to let students program their apps in Java code while still allowing for browser support.
Content created by students is scaled to fit the showcase frame while maintaining aspect ratio and cursor position. This is why some projects may appear blurry in fullscreen, or why some small details may not be visible on a small screen
<iframe width='500px' height='400px' src='https://nest.ktbyte.com/nest#2621' allowfullscreen></iframe>
int gameMode = 0; float count = 28; float G = 0.001; // gravitational constant int counter = 0; Planet earth; Planet sun; ArrayList<Spaceship> spaceships = new ArrayList <Spaceship>(); boolean LaunchPermission = true; boolean GameOver = false; PImage InitialScreen; PImage SpaceShip; int index_ship = -1; int people = 600000000; class Spaceship { float xpos; float ypos; float Vx = 0; float Vy = 0; float rotation; boolean showShip = false; boolean firstTime = true; void display() { pushMatrix(); translate(xpos, ypos); rotate(rotation); image(SpaceShip, 0, 0); popMatrix(); } void move() { if (firstTime) { xpos = earth.x; ypos = earth.y; if (earth.y > 200 && earth.y < 400) { if (earth.x < 300) { rotation = 3*PI/2; //rotate 270 Vx=-1; } else { Vx=1; rotation = PI/2; //rotate 90 } } else if (earth.y<200) { Vy=-1; } else { Vy=1; rotation = PI; //rotate 180 } firstTime = false; } xpos += Vx; ypos += Vy; } } class Planet { float x; float y; float vx; // velocity in x direction float vy; float mass; float r; // r is radius, but not to scale color c; } void setup() { SpaceShip = loadImage("http://pixeljoint.com/files/icons/spacesjip8_final.png"); for (int i = 0; i<260; i++) { Spaceship temp = new Spaceship(); spaceships.add(temp); } size(600, 600); InitialScreen = loadImage("http://i.imgur.com/wbgIOCA.jpg"); earth = new Planet(); earth.x = 550; earth.y = 300; earth.vx = 0; earth.vy = 2.9; earth.mass = 6.0; earth.r = 15; earth.c = color(0, 96, 128); sun = new Planet(); sun.x = 300; sun.y = 300; sun.vx = 0; sun.vy = 0; sun.mass = 2000000.0; sun.r = 100; sun.c = color(255, 128, 0); } void draw() { if (gameMode == 0) { image(InitialScreen, 0, 0, 600, 600); fill(0, 255, 0); textSize(26); textAlign(CENTER); text("Press the spacebar to view ", width/2, height-50); text("instructions ", width/2, height-20); } if (gameMode == 2) { background(0); textSize(16); fill(255); textAlign(CENTER); text("You must save all 600 million remaining people on earth", width/2, 80); text("from the expanding sun by pressing the spacebar to release", width/2, 100); text("spaceships. Each time you press the spacebar", width/2, 120); text("you release 1 spaceship. Each spaceship carries 4,100,000 people in Easy", width/2, 140); text("3,890,000 people in Normal difficulty, 3,780,000 people in Hard difficulty", width/2, 160); text("and 3,775,000 people in Very Hard difficulty", width/2, 180); text("difficulty. The blue number at the top of", width/2, 200); text("the gameplay screen will show you the amount of time", width/2, 220); text("you have left(in seconds). The larger green number below will", width/2, 240); text("show you how many people are left on the earth. ", width/2, 260); text("You will have 28 seconds to evacuate all 600 million", width/2, 280); text("people by the time the expanding sun contacts the earth", width/2, 300); text("or else you will lose. Good luck!", width/2, 320); text("Press 'E' to play Easy difficulty", width/2, 340); text("Press 'N' to play Normal difficulty", width/2, 360); text("Press 'H' to play Hard difficulty", width/2, 380); text("Press 'V' to play Very Hard difficulty", width/2, 400); text("(PLEASE NOTE THAT THE GAME WILL", width/2, 420); text("START IMMEDIATELY AFTER YOU PRESS 'E', 'N','H' or 'V'", width/2, 440); text("TO START)", width/2, 460); } if (gameMode == 3) { counter++; background(0); if (index_ship >= 0) { spaceships.get(index_ship).showShip = true; } for (int i = 0; i < spaceships.size (); i++) { if (spaceships.get(i).showShip == true) { spaceships.get(i).move(); spaceships.get(i).display(); } } drawPlanet(earth); drawPlanet(sun); doGravity(earth, sun); movePlanet(earth); movePlanet(sun); sun.r = sun.r + (6.4 /60.0); fill(0, 255, 0); textSize(12); textAlign(CENTER); text("Difficulty: Easy", width/2, 65); fill(0, 0, 255); textSize(18); textAlign(CENTER); if (counter%43== 0) { count=max(0, count-1); } text(count, 300, 100); fill(0, 255, 0); textSize(26); textAlign(CENTER); text(people, 300, 250); println(earth.x, earth.y); if (dist(earth.x, earth.y, sun.x, sun.y)<=earth.r+sun.r) { GameOver=true; textSize(30); textAlign(CENTER); fill(255, 0, 0); text("GAME OVER", 300, 300); if (people<=0) { textSize(36); text("YOU WIN", 300, 350); textSize(12); text("Press 'r' to restart", 300, 365); } else { text("YOU FAILED", 300, 350); textSize(12); text("Press 'r' to restart", 300, 365); } } } // end of game mode 3 if (gameMode == 4) { counter++; background(0); if (index_ship >= 0) { spaceships.get(index_ship).showShip = true; } for (int i = 0; i < spaceships.size (); i++) { if (spaceships.get(i).showShip == true) { spaceships.get(i).move(); spaceships.get(i).display(); } } drawPlanet(earth); drawPlanet(sun); doGravity(earth, sun); movePlanet(earth); movePlanet(sun); sun.r = sun.r + (6.5/60.0); fill(#F9FA0D); textSize(12); textAlign(CENTER); text("Difficulty: Normal", width/2, 65); fill(0, 0, 255); textSize(18); textAlign(CENTER); if (counter%43 == 0) { count=max(0, count-1); } text(count, 300, 100); fill(0, 255, 0); textSize(26); textAlign(CENTER); text(people, 300, 250); println(earth.x, earth.y); if (dist(earth.x, earth.y, sun.x, sun.y)<=earth.r+sun.r) { GameOver=true; textSize(30); textAlign(CENTER); fill(255, 0, 0); text("GAME OVER", 300, 300); if (people<=0) { textSize(36); text("YOU WIN", 300, 350); textSize(12); text("Press 'r' to restart", 300, 365); } else { text("YOU FAILED", 300, 350); textSize(12); text("Press 'r' to restart", 300, 365); } } } // end of game mode 4 if (gameMode == 5) { counter++; background(0); if (index_ship >= 0) { spaceships.get(index_ship).showShip = true; } for (int i = 0; i < spaceships.size (); i++) { if (spaceships.get(i).showShip == true) { spaceships.get(i).move(); spaceships.get(i).display(); } } drawPlanet(earth); drawPlanet(sun); doGravity(earth, sun); movePlanet(earth); movePlanet(sun); sun.r = sun.r + (6.5/60.0); fill(#FF7C00); textSize(12); textAlign(CENTER); text("Difficulty: Hard", width/2, 65); fill(0, 0, 255); textSize(18); textAlign(CENTER); if (counter%43 == 0) { count=max(0, count-1); } text(count, 300, 100); fill(0, 255, 0); textSize(26); textAlign(CENTER); text(people, 300, 250); println(earth.x, earth.y); if (dist(earth.x, earth.y, sun.x, sun.y)<=earth.r+sun.r) { GameOver=true; textSize(30); textAlign(CENTER); fill(255, 0, 0); text("GAME OVER", 300, 300); if (people<=0) { textSize(36); text("YOU WIN", 300, 350); textSize(12); text("Press 'r' to restart", 300, 365); } else { text("YOU FAILED", 300, 350); textSize(12); text("Press 'r' to restart", 300, 365); } } } if (gameMode == 6) { counter++; background(0); if (index_ship >= 0) { spaceships.get(index_ship).showShip = true; } for (int i = 0; i < spaceships.size (); i++) { if (spaceships.get(i).showShip == true) { spaceships.get(i).move(); spaceships.get(i).display(); } } drawPlanet(earth); drawPlanet(sun); doGravity(earth, sun); movePlanet(earth); movePlanet(sun); sun.r = sun.r + (6.5/60.0); fill(255, 0, 0); textSize(12); textAlign(CENTER); text("Difficulty: Very Hard", width/2, 65); fill(0, 0, 255); textSize(18); textAlign(CENTER); if (counter%43 == 0) { count=max(0, count-1); } text(count, 300, 100); fill(0, 255, 0); textSize(26); textAlign(CENTER); text(people, 300, 250); println(earth.x, earth.y); if (dist(earth.x, earth.y, sun.x, sun.y)<=earth.r+sun.r) { GameOver=true; textSize(30); textAlign(CENTER); fill(255, 0, 0); text("GAME OVER", 300, 300); if (people<=0) { textSize(36); text("YOU WIN", 300, 350); textSize(12); text("Press 'r' to restart", 300, 365); } else { text("YOU FAILED", 300, 350); textSize(12); text("Press 'r' to restart", 300, 365); } } } } void doGravity(Planet p1, Planet p2) { float d = dist(p1.x, p1.y, p2.x, p2.y); // first p second p float force = G * p1.mass * p2.mass / (d * d); float dx = p1.x - p2.x; float dy = p1.y - p2.y; float accel1 = force / p1.mass; float accel2 = force / p2.mass; p1.vx -= accel1 * dx / d; p1.vy -= accel1 * dy / d; p2.vx += accel2 * dx / d; p2.vy += accel2 * dy / d; println(d); } void movePlanet(Planet p) { p.x += p.vx; p.y += p.vy; } void drawPlanet(Planet p) { fill(p.c); ellipse(p.x, p.y, p.r * 2, p.r * 2); } void calculateCountdown() { count = 29.0-(frameCount/60.0); } void keyPressed() { if (gameMode == 0 && key == ' ') { gameMode =2; } else if ( gameMode == 2 && (key == 'e' || key == 'e')) { gameMode = 3; } if ( gameMode == 2 && (key == 'n' || key == 'N')) { gameMode = 4; } if ( gameMode == 2 && (key == 'h' || key == 'H')) { gameMode = 5; } if ( gameMode == 2 && (key == 'v' || key =='V')) { gameMode = 6; } if (gameMode == 3 && key == ' ') { if (index_ship < spaceships.size()-1 && LaunchPermission && !GameOver) { index_ship++; people=max(0, people-4100000); LaunchPermission = false; } } if (gameMode == 4 && key == ' ') { if (index_ship < spaceships.size()-1 && LaunchPermission && !GameOver) { index_ship++; people=max(0, people-3890000); LaunchPermission = false; } } if (gameMode == 5 && key == ' ') { if (index_ship < spaceships.size()-1 && LaunchPermission && !GameOver) { index_ship++; people=max(0, people-3780000); LaunchPermission = false; } } if (gameMode == 6 && key == ' ') { if (index_ship < spaceships.size()-1 && LaunchPermission && !GameOver) { index_ship++; people=max(0, people-3775000); LaunchPermission = false; } } if (gameMode == 3 && GameOver == true && key == 'r') { //resetting everything gameMode = 3; counter = 0; count = 28; people = 600000000; sun.r = 100; index_ship = -1; GameOver = false; spaceships = new ArrayList<Spaceship>(); for (int i = 0; i<260; i++) { Spaceship temp = new Spaceship(); spaceships.set(i, temp); } } if (gameMode == 4 && GameOver == true && key == 'r') { //resetting everything gameMode = 4; counter = 0; count = 28; people = 600000000; sun.r = 100; index_ship = -1; GameOver = false; // spaceships = new ArrayList<Spaceship>(); for (int i = 0; i<260; i++) { Spaceship temp = new Spaceship(); spaceships.set(i, temp); } } if (gameMode == 5 && GameOver == true && key == 'r') { //resetting everything gameMode = 4; counter = 0; count = 28; people = 600000000; sun.r = 100; index_ship = -1; GameOver = false; // spaceships = new ArrayList<Spaceship>(); for (int i = 0; i<260; i++) { Spaceship temp = new Spaceship(); spaceships.set(i, temp); } } if (gameMode == 6 && GameOver == true && key == 'r') { //resetting everything gameMode = 4; counter = 0; count = 28; people = 600000000; sun.r = 100; index_ship = -1; GameOver = false; // spaceships = new ArrayList<Spaceship>(); for (int i = 0; i<260; i++) { Spaceship temp = new Spaceship(); spaceships.set(i, temp); } } } void keyReleased() { if (key == ' ') { LaunchPermission = true; } }