View Game: Flap4Kanabalt

Flap4Kanabalt (http://apo-games.de/flap4kanabalt/)

By ApoGames, submitted on Feb 22, 2014
Min JRE version: 1.6
1615 downloads.
This game was submitted in the Java4K 2014 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

Flap4Kanabalt is a mix of flappy bird and Canabalt.

Instructions

Press the mouse or the spacebar to start the game and to flap.

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.Color; import java.awt.Event; import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import javax.imageio.ImageIO; public class V extends Applet implements Runnable { @Override public void start() { new Thread(this).start(); } private boolean down; private final static char[] ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".toCharArray(); private static int[] toInt = new int[128]; static { for(int i=0; i< alphabet.length;="" i++){="" toint[alphabet[i]]="i;" }="" }="" *="" *="" translates="" the="" specified="" base64="" string="" into="" a="" byte="" array.="" *="" *="" @param="" s="" the="" base64="" string="" (not="" null)="" *="" @return="" the="" byte="" array="" (not="" null)="" */="" public="" static="" byte[]="" decode(string="" s){="" int="" delta="s.endsWith(" "="="" )="" 2="" :="" s.endswith(="" "=" ) ? 1 : 0; byte[] buffer = new byte[s.length()*3/4 - delta]; int mask = 0xFF; int index = 0; for(int i=0; i< s.length(); i+=4){ int c0 = toInt[s.charAt( i )]; int c1 = toInt[s.charAt( i + 1)]; buffer[index++]= (byte)(((c0 << 2) | (c1 >> 4)) & mask); if(index >= buffer.length){ return buffer; } int c2 = toInt[s.charAt( i + 2)]; buffer[index++]= (byte)(((c1 << 4) | (c2 >> 2)) & mask); if(index >= buffer.length){ return buffer; } int c3 = toInt[s.charAt( i + 3 )]; buffer[index++]= (byte)(((c2 << 6) | c3) & mask); } return buffer; } @Override public void run() { BufferedImage iBackground = new BufferedImage(320, 205, BufferedImage.TYPE_INT_ARGB_PRE); Graphics2D g = iBackground.createGraphics(); try { // g.drawImage(ImageIO.read(V.class.getResource(" a.png")),="" 0,="" 0,="" 320,="" 205,="" 0,="" 0,="" 120,="" 77,="" null);="" g.drawimage(imageio.read(new="" bytearrayinputstream(datatypeconverter.parsebase64binary(="" "r0lgodlheabnapeaaiaglrcwv2rqfqaaacwaaaaaeabnaeec/4ypqct94kkcniilfd670uwtebga5mslale2yjpgmfesnsmjthoiwv3bcxe6odemscqxyo2ocw1gl4bk9ym9aq3cbhd7rkam5ldkqjwrnbliuu2om9dsn/3ejg/l/d4rjofun0hyapi2goymnhd2+ahjgpz0gsgyizlz6mkpcfezego6+lkaynl62smct6rh+holikr6ekthmxibymvbzbsfasxcgpjbm8g3jnd5jpz3xnksiecvjbsodjx5nbznznlnfcmoysxmh2y+vs4iumwel49zca44j48ju2rronrsd5ambjd2dyhmattafszamztf758fib8cggzoicudip8thzteyfhitzek/1hcvtilnjuqgbxspkfyfi80y3y5sxomzpsqs02bv6zemji/n4uzblsougctw/n6dchyfwkvqs5dzeatmxbvk8berk/phy49b8gkajyf0zpwq6l9qy1zpanw63pl9i4iwq9287lml6evyd/b5joajlgrfxs2l15nbpehc4ysova+pkurrsz+mouslsf0qtakd9kqvhn0syecjzampdkka1cjmvpweag1a9got78aeeeha3+pf3bcuqm4ls7ki3p83nbmczxmwd3ecklgayptpapwdn5jbi3he0r3cx3gskfi4rb1il48m6bup07c+rjps8kpiupbon/oneodtddub1aizyh2gsitggb2crcx/j2izmh8srgugwvrvwavrxxcvzeeasaewxccwe1e+ug1xjbipuhwv4iimbu3bhlw1yezbknpigzud0+a5fr4hzxlxzjwfzemqzrweou1idqiljrohchog86ujk6ofjy4psulpml86ggywga5ijhmsqpxl0kmsyaby2r5povxeommu3dcvhitge1zl0xzpikgof3+rseghooj05+lsbeoygdpkchakcztaaa7"="" ))),="" 0,="" 0,="" 320,="" 205,="" 0,="" 0,="" 120,="" 77,="" null);="" g.drawimage(imageio.read(new="" bytearrayinputstream((new="" base64decoder()).decodebuffer(="" "r0lgodlheabnapeaaiaglrcwv2rqfqaaacwaaaaaeabnaeec/4ypqct94kkcniilfd670uwtebga5mslale2yjpgmfesnsmjthoiwv3bcxe6odemscqxyo2ocw1gl4bk9ym9aq3cbhd7rkam5ldkqjwrnbliuu2om9dsn/3ejg/l/d4rjofun0hyapi2goymnhd2+ahjgpz0gsgyizlz6mkpcfezego6+lkaynl62smct6rh+holikr6ekthmxibymvbzbsfasxcgpjbm8g3jnd5jpz3xnksiecvjbsodjx5nbznznlnfcmoysxmh2y+vs4iumwel49zca44j48ju2rronrsd5ambjd2dyhmattafszamztf758fib8cggzoicudip8thzteyfhitzek/1hcvtilnjuqgbxspkfyfi80y3y5sxomzpsqs02bv6zemji/n4uzblsougctw/n6dchyfwkvqs5dzeatmxbvk8berk/phy49b8gkajyf0zpwq6l9qy1zpanw63pl9i4iwq9287lml6evyd/b5joajlgrfxs2l15nbpehc4ysova+pkurrsz+mouslsf0qtakd9kqvhn0syecjzampdkka1cjmvpweag1a9got78aeeeha3+pf3bcuqm4ls7ki3p83nbmczxmwd3ecklgayptpapwdn5jbi3he0r3cx3gskfi4rb1il48m6bup07c+rjps8kpiupbon/oneodtddub1aizyh2gsitggb2crcx/j2izmh8srgugwvrvwavrxxcvzeeasaewxccwe1e+ug1xjbipuhwv4iimbu3bhlw1yezbknpigzud0+a5fr4hzxlxzjwfzemqzrweou1idqiljrohchog86ujk6ofjy4psulpml86ggywga5ijhmsqpxl0kmsyaby2r5povxeommu3dcvhitge1zl0xzpikgof3+rseghooj05+lsbeoygdpkchakcztaaa7"="" ))),="" 0,="" 0,="" 320,="" 205,="" 0,="" 0,="" 120,="" 77,="" null);="" g.drawimage(imageio.read(new="" bytearrayinputstream(decode(="" "r0lgodlheabnapeaaiaglrcwv2rqfqaaacwaaaaaeabnaeec/4ypqct94kkcniilfd670uwtebga5mslale2yjpgmfesnsmjthoiwv3bcxe6odemscqxyo2ocw1gl4bk9ym9aq3cbhd7rkam5ldkqjwrnbliuu2om9dsn/3ejg/l/d4rjofun0hyapi2goymnhd2+ahjgpz0gsgyizlz6mkpcfezego6+lkaynl62smct6rh+holikr6ekthmxibymvbzbsfasxcgpjbm8g3jnd5jpz3xnksiecvjbsodjx5nbznznlnfcmoysxmh2y+vs4iumwel49zca44j48ju2rronrsd5ambjd2dyhmattafszamztf758fib8cggzoicudip8thzteyfhitzek/1hcvtilnjuqgbxspkfyfi80y3y5sxomzpsqs02bv6zemji/n4uzblsougctw/n6dchyfwkvqs5dzeatmxbvk8berk/phy49b8gkajyf0zpwq6l9qy1zpanw63pl9i4iwq9287lml6evyd/b5joajlgrfxs2l15nbpehc4ysova+pkurrsz+mouslsf0qtakd9kqvhn0syecjzampdkka1cjmvpweag1a9got78aeeeha3+pf3bcuqm4ls7ki3p83nbmczxmwd3ecklgayptpapwdn5jbi3he0r3cx3gskfi4rb1il48m6bup07c+rjps8kpiupbon/oneodtddub1aizyh2gsitggb2crcx/j2izmh8srgugwvrvwavrxxcvzeeasaewxccwe1e+ug1xjbipuhwv4iimbu3bhlw1yezbknpigzud0+a5fr4hzxlxzjwfzemqzrweou1idqiljrohchog86ujk6ofjy4psulpml86ggywga5ijhmsqpxl0kmsyaby2r5povxeommu3dcvhitge1zl0xzpikgof3+rseghooj05+lsbeoygdpkchakcztaaa7"="" ))),="" 0,="" 0,="" 320,="" 205,="" 0,="" 0,="" 120,="" 77,="" null);="" }="" catch="" (exception="" e1)="" {="" }="" graphische="" grundlagen="" fãƒâ¼r="" das="" double="" buffering="" bufferedimage="" screen="new" bufferedimage(320,="" 480,="" bufferedimage.type_int_rgb);="" 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="10000000L;" string="" s="" ;="" int="" x="0;" int="" curframe="0;" int="" frametime="0;" int="" i="0;" int="" j="0;" int="" score="0;" int="" maxscore="0;" boolean="" bcurdown="false;" boolean="" bstart="false;" boolean="" bwin="false;" final="" float="" change_dif="1.2f;" final="" color="" downcolor="new" color(100,="" 106,="" 125);="" final="" color="" windowcolor="new" color(176,="" 176,="" 191);="" final="" color="" darkcolor="new" color(53,="" 53,="" 61);="" final="" color="" brightcolor="new" color(230,="" 230,="" 230);="" float="" playery="240;" float="" playerx="60;" float="" curvecy="0;" float="" curdif="0;" int[]="" level="new" int[4];="" level[0]="level[1]" =="" 400;="" 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 (this.down) { if (!bStart) { playerX = 60; playerY = 240; this.down = false; bCurDown = false; x = 400; curVecY = -1f; curDif = 0; score = 0; level = new int[2048]; for (i = 0; i < level.length;="" i="" +="4)" {="" level[i]="x;" level[i="" +="" 1]="(int)" (math.random()="" *="" 300)="" +="" 30;="" level[i="" +="" 2]="(int)" (math.random()="" *="" 50)="" +="" 70;="" level[i="" +="" 3]="(int)" (math.random()="" *="" 5)="" +="" 78;="" x="" +="165" +="" level[i="" +="" 2];="" }="" bstart="true;" bwin="false;" }="" if="" (bwin)="" {="" bwin="false;" bstart="false;" this.down="false;" playerx="60;" playery="240;" curdif="0;" if="" (maxscore="">< score)="" {="" maxscore="score;" }="" }="" }="" if="" (!bwin)="" {="" curdif="" +="CHANGE_DIF;" frametime="" +="10;" if="" (frametime="">= 200) { frameTime -= 200; curFrame += 1; if (curFrame > 3) { curFrame = 0; } } } if ((!bStart) && (curDif >= 0)) { curDif -= 10; } if (bStart) { playerY += curVecY; curVecY += 0.051f; if (bWin) { if (playerY + curFrame + 6 >= 460) { curVecY = 0; playerY = 460 - 6 - curFrame; } } if (playerY >= 460) { bWin = true; } if (playerY - 6 < 0)="" {="" playery="6;" if="" (curvecy="">< 0)="" {="" curvecy="0;" }="" }="" for="" (i="0;" i="">< level.length;="" i="" +="4)" {="" if="" (curdif="" +="" playerx="" +="" 6="">< level[i]="" -="" level[i="" +="" 2]="" 2)="" {="" break;="" }="" if="" (curdif=""> level[i] + level[i + 2] / 2) { continue; } if ((curDif + playerX - CHANGE_DIF < level[i])="" &&="" (curdif="" +="" playerx="">= level[i]) && (!bWin)) { score += 1; } if ((curDif + playerX + 6 > level[i] - level[i + 2] / 2) && (curDif + playerX - 6 < level[i]="" +="" level[i="" +="" 2]="" 2))="" {="" if="" ((playery="" -="" curframe="" -="" 6="">< level[i="" +="" 1])="" ||="" (playery="" -="" curframe="" +="" 6=""> level[i + 1] + level[i + 3])) { bWin = true; this.down = false; } } } // do action if ((this.down) && (!bCurDown)) { bCurDown = true; curVecY = -2.45f; } } if ((!this.down) && (bCurDown)) { bCurDown = false; } } lastTime = now; // Renderabschnitt // Hintergrund malen g.setColor(windowColor); g.fillRect(0, 0, 320, 140); g.setColor(downColor); g.fillRect(0, 320, 320, 140); g.drawImage(iBackground, 0, 138, null); g.setColor(darkColor); if (!bStart) { g.setFont(g.getFont().deriveFont(25f).deriveFont(1)); s = "Flap4kanabalt"; g.drawString(s, 160 - g.getFontMetrics().stringWidth(s) / 2, 30); g.setFont(g.getFont().deriveFont(20f).deriveFont(1)); s = "Tap to fly"; g.drawString(s, 160 - g.getFontMetrics().stringWidth(s) / 2, 100); g.setColor(windowColor); s = "a 4k mix of flappy bird"; g.drawString(s, 160 - g.getFontMetrics().stringWidth(s) / 2, 380); s = "and Canabalt"; g.drawString(s, 160 - g.getFontMetrics().stringWidth(s) / 2, 410); } g.setColor(darkColor); g.fillRect(0, 460, 320, 20); for (i = 0; i < level.length;="" i="" +="4)" {="" if="" (curdif="" +="" 320="">< level[i]="" -="" level[i="" +="" 2]="" 2)="" {="" break;="" }="" if="" (curdif=""> level[i] + level[i + 2] / 2) { continue; } g.setColor(darkColor); g.fillRect((int) (level[i] - curDif - level[i + 2] / 2), 0, level[i + 2], level[i + 1]); g.fillRect((int) (level[i] - curDif - level[i + 2] / 2), level[i + 1] + level[i + 3], level[i + 2], 460 - level[i + 1] - level[i + 3]); g.setColor(windowColor); for (x = level[i] - level[i + 2] / 2; x < level[i]="" +="" level[i="" +="" 2]="" 2="" -="" 14;="" x="" +="16)" {="" for="" (j="0;" j="">< level[i="" +="" 1]="" -="" 16;="" j="" +="16)" {="" g.fillrect((int)="" (x="" -="" curdif)="" +="" 4,="" j="" +="" 4,="" 8,="" 8);="" }="" }="" for="" (x="level[i]" -="" level[i="" +="" 2]="" 2;="" x="">< level[i]="" +="" level[i="" +="" 2]="" 2="" -="" 14;="" x="" +="16)" {="" for="" (j="level[i" +="" 1]="" +="" level[i="" +="" 3];="" j="">< 440;="" j="" +="16)" {="" g.fillrect((int)="" (x="" -="" curdif)="" +="" 4,="" j="" +="" 4,="" 8,="" 8);="" }="" }="" }="" g.setcolor(windowcolor);="" for="" (i="0;" i="">< 500;="" i="" +="10)" {="" for="" (j="0;" j="">< 20;="" j="" +="10)" {="" g.fillrect((int)="" (-curdif="" +="" 100)="" %="" 10="" +="" i,="" 465="" +="" j,="" 5,="" 5);="" }="" }="" g.setcolor(brightcolor);="" if="" (curframe="=" 0)="" {="" g.fillrect((int)="" (playerx="" -="" 14),="" (int)="" (playery="" -="" 12),="" 4,="" 8);="" g.fillrect((int)="" (playerx="" -="" 10),="" (int)="" (playery="" -="" 8),="" 4,="" 8);="" g.fillrect((int)="" (playerx="" -="" 6),="" (int)="" (playery="" -="" 4),="" 12,="" 12);="" g.fillrect((int)="" (playerx="" +="" 6),="" (int)="" (playery="" -="" 8),="" 4,="" 8);="" g.fillrect((int)="" (playerx="" +="" 10),="" (int)="" (playery="" -="" 12),="" 4,="" 8);="" }="" if="" ((curframe="=" 1)="" ||="" (curframe="=" 3))="" {="" g.fillrect((int)="" (playerx="" -="" 14),="" (int)="" (playery="" -="" 5),="" 28,="" 6);="" g.fillrect((int)="" (playerx="" -="" 6),="" (int)="" (playery="" +="" 1),="" 12,="" 6);="" }="" if="" (curframe="=" 2)="" {="" g.fillrect((int)="" (playerx="" -="" 14),="" (int)="" (playery="" +="" 6),="" 4,="" 8);="" g.fillrect((int)="" (playerx="" -="" 10),="" (int)="" (playery="" +="" 2),="" 4,="" 8);="" g.fillrect((int)="" (playerx="" -="" 6),="" (int)="" (playery="" -="" 6),="" 12,="" 12);="" g.fillrect((int)="" (playerx="" +="" 6),="" (int)="" (playery="" +="" 2),="" 4,="" 8);="" g.fillrect((int)="" (playerx="" +="" 10),="" (int)="" (playery="" +="" 6),="" 4,="" 8);="" }="" g.setfont(g.getfont().derivefont(16f).derivefont(1));="" s="best: " +="" maxscore;="" g.setcolor(windowcolor);="" g.fillrect(306="" -="" g.getfontmetrics().stringwidth(s),="" 2,="" g.getfontmetrics().stringwidth(s)="" +="" 8,="" 20);="" g.setcolor(darkcolor);="" g.drawrect(306="" -="" g.getfontmetrics().stringwidth(s),="" 2,="" g.getfontmetrics().stringwidth(s)="" +="" 8,="" 20);="" g.drawstring(s,="" 310="" -="" g.getfontmetrics().stringwidth(s),="" 18);="" if="" (bstart)="" {="" g.setfont(g.getfont().derivefont(35f).derivefont(1));="" if="" (bwin)="" {="" s="Score: " +="" score;="" x="g.getFontMetrics().stringWidth(s);" g.setcolor(windowcolor);="" g.fillrect(150="" -="" x/2,="" 210,="" x="" +="" 20,="" 60);="" g.setcolor(darkcolor);="" g.drawrect(150="" -="" x/2,="" 210,="" x="" +="" 20,="" 60);="" g.drawstring(s,="" 160="" -="" x="" 2,="" 257);="" }="" else="" {="" if="" ((!bwin)="" &&="" (bstart))="" {="" s="" +="" score;="" g.drawstring(s,="" 160="" -="" g.getfontmetrics().stringwidth(s)="" 2,="" 60);="" }="" }="" }="" render="" das="" ganze="" auf="" den="" bildschirm="" appletgraphics.drawimage(screen,="" 0,="" 0,="" null);="" try="" {="" thread.sleep(4);="" }="" catch="" (exception="" e)="" {="" *="" nicht="" schãƒâ¶n="" aber="" selten="" */="" }="" ;="" if="" (!isactive())="" {="" return;="" }="" }="" }="" @override="" public="" boolean="" handleevent(event="" e)="" {="" switch="" (e.id)="" {="" case="" event.key_press:="" case="" event.mouse_down:="" down="true;" break;="" case="" event.mouse_up:="" case="" event.key_release:="" down="false;" break;="" }="" return="" false;="" }="">