View Game: ApoSanta4k

ApoSanta4k

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

You are Santa Claus and you have to bring all the presents to the kids.

Instructions

Fly santas sled with the cursor keys and throw the presents with spacebar.

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.

< 50)) { lookup[i] = (dHeight+0.8)*Math.cos(dDiff + ((double)i/(double)lookup.length*Math.PI*dPi)); } else { lookup[i] = (dHeight+0.8)*Math.sin((double)i/(double)lookup.length*Math.PI*dPi); } } if (bFirst) { bFirst = false; values[2] = 0; } } } else { if (pressed[KeyEvent.VK_ESCAPE]) { values[2] = 0; pressed[KeyEvent.VK_ESCAPE] = false; } else { values[9] += 10; values[3] += 0.5f; values[0] += 10; values[1] += 0.01f; if (values[0] >= 90000) { values[2] = 0; } if (pressed[KeyEvent.VK_SPACE]) { if (values[9] > 1500) { values[9] = 0; int curInt = (int)(12 + values[8] * 4); values[curInt] = values[4] + 11; values[curInt + 1] = values[5] + 8; values[curInt + 2] = values[6]; values[curInt + 3] = 0.001f; values[8] += 1; } } float addVecX = 0; if (pressed[KeyEvent.VK_RIGHT]) { addVecX = 0.03f; } else if (pressed[KeyEvent.VK_LEFT]) { addVecX -= 0.03f; } values[6] += addVecX; if (values[6] < -1.5) values[6] = -1.5f; if (values[6] > 1.5) values[6] = 1.5f; values[4] += values[6]; if (addVecX == 0) values[6] *= 0.95f; if (values[4] < values[3]) values[4] = values[3]; if (values[4] + 39 > values[3] + 480) values[4] = values[3] + 441; float addVecY = 0.006f; if (pressed[KeyEvent.VK_DOWN]) { addVecY = 0.02f; } else if (pressed[KeyEvent.VK_UP]) { addVecY -= 0.02f; } values[7] += addVecY; if (values[7] < -1.1) values[7] = -1.1f; if (values[7] > 1.1) values[7] = 1.1f; values[5] += values[7]; if (addVecY == 0.006f) { values[7] *= 0.99f; } if (values[5] < 30) { values[5] = 30; values[7] = 0.001f; } if (this.getHeight(lookup, values[4] + 12) - 14 < values[5]) { values[2] = -1; values[8] = 0; for (i = 12; i < (int)(values.length); i += 4) { values[8] += 1; values[i] = values[4] + 11; values[i+1] = values[5] + 6; values[i+2] = (float)(Math.random() * 2.4) - 1.20f; values[i+3] = (float)(Math.random() * -0.7) - 0.3f; } break; } } } for (i = 12; i < (int)(12 + 4 * values[8]); i += 4) { if ((values[i+1] != 0) && (values[i] > values[3])) { if (values[i+3] != 0) { values[i] += values[i+2]; values[i+1] += values[i+3]; values[i+2] *= 0.99f; if ((values[i+2] > -0.001f) && (values[i+2] < 0.001f)) { values[i+2] = 0; } values[i+3] += 0.006f; int h = (int)this.getHeight(lookup, values[i]); if (values[i+1] > h) { values[i+3] = 0; if (values[2] > 0) { values[1] -= 2; } } if ((h - 20 < values[i+1]) && (values[2] > 0)) { boolean bBreak = false; for (int j=(int)(-35+values[i]);j<=(int)(values[i]+35);j++) { int pos = (int)(j); if (pos%45==0 && sin(lookup, (pos*0.3+sin(lookup, pos*0.2)+Math.PI*0.5))*sin(lookup, pos*0.1+Math.PI*0.5)>0) { for (int t = 0; t < target[0] + 1; t++) { if ((pos) == target[t]) { bBreak = true; break; } } if (!bBreak) { if ((pos - 16 < values[i]) && (pos + 17 > values[i])) { target[0] += 1; target[target[0]] = pos; values[1] += 10; values[i] = -1; } } } } } } } } } lastTime = now; // Renderabschnitt // Hintergrund malen g.setColor(new Color(40, 40, 80)); g.fillRect(0, 30, 480, 300 - 30); g.setColor(Color.WHITE); for (i = 0; i < snow.length; i+=4) { int change = (int)(values[3] % 480); int add = -change; if (snow[i] < change) { add += 480; } g.fillRect((int)(snow[i] - 1 + add), (int)(snow[i + 1] - 1) + 30, 2, 2); } g.setColor(new Color(150, 150, 190)); g.fillRect(0, 0, 480, 30); g.setColor(new Color(40, 40, 80)); g.drawRect(0, 0, 479, 30); /** render die Spielinfos */ g.setFont(g.getFont().deriveFont(20f).deriveFont(1)); s = "ApoSanta4k"; g.drawString(s, 240 - g.getFontMetrics().stringWidth(s)/2, 25); g.setFont(g.getFont().deriveFont(15f).deriveFont(1)); g.drawString("points: "+String.valueOf((int)(values[1])), 10, 25); s = "time: "+String.valueOf(90 - (int)(values[0]/1000)); g.drawString(s, 470 - g.getFontMetrics().stringWidth(s), 25); int xpos[]=new int[480+3],ypos[] = new int[480+3]; //g.fillRect((int)r.getMinX(),(int)(y+200),(int)r.getWidth(),(int)r.getHeight()); for (i=0;i <= 480;i++) { double pos = i + values[3]; double h = getHeight(lookup, pos); xpos[i] = i; ypos[i] = (int)h; } xpos[480+1] = 480; ypos[480+1] = 300; xpos[480+2] = 0; ypos[480+2] = 300; g.setColor(new Color(230,230,230)); g.fillPolygon(xpos,ypos,480+3); g.setColor(new Color(200,200,200)); g.setStroke(new BasicStroke(3)); g.drawPolyline(xpos,ypos,480); g.setStroke(new BasicStroke(1)); for (i=-20;i<480+20;i++) { int pos = (int)(i + values[3]); if (pos%(int)(sin(lookup, pos*0.1)*sin(lookup, pos*0.01+Math.PI*0.5)*8+30)==0 && sin(lookup, pos*0.25+sin(lookup, pos*0.2+0.2)+Math.PI*0.5)*sin(lookup, pos*0.11+Math.PI*0.5)>0) { g.drawImage(iImages[0],i,(int)(getHeight(lookup, pos)-18),null); } } for (i = 12; i < (int)(12 + 4 * values[8]); i += 4) { if ((values[i+1] != 0) && (values[i] > values[3])) { g.setColor(Color.YELLOW); g.fillRect((int)(values[i] - values[3] - 2), (int)(values[i+1] - 2), 5, 5); g.setColor(Color.RED); g.fillRect((int)(values[i] - values[3]), (int)(values[i+1] - 2), 1, 5); g.fillRect((int)(values[i] - values[3] - 2), (int)(values[i+1]), 5, 1); } } for (i=-35;i<=480+35;i++) { int pos = (int)(i + values[3]); if (pos%45==0 && sin(lookup, (pos*0.3+sin(lookup, pos*0.2)+Math.PI*0.5))*sin(lookup, pos*0.1+Math.PI*0.5)>0) { int h = (int)(getHeight(lookup, pos)-25); g.drawImage(iImages[2], pos - 16 - (int)(values[3]), h,null); for (x = 0; x < target[0] + 1; x++) { if (pos == target[x]) { g.setColor(new Color(255, 255, 135)); g.fillRect(pos - 16 - (int)(values[3]) + 20, h + 21, 3, 2); g.fillRect(pos - 16 - (int)(values[3]) + 20, h + 15, 3, 2); g.fillRect(pos - 16 - (int)(values[3]) + 20, h + 12, 3, 2); g.fillRect(pos - 16 - (int)(values[3]) + 10, h + 13, 2, 2); g.fillRect(pos - 16 - (int)(values[3]) + 13, h + 13, 2, 2); g.fillRect(pos - 16 - (int)(values[3]) + 10, h + 16, 5, 3); if (animation > 0) { g.setColor(new Color(224, 224, 224)); g.fillOval(pos - 16 - (int)(values[3]) + 22, h - 1, 3, 2); if (animation >= 2) { g.fillOval(pos - 16 - (int)(values[3]) + 22, h - 5, 4, 4); if (animation >= 3) { g.fillOval(pos - 16 - (int)(values[3]) + 23, h - 8, 3, 4); } } } } } } } g.drawImage(iImages[1], (int)(values[4] - values[3]), (int)(values[5]), null); g.setColor(new Color(115, 25, 20)); if (animation % 2 == 0) { g.drawLine((int)(values[4] - values[3] + 30), (int)(values[5] + 10), (int)(values[4] - values[3] + 26), (int)(values[5] + 14)); g.drawLine((int)(values[4] - values[3] + 33), (int)(values[5] + 10), (int)(values[4] - values[3] + 29), (int)(values[5] + 14)); } else { g.drawLine((int)(values[4] - values[3] + 30), (int)(values[5] + 10), (int)(values[4] - values[3] + 30), (int)(values[5] + 14)); g.drawLine((int)(values[4] - values[3] + 33), (int)(values[5] + 10), (int)(values[4] - values[3] + 33), (int)(values[5] + 14)); } if (values[2] <= 0) { if (values[1] > 0) { g.setColor(new Color(230,230,230)); g.setFont(g.getFont().deriveFont(30f).deriveFont(1)); s = "Hohohoho"; if (values[2] < 0) { s = "Oh no, Santa crashed"; } g.drawString(s, 240 - g.getFontMetrics().stringWidth(s)/2, 80); s = "You got "+(int)(values[1])+" points"; g.drawString(s, 240 - g.getFontMetrics().stringWidth(s)/2, 140); } s = "Press 'space' to start"; } else { s = "Press 'space' to throw a present"; } g.setColor(Color.BLACK); g.setFont(g.getFont().deriveFont(15f).deriveFont(1)); g.drawString(s, 240 - g.getFontMetrics().stringWidth(s)/2, 290); // 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; } } } /** * * @param x * @return Zahl aus lookuptabelle */ private double sin (double[] lookup, double x) { int i=(int)(x/Math.PI*lookup.length); i%=lookup.length; if(i<0) i+=lookup.length; return lookup[i]; } public double getHeight(double[] lookup, double pos) { pos*=0.25; return 310-(sin(lookup, pos*0.1)*5*sin(lookup, pos*0.01+Math.PI*0.5)+sin(lookup ,pos*0.01)*15+sin(lookup, pos*0.015)*sin(lookup, pos*0.02+Math.PI*0.5)*30+100); } @Override public void processEvent(AWTEvent e) { KeyEvent event = (KeyEvent) e; if (e.getID() == KeyEvent.KEY_PRESSED) { if (event.getKeyCode() < 256) { pressed[event.getKeyCode()] = true; } } if (e.getID() == KeyEvent.KEY_RELEASED) { if (event.getKeyCode() < 256) { pressed[event.getKeyCode()] = false; } } } }