View Game: ApoStress4k

ApoStress4k (http://www.apo-games.de/apoStress4k/)

By ApoGames, submitted on Dec 2, 2012
Min JRE version: 1.6
2440 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

It's a simple game.

Survive as long as you can and reach the best score.

Instructions

Play all sqaures with the cursor keys and spacebar.
Try out what you have to do.

User Comments

Total 1 comments:

#1 By StephR Jan 12, 2013 at 17:48:29
An interesting, original and a bit crazy concept. However, I'm not sure you should oblige players to figure out what to do by themselves. People are so impatient these days !

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.AWTEvent; import java.awt.Color; import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.event.KeyEvent; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; public class H extends Applet implements Runnable { private static final Color[] c = new Color[] { new Color(204, 34, 35), new Color(113, 183, 61), new Color(249, 187, 40), new Color(20, 130, 191), }; private static final int[] t = new int[] { 15000, 35000, 60000 }; /** * p[0] == linke Pfeiltaste pressed * p[1] == rechte Pfeiltaste pressed * p[2] == obere Pfeiltaste pressed * p[3] == untere Pfeiltaste pressed * p[4] == Spiel gestartet * p[5] == Zeit * p[6] == Punkte * p[7] == Leertaste gedrückt */ private final float[] p = new float[8]; public void start() { enableEvents(AWTEvent.KEY_EVENT_MASK); new Thread(this).start(); } public void run() { setSize(400, 400); // für den AppletViewer // Graphische Grundlagen für das Double Buffering BufferedImage screen = new BufferedImage(400,400,BufferedImage.TYPE_INT_RGB); Graphics2D g = screen.createGraphics(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Graphics2D appletGraphics = (Graphics2D)getGraphics(); // Variablen zum Zeitmessen und genau Timen wann geupdatet werden soll long lastTime = System.nanoTime(); long think = lastTime; /** * 0 = shoot player x * 1 = shoot player y * 2 = shoot particle x * 3 = shoot particle y * 4 = particle x * 5 = particle y * 6 = particle vec y * 7 = paddle x * 8 = paddle y * 9 = ball x * 10 = ball y * 11 = ball vec x * 12 = ball vec y * 13 = down position y * 14 = down position vec y * 15 = run player x * 16 = run player y * 17 = catch player x * 18 = catch player y */ float[] players = new float[19]; boolean bSpacePressed = false; // Game loop. while (true) { long now = System.nanoTime(); long delta = now - lastTime; think += delta; // Update / think // Wenn 10 ms vergangen sind, dann denke nach while (think >= 10000000L) { think -= 10000000L; if (p[4] > 0) { if (p[5] == 0) { // reset all values players = new float[19]; players[0] = 92; players[1] = 167; players[4] = (int)(Math.random() * 160) + 15; players[5] = -10; players[6] = 0.1f; players[7] = 210; players[8] = 80; players[9] = 295; players[10] = 95; players[11] = 0.25f; players[12] = 0.25f; players[13] = 300; players[15] = 10; players[16] = 210; players[17] = 93; players[18] = 293; p[5] = t[2]; } if (p[0] > 0) { players[0] -= 0.8f; if (players[0] < 4) { players[0] = 4; } } else if (p[1] > 0) { players[0] += 0.8f; if (players[0] > 186) { players[0] = 186; } } players[5] += players[6]; if (players[5] > 157) { p[4] = 0; } if ((p[7] > 0) && (!bSpacePressed) && (players[2] <= 0)) { players[2] = players[0] + 2; players[3] = players[1]; } if (players[2] > 0) { players[3] -= 0.8f; if (players[3] < 4) { players[2] = 0; } if (new Rectangle2D.Float(players[2], players[3], 10, 10).intersects(players[4], players[5], 15, 15)) { players[2] = 0; players[4] = (int)(Math.random() * 160) + 15; players[5] = -10; players[6] = 0.1f + p[5] / 300000f; } } if (p[5] > t[0]) { if (p[2] > 0) { players[8] -= 0.8f; if (players[8] < 4) { players[8] = 4; } } else if (p[3] > 0) { players[8] += 0.8f; if (players[8] > 156) { players[8] = 156; } } if ((p[7] > 0) && (!bSpacePressed)) { players[7] += 170; if (players[7] > 400) { players[7] = 210; } } players[9] += players[11]; players[10] += players[12]; if (players[11] < 0) { players[11] -= 0.00002; } else { players[11] += 0.00002; } if ((players[10] < 4) || (players[10] > 186)) { players[12] = -players[12]; } if (new Rectangle2D.Float(players[7], players[8], 10, 40).intersects(players[9], players[10], 10, 10)) { players[11] = -players[11]; if (players[9] < 220) { players[9] = 220; } if (players[9] > 370) { players[9] = 370; } } if ((players[9] < 210) || (players[9] > 380)) { p[4] = 0; } if (p[5] > t[1]) { if (p[7] > 0) { players[14] = -0.4f; } else { if (players[14] < 0) { players[14] = 0; } players[14] += 0.001f; } players[13] += players[14]; if ((players[13] < 203) || (players[13] > 397)) { p[4] = 0; } if (p[5] > t[2]) { if (p[0] > 0) { players[15] -= 0.8f; if (players[15] < 4) { players[15] = 4; } } else if (p[1] > 0) { players[15] += 0.8f; if (players[15] > 176) { players[15] = 176; } } if (p[2] > 0) { players[16] -= 0.7f; if (players[16] < 204) { players[16] = 204; } } else if (p[3] > 0) { players[16] += 0.7f; if (players[16] > 376) { players[16] = 376; } } if ((p[7] > 0) && (!bSpacePressed)) { if (players[15] + 5 < players[17]) { players[17] -= (15 + ((p[5] - t[2])/10000f)); if (players[15] >= players[17]) { players[17] = players[15]; } } else if (players[15] - 5 > players[17]) { players[17] += (15 + ((p[5] - t[2])/10000f)); if (players[15] <= players[17]) { players[17] = players[15]; } } else if (players[16] - 5 > players[18]) { players[18] += (15 + ((p[5] - t[2])/10000f)); if (players[16] <= players[18]) { players[18] = players[16]; } } else { players[18] -= (15 + ((p[5] - t[2])/10000f)); if (players[16] >= players[18]) { players[18] = players[16]; } } } if (new Rectangle2D.Float(players[15], players[16], 20, 20).intersects(players[17], players[18], 15, 15)) { p[4] = 0; } } } } p[5] += 10; p[6] += 1 + p[5] / 100000f; bSpacePressed = false; if (p[7] > 0) { bSpacePressed = true; } } } lastTime = now; // Renderabschnitt // Hintergrund malen g.setColor(Color.WHITE); g.fillRect(0, 0, 400, 400); if (p[4] <= 0) { g.setColor(Color.BLACK); g.fillRect(30, 350, 150, 30); for (int i = 0; i < 3; i++) { g.fillRect(250 + i * 35, 350, 30, 30); } g.fillRect(285, 315, 30, 30); g.setFont(g.getFont().deriveFont(25f).deriveFont(1)); String s = "ApoStress4k"; int w = g.getFontMetrics().stringWidth(s); g.drawString(s, 200 - w/2, 40); s = "Press space to start"; w = g.getFontMetrics().stringWidth(s); g.drawString(s, 200 - w/2, 275); s = "Play the game with"; w = g.getFontMetrics().stringWidth(s); g.drawString(s, 200 - w/2, 305); if (p[6] > 0) { g.setFont(g.getFont().deriveFont(40f).deriveFont(1)); s = "Points: "+String.valueOf((int)(p[6])); w = g.getFontMetrics().stringWidth(s); g.drawString(s, 200 - w/2, 190); } } else { g.setColor(c[0]); g.fillRect(3, 3, 194, 194); g.setColor(Color.BLACK); g.fillRect((int)(players[0]), (int)(players[1]), 15, 30); g.fillRect((int)(players[4]), (int)(players[5]), 15, 15); if (players[2] > 0) { g.fillRect((int)(players[2]), (int)(players[3]), 10, 10); } if (p[5] > t[0]) { g.setColor(c[1]); g.fillRect(203, 3, 194, 194); g.setColor(Color.BLACK); g.fillRect((int)(players[7]), (int)(players[8]), 10, 40); g.fillRect((int)(players[9]), (int)(players[10]), 10, 10); if (p[5] > t[1]) { g.setColor(c[2]); g.fillRect(203, 203, 194, 194); g.setColor(Color.BLACK); g.fillRect((int)(260), (int)(players[13]), 80, 397 - (int)(players[13])); if (p[5] > t[2]) { g.setColor(c[3]); g.fillRect(3, 203, 194, 194); g.setColor(Color.BLACK); g.fillRect((int)(players[15]), (int)(players[16]), 20, 20); g.setColor(Color.WHITE); g.fillRect((int)(players[17]), (int)(players[18]), 15, 15); } } } } // Render das Ganze auf den Bildschirm appletGraphics.drawImage(screen, 0, 0, null); try { Thread.sleep(10); } catch (Exception e) { /** nicht schön aber selten */ } ; if (!isActive()) { return; } } } @Override public void processEvent(AWTEvent e) { KeyEvent event = (KeyEvent) e; if (e.getID() == KeyEvent.KEY_PRESSED) { if (p[4] > 0) { if (event.getKeyCode() == KeyEvent.VK_LEFT) { p[0] = 1; } else if (event.getKeyCode() == KeyEvent.VK_RIGHT) { p[1] = 1; } if (event.getKeyCode() == KeyEvent.VK_UP) { p[2] = 1; } else if (event.getKeyCode() == KeyEvent.VK_DOWN) { p[3] = 1; } if (event.getKeyCode() == KeyEvent.VK_SPACE) { p[7] = 1; } } } if (e.getID() == KeyEvent.KEY_RELEASED) { if (p[4] > 0) { if (event.getKeyCode() == KeyEvent.VK_LEFT) { p[0] = 0; } if (event.getKeyCode() == KeyEvent.VK_RIGHT) { p[1] = 0; } if (event.getKeyCode() == KeyEvent.VK_UP) { p[2] = 0; } if (event.getKeyCode() == KeyEvent.VK_DOWN) { p[3] = 0; } if (event.getKeyCode() == KeyEvent.VK_SPACE) { p[7] = 0; } if (event.getKeyCode() == KeyEvent.VK_ESCAPE) { p[4] = 0; } } else { if (event.getKeyCode() == KeyEvent.VK_SPACE) { for (int i = 0; i < 6; i++) { p[i] = 0; } p[4] = 1; } } } } }