View Game: ApoBubble4k

ApoBubble4k (http://www.apo-games.de/apoBubble4k/)

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

(Click on game for focus)


You need Java installed to play this game.
You may use the button below to get it.

Get Java


Description

The agent loves gold. So please guide him to the treasure.
But it is a strange world. Everywhere are pink and blue bubbles. You can blow the bubbles or walk over them. Sounds strange? No it is a clever puzzle game.

FAQ:

Q: I want more levels?
A: Then try the 'big' version of the game and play ApoBubble with an ingame editor and more than 30 levels. Link: http://apo-games.de/apoBubble/

Q: I can't beat a level?
A: Press F2 to load the next level

Instructions

Use the arrow keys to move.
Press a mouse button on a bubble to blow it up.

Pink and blue tiles are bubbles.

The bubbles will explode when they hit a spike.
The blue bubbles will explode after 3 blow ups.

You can be catched in a bubble. Then you can't move
until the bubble explodes.

To restart, press backspace or delete.

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.Event; import java.awt.Color; import java.awt.Graphics; import java.awt.image.BufferedImage; public class G extends Applet implements Runnable { /** die eigentlichen Levels ... repräsentiert als String */ private final static String[] l = new String[] { // "99000000"+ // "000000000000000"+ // "000000000000000"+ // "000000000000000"+ // "000000111000000"+ // "0001211111318", // // "99000000"+ // "000000000000000"+ // "000000111000000"+ // "000121111131000"+ // "000000010000000"+ // "000000040000000"+ // "000000010000000"+ // "000000058", // // "99000000"+ // "001111111111100"+ // "001111111111100"+ // "001211111113100"+ // "000401111100000"+ // "000001111100000"+ // "000001111100000"+ // "0000005558", //// //// "000000000000000"+ //// "000000000000000"+ //// "000000113000000"+ //// "000000100000000"+ //// "000000100000000"+ //// "000000100000000"+ //// "000011111110000"+ //// "000010100010000"+ //// "000050111110000"+ //// "000000001010000"+ //// "000000111110000"+ //// "000000111000000"+ //// "000000121000000"+ //// "000000048", // // "99000000"+ // "000005555500000"+ // "011111111111110"+ // "011111111111110"+ // "012111711111310"+ // "000011111110000"+ // "000071111110000"+ // "000011111718", // //// "000000000000000"+ //// "000000000000000"+ //// "000000000000000"+ //// "000000000000000"+ //// "000000000000000"+ //// "000000000000000"+ //// "001111111111100"+ //// "001211111113100"+ //// "000001111000000"+ //// "000041111000000"+ //// "000001111700000"+ //// "000001111000000"+ //// "000001111000000"+ //// "000005550000000"+ //// "000000000000000", //// //// "000000000000000"+ //// "000000000000000"+ //// "000000000000000"+ //// "000000000000000"+ //// "000011111111000"+ //// "000013111111000"+ //// "000000011000000"+ //// "000000011000000"+ //// "000070011000000"+ //// "001111111111110"+ //// "001111111111110"+ //// "005511121111550"+ //// "000000040007000"+ //// "000000000000000"+ //// "000000000000000", // // "66700000000"+ // "000001110000000"+ // "000001110000000"+ // "000000100000000"+ // "001111100000000"+ // "001110101111000"+ // "001110101111000"+ // "001110111111000"+ // "001211101135000"+ // "00048", //// //// "000000000000000"+ //// "000000000000000"+ //// "000000000000000"+ //// "000111111111110"+ //// "000100010010010"+ //// "001110111010110"+ //// "041110111410110"+ //// "001210111010130"+ //// "000010100010000"+ //// "000014100010000"+ //// "000010100010000"+ //// "000010500010000"+ //// "000010000010000"+ //// "000050000050000"+ //// "000000000000000", //// //// "3440000000000"+ //// "000111000000000"+ //// "000111000011110"+ //// "000121111110130"+ //// "000040104010000"+ //// "000010111110000"+ //// "000010100000000"+ //// "000011100000000"+ //// "000000100000000"+ //// "000000100000000"+ //// "000000100000000"+ //// "00000058", //// //// "000000000000000"+ //// "000001111100000"+ //// "000001000100000"+ //// "000001001110000"+ //// "000001001110000"+ //// "000001115351000"+ //// "000001010001000"+ //// "000111111111000"+ //// "000100010100000"+ //// "000111111100000"+ //// "000001010100000"+ //// "000001111100000"+ //// "000000011100000"+ //// "000000012100000"+ //// "000000040400000", //// // // "1911113100000"+ // "000001100000000"+ // "000001100000000"+ // "000001100000000"+ // "001111111111000"+ // "005511111155000"+ // "000001111000000"+ // "000001111700000"+ // "000001111000000"+ // "000001111000000"+ // "000001111400000"+ // "000001111000000"+ // "000001211000000"+ // "0000000048", // // "99000000"+ // "000000111000000"+ // "000000111111110"+ // "011111141111210"+ // "013111111111410"+ // "014111111111110"+ // "011111111117000"+ // "00005070058", // //// "54111100"+ //// "000000000113100"+ //// "000000411110000"+ //// "000000111100000"+ //// "005111111100000"+ //// "000111111100000"+ //// "000101111100000"+ //// "001111141111500"+ //// "001411511100000"+ //// "001211114100000"+ //// "00100114118", // // "504000000000"+ // "001111000000000"+ // "001111004000000"+ // "001111411117000"+ // "003511111110000"+ // "040001111115500"+ // "011041111111100"+ // "011111510111110"+ // "011151144111120"+ // "0000011000048", // // "477004040005000"+ // "001111111111100"+ // "001111111113100"+ // "041050040050100"+ // "001101101101100"+ // "001101201105100"+ // "001001040100100"+ // "001111111111100"+ // "041111111111140"+ // "001701040107100"+ // "00500500050058", // // "623111111111000"+ // "000111111101000"+ // "004111111101000"+ // "000000501101000"+ // "000510001101000"+ // "000011011401000"+ // "000411111101000"+ // "000001210405000"+ // "00000048", "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001111100000001211111113100000000000000000000000000000000000000000000000000000000000000", "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001111000000001211111113100000000010000000000000040000000000000010000000000000050000000000000000000000000000000000000", "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001110001111100001111111111100001111111111100001211111113100000401111100000000001111100000000001111100000000000555000000000000000000000", "000011111110000004010000011000001011000001000001111100001000000001110001000000111111001000000501111001000000001111001000021001004001000001111000001000000001400003000000001000000000000001000000000000005000000000000000000000000", "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011111111111110011111111111110011111111111110012111711111310000011111110000000071111110000000011111710000000000000000000000000000000000", "000000000000000000000111310000000000100000000000000100000000000000100000000000011111110000000010100010000000050111110000000000001010000000000111110000000000111000000000000121000000000000040000000000000000000000000000000000000", "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001111111111100001000000000100001001111100100001211111113100004005555500400000000000000000000000000000000000000000000000", "000000000000000000000000000000000000000000000000000000000000000000000000000001111111111100001211111113100000001111000000000041111000000000001111700000000001111000000000001111000000000005551000000000000000000000000000000000000", "000000000000000000000000000000000000000000000000000000000000000000000000000000011111100000000031111100000000000110000000000000110000000000700110000000011111111111100011111111111100055111211115500000000400070000000000000000000", "000000000000000000011111111110000010001001010000111011101010004111011141010000121011101010000001010001030000001410001000000001010001000000001050001000000001000001000000005000005000000000000000000000000000000000000000000000000", "000000000000000000040000000000000111000000110000111000011110000121111110130000040104010000000010111110000000010100000000000011100000000000000100000000000000100000000000000100000000000000500000000000000000000000000000000000000", "000000000000000000055555500000001111111111000001111111111000041111111111400001111111111000002111111113000000411111140000000011111100000000011111100000000011111100000000055555500000000000000000000000000000000000000000000000000", "000001111100000000001000100000000001001110000000001001110000000001115351000000001010001000000111111111000000100010100000000111111100000000001010100000000001111100000000000011100000000000012100000000000040400000000000000000000", "000000000000000000000000000000000000000000000000000000000000000000700000000000001110000000000000100000000000000100000000001111100000000001110100111000001110100111000001110111111000001211100135000000400000000000000000000000000", "000000000000000007000000000000001111111111100001111111111100001111111111100071107050705100001000000000100001111213111100007000050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "000000000000000000121000000000000101000000000000101000000000000101011101110000111011111110000111711141110000111011101110000515001000100000010041000150000011111113100000000004050000000000000000000000000000000000000000000000000", "000000111111100000000111000100000011111110110000011101110110000511111115110000011040110130000011407110000000011111110000000001111100000000000010000000000021110000000000000040000000000000000000000000000000000000000000000000000", "000000000000000000000000000000000070040000000000011111111000000512111131500000004050700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "000000000000000000000000000000000000000000000000000000000000000000000000000000000040404000001111111111150001111111111300001111111111400001105070500000001200000000000004000000000000000000000000000000000000000000000000000000000", "000000000000000000000000000000000000000000000000011000110000000411404114000000111131111000000111111111000000111111111000000411111114000000011111110000000051111150000000000111000000000000020000000000000040000000000000000000000", "000000000700000021111411111100000010101111300001110100105000001117150100000001110000100000001550001111110001000000401100001110005001170001111111111100000000000011100000000000007000000000000000000000000000000000000000000000000", "000000000000000000000000000000000004050400000000001111111300000041111111000000001111115000000051111110000000711111117000000011111110000000011111115000001211111110000000000400040000000000000000000000000000000000000000000000000", "000011113100000000001100000000000001100000000000001100000000001111111111000005511111155000000001111000000000001111700000000001111000000000001111000000000001111400000000001111000000000001211000000000000004000000000000000000000", "000000000000000000001111100000000051000150000000001040100000000111111111000007111111111700001111040111100001211111111300004711101117000001055505550100001000000000100001111111111100000000000000000000000000000000000000000000000", "000000000000000000000000000000000000000000000000000111000000000000111111110011111141111210013111111111410014111111111110011111111117000000050700500000000000000000000000000000000000000000000000000000000000000000000000000000000", "000000000000000000000000111100000000000113100000000411110000000000111100000005111111100000000111111100000000101111100000001111141111500001411511100000001211114100000001001141100000000000000000000000000000000000000000000000000", "000000000000000000000000000000000000400000000000111100000000000111100400000000111141111700000351111111000004000111111550001104111111110001111151011110001115114411120000110000000400000000000000000000000000000000000000000000000", "000000000000000000000000000000000000000012100000000000014100001310004011100001011111111100001111111111140041111111111100001111111111100041111111111140001111111111100005555555555500000000000000000000000000000000000000000000000", "000000404000000021111111111130001111111111100041111111111140011511111115110011000404000110011000000000110011400000004110011000000000110011111000111110011111111111110011111111111110055510000015550000000000000000000000000000000", "000000000000000"+ "000000000000000"+ "000000000000000"+ "007004040005000"+ "001111111111100"+ "001111111113100"+ "041050040050100"+ "001101101101100"+ "001101201105100"+ "001001040100100"+ "001111111111100"+ "041111111111140"+ "001701040107100"+ "005005000500500", "000000000000000003111111111000000111111101000004111111101000000000501101000000510001101000000011011401000000411111101000000001210405000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000" }; public void start() { new Thread(this).start(); } /** pX[0] == Spieler X-Wert * pX[1] == Ziel X-Wert * pX[2] == Anzahl der rosa Kaugummis * pX[3] == Anzahl der blauen Kaugummis * pX[4] == Mauskoordinate X-Wert * pX[5] == derzeitiges Level * pX[6] == Spieler Y-Wert * pX[7] == Ziel Y-Wert * pX[8] == Mauskoordinate Y-Wert * pX[9] == Wenn > 0 Spieler will nach links ansonsten 0 * pX[10] == Level neu starten wenn > 0 * pX[11] == Wenn > 0 Spieler hat die Maus gedrückt, ansonsten 0 * pX[12] == y runter vec */ private final float[] pX = new float[13]; public void run() { // setSize(450, 480); // für den AppletViewer // Graphische Grundlagen für das Double Buffering BufferedImage screen = new BufferedImage(480,480,BufferedImage.TYPE_INT_RGB); Graphics g = screen.getGraphics(); Graphics appletGraphics = getGraphics(); /** eigentliches Spiellevel, dabei gilt * 0 = Wand * 1 = frei * 2 = Spieler * 3 = Ziel * 4 = rosa Kaugummi * 5 = Spikes * 6 = derzeitig belegt durch Kaugummi * 7 = blauer Kaugummi */ final int[][] a = new int[15][15]; // Variablen zum Zeitmessen und genau Timen wann geupdatet werden soll long lastTime = System.nanoTime(); long think = lastTime; // Variable die angibt, welcher X-Wert als nächstes erreicht werden soll int nextX = -1; /** * 3dimensionales Array für die Kaugummis * 1 Dimension von 0 <= 7 sind die rosa Kaugummis von 8 bis Ende die blauen * 2 und 3 Dimension geben das Level wieder, die Werte die sie annehmen sind: * 1 für das Startkaugummi, pro Klick und Ausdehnung der Kaugummis += 1 */ int[][][] bubbles = new int[16][15][15]; a[0][0] = -1; boolean vL = 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 ((a[0][0] == -1) || (pX[10] > 0)) { if (pX[5] >= l.length) { pX[5] = 0; } if (pX[5] < 0) { pX[5] = l.length -1; } String l = G.l[(int)(pX[5])]; // erstmal alles resetten for (int c = 0; c < bubbles.length; c++) { for (int y1 = 0; y1 < bubbles[0].length; y1++) { for (int x1 = 0; x1 < bubbles[0][0].length; x1++) { bubbles[c][y1][x1] = 0; if (c == 0) { a[y1][x1] = 0; } } } } pX[9] = pX[10] = pX[12] = 0; /** x und y sind die aktuellen Koordinaten im Level * b und b3 stehen für die maximale Anzahl von Kaugummi (b für rosa und b3 für blau) * die ersten 2 Buchstaben geben an wieviel Wände erstmal kommen */ int x = 0, y = 1, b = 0, b3 = 0; for (int i = 0; i < l.length(); i++) { if (y >= a.length) break; a[y][x] = Integer.valueOf(l.substring(i, i+1)); if ((a[y][x] != 0) && (a[y][x] != 5)) { // Wenn der Spieler dort dann setze die Werte in pX und das eigentliche Level denkt da ist frei if (a[y][x] == 2) { pX[0] = x * 30; pX[6] = y * 30; a[y][x] = 1; } // Wenn das Ziel dort dann setze die Werte in pX und das eigentliche Level denkt da ist frei if (a[y][x] == 3) { pX[1] = x * 30; pX[7] = y * 30; a[y][x] = 1; } // Falls ein rosa Kaugummi dort schreibe das in das bubbleArray und sage dem eigentlichen level nur, // das dort ein Kaugummi ist if (a[y][x] == 4) { bubbles[b][y][x] = 1; b += 1; a[y][x] = 6; } // Falls ein blauer Kaugummi dort schreibe das in das bubbleArray und sage dem eigentlichen level nur, // das dort ein Kaugummi ist if (a[y][x] == 7) { bubbles[b3 + 8][y][x] = 1; b3 += 1; a[y][x] = 6; } // Wenn eine 8 kommt, dann kommen danach nur noch Wände, es kann also abgebrochen werden if (a[y][x] == 8) { a[y][x] = 0; break; } } x += 1; if (x >= 15) { x = 0; y += 1; } } pX[2] = b; pX[3] = b3; } boolean bDown = true; int x = (int)(pX[0]/30); int y = (int)(pX[6]/30); // Falls sich derzeit in x-Richtung bewegt wird, dann bewege den Spieler weiter // bis er ein neues Tile erreicht hat if ((this.pX[0] % 30f != 0) && (this.pX[12] == 0)) { pX[0] = pX[0] + 1f; int n = (int)(pX[0]/30); if (vL) { pX[0] = pX[0] - 2f; n = (int)((pX[0]-1)/30); } bDown = false; // neues Tile ist erreicht, dann setze den Spieler auf die neuen Werte und stoppe den Spieler if (n == nextX) { pX[0] = (int)(nextX * 30); if (vL) { pX[0] = (int)((nextX+1) * 30); nextX -= 1; } bDown = true; } } x = (int)(pX[0]/30); if (bDown) { // Falls der Spieler gerade nicht von einer Bubble gefangen ist dann if (a[y][x] != 6) { // Wenn der Spieler sich gerade nicht in y-Richtung bewegt, dann schaue ist drunter frei ... // Falls ja dann lass den Spieler fallen, ansonsten nicht if ((this.pX[6] % 30f == 0)) { if ((y + 1 < a.length) && (a[y + 1][x] != 0) && (a[y + 1][x] != 6)) { pX[6] = pX[6] + 2f; pX[12] = 1; } else { pX[6] = y * 30; pX[12] = 0; } } else { // Spieler bewegt sich derzeit nach unten ... // solange bis er wieder ein neues Tile erreicht hat pX[6] = pX[6] + 2f; pX[12] = 1; int n = (int)(pX[6]/30); if ((n + 1 >= a.length) || (a[n+1][x] == 0) || (a[n+1][x] == 6)) { pX[6] = n * 30; pX[12] = 0; } if (n != y) { if ((y + 1 >= a.length) || (a[y+1][x] == 0) || (a[y+1][x] == 6)) { pX[6] = n * 30; pX[12] = 0; } } } } } x = (int)(pX[0]/30); y = (int)(pX[6]/30); // Ist der Spieler gerade im Stachel? if (a[y][x] == 5) { a[0][0] = -1; } // Steht der Spieler im Ziel? if ((y == (int)(pX[7]/30)) && (x == (int)(pX[1]/30))) { if ((vL) && ((int)((pX[0]-1)/30) == (int)(pX[0]/30))) { } else { pX[5] += 1; a[0][0] = -1; } } // Falls sich der Spieler nicht bewegt if ((this.pX[0] % 30f == 0) && (this.pX[6] % 30f == 0)) { // wurde die Maus geklickt? Falls ja dann überprüfe, ob auf die Kaugummis geklickt wurde if (pX[11] > 0) { pX[11] = 0; /** Bubbles */ if ((pX[4] >= 0) && (pX[8] >= 0) && (pX[4] < 15) && (pX[8] < 15)) { // gehe nur die Kaugummis durch, die gefordert sind (rosa oder blau) int curX = (int)pX[4]; int curY = (int)pX[8]; int p = (int)pX[2]; int[][][] w = bubbles; for (int i = 0; i < 2; i++) { int s = 0; if (i == 1) { s = 8; p = (int)pX[3]; } int curC = -1; boolean bBreak = false; boolean bClear = false; for (int c = s; c < s + (int)p; c++) { // wenn dort ein Kaugummi ist, DANN if (w[c][curY][curX] != 0) { // Hole den größten Wert im Array // Ist wichtig um nur die Kaugummis größer werden zu lassen, die schon da waren int max = 1; for (int y1 = 0; y1 < w[0].length; y1++) { for (int x1 = 0; x1 < w[0][0].length; x1++) { if (w[c][y1][x1] > max) { max = w[c][y1][x1]; } } } // Falls es ein blauer Kaugummi ist und zu oft drauf geklickt wurde dann platze if ((max == 4) && (i == 1)) { curC = c; bClear = true; bBreak = true; break; } // Falls der Spieler nach oben versetzt werden muss und kann, dann setze ihn nach oben for (int y1 = 0; y1 < w[0].length; y1++) { if (bBreak) { break; } for (int x1 = 0; x1 < w[0][0].length; x1++) { if (((int)pX[0]/30 == x1) && ((int)pX[6]/30 == y1 - 1) && (y1 - 1 > 0) && (a[y1-1][x1] != 6) && ((a[y1-2][x1] == 1) || (a[y1-2][x1] == 5)) && (w[c][y1][x1] > 0)) { pX[6] -= 30; if (a[y1-2][x1] == 5) { a[0][0] = -1; bBreak = true; } break; } } } // gehe alle Kaugummitiles druch und erweiter sie nach links, recht, oben und unten falls möglich // wenn dort ein Spieler ist, dann bewege ihn in die bestimmte Richtung for (int y1 = 0; y1 < w[0].length; y1++) { if (bBreak) { break; } for (int x1 = 0; x1 < w[0][0].length; x1++) { if (bBreak) { break; } if ((w[c][y1][x1] <= max) && (w[c][y1][x1] > 0)) { if ((y1 - 1 >= 0) && (((int)pX[1]/30 != x1) || ((int)pX[7]/30 != y1 - 1))) { if (a[y1-1][x1] == 1) { a[y1-1][x1] = 6; w[c][y1-1][x1] = (max + 1); } if (a[y1-1][x1] == 5) { curC = c; bClear = true; bBreak = true; break; } } if ((x1 - 1 >= 0) && (((int)pX[1]/30 != x1 - 1) || ((int)pX[7]/30 != y1))) { if (a[y1][x1 - 1] == 1) { if (((int)pX[0]/30 == x1 - 1) && ((int)pX[6]/30 == y1) && (x1 - 1 > 0) && ((a[y1][x1-2] == 1) || (a[y1][x1-2] == 5)) && (w[c][y1][x1] > 0)) { pX[0] -= 30; if (a[y1][x1-2] == 5) { a[0][0] = -1; bBreak = true; break; } } a[y1][x1-1] = 6; w[c][y1][x1-1] = (max + 1); } if (a[y1][x1 - 1] == 5) { curC = c; bClear = true; bBreak = true; break; } } if ((x1 + 1 < 15) && (((int)pX[1]/30 != x1 + 1) || ((int)pX[7]/30 != y1))) { if (a[y1][x1 + 1] == 1) { if (((int)pX[0]/30 == x1 + 1) && ((int)pX[6]/30 == y1) && (x1 + 1 < 14) && ((a[y1][x1+2] == 1) || (a[y1][x1+2] == 5)) && (w[c][y1][x1] > 0)) { pX[0] += 30; if (a[y1][x1+2] == 5) { a[0][0] = -1; bBreak = true; break; } } a[y1][x1+1] = 6; w[c][y1][x1+1] = (max + 1); } if (a[y1][x1 + 1] == 5) { curC = c; bClear = true; bBreak = true; break; } } if ((y1 + 1 < 15) && (((int)pX[1]/30 != x1) || ((int)pX[7]/30 != y1 + 1))) { if (a[y1+1][x1] == 1) { a[y1+1][x1] = 6; w[c][y1+1][x1] = (max + 1); } if (a[y1+1][x1] == 5) { curC = c; bClear = true; bBreak = true; break; } } } } } bBreak = true; break; } } if (bClear) { for (int y1 = 0; y1 < w[0].length; y1++) { for (int x1 = 0; x1 < w[0][0].length; x1++) { if (w[curC][y1][x1] > 1) { w[curC][y1][x1] = 0; a[y1][x1] = 1; } } } pX[9] = 0; } } } } else { // Falls der Spieler frei ist dann if ((a[y][x] != 0) && (a[y][x] != 6)) { // soll der Spieler nach links gehen? dann schicke ihn links, falls da frei ist if (pX[9] == Event.LEFT) { if ((x - 1 >= 0) && (a[y][x-1] != 0) && (a[y][x-1] != 6)) { vL = true; pX[0] = pX[0] - 1f; nextX = (int)(pX[0]/30) - 1; } // soll der Spieler nach rechts gehen? dann schicke ihn nach rechts, falls da frei ist } if (pX[9] == Event.RIGHT) { if ((x + 1 < a[0].length) && (a[y][x+1] != 0) && (a[y][x+1] != 6)) { vL = false; pX[0] = pX[0] + 1f; nextX = (int)(pX[0]/30) + 1; } } } } } pX[10] = 0; } lastTime = now; // Renderabschnitt // Hintergrund malen g.setColor(Color.GRAY); g.fillRect(0, 0, 480, 480); /** Render das Level */ for (int y = 0; y < a.length; y++) { for (int x = 0; x < a[0].length; x++) { if (a[y][x] != 0) { // Wenn begehbar dann render ein weißes Rechteck g.setColor(Color.LIGHT_GRAY); g.fillRect(x * 30, y * 30, 30, 30); // Wenn ein Stachel dort ist, dann render den Stachel g.setColor(Color.BLACK); if (a[y][x] == 5) { g.fillPolygon(new int[] {x * 30, x * 30 + 5, x * 30 + 10, x * 30 + 15, x * 30 + 20, x * 30 + 25, x * 30 + 30}, new int[] {(y + 1) * 30,(y + 1) * 30 - 29, (y + 1) * 30,(y + 1) * 30 - 29, (y + 1) * 30,(y + 1) * 30 - 29, (y + 1) * 30}, 7); } // Render die Umrandungen, erst links schauen, falls da nicht begehbar dann render eine schwarze Linie if ((x - 1 < 0) || (a[y][x-1] == 0)) { g.drawLine(x * 30 - 1, y * 30, x * 30 - 1, (y + 1) * 30 - 1); } // falls rechts davon nicht begehbar dann render eine schwarze Linie if ((x + 1 >= 15) || (a[y][x+1] == 0)) { g.drawLine((x+1) * 30, y * 30, (x+1) * 30, (y + 1) * 30 - 1); } // falls drüber nicht begehbar dann render eine schwarze Linie if ((y - 1 < 0) || (a[y- 1][x] == 0)) { g.drawLine(x * 30, y * 30 - 1, (x + 1) * 30 - 1, (y + 0) * 30 - 1); } // falls drunter nicht begehbar dann render eine schwarze Linie if ((y + 1 >= 15) || (a[y+ 1][x] == 0)) { g.drawLine(x * 30, (y+1) * 30 - 1, (x + 1) * 30 - 1, (y + 1) * 30 - 1); } } } } /** Render das Ziel */ g.setColor(Color.YELLOW); g.fillRect((int)pX[1] + 8, (int)pX[7] + 12, 16, 16); g.setColor(Color.WHITE); g.fillRect((int)pX[1] + 8, (int)pX[7] + 14, 14, 2); g.setColor(new Color(162, 97, 79)); g.fillRect((int)pX[1] + 10, (int)pX[7] + 12, 3, 8); g.fillRect((int)pX[1] + 18, (int)pX[7] + 12, 3, 8); g.setColor(Color.BLACK); g.drawRect((int)pX[1] + 7, (int)pX[7] + 11, 16, 16); g.drawRect((int)pX[1] + 9, (int)pX[7] + 11, 4, 9); g.drawRect((int)pX[1] + 17, (int)pX[7] + 11, 4, 9); g.drawRect((int)pX[1] + 7, (int)pX[7] + 22, 16, 5); g.drawRect((int)pX[1] + 9, (int)pX[7] + 22, 4, 3); g.drawRect((int)pX[1] + 17, (int)pX[7] + 22, 4, 3); /** Render den Spieler */ g.setColor(new Color(129, 82, 62)); g.fillRect((int)pX[0] + 10, (int)pX[6] + 5, 9, 2); g.fillRect((int)pX[0] + 8, (int)pX[6] + 7, 13, 6); g.setColor(new Color(253, 188, 111)); g.fillRect((int)pX[0] + 10, (int)pX[6] + 9, 9, 8); g.fillRect((int)pX[0] + 9, (int)pX[6] + 13, 11, 3); g.setColor(Color.BLACK); g.fillRect((int)pX[0] + 8, (int)pX[6] + 12, 13, 1); g.fillRect((int)pX[0] + 10, (int)pX[6] + 11, 4, 4); g.fillRect((int)pX[0] + 15, (int)pX[6] + 11, 4, 4); g.fillRect((int)pX[0] + 11, (int)pX[6] + 27, 2, 2); g.fillRect((int)pX[0] + 16, (int)pX[6] + 27, 2, 2); g.setColor(new Color(217, 255, 217)); g.fillRect((int)pX[0] + 7, (int)pX[6] + 18, 15, 3); g.fillRect((int)pX[0] + 9, (int)pX[6] + 17, 11, 1); g.setColor(new Color(43, 43, 129)); g.fillRect((int)pX[0] + 9, (int)pX[6] + 21, 11, 2); g.fillRect((int)pX[0] + 10, (int)pX[6] + 23, 9, 2); g.fillRect((int)pX[0] + 11, (int)pX[6] + 25, 2, 2); g.fillRect((int)pX[0] + 16, (int)pX[6] + 25, 2, 2); g.setColor(new Color(253, 188, 111)); g.fillRect((int)pX[0] + 8, (int)pX[6] + 20, 2, 2); g.fillRect((int)pX[0] + 19, (int)pX[6] + 20, 2, 2); /** render die Kaugummis samt Umrandungen */ final Color bubbleColor = new Color(255, 210, 240, 180); final Color bubbleColorWall = new Color(255, 127, 210); final Color bubbleColorBlue = new Color(76, 255, 255, 180); final Color bubbleColorWallBlue = new Color(0, 127, 127); for (int c = 0; c < 8 + (int)pX[3]; c++) { for (int y1 = 0; y1 < bubbles[0].length; y1++) { for (int x1 = 0; x1 < bubbles[0][0].length; x1++) { // Ist dort überhaupt ein Kaugummi? Falls ja dann if ((bubbles[c][y1][x1] != 0) && ((c < (int)pX[2]) || (c >= 8))) { g.setColor(bubbleColor); if (c >= 8) { g.setColor(bubbleColorBlue); } int x = x1 * 30; int y = y1 * 30; int size = 3; // Male den Background davon g.fillRect(x + size, y + size, 30 - 2 * size, 30 - 2 * size); // Ist links vom Kaugummi frei? boolean bLeftFree = true; if ((x1 - 1 < 0) || (bubbles[c][y1][x1 - 1] == 0)) { bLeftFree = false; } // Ist rechts vom Kaugummi frei? boolean bRightFree = true; if ((x1 + 1 >= bubbles[0][0].length) || (bubbles[c][y1][x1 + 1] == 0)) { bRightFree = false; } // Ist über dem Kaugummi frei? boolean bUpFree = true; if ((y1 - 1 < 0) || (bubbles[c][y1 - 1][x1] == 0)) { bUpFree = false; } // Ist unter dem Kaugummi frei? boolean bDownFree = true; if ((y1 + 1 >= bubbles[0].length) || (bubbles[c][y1 + 1][x1] == 0)) { bDownFree = false; } // Render die Wände der Kaugummis g.setColor(bubbleColorWall); if (c >= 8) { g.setColor(bubbleColorWallBlue); } if (!bUpFree) { if (!bLeftFree) { g.fillRect(x + size, y, 15 - size, size); } else { g.fillRect(x, y, 15, size); } if (!bRightFree) { g.fillRect(x + 15, y, 15 - size, size); g.setColor(Color.WHITE); g.fillRect(x + 15 + size - 1, y + 3, 7, 4); g.fillRect(x + 15 + size + 2, y + 7, 4, 4); } else { g.fillRect(x + 15, y, 15, size); } } else { g.setColor(bubbleColor); if (c >= 8) { g.setColor(bubbleColorBlue); } g.fillRect(x, y, 30, size); } g.setColor(bubbleColorWall); if (c >= 8) { g.setColor(bubbleColorWallBlue); } if (!bDownFree) { if (!bLeftFree) { g.fillRect(x + size, y + 30 - size, 30/2 - size, size); } else { g.fillRect(x, y + 30 - size, 30/2, size); } if (!bRightFree) { g.fillRect(x + 30/2, y + 30 - size, 30/2 - size, size); } else { g.fillRect(x + 30/2, y + 30 - size, 30/2, size); } } else { g.setColor(bubbleColor); if (c >= 8) { g.setColor(bubbleColorBlue); } g.fillRect(x, y + 30 - size, 30, size); } g.setColor(bubbleColorWall); if (c >= 8) { g.setColor(bubbleColorWallBlue); } if (!bLeftFree) { if (!bUpFree) { g.fillRect(x, y + size, size, 30/2 - size); } else { g.fillRect(x, y, size, 30/2); } if (!bDownFree) { g.fillRect(x, y + 30/2, size, 30/2 - size); } else { g.fillRect(x, y + 30/2, size, 30/2); } } else { g.setColor(bubbleColor); if (c >= 8) { g.setColor(bubbleColorBlue); } g.fillRect(x, y + size, size, 30 - 2 * size); } g.setColor(bubbleColorWall); if (c >= 8) { g.setColor(bubbleColorWallBlue); } if (!bRightFree) { if (!bUpFree) { g.fillRect(x + 30 - size, y + size, size, 30/2 - size); } else { g.fillRect(x + 30 - size, y, size, 30/2); } if (!bDownFree) { g.fillRect(x + 30 - size, y + 30/2, size, 30/2 - size); } else { g.fillRect(x + 30 - size, y + 30/2, size, 30/2); } } else { g.setColor(bubbleColor); if (c >= 8) { g.setColor(bubbleColorBlue); } g.fillRect(x + 30 - size, y + size, size, 30 - 2 * size); } } } } } /** render die Spielinfos */ g.setColor(Color.WHITE); g.fillRect(5, 5, 85, 50); g.setColor(Color.BLACK); g.drawRect(5, 5, 85, 50); g.drawString("ApoBubble4k", 10, 25); g.drawString("Level: "+String.valueOf((int)pX[5]+1)+" / "+l.length, 10, 45); // // Render die Hinweise in den ersten Levels // if ((int)(pX[5]) <= 3) { // g.setColor(Color.WHITE); // g.fillRect(225 - 125, 30, 250, 30); // g.setColor(Color.BLACK); // g.drawRect(225 - 125, 30, 250, 30); // if ((int)(pX[5]) == 0) { // g.drawString("Move with the cursor keys", 225 - 75 + 5, 50); // } // if ((int)(pX[5]) == 1) { // g.drawString("Click on a bubble to make a bigger bubble", 225 - 112, 50); // } // if ((int)(pX[5]) == 2) { // g.drawString("Press 'backspace' to restart a level", 225 - 100, 50); // } // if ((int)(pX[5]) == 3) { // g.drawString("Blue bubbles will explode after 3 blow ups", 225 - 120, 50); // } // } // 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; } } } public boolean handleEvent(Event e) { switch (e.id) { case Event.KEY_PRESS: case Event.KEY_ACTION: if ((e.key == Event.LEFT) || (e.key == Event.RIGHT)) { pX[9] = e.key; } if ((e.key == Event.BACK_SPACE) || (e.key == Event.DELETE)) { // Level resetten pX[10] = 1; } if (e.key == Event.F2) { // Level weiter, also gewonnen pX[10] = 1; pX[5] += 1; } break; case Event.KEY_RELEASE: case Event.KEY_ACTION_RELEASE: if ((e.key == Event.LEFT) || (e.key == Event.RIGHT)) { pX[9] = 0; } break; case Event.MOUSE_DOWN: if ((this.pX[0] % 30f == 0) && (this.pX[6] % 30f == 0)) { pX[11] = 1; } break; case Event.MOUSE_MOVE: case Event.MOUSE_DRAG: pX[4] = e.x/30; pX[8] = e.y/30; break; } return false; } }