Linh Tran avatar Linh Tran committed 3e8cb8b

finalize the project

Comments (0)

Files changed (10)

AndroidManifest.xml

     android:versionCode="1"
     android:versionName="1.0" >
 
-    <uses-sdk android:minSdkVersion="7" />
+    <uses-sdk android:minSdkVersion="8" />
 	<uses-permission android:name="android.permission.WAKE_LOCK" />
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
     
Add a comment to this file

assets/items.png

Old
Old image
New
New image
Added
New image

project.properties

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

src/com/androidgame/motorlite/AIMotor.java

 	}
 	
 	public void evade(int direct) {
-		super.changeLane(direct);
+		if (rand.nextFloat() <= 0.6f) {
+			super.changeLane(direct);
+		}
 	}
 	
 	public void hinder(Motor player) {
 		float gapX = position.x - player.position.x;
 		float gapY = position.y - player.position.y;
 		if (gapX >= 0 && gapX <= 5 && gapY != 0 && gapY != 0.4f && gapY != -0.4f) {
-			if (rand.nextFloat() > 0.2f) {
-				position.y = player.position.y;
+			float chance = gapX == 0 ? 0.9f : 0.5f;
+			if (rand.nextFloat() >= chance) {
+				if (position.y >= 4.6f) {
+					position.y -= 1.8f;
+				} else {
+					position.y += 1.8f;
+				}
 			}
 		}
 	}

src/com/androidgame/motorlite/Assets.java

     public static TextureRegion brick;
     public static TextureRegion milestone;
     public static TextureRegion flag;
+    public static TextureRegion minimap;
+    public static TextureRegion mapPlayer;
+    public static TextureRegion mapAI;
     
     public static Texture menus;
     public static TextureRegion pausedMenu;
     public static Texture motors;
     public static Animation motor;
     public static Animation aiMotor;
+    
     public static Texture fontTex;
+    public static Texture speedFontTex;
     
     public static Music music;
     public static Sound sound;
     
     public static Font font;
+    public static Font speedFont;
     
     public static void load(GLGame game) {
     	maps  = new Texture[4];
         nails = new TextureRegion(items, 128, 0, 64, 32);
         flag = new TextureRegion(items, 0, 64, 416, 416);
         milestone = new TextureRegion(items, 192, 0, 64, 64);
+        minimap = new TextureRegion(items, 256, 0, 640, 44);
+        mapPlayer = new TextureRegion(items, 896, 0, 10, 10);
+        mapAI = new TextureRegion(items, 928, 0, 10, 10);
         
         menus = new Texture(game, "menu.png");
         pausedMenu = new TextureRegion(menus, 0, 0, 144, 288);
         }
         
         motors = new Texture(game, "motors.png");
-        motor = new Animation(0.02f,
+        motor = new Animation(0.01f,
         		new TextureRegion(motors, 0, 0, 160, 160),
         		new TextureRegion(motors, 160, 0, 160, 160)
         );
-        aiMotor = new Animation(0.02f,
+        aiMotor = new Animation(0.01f,
         		new TextureRegion(motors, 0, 160, 160, 160),
         		new TextureRegion(motors, 160, 160, 160, 160)
        ); 
+        
+        speedFontTex = new Texture(game, "speedfont.png");
         fontTex = new Texture(game, "font.png");
         font = new Font(fontTex, 0, 0, 12, 21, 28);
+        speedFont = new Font(speedFontTex, 0, 0, 8, 32, 32);
 //        for (int i = 0; i < 2; i++) {
 //			motor[i] = new TextureRegion(motors, 0, 0+i*160, 160, 160);
 //		}

src/com/androidgame/motorlite/GameScreen.java

 	    if (state == GameState.GameOver) {
 	    	presentOverText();
 	    }
+	    
+	    if (state == GameState.Running) {
+	    	presentStatus();
+	    }
 	    gl.glDisable(GL10.GL_BLEND);
 	    fpsCounter.logFrame();
 	}
 	
-	public void presentReady(int ready) {
+	private void presentReady(int ready) {
 		batcher.drawSprite(344+144/2, 136+288/2, 144, 288, Assets.readyMenu[2-ready]);
 	}
 	
-	public void presentRunning() {
+	private void presentRunning() {
 		batcher.drawSprite(32, 256, 64, 192, Assets.leftMenu);
 		batcher.drawSprite(800-32, 256, 64, 192, Assets.rightMenu);
 	}
 	
-	public void presentPaused() {
+	private void presentStatus() {
+		batcher.beginBatch(Assets.speedFontTex);
+		Assets.speedFont.drawText(batcher, String.format("%.1f",5*world.player.velocity.x)+" KM /H", 20, 480-24, 18);
+		batcher.endBatch();
+		batcher.beginBatch(Assets.items);
+		batcher.drawSprite(480, 480-22, 640, 44, Assets.minimap);
+		presentMapMotors();
+		batcher.endBatch();
+	}
+	
+	private void presentMapMotors() {
+		float playerMapX = 160 + world.player.position.x/52 * 32;
+		float playerMapY = world.player.position.y >= 4.6f ? 480 - 11 : 480 - 33;
+		float aiMapX = 160 + world.aiPlayer.position.x/52 * 32;
+		float aiMapY = world.aiPlayer.position.y >= 4.6f ? 480 - 11 : 480 - 33;
+		batcher.drawSprite(playerMapX, playerMapY, 10, 10, Assets.mapPlayer);
+		batcher.drawSprite(aiMapX, aiMapY, 10, 10, Assets.mapAI);
+	}
+	
+	private void presentPaused() {
 		batcher.drawSprite(344+144/2, 136+288/2, 144, 288, Assets.pausedMenu);
 	}
 	
-	public void presentGameOver() {
+	private void presentGameOver() {
 		batcher.drawSprite(344+144/2, 136+288/2, 144, 288, Assets.gameOverMenu);
 	}
 	
-	public void presentOverText() {
+	private void presentOverText() {
 		batcher.beginBatch(overText);
 		TextureRegion textRegion = new TextureRegion(overText, 0, 0, overText.width, overText.height);
 		batcher.drawSprite(344+144/2, 136+288, overText.width, overText.height, textRegion);

src/com/androidgame/motorlite/Motor.java

 	public static final float ACCEL = 4f;
 	public boolean isLiftUp;
 	public boolean isReachGoal;
+	public boolean isStopped;
 	public int timePast;
 	public float startTime;
 	public int place;
 		super(x, y, WIDTH, HEIGHT);
 		isLiftUp = false;
 		isReachGoal = false;
+		isStopped = false;
 		timePast = 0;
 		startTime = 0;
 		stateTime = 0;
 //		state = 0;
 		this.motorType = type;
-		this.bounds = new Rectangle(x - WIDTH/2 + 0.5f, y - HEIGHT/2, WIDTH - 1f, 0.8f);
+		this.bounds = new Rectangle(x - WIDTH/2 + 0.5f, y - HEIGHT/2, WIDTH - 1f, 1f);
 	}
 	
 	public void update(float deltaTime) {
-		if (position.x >= World.WORLD_WIDTH - 20) {
+		if (position.x >= World.WORLD_WIDTH - 26) {
 			isReachGoal = true;
+		}
+		
+		if (position.x >= World.WORLD_WIDTH - 20) {
+			isStopped = true;
 			velocity.x = 0;
 			velocity.y = 0;
 		}
 		
-		if (!isReachGoal) {
+		if (!isStopped) {
 			if (velocity.x < MAX_VELOCITY) velocity.add(ACCEL*deltaTime, 0);
 			position.add(velocity.x*deltaTime, 0);
-			bounds.lowerLeft.set(position.x -WIDTH/2 + 0.5f, position.y - HEIGHT/2);
+			if (!isLiftUp) {
+				bounds.lowerLeft.set(position.x -WIDTH/2 + 0.5f, position.y - HEIGHT/2);
+			} else {
+				bounds.lowerLeft.set(position.x, position.y - HEIGHT/2);
+			}
 			if (System.nanoTime() - startTime >= 1000000000.0f) {
 				timePast++;
 				startTime = System.nanoTime();
 		isLiftUp = !isLiftUp;
 		if (isLiftUp == true) {
 			position.y += 0.4f;
-//			bounds.width = bounds.width / 2;
+			bounds.width = bounds.width / 2;
 		} else {
 			position.y -= 0.4f;
-//			bounds.width = bounds.width * 2;
+			bounds.width = bounds.width * 2;
 		}
 	}
 	

src/com/androidgame/motorlite/World.java

 import com.androidgame.framework.math.OverlapTester;
 
 public class World {
-	public static final float WORLD_WIDTH = 1024;
+	public static final float WORLD_WIDTH = 1040;
 	public static final float WORLD_HEIGHT = 15;
 	
 	public final Motor player;
 	public void generateRoad() {
 		int x = 25;
 		int y = 50;
-		while (x < WORLD_WIDTH - 34) {
+		while (x < WORLD_WIDTH - 36) {
 			addObstacle(x, rand.nextInt(3));
 			x += 6+rand.nextInt(20);
 		}
-		while (y < WORLD_WIDTH - 24) {
+		while (y < WORLD_WIDTH - 26) {
 			Milestone milestone = new Milestone(y, 5);
 			milestone.miles = (20 - y/50) + "";
 			milestones.add(milestone);
 	
 	private void checkClash() {
 		checkClashObstacles();
-		checkClassMotors();
+		checkClashMotors();
 	}
 	
 	private void checkClashObstacles() {
 			Obstacle obstacle = obstacles.get(i);
 			float dist = obstacle.position.x - player.position.x;
 			float dist2 = obstacle.position.x - aiPlayer.position.x;
-			if (dist >= 0 && dist < 10) {
+			if (dist >= -4.5f && dist <= 6) {
 				if (OverlapTester.overlapRectangles(player.bounds, obstacle.bounds)) {
 					player.hit(true);
 				}
 			}
 			
-			if (dist2 >= 0 && dist2 < 10) {
+			if (dist2 >= -4.5f && dist2 <= 6) {
 				if (dist2 <= 6 && isSameLane(aiPlayer.position.y, obstacle.position.y)) {
 					if (obstacle.position.y == 0.8f) {
 						aiPlayer.evade(1);
 		}
 	}
 	
-	private void checkClassMotors() {
+	private void checkClashMotors() {
 		float gapX = player.position.x - aiPlayer.position.x;
 		float gapY = player.position.y - aiPlayer.position.y;
-		if (gapX >= 0 && gapX <= 6) {
-			if (gapY == 0 || gapY == 0.4 || gapY == -0.4) {
+		if (gapX > 0 && gapX <= 6) {
+			if (gapY == 0 || gapY == 0.4f || gapY == -0.4f) {
 				if (aiPlayer.position.y >= 4.6) {
 					aiPlayer.evade(2);
 				} else {
 					aiPlayer.evade(1);
 				}
 			}
-			
+		
+		}
+		
+		if (gapX >= -4.5f && gapX <= 4.5f) {
 			if (OverlapTester.overlapRectangles(player.bounds, aiPlayer.bounds)) {
 				if (aiPlayer.position.x != player.position.x) {
 //					Motor hinderedOne = aiPlayer.position.x > player.position.x ? player : aiPlayer;
 	
 	private void checkGameOver() {
 		if (player.isReachGoal) {
-			isGameOver = true;
 			if (player.timePast < aiPlayer.timePast) {
 				player.place = 1;
 				aiPlayer.place = 2;
 				aiPlayer.place = 1;
 			}
 		}
+		
+		if (player.isStopped) {
+			isGameOver = true;
+		}
 	}
 	
 	private boolean isSameLane(float motorY, float obstacleY) {

src/com/androidgame/motorlite/WorldRenderer.java

 
 import javax.microedition.khronos.opengles.GL10;
 
-import android.util.Log;
+//import android.util.Log;
 
 import com.androidgame.framework.gl.Animation;
 import com.androidgame.framework.gl.Camera2D;
         gl.glEnable(GL10.GL_BLEND);
         gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
 		batcher.beginBatch(Assets.items);
-		batcher.drawSprite(World.WORLD_WIDTH - 24, 6, 13, 13, Assets.flag);
+		batcher.drawSprite(World.WORLD_WIDTH - 26, 6, 13, 13, Assets.flag);
 		batcher.endBatch();
 		
 		int len = world.milestones.size();
 		batcher.endBatch();
 		
 		batcher.beginBatch(Assets.fontTex);
-		Log.d("font Size", Assets.fontTex.width+"");
+//		Log.d("font Size", Assets.fontTex.width+"");
 		for (int i = 0; i < len; i++) {
 			Milestone milestone = world.milestones.get(i);
 			float posX = milestone.miles.length() > 1 ? milestone.position.x - 0.2f : milestone.position.x;
-			Assets.font.drawTextInWorld(batcher, milestone.miles, posX, milestone.position.y-0.2f, 32, 0.2f);
+			Assets.font.drawText(batcher, milestone.miles, posX, milestone.position.y-0.2f, 32, 0.2f);
 		}
 		batcher.endBatch();
 	}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.