No description provided
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#594531' allowfullscreen></iframe>
//GLOBAL VARIABLES int fuel = 200; int fuelDown = 0; int numOfTanks = 0; KTAudioController ktAudio; KTSound clickEffect; SoundCipher shoot = new SoundCipher(this); boolean machineGunOn = false; int changeSpeed = 0; int hardness = 1; ArrayList<Sprite> shots = new ArrayList<Sprite>(); ArrayList<Sprite> toRemove = new ArrayList<Sprite>(); Sprite heart1 = new Sprite("https://cdn.pixabay.com/photo/2017/09/23/16/33/pixel-heart-2779422_1280.png", 20, 580, 40, 40); Sprite heart2 = new Sprite("https://cdn.pixabay.com/photo/2017/09/23/16/33/pixel-heart-2779422_1280.png", 60, 580, 40, 40); Sprite heart3 = new Sprite("https://cdn.pixabay.com/photo/2017/09/23/16/33/pixel-heart-2779422_1280.png", 100, 580, 40, 40); int hearts = 3; int lives = 3; int freeze = 1; boolean touched = false; boolean gameover = false; String ship = "https://opengameart.org/sites/default/files/Pirate%20Ship%20%28Idle%29%20PREVIEW.png"; String helicopter = "https://img.devrant.com/devrant/rant/r_4011882_Md69F.gif"; String jet = "https://dejpknyizje2n.cloudfront.net/marketplace/products/ee14124b83e84b7682ea81b0665669f8.png"; String tank = "https://cdn-icons-png.flaticon.com/512/190/190043.png?w=360"; String heart = "https://cdn.pixabay.com/photo/2017/09/23/16/33/pixel-heart-2779422_1280.png"; boolean movingRight = false; boolean movingLeft = false; boolean shooting = false; Sprite player = new Sprite("https://images-na.ssl-images-amazon.com/images/I/21JE0t02ZBL.png", 300, 480, 40, 40); /* Sprite bullet = new Sprite("http://pixelartmaker-data-78746291193.nyc3.digitaloceanspaces.com/image/874fa0e5bf7b854.png", 200, 200, 40, 40); Sprite bullet2 = new Sprite("https://res.cloudinary.com/mirukusheku/image/upload/v1495140035/Red_laser-ConvertImage_votu8o.png", 300, 300, 40, 40); Sprite ship = new Sprite("https://opengameart.org/sites/default/files/Pirate%20Ship%20%28Idle%29%20PREVIEW.png", 300, -10, 45, 45); Sprite helicopter = new Sprite("https://img.devrant.com/devrant/rant/r_4011882_Md69F.gif", 300, -10, 35, 35); */ Sprite[] ships = new Sprite[15]; Sprite[] helicopters = new Sprite[15]; //making enemies class class Enemies { String URL; Sprite pic; int x; int y; int d; Enemies(String URL, int x, int y, int d) { this.x = x; this.y = y; this.URL = URL; this.pic = new Sprite(URL, x, y, 60, 45); this.d = d; } /* Two options for creating a constructor: - Create a function to create an instance Enemies makeEnemy(String URL, boolean onScreen) { this.URL = URL; this.onScreen = onScreen; return this; } - Use implicit constructor to create an instance Enemies(String URL, boolean onScreen) { this.URL = URL; this.onScreen = onScreen; } */ } class Bullet{ int x; int y; String URL = "http://pixelartmaker-data-78746291193.nyc3.digitaloceanspaces.com/image/874fa0e5bf7b854.png"; Sprite s; Bullet(int x, int y){ this.x = x; this.y = y; s = new Sprite(URL, x, y, 40, 40); } void move(){ s.moveY(-10); } } Enemies[] enemy = new Enemies[9]; Sprite[] tanks = new Sprite[5]; void setup() { textSize(15); size(600, 600); rectMode(CORNERS); ktAudio = new KTAudioController(this); clickEffect = new KTSound(this, "http://www.noiseaddicts.com/samples_1w72b820/3731.mp3"); ktAudio.add(clickEffect); //Filling in enemies array for (int i = 0; i < enemy.length; i++) { String vehicle; int x = (int)random(1, 4); if(x != 1 && x!= 2){ numOfTanks++; } if(numOfTanks > 2){ x = (int)random(1, 3); } if(x == 1){ vehicle = ship; }else if(x == 2){ vehicle = helicopter; }else{ vehicle = tank; } enemy[i] = new Enemies(vehicle, (int) random(90, 510), (int) random( - 800, -50), 1); } } void draw() { screen(); hearts(); enemies(); fuelBar(); playerControl(); player.display(); collisionDetection(); freeze(); managingShots(); gameOver(); } void screen() { noStroke(); background(0, 0, 225); fill(30, 120, 20); rect(0, 0, 50, 600); rect(550, 0, 600, 600); } void enemies() { for (int i = 0; i < enemy.length; i++) { enemy[i].pic.moveY(2 * freeze + changeSpeed); enemy[i].pic.moveX(enemy[i].d * 1.5 * freeze); if (enemy[i].pic.getY() > 650) { enemy[i].pic.setY((int) random( - 100, -300)); enemy[i].pic.setX((int)random(90 , 550)); } if (enemy[i].pic.getX() > 510) { enemy[i].d = -1; } if (enemy[i].pic.getX() < 90) { enemy[i].d = 1; } enemy[i].pic.display(); } } void fuelBar() { noFill(); stroke(225, 225, 225); rect(200, 560, 400, 580); fuelDown++; if (fuelDown == 60) { fuelDown = 0; if (fuel > 0) { fuel = fuel - 10; } } fill(225, 225, 225); rect(200, 560, fuel + 200, 580); fill(0); textSize(20); text(fuel, 290, 575); text("FUEL:", 280, 550); if(fuel <= 0){ player.setX(300); touched = true; if(lives == 1){ gameover = true; }else{ lives--; fuel = 200; } } } int c = 0; void collisionDetection(){ for(int i = 0;i < enemy.length;i++){ if(player.touchingSprite(enemy[i].pic)){ if(enemy[i].URL == "https://cdn-icons-png.flaticon.com/512/190/190043.png?w=360"){ enemy[i].pic.setY((int)random(-800, -1200)); fuel = 200; }else{ player.setX(300); enemy[i].pic.setY(-100); touched = true; if(lives == 1){ gameover = true; }else{ lives--; fuel = 200; } } } } } void freeze(){ if(touched){ freeze = 0; c++; fill(200, 0, 0); textSize(60); text("You Lost 1 Life", 100, 300); if(c == 120){ c = 0; freeze = 1; touched = false; } } } void hearts(){ if(lives == 3){ heart3.display(); } if(lives >= 2){ heart2.display(); } if(lives >= 1){ heart1.display(); } } void gameOver(){ if(gameover){ background(0, 0, 0); fill(0, 150, 0); textSize(50); text("GAME OVER", 300, 300); freeze = 0; } } void playerControl() { if (movingRight && player.getX() < 525) { player.moveX(6.5); } if (movingLeft && player.getX() > 75) { player.moveX( - 6.5); } } void managingShots(){ for(int i = 0;i < shots.size();i++){ Sprite s = shots.get(i); s.display(); s.moveY(-10); if(!s.isInsideScreen()){ toRemove.add(s); } for(int j = 0;j < enemy.length;j++){ if(enemy[j].pic.touchingSprite(s)){ enemy[j].pic.setY((int)random(-300, -600)); toRemove.add(s); shots.removeAll(toRemove); } } } } void keyPressed() { if (keyCode == RIGHT) { movingRight = true; } if (keyCode == LEFT) { movingLeft = true; } if(keyCode == UP){ changeSpeed = 1; } if(keyCode == DOWN){ changeSpeed = -1; } if(key == ' '){ clickEffect.play(); Sprite clone = new Sprite("http://pixelartmaker-data-78746291193.nyc3.digitaloceanspaces.com/image/874fa0e5bf7b854.png", player.getX(), player.getY(), 40, 40); shots.add(clone); } } void keyReleased() { if (keyCode == RIGHT) { movingRight = false; } if (keyCode == LEFT) { movingLeft = false; } if(key == ' '){ shooting = false; } if(keyCode == UP){ changeSpeed = 0; } if(keyCode == DOWN){ changeSpeed = 0; } }