- return jonathanhfisher.co.uk/m/SummerLand.jadPorted a special mini-game I created for BlackBerry at Christmas called 'WinterLand' to Mobile Processing, download the zip here (includes standard midlet and BlackBerry cod), chaged some graphics and added some missiles to avoid, just a proof-of-concept and not tweaked for playability. Source below displays some common gaming patterns, collision detection and parallax scrolling: double factor; double piDouble; int life = 100; int score = 0; int count = 0; int missileCount = 0; int numGroups = 5; int numMissiles = 4; int playerSpeed = 3; int flowerSpeed = 5; int missileSpeed = 7; int missileX; int missileY; int flowerX; int flowerY; int flowery1; int flowery2; int flowery3; int flowery4; int flowery5; int xpos; int ypos; int midgroundscroll1 = 0; int midgroundscroll2 = 240; int foregroundscroll1 = 0; int foregroundscroll2 = 240; int[] missilexArray = new int[numMissiles]; int[] missileyArray = new int[numMissiles]; int[] xArray = new int[numGroups]; int[] yArray = new int[numGroups]; boolean[] flowerLive1 = new boolean[numGroups]; boolean[] flowerLive2 = new boolean[numGroups]; boolean[] flowerLive3 = new boolean[numGroups]; boolean[] flowerLive4 = new boolean[numGroups]; boolean[] flowerLive5 = new boolean[numGroups]; boolean left = false; boolean right = false; boolean up = false; boolean down = false; PLabel label; PImage mg; PImage fg; PImage playerSprite; PImage missile; PImage s1; PImage s2; PImage s3; PImage s4; PImage s5; PImage gameover; void setup() { framerate(13); label = new PLabel("Score: " + score + " | Life " + life); label.align = CENTER; label.calculateBounds(4, 4, width - 8, height); label.setBounds(4, 4, width - 8, label.height); label.initialize(); mg = loadImage("parallaxMidground.png"); fg = loadImage("parallaxForeground.png"); playerSprite = loadImage("playerSprite.png"); missile = loadImage("missile.png"); s1 = loadImage("s1.png"); s2 = loadImage("s2.png"); s3 = loadImage("s3.png"); s4 = loadImage("s4.png"); s5 = loadImage("s5.png"); gameover = loadImage("gameover.png"); xpos = width/2; ypos = height/2; initialiseCartesians(); initialiseMissileCartesians(); initialiseFlowerLiveArray(); } void draw() { background(123, 154, 255); label.draw(); //parallax image(mg, midgroundscroll1,height-100); image(mg, midgroundscroll2,height-100); image(fg, foregroundscroll1,height-50); image(fg, foregroundscroll2,height-50); if(life >0){ midgroundscroll1=midgroundscroll1-2; midgroundscroll2=midgroundscroll2-2; if(midgroundscroll1==-240){ midgroundscroll1=240; } if(midgroundscroll2==-240){ midgroundscroll2=240; } foregroundscroll1=foregroundscroll1-4; foregroundscroll2=foregroundscroll2-4; if(foregroundscroll1==-240){ foregroundscroll1=240; } if(foregroundscroll2==-240){ foregroundscroll2=240; } //calculate player position if(left && xpos > 0){xpos = xpos - playerSpeed;} if(right && xpos < width){xpos = xpos + playerSpeed;} if(up && ypos > 0){ypos = ypos - playerSpeed;} if(down && ypos < (height - 34)){ypos = ypos + playerSpeed;} //calculate and draw flowers for(int i = 0 ; i < numGroups ; i++){ flowerX = xArray[i]; flowerY = yArray[i]; if(flowerX < width){ if(flowerLive1[i] == true){ flowery1 = flowerY+getNormalizedSine(flowerX, 10, width); if(isCollision(flowerX+16, flowery1, flowerX+27, flowery1+11 )){ flowerLive1[i] = false; score = score + 11; }else{ image(s3, flowerX+16,flowery1); } } if(flowerLive2[i] == true){ flowery2 = flowerY+getNormalizedSine(flowerX+29, 10, width)+3; if(isCollision(flowerX+29, flowery2, flowerX+50, flowery2+21 )){ flowerLive2[i] = false; score = score + 21; }else{ image(s4, flowerX+29,flowery2); } } if(flowerLive3[i] == true){ flowery3 = flowerY+getNormalizedSine(flowerX+52, 10, width)+8; if(isCollision(flowerX+52, flowery3, flowerX+63, flowery3+11 )){ flowerLive3[i] = false; score = score + 31; }else{ image(s3, flowerX+52,flowery3); } } if(flowerLive4[i] == true){ flowery4 = flowerY+getNormalizedSine(flowerX+65, 10, width)+10; if(isCollision(flowerX+65, flowery4, flowerX+72, flowery4+7 )){ flowerLive4[i] = false; score = score + 41; }else{ image(s2, flowerX+65,flowery4); } } if(flowerLive5[i] == true){ flowery5 = flowerY+getNormalizedSine(flowerX+74, 10, width)+12; if(isCollision(flowerX+74, flowery5, flowerX+77, flowery5+3 )){ flowerLive5[i] = false; score = score + 51; }else{ image(s1, flowerX+74, flowery5); } } if(flowerX+74 < -3){ count++; } } } //calculate and draw missiles for(int i = 0 ; i < numMissiles ; i++){ if(isCollision(missilexArray[i], missileyArray[i]+14, missilexArray[i]+83, missileyArray[i])){ life = life-5; } if(missilexArray[i] < -85){ missileCount++; } image(missile, missilexArray[i], missileyArray[i]); } //all flowers offscreen? if (count == numGroups){ initialiseCartesians(); initialiseFlowerLiveArray(); } //all missiles offscreen? if(missileCount == numMissiles){ initialiseMissileCartesians(); } //reset count for next round count = 0; missileCount = 0; //move flowers to left updateCartesians(); updateMissileCartesians(); //draw player sprite image(playerSprite, xpos, ypos); }else{ image(gameover, (width/2)-63, (height/2)-11); } //update score/life label.text = "Score: " + (score/2) + " | Life " + life; } void keyPressed() { switch (keyCode) { case UP: up=true;down=false; break; case DOWN: down=true;up=false; break; case LEFT: left = true;right = false; break; case RIGHT: right = true;left = false; break; } } int getNormalizedSine(int x, int halfY, int maxX) { piDouble = 2 * Math.PI;//OOPS! - THIS SHOULD BE IN CONSTRUCTOR factor = piDouble / maxX; return (int) (Math.sin(x * factor) * halfY + halfY); } public void initialiseCartesians(){ for(int i = 0 ; i < numGroups ; i++){ xArray[i] = random(200)+width;//make sure group originates offscreen yArray[i] = random(height); } } public void initialiseMissileCartesians(){ for(int i = 0 ; i < numMissiles ; i++){ missilexArray[i] = random(200)+width;//make sure group originates offscreen missileyArray[i] = random(height); } } void initialiseFlowerLiveArray(){ for(int i = 0 ; i < numGroups ; i++){ flowerLive1[i] = true; flowerLive2[i] = true; flowerLive3[i] = true; flowerLive4[i] = true; flowerLive5[i] = true; } } public void updateCartesians(){ for(int i = 0 ; i < numGroups ; i++){ xArray[i] = xArray[i] - flowerSpeed; } } public void updateMissileCartesians(){ for(int i = 0 ; i < numMissiles ; i++){ missilexArray[i] = missilexArray[i] - missileSpeed; } } public boolean isCollision(int x1, int y1, int x2, int y2){ if(x1 > xpos+27)return false; if(x2 < xpos)return false; if(y1 > ypos+27)return false; if(y2 < ypos)return false; return true; } |