View Game: ApoSimple4k

ApoSimple4k (www.apo-games.de/apoSimple4k/)

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

Your goal is to clear all colored pieces to finish the level.
Start moving by clicking on a piece.

Whenever a new piece is reached movement changes to its direction.
Sounds easy? It is!

Big version with achivements and highscoreladder: http://apo-games.de/apoSimple/

Basic game idea by: http://www.tonypa.pri.ee/

Instructions

Play with the mouse and start moving a piece by clicking on it.

User Comments

No comments have been made.

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.BasicStroke; import java.awt.Event; import java.awt.Color; import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.image.BufferedImage; public class S extends Applet implements Runnable { /* * 0 = mouseX * 1 = mouseY * 2 = points * 3 = level * 4 = width rec around * 5 = moves * 6 = x-Wert Entität, die sich bewegt * 7 = y-Wert Entität, die sich bewegt * 8 = Richtung der Entität, die sich bewegt * 9 = dazu add Points für den nächsten (insgesamt) * 10 = addPoints */ private final float[] values = new float[15]; 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(640,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; values[4] = 624; /* * level 0-6 das eigentliche level * level 7-13 Fallhöhe * level 8-20 Blume ja nein */ int[][] level = new int[21][7]; String[] strings = new String[21]; // Game loop. while (true) { long now = System.nanoTime(); long delta = now - lastTime; think += delta; // Update / think while (think >= 10000000L) { think -= 10000000L; // wenn das Spiel gestartet wurde if (values[14] > 0) { for (int i = 0; i < strings.length; i++) { if ((strings[i] != null) && (strings[i].length() > 0)) { int time = Integer.valueOf(strings[i].substring(0,4)) - 10; if (time > 0) { strings[i] = String.valueOf(time) + strings[i].substring(4); int count = String.valueOf(time).length(); while (count < 4) { strings[i] = "0"+strings[i]; count += 1; } } else { strings[i] = ""; } } } // verkleiner das Spielfeld if (values[4] > 465) { values[4] -= 2.5f; } else if (values[12] > 0) { values[12] -= 10; } else { // falls es noch kein Level gibt, dann erstelle eins if (level[0][0] == -1) { for (int y = 0; y < 7; y++) { for (int x = 0; x < level[0].length; x++) { int rand = (int)(Math.random() * 100); if (rand < 8) { level[y][x] = 1; } else if (rand < 33) { level[y][x] = 2; } else if (rand < 56) { level[y][x] = 3; } else if (rand < 78) { level[y][x] = 4; } else { level[y][x] = 5; } level[y+7][x] = 465; level[y+14][x] = 0; } } // erstelle die farbigen Felder int flow = (int)(values[3] + 3); if (flow > 40) { flow = 40; } while (flow > 0) { int x = (int)(Math.random() * 7); int y = (int)(Math.random() * 7); if (level[y+14][x] <= 0) { level[y+14][x] = 2; flow--; } } if (values[3] <= 0) { values[5] = 5; } else { values[5] += 5; if (values[5] > 7) { values[5] = 7; } } this.values[9] = 0; strings = new String[49]; } int mouseX = -1; int mouseY = -1; // wenn die Maus gedrückt wurde if (values[13] > 0) { values[13] = 0; if ((values[0] >= 480) && (values[0] <= 630) && (values[1] >= 425) && (values[1] <= 465)) { values[14] = 0; break; } if ((values[0] >= 480) && (values[0] <= 630) && (values[1] >= 375) && (values[1] <= 415)) { level[0][0] = -1; values[3] = 0; break; } if ((values[0] >= 10) && (values[0] < 465) && (values[1] >= 10) && (values[1] < 465)) { // Ins Spielfeld gedrückt mouseX = (int)((values[0] - 10) / 65); mouseY = (int)((values[1] - 10) / 65); } } if (this.values[8] > 0) { // Entität bewegt sich int oldX = (int)((this.values[6] - 10) / 65); int oldY = (int)((this.values[7] - 10) / 65); if ((int)(this.values[8]) == 2) { oldY = (int)((this.values[7] + 65 - 10) / 65); this.values[7] -= 2.2f; } if ((int)(this.values[8]) == 3) { this.values[6] += 2.2f; } if ((int)(this.values[8]) == 4) { this.values[7] += 2.2f; } if ((int)(this.values[8]) == 5) { oldX = (int)((this.values[6] + 65 - 10) / 65); this.values[6] -= 2.2f; } if ((this.values[6] <= -50) || (this.values[7] <= -50) || (this.values[6] >= 465) || (this.values[7] >= 465)) { this.values[8] = 0; boolean bFlower = false; for (int y = 0; y < 7; y++) { for (int x = 0; x < level[0].length; x++) { if (level[y+14][x] > 0) { bFlower = true; } } } if (!bFlower) { this.values[2] += (int)(this.values[3] + 2) * 10; this.values[3] += 1; level[0][0] = -1; values[12] = 2000; } else { if ((int)(this.values[5]) <= 0) { level[0][0] = -1; values[14] = 0; } else { int add = 0; for (int x = 0; x < level[0].length; x++) { add = 0; for (int y = 6; y >= 0; y--) { if (level[y][x] == 0) { add += 65; level[y][x] = 0; } else if (add > 0) { level[y + add/65][x] = level[y][x]; level[y][x] = 0; level[y + 7 + add/65][x] = add; } } int count = 0; for (int y = 6; y >= 0; y--) { if (level[y][x] == 0) { int rand = (int)(Math.random() * 100); if (rand < 8) { level[y][x] = 1; } else if (rand < 33) { level[y][x] = 2; } else if (rand < 56) { level[y][x] = 3; } else if (rand < 78) { level[y][x] = 4; } else { level[y][x] = 5; } level[y + 7][x] = (y + 1) * 65 + count * 65; count += 1; } } } } } } else { int newX = (int)((this.values[6] - 10) / 65); if ((int)(this.values[8]) == 5) { newX = (int)((this.values[6] + 65 - 10) / 65); } int newY = (int)((this.values[7] - 10) / 65); if ((int)(this.values[8]) == 2) { newY = (int)((this.values[7] + 65 - 10) / 65); } if ((newX != oldX) || (newY != oldY)) { int add = 0; if (level[newY][newX] > 0) { this.values[6] = newX * 65 + 10; this.values[7] = newY * 65 + 10; if (level[newY][newX] > 1) { this.values[8] = level[newY][newX]; } if (level[newY+14][newX] > 0) { level[newY+14][newX] = 0; this.values[10] += 1; this.values[11] += 20; } this.values[9] += 1; add = (int)(this.values[9] * 1 * this.values[10] + this.values[11]); for (int i = 0; i < strings.length; i++) { if ((strings[i] == null) || (strings[i].length() <= 0)) { String sx = String.valueOf(newX * 65 + 10 + 100); String sy = String.valueOf(newY * 65 + 10 + 100); strings[i] = "1400"+sx+sy+"+ "+String.valueOf(add); break; } } if ((int)(this.values[9]) % 10 == 0) { this.values[5] += 1; for (int i = 0; i < strings.length; i++) { if ((strings[i] == null) || (strings[i].length() <= 0)) { String sx = String.valueOf(newX * 65 + 10 + 100); String sy = String.valueOf(newY * 65 + 10 + 25 + 100); strings[i] = "2000"+sx+sy+"+ Extramove"; break; } } } level[newY][newX] = 0; } this.values[2] += add; } } } else { // Fallen die Dinger? boolean bDown = false; for (int y = 0; y < 7; y++) { for (int x = 0; x < level[0].length; x++) { if (level[y+7][x] > 0) { level[y+7][x] -= 5.0f; if (level[y+7][x] <= 0) { level[y+7][x] = 0; } bDown = true; } } } // wurde ins Spielfeld geklickt? if ((mouseX >= 0) && (mouseY >= 0) && (!bDown)) { if ((level[mouseY+14][mouseX] <= 0) && (level[mouseY][mouseX] > 1)) { this.values[6] = mouseX * 65 + 10; this.values[7] = mouseY * 65 + 10; this.values[8] = level[mouseY][mouseX]; level[mouseY][mouseX] = 0; this.values[5] -= 1; this.values[9] = 0; this.values[10] = 1; this.values[11] = 0; } } } } } else { if (values[4] < 624) { values[4] += 2.5f; } else { if (values[13] > 0) { if ((values[0] >= 240) && (values[0] <= 400) && (values[1] >= 360) && (values[1] <= 400)) { // Spiel starten values[14] = 1; level[0][0] = -1; values[2] = 0; values[3] = 0; values[6] = -1; values[7] = -1; } } } values[13] = 0; } } lastTime = now; // Render g.setColor(Color.WHITE); g.fillRect(0, 0, 640, 480); g.setColor(Color.LIGHT_GRAY); g.fillRoundRect(6, 6, (int)(values[4]), 464, 30, 30); if (values[14] <= 0) { g.setColor(Color.WHITE); g.fillRect(4, 210, (int)(values[4] + 8), 60); if (values[4] >= 624) g.fillRoundRect(240, 360, 160, 40, 5, 5); } g.setColor(Color.DARK_GRAY); g.setStroke(new BasicStroke(3)); g.drawRoundRect(6, 6, (int)(values[4]), 464, 30, 30); if (values[14] <= 0) { g.setColor(Color.DARK_GRAY); g.drawLine(6, 210, (int)(values[4] + 6), 210); g.drawLine(6, 270, (int)(values[4] + 6), 270); g.setColor(Color.BLACK); if (values[4] >= 620) { g.setFont(g.getFont().deriveFont(50f).deriveFont(1)); String s = "ApoSimple4k"; int w = g.getFontMetrics().stringWidth(s); g.drawString(s, 320 - w/2, 255); if (this.values[2] > 0) { s = "Points: "+String.valueOf((int)(this.values[2])); w = g.getFontMetrics().stringWidth(s); g.drawString(s, 320 - w/2, 125); } g.setFont(g.getFont().deriveFont(30f).deriveFont(1)); s = "start"; w = g.getFontMetrics().stringWidth(s); g.drawString(s, 320 - w/2, 390); g.setColor(Color.DARK_GRAY); if ((values[0] >= 240) && (values[0] <= 400) && (values[1] >= 360) && (values[1] <= 400)) { g.setColor(Color.YELLOW); } g.drawRoundRect(240, 360, 160, 40, 5, 5); } } else { if (values[4] <= 465) { int mouseX = -1; int mouseY = -1; if ((values[0] >= 10) && (values[0] < 465) && (values[1] >= 10) && (values[1] < 465)) { // Ins Spielfeld gedrückt mouseX = (int)((values[0] - 10) / 65); mouseY = (int)((values[1] - 10) / 65); } g.setClip(10, 10, 455, 455); String levelup = "levelup"; for (int y = 0; y < 7; y++) { for (int x = 0; x < level[0].length; x++) { g.setStroke(new BasicStroke(5)); if (level[y][x] > 0) { g.setColor(Color.WHITE); if (level[y+14][x] > 0) { g.setColor(Color.GREEN); } g.fillOval(12 + x * 65, 12 + y * 65 - (int)(level[y+7][x]), 56, 56); g.setColor(Color.DARK_GRAY); if ((mouseX >= 0) && (mouseX == x) && (mouseY == y)) { g.setColor(Color.RED); if ((level[y][x] >= 2) && (level[y+14][x] <= 0)) { g.setColor(Color.YELLOW); } } g.drawOval(11 + x * 65, 11 + y * 65 - (int)(level[y+7][x]), 58, 58); g.setColor(Color.BLACK); if (this.values[12] > 0) { g.setFont(g.getFont().deriveFont(50f).deriveFont(1)); int step = 2000 / 49; if (2000 - this.values[12] > y * step * 7 + x * step) { String s = levelup.substring(x, x + 1); g.drawString(s, 11 + x * 65 + 30 - g.getFontMetrics().stringWidth(s)/2, 11 + y * 65 + 47); } } else if (level[y][x] >= 2) { g.setStroke(new BasicStroke(7)); if (level[y][x] == 2) { g.setClip(11 + x * 65, 11 + y * 65 - (int)(level[y+7][x]), 58, 29); } if (level[y][x] == 3) { g.setClip(11 + x * 65 + 29, 11 + y * 65 - (int)(level[y+7][x]), 29, 58); } if (level[y][x] == 4) { g.setClip(11 + x * 65, 11 + y * 65 + 29 - (int)(level[y+7][x]), 58, 29); } if (level[y][x] == 5) { g.setClip(11 + x * 65, 11 + y * 65 - (int)(level[y+7][x]), 29, 58); } g.drawOval(25 + x * 65, 25 + y * 65 - (int)(level[y+7][x]), 30, 30); } } g.setClip(6, 6, 460, 460); } } g.setStroke(new BasicStroke(1)); g.setFont(g.getFont().deriveFont(20f).deriveFont(1)); for (int i = 0; i < strings.length; i++) { if ((strings[i] != null) && (strings[i].length() > 0)) { String s = strings[i].substring(10); int w = g.getFontMetrics().stringWidth(s); int x = Integer.valueOf(strings[i].substring(4,7)) - 100; int y = Integer.valueOf(strings[i].substring(7,10)) - 100; g.setColor(Color.BLACK); g.drawString(s, x - w/2 + 30, y + 40); } } if (this.values[8] > 0) { g.setColor(Color.WHITE); g.fillOval((int)(this.values[6]), (int)(this.values[7]), 58, 58); g.setStroke(new BasicStroke(5)); g.setColor(Color.BLUE); g.drawOval((int)(this.values[6]), (int)(this.values[7]), 58, 58); g.setColor(Color.BLACK); g.setStroke(new BasicStroke(7)); if ((int)(this.values[8]) == 2) { g.setClip((int)(this.values[6]), (int)(this.values[7]), 58, 29); } if ((int)(this.values[8]) == 3) { g.setClip((int)(this.values[6] + 29), (int)(this.values[7]), 29, 58); } if ((int)(this.values[8]) == 4) { g.setClip((int)(this.values[6]), (int)(this.values[7] + 29), 58, 29); } if ((int)(this.values[8]) == 5) { g.setClip((int)(this.values[6]), (int)(this.values[7]), 29, 58); } g.drawOval((int)(this.values[6] + 15), (int)(this.values[7] + 15), 30, 30); } g.setClip(0, 0, 640, 480); g.setStroke(new BasicStroke(3)); g.setFont(g.getFont().deriveFont(20f).deriveFont(1)); String s = "points"; g.drawString(s, 480, 25); s = "level"; g.drawString(s, 480, 285); s = "moves"; g.drawString(s, 480, 325); g.fillOval(540, 265, 50, 50); g.fillOval(580, 305, 50, 50); for (int i = 0; i < String.valueOf((int)this.values[2]).length(); i++) { g.fillOval(580, 15 + i *30, 30, 30); } g.setColor(Color.DARK_GRAY); g.drawOval(540, 265, 50, 50); g.drawOval(580, 305, 50, 50); g.drawLine(470, 30, 580, 30); g.drawLine(470, 290, 540, 290); g.drawLine(470, 330, 580, 330); for (int i = 0; i < String.valueOf((int)this.values[2]).length(); i++) { g.drawOval(580, 15 + i *30, 30, 30); } g.setColor(Color.WHITE); g.setFont(g.getFont().deriveFont(40f).deriveFont(1)); s = String.valueOf((int)(values[3] + 1)); g.drawString(s, 565 - g.getFontMetrics().stringWidth(s)/2, 305); s = String.valueOf((int)(values[5])); g.drawString(s, 605 - g.getFontMetrics().stringWidth(s)/2, 345); g.setFont(g.getFont().deriveFont(25f).deriveFont(1)); for (int i = 0; i < String.valueOf((int)this.values[2]).length(); i++) { s = String.valueOf((int)this.values[2]).substring(i, i +1); g.drawString(s, 595 - g.getFontMetrics().stringWidth(s)/2, 40 + i * 30); } g.setColor(Color.BLACK); g.setFont(g.getFont().deriveFont(30f).deriveFont(1)); s = "menu"; g.drawString(s, 555 - g.getFontMetrics().stringWidth(s)/2, 455); s = "restart"; g.drawString(s, 555 - g.getFontMetrics().stringWidth(s)/2, 405); g.setColor(Color.DARK_GRAY); if ((values[0] >= 480) && (values[0] <= 630) && (values[1] >= 425) && (values[1] <= 465)) { g.setColor(Color.YELLOW); } g.drawRoundRect(480, 425, 150, 40, 5, 5); g.setColor(Color.DARK_GRAY); if ((values[0] >= 480) && (values[0] <= 630) && (values[1] >= 375) && (values[1] <= 415)) { g.setColor(Color.YELLOW); } g.drawRoundRect(480, 375, 150, 40, 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.MOUSE_DOWN: // mouse button pressed values[13] = 1; break; case Event.MOUSE_MOVE: case Event.MOUSE_DRAG: values[0] = e.x; values[1] = e.y; break; } return false; } }