BreakCeption (http://apo-games.de/breakCeption/)
By ApoGames, submitted on Feb 1, 2014 |
(Click on game for focus) |
BreakCeption is a breakout game in a breakout game.
Java doesn't start? Try the Javascript version: http://apo-games.de/breakCeption/index_2.php
Play the game with the keyboard.
No comments have been made.
You need be logged in to write comments. If you need to register click here.
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.Font; import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.event.KeyEvent; import java.awt.image.BufferedImage; public class B extends Applet implements Runnable { private boolean left, right, enter; 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(540,480,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; String s = ""; int balls = 0; int state = 0; int time = 0; int i = 0; int j = 0; int x = 0; int y = 0; int z = 0; int w = 0; float paddleX = 210; final float DIF = 7.01298701298f;//8.8311688311688f; final int STARTX = 32; final int STARTY = 8; final Color[] colors = new Color[] { new Color(255, 255, 255), new Color(200, 100, 100), new Color(200, 175, 100), new Color(150, 200, 100), // new Color(100, 200, 125), new Color(100, 200, 200), new Color(100, 125, 200), new Color(150, 100, 200), new Color(200, 100, 175), // new Color(200, 50, 50), new Color(200, 150, 50), new Color(125, 200, 50), new Color( 50, 200, 75), // new Color( 50, 200, 200), new Color( 50, 75, 200), new Color(125, 50, 200), new Color(200, 50, 175), }; /** * 0 = wholeVisible [0 = visible; 1 = invisible] * 1 = ballX * 2 = ballY * 3 = vecX * 4 = vecY * 5 = colorvalue * ... max 50 balls * 251 = brickVisible [0 = visible; 1 = invisible] * ... max 16 bricks */ float[] level = new float[4539]; // 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 (state == 0) { if (this.enter) { state = 1; balls = 1; time = 0; level = new float[4539]; for (j = 0; j < 13;="" j="" +="1)" {="" for="" (i="1;" i="">< 251;="" i="" +="5)" {="" level[j*267="" +="" i]="-1;" make="" balls="" invisible="" level[j*267="" +="" 4="" +="" i]="j;" color="" of="" the="" balls="" }="" }="" for="" (i="0;" i="">< 5;="" i++)="" {="" level[i*5+1]="265;" level[i*5+2]="445;" level[i*5+3]="(float)(Math.random()" *="" 3="" -="" 1.5f);="" level[i*5+4]="-1.6f;" }="" paddlex="210;" }="" }="" else="" if="" (state="=" 1)="" {="" time="" +="10;" if="" (this.left)="" {="" paddlex="" -="4.5f;" }="" if="" (this.right)="" {="" paddlex="" +="4.5f;" }="" if="" (paddlex="">< 0)="" {="" paddlex="0;" }="" if="" (paddlex=""> 420) { paddleX = 420; } balls = 0; int visible = 12; int curX = 0; // + 77 int curY = 0; // + 58 for (j = 0; j < 13;="" j="" +="1)" {="" if="" (level[j="" *="" 267]="=" 0)="" {="" for="" (i="1;" i="">< 251;="" i="" +="5)" {="" if="" (level[i+j*267]="">= 0) { balls += 1; level[i+j*267] += level[i+j*267+2]; level[i+j*267+1] += level[i+j*267+3]; if (level[i+j*267+3] > 0) { level[i+j*267+3] += 0.0001f; } else if (level[i+j*267+3] < 0)="" {="" level[i+j*267+3]="" -="0.0001f;" }="" check="" above="" if="" ((level[i+j*267+1]="">< cury)="" &&="" (level[i+j*267+3]="">< 0))="" {="" level[i+j*267+3]="-level[i+j*267+3];" level[i+j*267+1]="curY;" }="" if="" (j="=" 0)="" {="" if="" (((level[i+j*267]=""><= 0)="" &&="" (level[i+j*267+2]=""></=>< 0))="" ||="" ((level[i+j*267]="" +="" 10=""> 540) && (level[i+j*267+2] > 0))) { level[i+j*267+2] = -level[i+j*267+2]; if (level[i+j*267] <= 0)="" {="" level[i+j*267]="0.0001f;" }="" }="" if="" ((level[i+j*267+1]=""> 480) && (level[i+j*267+3] > 0)) { balls -= 1; level[i+j*267] = -1; } if ((level[i+j*267+3] > 0) && (level[i+j*267] < paddlex="" +="" 120)="" &&="" (level[i+j*267]="" +="" 10=""> paddleX) && (level[i+j*267+1] < 465)="" &&="" (level[i+j*267+1]="" +="" 10=""> 455)) { level[i+j*267+3] = -level[i+j*267+3]; level[i+j*267+2] = 1.5f - ((paddleX + 120f - level[i+j*267]) * 3f / 130f); } x = STARTX; // + 77 y = STARTY; // + 58 int a = -1; w = -1; float curW = -1; float allW = -1; for (z = 1; z < 13;="" z="" +="1)" {="" if="" (level[z*267]="=" 0)="" {="" if="" ((level[i+j*267]="">< x="" +="" 77)="" &&="" (level[i+j*267]="" +="" 10=""> x) && (level[i+j*267+1] < y="" +="" 58)="" &&="" (level[i+j*267+1]="" +="" 10=""> y)) { // check downside if (level[i+j*267+1] > y + 53) { // if on the left side if ((level[i+j*267] + 10 < x="" +="" 5)="" &&="" (level[i+j*267]="" +="" 10="" -="" x=""> z + 58 - level[i+j*267+1])) { curW = level[i+j*267] + 10 - x; } else if ((level[i+j*267] - 5 > x + 77) && (x + 77 - level[i+j*267] > y + 58 - level[i+j*267+1])) { curW = x + 77 - level[i+j*267]; } else { curW = y + 58 - level[i+j*267+1]; } } else // check upside if (level[i+j*267+1] + 10 < y="" +="" 5)="" {="" if="" on="" the="" left="" side="" if="" ((level[i+j*267]="" +="" 10="">< x="" +="" 5)="" &&="" (level[i+j*267]="" +="" 10="" -="" x=""> level[i+j*267+1] + 10 - y)) { curW = level[i+j*267] + 10 - x; } else if ((level[i+j*267] - 5 > x + 77) && (x + 77 - level[i+j*267] > level[i+j*267+1] + 10 - y)) { curW = x + 77 - level[i+j*267]; } else { curW = level[i+j*267+1] + 10 - y; } } else { curW = 6; } if ((a < 0)="" ||="" (allw="">< curw))="" {="" a="z;" allw="curW;" }="" }="" }="" x="" +="77;" if="" (x=""> 460) { x = STARTX; y += 58; } } x = STARTX; // + 77 y = STARTY; // + 58 if (a >= 0) { for (z = 1; z < 13;="" z="" +="1)" {="" if="" (z="=" a)="" {="" check="" downside="" if="" (level[i+j*267+1]=""> y + 53) { // if on the left side if ((level[i+j*267] + 10 < x="" +="" 5)="" &&="" (level[i+j*267]="" +="" 10="" -="" x=""> z + 58 - level[i+j*267+1])) { level[i+j*267+2] = -level[i+j*267+2]; level[i+j*267] = x - 10; w = 3; } else if ((level[i+j*267] - 5 > x + 77) && (x + 77 - level[i+j*267] > y + 58 - level[i+j*267+1])) { level[i+j*267+2] = -level[i+j*267+2]; level[i+j*267] = x + 77; w = 1; } else { level[i+j*267+3] = -level[i+j*267+3]; level[i+j*267+1] = y + 58; w = 2; } } else // check upside if (level[i+j*267+1] + 10 < y="" +="" 5)="" {="" if="" on="" the="" left="" side="" if="" ((level[i+j*267]="" +="" 10="">< x="" +="" 5)="" &&="" (level[i+j*267]="" +="" 10="" -="" x=""> level[i+j*267+1] + 10 - y)) { level[i+j*267+2] = -level[i+j*267+2]; level[i+j*267] = x - 10; w = 3; } else if ((level[i+j*267] - 5 > x + 77) && (x + 77 - level[i+j*267] > level[i+j*267+1] + 10 - y)) { level[i+j*267+2] = -level[i+j*267+2]; level[i+j*267] = x + 77; w = 1; } else { level[i+j*267+3] = -level[i+j*267+3]; level[i+j*267+1] = y - 10; w = 0; } } else { w = 1; if (level[i+j*267] + 10 < x="" +="" 10)="" {="" w="3;" level[i+j*267]="x" -="" 10;="" }="" else="" {="" level[i+j*267]="x" +="" 77;="" }="" level[i+j*267+2]="-level[i+j*267+2];" }="" for="" (a="1;" a="">< 251;="" a="" +="5)" {="" if="" (level[z*267+a]="">< 0)="" {="" level[z*267+a]="level[i+j*267]" +="" 4;="" level[z*267+a+1]="level[i+j*267+1]" +="" 11;="" level[z*267+a+2]="level[i+j*267+2]/DIF;" level[z*267+a+3]="-level[i+j*267+3]/DIF;" if="" (w="=" 2)="" {="" level[z*267+a+1]="level[i+j*267+1]" -="" 3;="" }="" if="" (w="=" 1)="" {="" level[z*267+a]="level[i+j*267]" -="" 3;="" level[z*267+a+1]="level[i+j*267+1]" +="" 4;="" level[z*267+a+2]="-level[i+j*267+2]/DIF;" level[z*267+a+3]="level[i+j*267+3]/DIF;" }="" if="" (w="=" 3)="" {="" level[z*267+a]="level[i+j*267]" +="" 11;="" level[z*267+a+1]="level[i+j*267+1]" +="" 4;="" level[z*267+a+2]="-level[i+j*267+2]/DIF;" level[z*267+a+3]="level[i+j*267+3]/DIF;" }="" break;="" }="" }="" break;="" }="" x="" +="77;" if="" (x=""> 460) { x = STARTX; y += 58; } } } } else { if (((level[i+j*267] <= curx)="" &&="" (level[i+j*267+2]=""></=>< 0))="" ||="" ((level[i+j*267]=""> curX + 75) && (level[i+j*267+2] > 0))) { level[i+j*267+2] = -level[i+j*267+2]; if (level[i+j*267] <= curx)="" {="" level[i+j*267]="curX" +="" 0.0001f;="" }="" }="" if="" ((level[i+j*267+1]=""> curY + 58) && (level[i+j*267+3] > 0)) { balls -= 1; level[i+j*267] = -1; } if ((level[i+j*267+3] > 0) && (level[i+j*267] < curx="" +="" (paddlex="" +="" 120)/dif)="" &&="" (level[i+j*267]="" +="" 2=""> curX + paddleX/DIF) && (level[i+j*267+1] < cury="" +="" 56)="" &&="" (level[i+j*267+1]="" +="" 1=""> curY + 55)) { level[i+j*267+3] = -level[i+j*267+3]; level[i+j*267+2] = (1.5f/DIF - (((curX + (paddleX + 120f)/DIF - level[i+j*267]) * (3f / (130f/DIF))) / DIF)); } x = curX + 6; y = curY + 4; w = 0; int count = 0; for (int c = 251; c < 263;="" c="" +="1)" {="" if="" (level[j*267+c]="=" 0)="" {="" if="" ((count=""><= 0)="" &&="" (level[i+j*267]=""></=>< x="" +="" 10)="" &&="" (level[i+j*267]="" +="" 2=""> x) && (level[i+j*267+1] < y="" +="" 4)="" &&="" (level[i+j*267+1]="" +="" 2=""> y)) { level[j*267+c] = 1; level[i+j*267+3] = -level[i+j*267+3]; count += 1; } } if (level[j*267+c] > 0) { w += 1; } x += 11; if (x > curX + 64) { x = curX + 6; y += 8; } } if (w >= 12) { level[j*267] = 1; for (int a = 1; a < 251;="" a="" +="5)" {="" if="" (level[a+j*267]="">= 0) { for (w = 1; w < 251;="" w="" +="5)" {="" if="" (level[w]="">< 0)="" {="" level[w]="level[a+j*267]-4;" level[w+1]="level[a+j*267+1]-4;" level[w+2]="level[a+j*267+2]*DIF;" level[w+3]="level[a+j*267+3]*DIF*2/3;" level[w+4]="j;" break;="" }="" }="" }="" }="" }="" }="" }="" }="" }="" if="" (j="=" 0)="" {="" curx="STARTX;" cury="STARTY;" }="" if="" (j="" !="0)" {="" curx="" +="77;" if="" (curx=""> 460) { curX = STARTX; curY += 58; } } if (level[j * 267] != 0) { visible -= 1; } } if ((balls <= 0)="" ||="" (visible=""></=><= 0))="" {="" state="0;" if="" (visible=""></=><= 0)="" {="" balls="0;" for="" (i="1;" i=""></=>< 251;="" i="" +="5)" {="" if="" (level[i]=""> 0) { balls += 1; } } break; } } } this.enter = false; } lastTime = now; // Renderabschnitt // Hintergrund malen g.setColor(Color.BLACK); g.fillRect(0, 0, 540, 480); g.setFont(new Font(Font.MONOSPACED, Font.BOLD, 20)); g.setColor(new Color(255, 255, 255)); g.fillRect((int)(paddleX), 455, 120, 20); for (i = 1; i < 251;="" i="" +="5)" {="" if="" (level[i]=""> 0) { g.setColor(colors[(int)(level[i+4])].darker()); g.fillRect((int)(level[i]), (int)(level[i + 1]), 10, 10); } } x = STARTX; // + 77 w = STARTY; // + 58 for (j = 1; j < 13;="" j="" +="1)" {="" if="" (level[j="" *="" 267]="=" 0)="" {="" g.setcolor(colors[j]);="" g.fillrect(x,="" w,="" 76,="" 57);="" g.setcolor(colors[j].darker());="" g.drawrect(x,="" w,="" 76,="" 57);="" for="" (i="1;" i="">< 251;="" i="" +="5)" {="" if="" (level[i+j*267]="">= 0) { g.setColor(colors[j].darker().darker()); g.fillRect((int)(level[i+j*267]), (int)(level[i+j*267 + 1]), 2, 2); } } g.setColor(new Color(0, 0, 0)); y = x + 5; z = w + 4; for (i = 251; i < 263;="" i="" +="1)" {="" if="" (level[i+j*267]="=" 0)="" {="" g.fillrect(y,="" z,="" 10,="" 4);="" }="" y="" +="11;" if="" (y=""> x + 64) { y = x + 5; z += 8; } } g.fillRect(x + (int)(paddleX/DIF), w + 54, 15, 2); } x += 77; if (x > 460) { x = STARTX; w += 58; } } if (state == 0) { g.setColor(new Color(255, 255, 255)); g.setFont(g.getFont().deriveFont(50f).deriveFont(1)); s = "BreakCeption"; w = g.getFontMetrics().stringWidth(s); g.drawString(s, 270 - w/2, 60); g.setFont(g.getFont().deriveFont(40f).deriveFont(1)); if (time > 0) { g.setColor(new Color(255, 175, 0)); if (balls > 0) { s = "Congratulation!"; w = g.getFontMetrics().stringWidth(s); g.drawString(s, 270 - w/2, 300); g.setColor(new Color(175, 50, 150)); g.setFont(g.getFont().deriveFont(23f).deriveFont(1)); s = "You cleared the field in "+String.valueOf(time/1000)+" seconds"; w = g.getFontMetrics().stringWidth(s); g.drawString(s, 270 - w/2, 370); } else { s = "You are out of balls!"; w = g.getFontMetrics().stringWidth(s); g.drawString(s, 270 - w/2, 300); g.setColor(new Color(175, 50, 150)); s = "Please try again"; w = g.getFontMetrics().stringWidth(s); g.drawString(s, 270 - w/2, 370); } s = "Press Enter to restart"; } else { s = "Press Enter to start the game"; } g.setColor(new Color(255, 255, 255)); g.setFont(g.getFont().deriveFont(23f).deriveFont(1)); w = g.getFontMetrics().stringWidth(s); g.drawString(s, 270 - w/2, 450); s = "The breakout game in a breakout game"; w = g.getFontMetrics().stringWidth(s); g.drawString(s, 270 - w/2, 180); s = "Play with the left/right buttons"; w = g.getFontMetrics().stringWidth(s); g.drawString(s, 270 - w/2, 210); } // 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) { if (e.getID() == KeyEvent.KEY_PRESSED) { KeyEvent event = (KeyEvent) e; if (event.getKeyCode() == KeyEvent.VK_LEFT) { this.left = true; } if (event.getKeyCode() == KeyEvent.VK_RIGHT) { this.right = true; } } if (e.getID() == KeyEvent.KEY_RELEASED) { KeyEvent event = (KeyEvent) e; if (event.getKeyCode() == KeyEvent.VK_LEFT) { this.left = false; } if (event.getKeyCode() == KeyEvent.VK_RIGHT) { this.right = false; } if (event.getKeyCode() == KeyEvent.VK_ENTER) { this.enter = true; } } } }</=></=>