Commits

Linh Tran  committed 56e6450

Create new image asset

  • Participants
  • Parent commits cde82ce
  • Branches development

Comments (0)

Files changed (32)

File assets/coupon.png

Added
New image

File assets/im0.png

Added
New image

File assets/im1.png

Added
New image

File assets/im2.png

Added
New image

File assets/im3.png

Added
New image

File assets/im4.png

Added
New image

File assets/im5.png

Added
New image

File assets/im6.png

Added
New image

File assets/im7.png

Added
New image

File assets/im8.png

Added
New image

File assets/im9.png

Added
New image

File assets/img0.png

Removed
Old image

File assets/img1.png

Removed
Old image

File assets/img2.png

Removed
Old image

File assets/img3.png

Removed
Old image

File assets/img4.png

Removed
Old image

File assets/img5.png

Removed
Old image

File assets/img6.png

Removed
Old image

File assets/img7.png

Removed
Old image

File assets/img8.png

Removed
Old image

File assets/img9.png

Removed
Old image

File gen/com/androidgame/balloon/R.java

     }
     public static final class drawable {
         public static final int ic_launcher=0x7f020000;
-        public static final int icon=0x7f020001;
     }
     public static final class layout {
         public static final int main=0x7f030000;

File gen/com/androidgame/framework/R.java

+/* AUTO-GENERATED FILE.  DO NOT MODIFY.
+ *
+ * This class was automatically generated by the
+ * aapt tool from the resource data it found.  It
+ * should not be modified by hand.
+ */
+
+package com.androidgame.framework;
+
+public final class R {
+    public static final class attr {
+    }
+    public static final class drawable {
+        public static final int ic_launcher=0x7f020000;
+    }
+    public static final class layout {
+        public static final int main=0x7f030000;
+    }
+    public static final class string {
+        public static final int app_name=0x7f040001;
+        public static final int hello=0x7f040000;
+    }
+}

File gen/com/androidgame/framework/ngin/R.java

-/* AUTO-GENERATED FILE.  DO NOT MODIFY.
- *
- * This class was automatically generated by the
- * aapt tool from the resource data it found.  It
- * should not be modified by hand.
- */
-
-package com.androidgame.framework.ngin;
-
-public final class R {
-    public static final class attr {
-    }
-    public static final class drawable {
-        public static final int ic_launcher=0x7f020000;
-        public static final int icon=0x7f020001;
-    }
-    public static final class layout {
-        public static final int main=0x7f030000;
-    }
-    public static final class string {
-        public static final int app_name=0x7f040001;
-        public static final int hello=0x7f040000;
-    }
-}

File project.properties

 # project structure.
 
 # Project target.
-target=android-7
-android.library.reference.1=../YaEngine
+target=android-8
+android.library.reference.1=../YaEngineGL

File src/com/androidgame/balloon/Assets.java

 	public static Pixmap disSoundIc;
 	
 	public static Pixmap[] images;
+	public static Pixmap coupon;
 	
 	public static Sound click;
 	public static Sound balloon;

File src/com/androidgame/balloon/GameOverScreen.java

 		// Draw the help interface
 		Graphic g = game.getGraphics();
 		
-		String text = "Bạn đã bắt được " + Settings.lastScore + " khoảnh khắc của Hà Nội";
+		String text = "Bạn đã chụp được " + Settings.lastScore + " khoảnh khắc của Hà Nội";
+		String text_coupon = "Cùng với " + Settings.lastCoupon + " coupon giảm giá"; 
 		g.drawPixmap(Assets.endBg, 0, 0);
 		g.drawPixmap(Assets.contBt, 230, 120);
 		g.drawPixmap(Assets.mainBt, 450, 120);
-		g.drawGraphicText(text, 200, 90, 25, 0, true, "", "red");
+		g.drawGraphicText(text, 180, 50, 25, 0, true, "", "red");
+		g.drawGraphicText(text_coupon, 300, 80, 23, 0, true, "", "blue");
 	}
 
 	@Override

File src/com/androidgame/balloon/GameScreen.java

 package com.androidgame.balloon;
 
 import java.util.List;
+import java.util.Random;
 
 import com.androidgame.framework.Game;
 import com.androidgame.framework.Graphic;
 	
 	GameState state = GameState.Ready;
 	int oldScore;
+	int oldCoupon;
 	String score = "0";
-	long timeStart;
+	String coupon = "0";
+	double timeStart;
 	float timeMoment;
 	Stage stage;
+	Random random;
+	boolean isCoupon = false;
 	
 	public GameScreen(Game game) {
 		super(game);
 		this.stage = new Stage();
+		random = new Random();
 	}
 
 	@Override
 		}
 		
 		if (state == GameState.Moment) {
-			updateMoment(touchEvents);
+			updateMoment(touchEvents, deltaTime);
 		}
 		
 		if (state == GameState.Paused) {
 			
 		}
 		
