Use the arrow keys to move Omnom. Help him eat junk food and don't let him near anything healthy! Try to beat the highscore.
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#1581' allowfullscreen></iframe>
class Food { boolean isJunk; PImage img; int x, y; Food(PImage image, int x, int y, boolean isJunk) { this.img = image; this.x = x; this.y = y; this.isJunk = isJunk; } } ArrayList<Food> allFood = new ArrayList<Food>(); PImage omNom; PImage taco; PImage hotdog; PImage donuts; PImage cupcake; PImage iceCream; PImage pizza; PImage mushroom; PImage broccoli ; PImage tomato; PImage playButton; PImage bg; PImage check; PImage xxx; PImage startDonut; PImage startTaco; PImage startCupcake; PImage startPizza; PImage startMushroom; PImage startTomato; PImage startBroccoli; PImage [] junkFood; PImage [] vegetables; int score; int highscore; float ySpeed; int state; boolean faster = false; void setup () { size(1200, 650); textAlign(CENTER); omNom = loadImage ("http://img06.deviantart.net/54b3/i/2011/003/9/c/omnom_wanna_eat_by_earnurm-d36bbty.png"); taco = loadImage ("http://www.clipartlord.com/wp-content/uploads/2012/10/taco.png"); hotdog = loadImage ("http://fc06.deviantart.net/fs7/i/2005/200/e/7/Hotdog_by_Loar5.gif"); donuts = loadImage ("http://media.giphy.com/media/HulIKdFlIz4Ws/giphy.gif"); cupcake = loadImage ("http://www.clipartlord.com/wp-content/uploads/2014/02/cupcake10.png"); iceCream = loadImage ("http://www.pd4pic.com/images/food-menu-silhouette-cartoon-free-soft-ice-cream.png"); pizza = loadImage ("http://www.clipartbest.com/cliparts/xig/jg8/xigjg8riA.png"); mushroom = loadImage ("http://www.pd4pic.com/images/food-mushroom-cartoon-little-salad-plant.png"); broccoli = loadImage ("http://www.clipartlord.com/wp-content/uploads/2013/03/broccoli.png"); tomato = loadImage ("http://www.clipartlord.com/wp-content/uploads/2014/06/tomato11.png"); playButton = loadImage ("http://myths.e2bn.org/images/play_button.gif"); bg = loadImage("http://penangmedia.com/wp-content/uploads/2015/05/light_green_background_21.jpg"); check = loadImage ("http://www.i2clipart.com/cliparts/d/3/c/e/clipart-green-checkmark-and-red-minus-d3ce.png"); xxx = loadImage ("http://images.clipshrine.com/getimg/PngThumb-Wrong-sign-3303.png"); startDonut = loadImage ("http://icons.iconarchive.com/icons/pixelkit/tasty-bites/128/donuts-icon.png"); startTaco = loadImage ("http://www.i2clipart.com/cliparts/9/3/4/c/clipart-taco-934c.png"); startCupcake = loadImage ("https://cdn0.iconfinder.com/data/icons/ie_yummy/128/cake_15.png"); startPizza = loadImage ("http://preloaders.net/preloaders/327/colored/5.png"); startMushroom = loadImage ("http://png-3.findicons.com/files/icons/1187/pickin_time/128/mushroom.png"); startTomato = loadImage ("http://www.i2clipart.com/cliparts/4/a/f/1/clipart-tomato-4af1.png"); startBroccoli = loadImage ("http://png-1.findicons.com/files/icons/1187/pickin_time/128/broccoli.png"); junkFood = new PImage [] { taco, hotdog, donuts, cupcake, iceCream, pizza }; vegetables = new PImage [] { mushroom, broccoli, tomato }; omNomY = height - 100; omNomX = width/2; imageMode(CENTER); for (int i=0; i<8; i++) { newFood(); } score = 0; ySpeed = 10; state = 0; state = 0; } void newFood() { Food someFood; if (random(0, 100) < 25) { int index = (int) random(0, 3); someFood = new Food (vegetables[index], 0, 0, false); } else { int index = (int) random (0, 6); someFood = new Food (junkFood[index], 0, 0, true); } someFood.x = (int)random(0, width - 50); someFood.y = (int)random(-height + 50, 0); allFood.add(someFood); } void checkCollisions () { Food food; for (int i=0; i<allFood.size (); i++) { food = allFood.get(i); if (dist(food.x, food.y, omNomX, omNomY) < 80) { if (food.isJunk) { score++; } else { state = 2; } allFood.remove(i); newFood(); } } } void gameOver () { if (score > highscore) { highscore = score; score = 0; } // PrintWriter highfile = createWriter("highscore.txt"); // highfile = createWriter("highscore.txt"); // highfile.println(highscore); for (int m = 0; m < allFood.size (); m++) { allFood.get(m); Food f = allFood.get(m); image (f.img, f.x, f.y, 100, 100); f.y += ySpeed; if (f.y > height) { allFood.remove(m); newFood(); } } ySpeed *= 0.9; PFont font = createFont("fatfont", 80); textFont(font); fill(104, 211, 47); textAlign(CENTER); text("GAME OVER", width/2, 275); PFont font2 = createFont("fatfont", 40); textFont(font2); text("Press the space key to try again", width/2, 475); } void mousePressed() { if (state == 0 && mouseX > (590 - playButton.width/2) && mouseX < (590 + playButton.width/2) && mouseY > (460 - playButton.height/2) && mouseY < (460 + playButton.height/2)) { state = 1; } } void instructions () { PFont font = createFont("fatfont", 30); image(bg, bg.width/2, bg.height/2); ySpeed = 10; textFont(font); fill(0); textAlign(CENTER); text("Om Nom is very hungry, but he only eats junk food!", width/2, 250 ); text("If he eats healthy food, he will die.", width/2, 300); text("Try to beat the highscore!", width/2, 350); text("Use the arrow keys to move", width/2, 400); PFont font3 = createFont("bubble man", 160); textFont(font3); fill(0); text("OMN M", width/2-30, 155); image(playButton, 590, 460); image(omNom, 680, 90); image(check, 150, 78); image(xxx, 1050, 80); image(startDonut, 140, 190); image(startTaco, 140, 299); image(startCupcake, 140, 408); image(startPizza, 140, 540); image(startMushroom, 1050, 200); image(startBroccoli, 1055, 360); image(startTomato, 1057, 520); } void displayScore () { textAlign(LEFT); PFont font = createFont("Georgia", 20); textFont(font); fill(0); text("Score: " + score, 50, 50); text("Highscore: " + highscore, 50, 100); textAling(CENTER); } void draw () { background (201, 255, 231); rectMode(CENTER); moveOmNom(); if (state == 0) { instructions(); } else if (state == 1) { if (score % 10 == 0 && faster) { ySpeed += 1; faster = false; } if (score % 10 == 1) { faster = true; } for (int m = 0; m < allFood.size (); m++) { allFood.get(m); Food f = allFood.get(m); image (f.img, f.x, f.y, 100, 100); f.y += ySpeed; if (f.y > height) { allFood.remove(m); newFood(); } } textAlign(LEFT); checkCollisions(); } else if (state == 2) { gameOver(); } } int omNomX; int omNomY; boolean up, down, left, right; void moveOmNom () { if (state != 0) { image (omNom, omNomX, omNomY ); displayScore(); } if (state == 1) { int speed = 20; if (up && omNomY - omNom.height / 2 > 0) { omNomY -= speed; } if (down && omNomY + omNom.height/2 < height ) { omNomY += speed; } if (left) { omNomX -= speed; if (omNomX < 0 - omNom.width) { omNomX = width; } } if (right) { omNomX += speed; if (omNomX > width) { omNomX = 0 - omNom.width; } } } } void keyPressed() { if (key == ' ' && state == 2) { state = 0; omNomY = height - 100; omNomX = width/2; ySpeed = 0; faster = false; } if (keyCode == UP) up = true; else if (keyCode == RIGHT) right = true; else if (keyCode == LEFT) left = true; else if (keyCode == DOWN) down = true; } void keyReleased() { if (keyCode == UP) up = false; else if (keyCode == RIGHT) right = false; else if (keyCode == LEFT) left = false; else if (keyCode == DOWN) down = false; }