A 2D platformer game where you are a red box.
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#330' allowfullscreen></iframe>
float shifty = 0, shiftyspeed = 2, x, y, w=20, h = 20, vx, vy, gravity = 0.3;// the varibles boolean left, right, up, down, dead = true; float platdefw = 50, platdefh = 20;// width and the height of the platform int score = 0, highscore=-1; float p, u; class Platform {// class for the platform is your own varible type float x, y, w = platdefw, h = platdefh; Platform(float x, float y) { this.x = x; this.y = y; } void display() {//displys the rectangle rect(x, y, w, h); } //returntype functionname( inputtype inputnname, inputtype inputname) boolean collide(float px, float py, float pw, float ph) { //abs(-3) is 3. abs stands for absolute value. //funcation that return abs(x-px) < (pw + w)/2 && abs(y-py) < (ph+h)/2; } } ArrayList<Platform> platforms = new ArrayList<Platform>(); class Powerup { float p, u; Powerup(float p, float u) { this.p = p; this.u = u; } void asdf() { fill(255, 100, 0); strokeWeight(1); ellipse(p, u, 40, 40); } } ArrayList<Powerup> powerups = new ArrayList<Powerup>(); void setup() { size(600, 600); rectMode(CENTER); for (int i = 0; i < 4; i++) { p = random(20, 540); u = random(20, 540); powerups.add(new Powerup(p, u)); } } void draw() { if (key=='`') { y = 0- shifty; vy = 0; } if (dead) { powerups.clear(); //the start screen highscore=max(highscore, score);//if score is bigger than highscore, then the score becomes the highscore. gravity = 0.3; background(0, 0, 255); fill(0); textAlign(CENTER); textSize(30); text("Click to start", 250, 250); if (score>0) { text("Previous Score: "+score, 250, 300); text("High Score: "+highscore, 250, 350); } if (mousePressed) { score= 0; // the powerups are created dead = false; if (powerups.size()==0) { for (int i = 0; i < 4; i++) { p = random(20, 540); u = random(20, 540); powerups.add(new Powerup(p, u)); } } } //if all powerups are gone, then make new ones, super gravity only exists for 5 seconds shiftyspeed=2; shifty = y = vx = vy = 0; platforms.clear(); for (int i = 0; i < 10; i++) { x = random(0, width); platforms.add(new Platform(x, i*30)); } } else { //the game screen background(255); for (int i = 0; i < powerups.size (); i++) { powerups.get(i).asdf(); } fill(0); pushMatrix(); translate(0, shifty); //shift everything down by shifty float tallest = height, tallestx = random(0, width); for (int i = 0; i < platforms.size (); i++) { //loop through each platform Platform p = platforms.get(i); //get the platform if (tallest > p.y) { //calculate where the highest platform is tallest = p.y;// tallest tallestx = p.x; } p.display(); //draw the platform if (p.y > height-shifty) platforms.remove(i--); //if the platform is off the bottom, remove it } if (tallest+shifty > 50) { //if the tallest platform near the top, is 50 from the top float newx = tallestx + random(-200, 200); //calculate a random x value that is close to that tallest if (newx < 0) newx = 0; if (newx > width) newx = width; platforms.add(new Platform(newx, -shifty)); //add a new platform } for (int i = 0; i < powerups.size (); i++) { Powerup p = powerups.get(i); if (dist(x, shifty+y, p.p, p.u) < 30) { powerups.remove(i); i--; //if you get a powerup, youre score increases by 10 and changes the gravity score = score + 10; gravity = 0.2; int briefCount = 0; if (frameRate%60==0) { briefCount++; if (briefCount >5) { gravity = 0.3; } } } //if I am touching the powerup // if (p.collide(x, y, w, h) } //draw our dudes fill(255, 0, 0); rect(x, y, w, h); x+=vx; //move our dude according to vx, vy y+=vy; vy+=gravity; vx = 0; if (left) vx += -5; else if (right) vx += 5; boolean onPlatform = false; for (Platform p : platforms) { //for every platform if (p.collide(x, y, w, h) && y < p.y && vy > 0) { //if you're touching the platform and you're moving down vy = 0; onPlatform = true; } } if (onPlatform && up) vy = -10; //you can jump when on a platform shifty += shiftyspeed; //moves everything down popMatrix(); if (y > height- shifty) dead = true; //if you fall off the bottom, you die fill(0); text("Score: " + score, 100, 400); if (frameCount%60==0) { score = score + 1;//score // gravity = gravity + 0.005;//how fast the charecter moves down shiftyspeed+=0.01;//makes the screen move faster every second } } } void keyPressed() { if (key==CODED && keyCode==UP) up = true; if (key==CODED && keyCode==DOWN) down = true; if (key==CODED && keyCode==LEFT) left = true; if (key==CODED && keyCode==RIGHT) right = true; } void keyReleased() { if (key==CODED && keyCode==UP) up = false; if (key==CODED && keyCode==DOWN) down = false; if (key==CODED && keyCode==LEFT) left = false; if (key==CODED && keyCode==RIGHT) right = false; }