-		stage.update(deltaTime, timeStart);
+		// Check if one second passed, decrease the timer
+		if (System.nanoTime() - timeStart >= 1000000000) {
+			stage.timeLeft--;
+			timeStart = System.nanoTime();
+		}
+		// If timer < 0 => game over
+		if (stage.timeLeft <= 0) {
+			stage.gameOver = true;
+		}
+		// Update the game world
+		stage.update(deltaTime);
 		if (stage.gameOver) {
 			state = GameState.Over;
 		}
 			oldScore = stage.score;
 			score = "" + oldScore;
 		}
+		
+		if (oldCoupon != stage.coupon) {
+			oldCoupon = stage.coupon;
+			coupon = "" + oldCoupon;
+		}
 	}
 	
-	private void updateMoment(List<TouchEvent> touchEvents) {
+	private void updateMoment(List<TouchEvent> touchEvents, float deltaTime) {
 		if ((System.nanoTime() - timeMoment)/1000000000.0f >= 1) {
 			state = GameState.Running;
 			return;
 		}		
+		updateRunning(touchEvents, deltaTime);
 	}
 
 	
 	public void touchMoment(TouchEvent touchEvent) {
 		for (Balloon item: stage.balloonList) {
 			if (inBounds(touchEvent, item.x, item.y, Stage.BALLOON_WIDTH, Stage.BALLOON_HEIGHT) && item.color == 0) {
+				isCoupon = false;
 				stage.score++;
 				// Use the red balloon's x,y to calculate the appearing image's x,y
 				stage.getImageXY(item.x, item.y);
 			}
 			
 			if (inBounds(touchEvent, item.x, item.y, Stage.BALLOON_WIDTH, Stage.BALLOON_HEIGHT) && item.color != 0) {
+				isCoupon = false;
+				if (random.nextInt(20) == 0) {
+					stage.coupon++;
+					stage.getImageXY(item.x, item.y);
+					timeMoment = System.nanoTime();
+					isCoupon = true;
+					state = GameState.Moment;
+				}
 				item.y = 490;
 				if (Settings.soundEnabled) {
 					Assets.balloon.play(1);
 		g.drawGraphicText(stage.calTimeLeft(), 738, 80, 23, 0, true, "", "white");
 		g.drawGraphicText("Score", 735, 120, 23, 0, true, "", "red");
 		g.drawGraphicText(score, 760, 150, 23, 1, true, "", "white");
+		g.drawGraphicText("Coupon", 725, 190, 21, 0, true, "", "red");
+		g.drawGraphicText(coupon, 760, 220, 23, 1, true, "", "white");
 		
 		if (Settings.soundEnabled) {
-			g.drawPixmap(Assets.enSoundIc, 745, 210);
+			g.drawPixmap(Assets.enSoundIc, 745, 260);
 		} else {
-			g.drawPixmap(Assets.disSoundIc, 745, 210);
+			g.drawPixmap(Assets.disSoundIc, 745, 260);
 		}
 		
-		g.drawPixmap(Assets.pauseIc, 745, 340);
+		g.drawPixmap(Assets.pauseIc, 745, 360);
 		
 		drawStage();
 		
 		Graphic g = game.getGraphics();
 		
 		// Draw the image after touch a red balloon
-		g.drawPixmap(Stage.image, Stage.image_x, Stage.image_y);
+		if (isCoupon) {
+			g.drawPixmap(Assets.coupon, Stage.image_x, Stage.image_y);
+		} else {
+			g.drawPixmap(Stage.image, Stage.image_x, Stage.image_y);
+		}
 	}
 
 	private void drawReadyUI() {
 			Settings.addScore(stage.score);
 			Settings.save(game.getFileIO());
 			Settings.lastScore = stage.score;
+			Settings.lastCoupon = stage.coupon;
 		}
 	}
 

File src/com/androidgame/balloon/HighscoreScreen.java

 	public HighscoreScreen(Game game) {
 		super(game);
 		
-		for (int i = 0; i < Settings.highscores.length; i++) {
-			lines[i] = "" + (i + 1) + ". " + "You:                " + Settings.highscores[i];
-		}
+//		for (int i = 0; i < Settings.highscores.length; i++) {
+//			lines[i] = "" + (i + 1) + ". " + "You:                " + Settings.highscores[i] + "   " + Settings.couponNum[i];
+//		}
 	}
 
 	@Override
 		g.drawPixmap(Assets.hscoreBg, 0, 0);
 		g.drawPixmap(Assets.mainBt, 80, 400);
 		g.drawPixmap(Assets.viewAllBt,580, 400);
+		g.drawGraphicText("Khoảnh khắc", 420, 120, 26, 1, true, "", "red");
+		g.drawGraphicText("Coupon", 580, 120, 26, 1, true, "", "blue");
 		drawScore(g);;
 	}
 	
 	private void drawScore(Graphic g) {
 		for (int i = 0; i < lines.length; i++) {
-			g.drawGraphicText(lines[i], 260, 160+i*24, 26, 0, true, "", "black");
+//			g.drawGraphicText(lines[i], 260, 160+i*24, 26, 0, true, "", "black");
+			drawLine(g, i);
 		}
 	}
+	
+	private void drawLine(Graphic g, int i) {
+		g.drawGraphicText(i+1+".", 260, 160+i*24, 26, 2, true, "", "red");
+		g.drawGraphicText("You", 280, 160+i*24, 26, 0, true, "", "black");
+		g.drawGraphicText(Settings.highscores[i]+"", 420, 160+i*24, 26, 1, true, "", "red");
+		g.drawGraphicText(Settings.couponNum[i]+"", 580, 160+i*24, 26, 1, true, "", "blue");
+	}
 
 	@Override
 	public void pause() {

File src/com/androidgame/balloon/LoadingScreen.java

 		Graphic g = game.getGraphics();
 		// Load game graphic and sound files
 		Assets.gameBg = g.newPixmap("game.png", PixmapFormat.ARGB8888);
-		Assets.helpBg = g.newPixmap("help.png", PixmapFormat.ARGB8888);
-		Assets.hscoreBg = g.newPixmap("highscore.png", PixmapFormat.ARGB8888);
-		Assets.endBg = g.newPixmap("notify.png", PixmapFormat.ARGB8888);
-		Assets.resumeBg = g.newPixmap("resume.png", PixmapFormat.ARGB8888);
-		Assets.startBg = g.newPixmap("start.png", PixmapFormat.ARGB8888);
-		Assets.helpBt = g.newPixmap("help_but.png", PixmapFormat.ARGB8888);
-		Assets.startBt = g.newPixmap("start_but.png", PixmapFormat.ARGB8888);
-		Assets.highscBt = g.newPixmap("highscore_but.png", PixmapFormat.ARGB8888);
-		Assets.mainBt = g.newPixmap("main_but.png", PixmapFormat.ARGB8888);
-		Assets.contBt = g.newPixmap("continue_but.png", PixmapFormat.ARGB8888);
-		Assets.viewAllBt = g.newPixmap("viewall_but.png", PixmapFormat.ARGB8888);
+		Assets.helpBg = g.newPixmap("help.png", PixmapFormat.RGB565);
+		Assets.hscoreBg = g.newPixmap("highscore.png", PixmapFormat.RGB565);
+		Assets.endBg = g.newPixmap("notify.png", PixmapFormat.RGB565);
+		Assets.resumeBg = g.newPixmap("resume.png", PixmapFormat.RGB565);
+		Assets.startBg = g.newPixmap("start.png", PixmapFormat.RGB565);
+		Assets.helpBt = g.newPixmap("help_but.png", PixmapFormat.RGB565);
+		Assets.startBt = g.newPixmap("start_but.png", PixmapFormat.RGB565);
+		Assets.highscBt = g.newPixmap("highscore_but.png", PixmapFormat.RGB565);
+		Assets.mainBt = g.newPixmap("main_but.png", PixmapFormat.RGB565);
+		Assets.contBt = g.newPixmap("continue_but.png", PixmapFormat.RGB565);
+		Assets.viewAllBt = g.newPixmap("viewall_but.png", PixmapFormat.RGB565);
 		Assets.redBl = g.newPixmap("red.png", PixmapFormat.ARGB8888);
 		Assets.blueBl = g.newPixmap("blue.png", PixmapFormat.ARGB8888);
 		Assets.violetBl = g.newPixmap("violet.png", PixmapFormat.ARGB8888);
 		Assets.butHeight = Assets.startBt.getHeight();
 		Assets.butWidth = Assets.startBt.getWidth();
 		
-		Assets.clockIc = g.newPixmap("clock.png", PixmapFormat.ARGB8888);
-		Assets.pauseIc = g.newPixmap("pause.png", PixmapFormat.ARGB8888);
-		Assets.enSoundIc = g.newPixmap("enable.png", PixmapFormat.ARGB8888);
-		Assets.disSoundIc = g.newPixmap("disable.png", PixmapFormat.ARGB8888);
+		Assets.clockIc = g.newPixmap("clock.png", PixmapFormat.RGB565);
+		Assets.pauseIc = g.newPixmap("pause.png", PixmapFormat.RGB565);
+		Assets.enSoundIc = g.newPixmap("enable.png", PixmapFormat.RGB565);
+		Assets.disSoundIc = g.newPixmap("disable.png", PixmapFormat.RGB565);
 		
+		Assets.coupon = g.newPixmap("coupon.png", PixmapFormat.ARGB4444);
 		Assets.images = new Pixmap[10];
 		for (int i = 0; i < 10; i++) {
-			Assets.images[i] = g.newPixmap("img"+i+".png", PixmapFormat.ARGB8888);
+			Assets.images[i] = g.newPixmap("im"+i+".png", PixmapFormat.ARGB4444);
 		}
 		
 		Assets.click = game.getAudio().newSound("click.ogg");

File src/com/androidgame/balloon/Settings.java

 	}
 	
 	public static boolean soundEnabled = true;
-	public static int[] highscores = new int[] { 100, 80, 50, 30, 10, 16, 17, 34, 45, 59 };
+	public static int[] highscores = new int[] { 100, 80, 59, 45, 36, 27, 25, 19, 15, 11 };
 	public static int lastScore;
+	public static int lastCoupon;
+	public static int[] couponNum = new int[] {10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
 	
 	public static void load(FileIO files) {
 		BufferedReader in = null;
+		String[] temp_array = new String[2];
 		try {
 			in = new BufferedReader(new InputStreamReader(files.readFile(".balloon")));
 //			soundEnabled = Boolean.parseBoolean(in.readLine());
 			for (int i = 0; i < 10; i++) {
-				highscores[i] = Integer.parseInt(in.readLine());
+				temp_array =  (in.readLine()).split(" ");;
+				highscores[i] = Integer.parseInt(temp_array[1]);
+				couponNum[i] = Integer.parseInt(temp_array[2]);
 			}
 		} catch (IOException e) {
 			// Default
 			out = new BufferedWriter(new OutputStreamWriter(files.writeFile(".mrnom")));
 //			out.write(Boolean.toString(soundEnabled));
 			for (int i = 0; i < 10; i++) {
-				out.write(Integer.toString(highscores[i]));
+				out.write(Integer.toString(highscores[i]) + " " + Integer.toString(couponNum[i]));
 				}
 		} catch (IOException e) {
 			// Default
 	}
 	
 	public static void addScore(int score) {
-		for (int i = 0; i < 5; i++) {
+		for (int i = 0; i < highscores.length; i++) {
 			if (highscores[i] < score) {
-				for (int j = 4; j > i; j--) {
+				for (int j = highscores.length - 1; j > i; j--) {
 					highscores[j] = highscores[j - 1];
 				}
 				highscores[i] = score;
 			}
 		}
 	}
+	
+	public static void addCoupon(int coupon) {
+		for (int i = 0; i < couponNum.length; i++) {
+			if (couponNum[i] < coupon) {
+				for (int j = couponNum.length - 1; j > i; j--) {
+					couponNum[j] = couponNum[j - 1];
+				}
+				couponNum[i] = coupon;
+				break;
+			}
+		}
+	}
 }

File src/com/androidgame/balloon/Stage.java

 import com.androidgame.framework.ngin.Pool.PoolObjectFactory;
 
 public class Stage {
-	static final float TICK = 0.04f;
+	static final float TICK = 0.03f;
 	static final int BALLOON_WIDTH = 46;
 	static final int BALLOON_HEIGHT = 54;
 	// Create the pool to hold and reuse balloon instance
 	public static Pixmap image;
 	public static int image_x;
 	public static int image_y;
-	int timeLeft = 1200;
+	int timeLeft = 120;
 	int createInterval = 0;
 	int score = 0;
+	int coupon = 0;
 	
 	public Stage() {
 		PoolObjectFactory<Balloon> factory = new PoolObjectFactory<Balloon>() {
 	}
 	
 	
-	public void update(float deltaTime, float timeStart) {
+	public void update(float deltaTime) {
 		if (gameOver) {
 			return;
 		}
-		int timePast = (int)(System.nanoTime() - timeStart)/1000000000;
-		timeLeft = timeLeft - timePast;
-		if (timeLeft <= 0) {
-			gameOver = true;
-		}
+		
 		tickTime += deltaTime;
 		// After TICK seconds update the state of the balloons
 		while (tickTime > TICK) {
 		}
 	}
 	public String calTimeLeft() {
-		int minute = timeLeft < 0 ? 0 : timeLeft / 600;
-		int second = timeLeft < 0 ? 0 : (timeLeft % 600)/10;
+//		int timeLeftSeconds = (int) (timeLeft/1000000);
+		int minute = (int) (timeLeft < 0 ? 0 : timeLeft / 60);
+		int second = (int) (timeLeft < 0 ? 0 : (timeLeft % 60));
 		String minute_s = "" + minute;
 		String second_s = second < 10 ? "0" + second : "" + second;
 		String time = minute_s + ":" + second_s;