View Game: ApoBalloon4k

ApoBalloon4k (http://www.apo-games.de/apoBalloon4k/)

By ApoGames, submitted on Dec 2, 2012
Min JRE version: 1.6
2569 downloads.
This game was submitted in the Java4K 2013 Competition.
Source code available! Show source code

(Click on game for focus)

Sorry, your Browser doesn't support Applets
You need Java installed to play this game.
You may use the button below to get it.

Get Java


Description

You are a sky ninja and you have one goal.
Your heaven is YOUR heaven, so destroy the balloons of the other ninjas and don't fall down.

Instructions

Play with the keyboard.

Key up: Jump
Key right: move right
Key left: move left

Enter: start the game

User Comments

Total 1 comments:

#1 By Sri Harsha Chilakapati Jan 8, 2013 at 11:56:04
Nice Graphics!

You need be logged in to write comments. If you need to register click here.

Source code

Note: We recommend you copy+paste this to a better editor. Some special character encoding may have been lost.

* All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ import java.applet.Applet; import java.awt.Event; import java.awt.Color; import java.awt.GradientPaint; import java.awt.Graphics2D; import java.awt.Paint; import java.awt.RenderingHints; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; /** * Balloongame. Jump and don't fall off the screen * @author Dirk Aporius * */ public class P extends Applet implements Runnable { private static final Color[] colors = new Color[] { Color.RED, Color.GREEN, Color.YELLOW, Color.CYAN, Color.LIGHT_GRAY, Color.MAGENTA, Color.ORANGE, Color.PINK }; /* * 0 = points * 1 = Player jump * 2 = Player right * 3 = Player left * 4 = should start * 5 = game started * 6 = lives */ private final float[] values = new float[7]; public void start() { new Thread(this).start(); } public void run() { // setSize(640, 480); // For AppletViewer, remove later. // Set up the graphics stuff, double-buffering. BufferedImage screen = new BufferedImage(480,480,BufferedImage.TYPE_INT_RGB); Graphics2D g = screen.createGraphics(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Graphics2D appletGraphics = (Graphics2D)getGraphics(); // Some variables to use for the fps. long lastTime = System.nanoTime(); long think = lastTime; /** * 0 = player x value * 1 = player y value * 2 = player vec x * 3 = player vec y * 4 = player is on balloon [number of balloon] * * max 20 balloon * 5 = balloon x value * 6 = balloon y value * 7 = balloon vec x * 8 = balloon vec y * 9 = which balloon (color) * 10 = balloon duration (if <= 0 balloon pop) * 11 = enemy on balloon (color) * * enemy on a balloon who is throwing little bombs that will explode after x time * 145 = enemy x value * 146 = enemy y value * 147 = enemy vec x * 148 = enemy show next time * * max 4 bombs * 149 = bomb x value * 150 = bomb y value * 151 = time to explode * 152 = bomb vec y * * 165 = x-Value pop * 166 = y-Value pop * 167 = time pop * 168 = color */ float[] entities = new float[169]; int curBalloons = 0; int maxBalloons = 17; int colorChangeWhileHit = 0; int curEnemies = 0; int curBombs = 0; // Game loop. while (true) { long now = System.nanoTime(); long delta = now - lastTime; think += delta; // Update / think while (think >= 10000000L) { think -= 10000000L; if (colorChangeWhileHit > 0) { colorChangeWhileHit -= 10; } if (this.values[5] == 0) { if (this.values[4] > 0) { entities = new float[169]; entities[5] = entities[6] = entities[1] = entities[0] = 240; entities[8] = -0.4f; this.values[6] = entities[9] = entities[10] = 3; this.values[5] = curBalloons = 1; this.values[0] = curEnemies = curBombs = 0; maxBalloons = 17; entities[148] = (int)(25000 + Math.random() * 5000); } } else { if (this.values[4] <= 0) { this.values[5] = 0; break; } if (entities[167] > 0) { entities[167] -= 10; } if (entities[148] > 0) { entities[148] -= 10; if (entities[148] <= 0) { entities[145] = -60; entities[146] = 10; } } else { entities[145] += 0.2f; if ((Math.random() < 0.005) && (curBombs < 1)) { curBombs += 1; if (entities[149+2] <= 0) { entities[149] = entities[145] + 25; entities[149+1] = entities[146]; entities[149+2] = (float)(Math.random() * 1000) + 1000; entities[149+3] = 0; break; } } if (entities[145] > 490) { entities[148] = (int)(5000 + Math.random() * 10000); } } while (curBalloons < maxBalloons) { for (int i = 5; i < 145; i += 7) { if (entities[i+5] <= 0) { entities[i] = (int)(Math.random() * 440) + 10; entities[i + 1] = 510; entities[i + 3] = (float)(Math.random() * 0.4) - 0.7f; entities[i + 4] = (int)(Math.random() * colors.length) + 1; entities[i + 5] = 2; entities[i + 2] = entities[i + 6] = 0; if ((curEnemies == 0) || ((curEnemies < 5) && (this.values[0] + Math.random() * 6000 > 5000))) { if (Math.random() < 0.3d) { entities[i + 6] = (int)(Math.random() * 8 + 1); curEnemies += 1; } } break; } } curBalloons += 1; } int oldScore = (int)(this.values[0]); // if player is on a balloon if (entities[4] >= 0) { this.values[0] += 0.1f; } else { this.values[0] += 0.2f; } if (oldScore / 500 < (int)(this.values[0]/500)) { maxBalloons -= 1; if (maxBalloons < 8) { maxBalloons = 8; } } if (entities[149+2] > 0) { entities[149+1] += entities[149+3]; entities[149+3] += 0.02f; entities[149+2] -= 10; if (entities[149+2] <= 0) { curBombs -= 1; for (int j = 5; j < 145; j += 7) { if (entities[j+5] > 0) { float sum = (entities[149] - entities[j+0]) * (entities[149] - entities[j+0]) + (entities[149+1] - entities[j+1]) * (entities[149+1] - entities[j+1]); if (sum <= 10000) { entities[j+2] = 0.9f * (10000 - (sum)) / 10000; if (entities[j] < entities[149]) { entities[j+2] = -entities[j+2]; } } } } } } // if player is on a balloon if (entities[4] >= 0) { if (values[1] > 0) { values[1] = 0; entities[3] = -1.7f; entities[5 + 5 + (int)(entities[4]) * 7] -= 1; if (entities[5 + 6 + (int)(entities[4]) * 7] > 0) { entities[5 + 5 + (int)(entities[4]) * 7] = 0; values[0] += 100; curEnemies -= 1; } if (entities[5 + 5 + (int)(entities[4]) * 7] <= 0) { curBalloons -= 1; entities[165] = entities[5 + (int)(entities[4]) * 7]; entities[166] = entities[6 + (int)(entities[4]) * 7] - 13; entities[167] = 500; entities[168] = entities[9 + (int)(entities[4]) * 7]; for (int i = 5; i < 145; i += 7) { if (entities[i+5] > 0) { float sum = (entities[5 + (int)(entities[4]) * 7] - entities[i+0]) * (entities[5 + (int)(entities[4]) * 7] - entities[i+0]) + (entities[6 + (int)(entities[4]) * 7] - entities[i+1]) * (entities[6 + (int)(entities[4]) * 7] - entities[i+1]); if (sum <= 8100) { entities[i+2] = 0.9f * (8100 - (sum)) / 8100; if (entities[i] < entities[5 + (int)(entities[4]) * 7]) { entities[i+2] = -entities[i+2]; } } } } } entities[1] = entities[5 + 1 + (int)(entities[4]) * 7] - 25; entities[4] = -1; } else { if (this.values[2] > 0) { entities[0] += 0.25; entities[5 + (int)(entities[4]) * 7] += 0.25f; if (entities[0] > 480) { entities[0] -= 0.25f; entities[5 + (int)(entities[4]) * 7] -= 0.25f; } } else if (this.values[3] > 0) { entities[0] -= 0.25f; entities[5 + (int)(entities[4]) * 7] -= 0.25f; if (entities[0] < 0) { entities[0] += 0.25f; entities[5 + (int)(entities[4]) * 7] += 0.25f; } } entities[6 + (int)(entities[4]) * 7] += 0.4f; entities[1] += 0.4f; } } else { if (this.values[2] > 0) { entities[0] += 0.8f; } else if (this.values[3] > 0) { entities[0] -= 0.8f; } if (entities[0] < 0) { entities[0] = 0; } else if (entities[0] + 24 >= 480) { entities[0] = 456; } entities[3] += 0.017f; entities[1] += entities[3]; for (int i = 5; i < 145; i += 7) { if (entities[i+5] > 0) { if (new Rectangle2D.Float(entities[0], entities[1] + 15, 24, 2).intersects(entities[i], entities[i+1] + 7, 2, 28)) { entities[4] = (i-5)/7; } } } } for (int i = 5; i < 145; i += 7) { if (entities[i+5] > 0) { if (entities[4] != (i-5)/7) { entities[i+1] += entities[i+3]; entities[i] += entities[i+2]; if (entities[i] < 15) { entities[i] = 15; } else if (entities[i] > 465) { entities[i] = 465; } if (entities[i+2] < 0) { entities[i+2] += 0.003f; if (entities[i+2] >= 0) { entities[i+2] = 0; } } else if (entities[i+2] > 0) { entities[i+2] -= 0.003f; if (entities[i+2] <= 0) { entities[i+2] = 0; } } if (entities[i+1] < -35) { if (entities[i+6] > 0) { colorChangeWhileHit = 100; values[6] -= 1; curEnemies -= 1; } entities[i+5] = 0; curBalloons -= 1; } } } } if ((entities[1] > 480) || (values[6] <= 0)) { values[4] = 0; } } } lastTime = now; // Render Paint paint = g.getPaint(); if (values[5] <= 0) { g.setColor(Color.WHITE); g.setPaint(new GradientPaint(240, 0, new Color(140, 190, 230), 240, 480, new Color(160, 225, 254))); g.fillRect(0, 0, 480, 480); g.setPaint(paint); g.setColor(Color.BLACK); g.setFont(g.getFont().deriveFont(50f).deriveFont(1)); String s = "ApoBalloon4k"; int w = g.getFontMetrics().stringWidth(s); g.drawString(s, 240 - w/2, 255); s = "ApoBall"; int w2 = g.getFontMetrics().stringWidth(s); s = "o"; int w3 = g.getFontMetrics().stringWidth(s); g.setColor(Color.RED); g.fillOval(240 - w/2 + w2, 225, 30, 40); g.fillOval(240 - w/2 + w2 + w3, 225, 30, 40); g.setColor(Color.BLACK); g.drawOval(240 - w/2 + w2, 225, 30, 40); g.drawOval(240 - w/2 + w2 + w3, 225, 30, 40); g.fillRect(240 - w/2 + w2 + 14, 265, 3, 45); g.fillRect(240 - w/2 + w2 + w3 + 14, 265, 3, 45); g.setFont(g.getFont().deriveFont(20f).deriveFont(1)); s = "Press Enter to start the game"; w = g.getFontMetrics().stringWidth(s); g.drawString(s, 240 - w/2, 475); s = "Play with the cursor keys"; w = g.getFontMetrics().stringWidth(s); g.drawString(s, 240 - w/2, 450); s = "The enemy ninjas must not reach the sky!"; w = g.getFontMetrics().stringWidth(s); g.drawString(s, 240 - w/2, 330); s = "And you please don't fall down!"; w = g.getFontMetrics().stringWidth(s); g.drawString(s, 240 - w/2, 360); if (this.values[0] > 0) { g.setFont(g.getFont().deriveFont(50f).deriveFont(1)); s = "Points: "+String.valueOf((int)this.values[0]); w = g.getFontMetrics().stringWidth(s); g.setColor(Color.WHITE); g.fillRoundRect(240 - w/2 - 10, 75, w + 20, 55, 7, 7); g.setColor(Color.BLACK); g.drawRoundRect(240 - w/2 - 10, 75, w + 20, 55, 7, 7); g.drawString(s, 240 - w/2, 120); } } else { if (colorChangeWhileHit > 0) { g.setColor(new Color(255, 128, 128)); } else { g.setPaint(new GradientPaint(240, 0, new Color(140, 190, 230), 240, 480, new Color(160, 225, 254))); } g.fillRect(0, 0, 480, 480); g.setPaint(paint); g.setFont(g.getFont().deriveFont(20f).deriveFont(1)); String s = "Points: "+String.valueOf((int)this.values[0]); int w = 120; g.setColor(Color.WHITE); g.fillRoundRect(-5, -5, w + 15, 35, 8, 8); g.setColor(Color.BLACK); g.drawRoundRect(-5, -5, w + 15, 35, 8, 8); g.drawString(s, 5, 25); s = "Lives: "+String.valueOf((int)this.values[6]); w = 90; g.setColor(Color.WHITE); g.fillRoundRect(390, -5, w + 15, 35, 8, 8); g.setColor(Color.BLACK); g.drawRoundRect(390, -5, w + 15, 35, 8, 8); g.drawString(s, 395, 25); for (int i = 5; i < 145; i += 7) { if (entities[i+5] > 0) { g.setColor(colors[(int)(entities[i+4] - 1)]); g.fillOval((int)(entities[i] - 10), (int)(entities[i+1] - 27), 20, 27); g.setColor(Color.BLACK); // if player is on a balloon if (entities[4] == (i-5)/7) { g.setColor(Color.WHITE); } g.drawOval((int)(entities[i] - 10), (int)(entities[i+1] - 27), 19, 26); g.fillRect((int)(entities[i]), (int)(entities[i+1]), 2, 35); } } for (int i = 5; i < 145; i += 7) { for (int j = 0; j < 3; j++) { if ((i != 5) && (j > 0)) { break; } if (j == 0) { if ((entities[i+5] <= 0) || ((int)(entities[i+6]) <= 0)) { continue; } } if (j == 2) { if (entities[148] > 0) { break; } } int x = (int)(entities[0]); int y = (int)(entities[1]); if (j == 0) { x = (int)(entities[i]) - 12; y = (int)(entities[i+1]); } else if (j == 2) { x = (int)(entities[145]) + 12; y = (int)(entities[146]); } if (/**((j == 1) && (entities[4] >= 0)) ||*/ (j == 0)) { x += 10; } Color c = Color.BLACK; if (j == 0) { c = colors[(int)(entities[i+6] - 1)]; } else if (j == 2) { c = Color.WHITE; } g.setColor(c); g.fillOval(x + 2, y, 20, 14); g.setColor(Color.GRAY); g.drawOval(x + 2, y, 20, 14); g.setColor(c); g.fillRoundRect(x + 5, y + 12, 14, 13, 4, 4); g.fillOval(x + 7, y + 22, 4, 8); g.fillOval(x + 14, y + 22, 4, 8); g.fillOval(x + 2, y + 14, 5, 3); g.fillOval(x + 17, y + 14, 5, 3); g.setColor(Color.GRAY); g.drawRoundRect(x + 5, y + 12, 14, 13, 4, 4); g.setColor(new Color(250, 177, 83)); g.fillRoundRect(x + 6, y + 5, 12, 3, 3, 3); if (j == 1) { g.setColor(Color.RED); g.fillRect(x + 5, y + 19, 14, 2); } } } if (entities[167] > 0) { int x = (int)(entities[165]) - 5; int y = (int)(entities[166]) - 5; g.setColor(colors[(int)(entities[168] - 1)]); for (int i = 0; i < 4; i++) { g.fillRect(x - 2, y, 5, 1); g.fillRect(x, y - 2, 1, 5); x += 10; if (i == 1) { y += 10; x = (int)(entities[165]) - 5; } } } if (entities[149+2] > 0) { g.setColor(Color.BLACK); g.fillOval((int)(entities[149] - 5), (int)(entities[149+1] - 5), 10, 10); } if (entities[148] <= 0) { g.setColor(Color.RED); g.fillOval((int)(entities[145]), (int)(entities[146] + 24), 20, 27); g.fillOval((int)(entities[145] + 25), (int)(entities[146] + 24), 20, 27); g.setColor(Color.BLACK); g.drawOval((int)(entities[145]), (int)(entities[146] + 24), 20, 27); g.drawOval((int)(entities[145] + 25), (int)(entities[146] + 24), 20, 27); } if (entities[1] < 0) { g.setColor(Color.BLACK); g.fillRect((int)(entities[0] + 10), 1, 5, 5); } } // Draw the entire results on the screen. appletGraphics.drawImage(screen, 0, 0, null); try { Thread.sleep(10); } catch (Exception e) { /* best practice */ }; if (!isActive()) { return; } } } public boolean handleEvent(Event e) { switch (e.id) { case Event.KEY_PRESS: case Event.KEY_ACTION: if (values[4] <= 0) { if (e.key == Event.ENTER) { values[4] = 1; } } else { } if (e.key == Event.LEFT) { values[3] = 1; } if (e.key == Event.RIGHT) { values[2] = 1; } if (e.key == Event.UP) { values[1] = 1; } break; case Event.KEY_ACTION_RELEASE: case Event.KEY_RELEASE: if (values[4] > 0) { if (e.key == Event.ESCAPE) { values[4] = 0; } } if (e.key == Event.LEFT) { values[3] = 0; } if (e.key == Event.RIGHT) { values[2] = 0; } if (e.key == Event.UP) { values[1] = 0; } break; } return false; } }