[alienbloodbath commit] r94 - New public release. Finishing up level selection and high score mechanism.

2 views
Skip to first unread message

codesite...@google.com

unread,
Apr 29, 2009, 7:11:20 AM4/29/09
to alien-blood-b...@googlegroups.com
Author: matt.burkhart
Date: Tue Apr 28 22:41:06 2009
New Revision: 94

Added:
trunk/content_package/avatar_win.mp3 (contents, props changed)
trunk/create_demo.sh
Modified:
trunk/AndroidManifest.xml
trunk/install.sh
trunk/prepare_content.sh
trunk/res/layout/level_select_row.xml
trunk/sign-release.sh
trunk/src/android/com/abb/AlienBloodBathMain.java
trunk/src/android/com/abb/AvatarDatabase.java
trunk/src/android/com/abb/Content.java
trunk/src/android/com/abb/GameState.java
trunk/src/android/com/abb/LevelSelectActivity.java
trunk/src/android/com/abb/Weapon.java

Log:
New public release. Finishing up level selection and high score mechanism.

Modified: trunk/AndroidManifest.xml
==============================================================================
--- trunk/AndroidManifest.xml (original)
+++ trunk/AndroidManifest.xml Tue Apr 28 22:41:06 2009
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="android.com.abb"
- android:versionCode="5"
- android:versionName="2.0.1">
+ android:versionCode="6"
+ android:versionName="2.1.0">

- <uses-sdk minSdkVersion="3" />
+ <uses-sdk android:minSdkVersion="3" />

<uses-permission android:name="android.permission.VIBRATE" />


Added: trunk/content_package/avatar_win.mp3
==============================================================================
Binary file. No diff available.

Added: trunk/create_demo.sh
==============================================================================
--- (empty file)
+++ trunk/create_demo.sh Tue Apr 28 22:41:06 2009
@@ -0,0 +1,31 @@
+#!/bin/bash
+
+rm content_package/Demo/*
+
+cp content_package/The_Second_Wave/ak47.*
content_package/Demo/
+cp content_package/The_Second_Wave/aug.*
content_package/Demo/
+
+cp content_package/The_Second_Wave/hopper.*
content_package/Demo/
+cp content_package/The_Second_Wave/big_hopper.*
content_package/Demo/
+cp content_package/The_Second_Wave/slimer.*
content_package/Demo/
+cp content_package/The_Second_Wave/fast_slimer.*
content_package/Demo/
+
+cp content_package/The_Second_Wave/background_industrial.jpg
content_package/Demo/
+cp content_package/The_Second_Wave/background_forest.jpg
content_package/Demo/
+
+cp content_package/The_Second_Wave/tiles_industrial.png
content_package/Demo/
+cp content_package/The_Second_Wave/tiles_forest.png
content_package/Demo/
+
+cp content_package/The_Second_Wave/level_0.txt
content_package/Demo/
+cp content_package/The_Second_Wave/level_1.txt
content_package/Demo/
+cp content_package/The_Second_Wave/level_2.txt
content_package/Demo/
+
+cp content_package/The_Second_Wave/description_0.txt
content_package/Demo/
+cp content_package/The_Second_Wave/description_1.txt
content_package/Demo/
+cp content_package/The_Second_Wave/description_2.txt
content_package/Demo/
+
+cp content_package/The_Second_Wave/tiles_default.txt
content_package/Demo/
+cp content_package/The_Second_Wave/tiles_2.txt
content_package/Demo/
+
+cp content_package/The_Second_Wave/effects_default.txt
content_package/Demo/
+cp content_package/The_Second_Wave/effects_2.txt
content_package/Demo/

Modified: trunk/install.sh
==============================================================================
--- trunk/install.sh (original)
+++ trunk/install.sh Tue Apr 28 22:41:06 2009
@@ -1,5 +1,5 @@
#!/bin/bash

./prepare_content.sh
-ant reinstall

+ant reinstall

Modified: trunk/prepare_content.sh
==============================================================================
--- trunk/prepare_content.sh (original)
+++ trunk/prepare_content.sh Tue Apr 28 22:41:06 2009
@@ -1,13 +1,16 @@
#!/bin/bash

+./create_demo.sh
+
TARGET="res/raw/content_package.zip"
EPOCH="content_package/epoch.txt"

ALL_FILES=`find -L content_package | grep -v \~ | grep -v \.svn | grep -v
\.drop`
DEMO_FILES=`find -L content_package | grep -v \~ | grep -v \.svn | grep -v
\.drop | grep -v Classic | grep -v The_Second_Wave`

+CONTENT_FILES=$DEMO_FILES
+
rm $TARGET
rm $EPOCH
-
-cat $ALL_FILES | sha1sum > $EPOCH
-zip $TARGET $ALL_FILES $EPOCH
+cat $CONTENT_FILES | sha1sum > $EPOCH
+zip $TARGET $CONTENT_FILES $EPOCH

Modified: trunk/res/layout/level_select_row.xml
==============================================================================
--- trunk/res/layout/level_select_row.xml (original)
+++ trunk/res/layout/level_select_row.xml Tue Apr 28 22:41:06 2009
@@ -30,18 +30,27 @@
android:layout_height="wrap_content"
android:orientation="horizontal"
>
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:paddingLeft="5px"
+ android:paddingRight="3px"
+ android:gravity="center_vertical"
+ android:textSize="12sp"
+ android:textStyle="italic"
+ android:text="Best:"
+ />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5px"
android:paddingRight="3px"
- android:src="@drawable/time"
+ android:src="@drawable/kills"
/>
<TextView
- android:id="@+id/ROW_TIME"
+ android:id="@+id/ROW_KILLS"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:paddingRight="10px"
android:gravity="center_vertical"
android:textSize="14sp"
android:text="--"
@@ -49,11 +58,27 @@
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
+ android:paddingLeft="5px"
android:paddingRight="3px"
android:src="@drawable/health"
/>
<TextView
android:id="@+id/ROW_HEALTH"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:gravity="center_vertical"
+ android:textSize="14sp"
+ android:text="--"
+ />
+ <ImageView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:paddingLeft="5px"
+ android:paddingRight="3px"
+ android:src="@drawable/time"
+ />
+ <TextView
+ android:id="@+id/ROW_TIME"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"

Modified: trunk/sign-release.sh
==============================================================================
--- trunk/sign-release.sh (original)
+++ trunk/sign-release.sh Tue Apr 28 22:41:06 2009
@@ -1,3 +1,4 @@
-(jarsigner -verbose -keystore release-key.keystore -certs
bin/alienbloodbath-unsigned.apk release-key &&
- mv bin/alienbloodbath-unsigned.apk bin/alienbloodbath-release.apk)
+#!/bin/bash

+(jarsigner -verbose -keystore release-key.keystore -certs
bin/.LevelSelectActivity-unsigned.apk release-key &&
+ mv bin/.LevelSelectActivity-unsigned.apk bin/alienbloodbath-release.apk)

Modified: trunk/src/android/com/abb/AlienBloodBathMain.java
==============================================================================
--- trunk/src/android/com/abb/AlienBloodBathMain.java (original)
+++ trunk/src/android/com/abb/AlienBloodBathMain.java Tue Apr 28 22:41:06
2009
@@ -20,6 +20,7 @@
import android.view.MenuItem;
import android.view.Window;
import android.view.WindowManager;
+import junit.framework.Assert;


public class AlienBloodBathMain extends Activity {

Modified: trunk/src/android/com/abb/AvatarDatabase.java
==============================================================================
--- trunk/src/android/com/abb/AvatarDatabase.java (original)
+++ trunk/src/android/com/abb/AvatarDatabase.java Tue Apr 28 22:41:06 2009
@@ -30,6 +30,7 @@
SQLiteDatabase db = mDatabaseOpenHelper.getWritableDatabase();
db.execSQL("DELETE FROM " + kDatabaseTable + " " +
"WHERE avatar_key = \"" + key + "\"");
+ db.close();
}

String getStringValue(String key) {
@@ -44,6 +45,7 @@
result = cursor.getString(0);
}
cursor.close();
+ db.close();
return result;
}

@@ -52,6 +54,7 @@
db.execSQL("REPLACE INTO " + kDatabaseTable + " " +
"(avatar_key, avatar_value) VALUES " +
"(\"" + key + "\", \"" + value + "\")");
+ db.close();
}

private class AvatarDatabaseOpenHelper extends SQLiteOpenHelper {

Modified: trunk/src/android/com/abb/Content.java
==============================================================================
--- trunk/src/android/com/abb/Content.java (original)
+++ trunk/src/android/com/abb/Content.java Tue Apr 28 22:41:06 2009
@@ -230,6 +230,11 @@
return readFileAndSplit(file_path, "\\s");
}

+ static public String[] readUriLines(Uri uri) {
+ String file_path = getTemporaryFilePath(uri);
+ return readFileLines(file_path);
+ }
+
/** Utility method to parse a set of key value tokens (as generated by
* readFileTokens(...) for example) and to insert the key value pairs
into a
* map. Only values with keys already present in the map are accepted and

Modified: trunk/src/android/com/abb/GameState.java
==============================================================================
--- trunk/src/android/com/abb/GameState.java (original)
+++ trunk/src/android/com/abb/GameState.java Tue Apr 28 22:41:06 2009
@@ -48,9 +48,10 @@
mAudioManager =
(AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
mVibrator =
(Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);

+ preloadSound(kSoundEnemyDeath);
preloadSound(kSoundAvatarDamage);
preloadSound(kSoundAvatarDeath);
- preloadSound(kSoundEnemyDeath);
+ preloadSound(kSoundAvatarWin);
}

public void initializeGraphics(Graphics graphics) {
@@ -85,7 +86,10 @@
mViewX = mTargetViewX = avatar.x;
mViewY = mTargetViewY = avatar.y;
mDeathTimer = kDeathTimer;
+ mKills = 0;
mTimer = 0.0f;
+ mWinTimer = kWinTimer;
+ mHasWon = false;
}

public boolean onKeyDown(int key_code) {
@@ -113,7 +117,7 @@
mTimer += time_step;

// Update the view parameters.
- if (avatar.life > 0.0f) {
+ if (avatar.life > 0.0f && !mHasWon) {
if (!avatar.has_ground_contact) {
mTargetZoom = kAirZoom;
} else {
@@ -127,18 +131,49 @@
mViewX += (mTargetViewX - mViewX) * kViewSpeed * time_step;
mViewY += (mTargetViewY - mViewY) * kViewSpeed * time_step;

+ // If we have reached the goal, stop updating the motion of game
entities.
+ if (mHasWon) {
+ mTargetZoom = kWinZoom;
+ mWinTimer -= time_step;
+ if (mWinTimer < 0) {
+ finish();
+ }
+ return;
+ }
+
// Step the avatar.
if (avatar.life > 0.0f) {
avatar.step(time_step);
map.collideEntity(avatar);
map.processTriggers(avatar);
if (Map.tileIsGoal(map.tileAt(avatar.x, avatar.y))) {
+ mHasWon = true;
+ playSound(kSoundAvatarWin);
+ avatar.stop();
+
+ // Update the high score for this level. The order of score
precedence
+ // is: kill count, avatar health, and then level completion time.
AvatarDatabase avatar_database = new AvatarDatabase(mContext);
- avatar_database.setStringValue(
- map.getLevelString() + "_health", Float.toString(avatar.life));
- avatar_database.setStringValue(
- map.getLevelString() + "_time", Float.toString(mTimer));
- finish();
+ String level_kills =
+ avatar_database.getStringValue(map.getLevelString()
+ "_kills");
+ String level_health =
+ avatar_database.getStringValue(map.getLevelString()
+ "_health");
+ String level_time =
+ avatar_database.getStringValue(map.getLevelString() + "_time");
+ if (level_kills == null ||
+ mKills > Integer.valueOf(level_kills) ||
+ (mKills == Integer.valueOf(level_kills) &&
+ avatar.life > Float.valueOf(level_health)) ||
+ (mKills == Integer.valueOf(level_kills) &&
+ avatar.life == Float.valueOf(level_health) &&
+ mTimer < Float.valueOf(level_time))) {
+ avatar_database.setStringValue(
+ map.getLevelString() + "_kills", Integer.toString(mKills));
+ avatar_database.setStringValue(
+ map.getLevelString() + "_health",
Float.toString(avatar.life));
+ avatar_database.setStringValue(
+ map.getLevelString() + "_time", Float.toString(mTimer));
+ }
}
} else {
if (mDeathTimer == kDeathTimer) {
@@ -197,6 +232,9 @@
(enemy.y + projectile.y) / 2.0f,
projectile.dx / 2.0f, projectile.dy / 2.0f);
projectile.life = 0.0f;
+ if (enemy.life > 0 && enemy.life - projectile.damage < 0) {
+ mKills++;
+ }
enemy.life -= projectile.damage;
break;
}
@@ -353,11 +391,6 @@
}

public void playSound(Uri uri) {
- int volume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
- if (volume <= 0) {
- return;
- }
-
int sound_id = -1;
if (mSoundMap.containsKey(uri)) {
sound_id = mSoundMap.get(uri).intValue();
@@ -368,6 +401,7 @@
mSoundMap.put(uri, new Integer(sound_id));
}

+ int volume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
mSoundPool.play(sound_id, volume, volume,
1 /*Priority*/, 0 /*Loop*/, 1.0f /*Rate*/);
}
@@ -418,6 +452,8 @@
private Context mContext;
private float mDeathTimer = kDeathTimer;
private TreeMap<Uri, Enemy> mEnemyCache = new TreeMap<Uri,
Enemy>();
+ private boolean mHasWon;
+ private int mKills;
private LinkedList<String> mPendingNotifications = new
LinkedList<String>();
private Random mRandom = new Random();
private TreeMap<Uri, Integer> mSoundMap = new TreeMap<Uri,
Integer>();
@@ -430,6 +466,7 @@
private float mViewX = 0.0f;
private float mViewY = 0.0f;
private TreeMap<Uri, Weapon> mWeaponCache = new TreeMap<Uri,
Weapon>();
+ private float mWinTimer = kWinTimer;
private float mZoom = kGroundZoom;

private static final float kAirZoom = 0.6f;
@@ -445,8 +482,11 @@
private static final int kMaxSounds = 5;
private static final Uri kSoundAvatarDamage =
Uri.parse("content://avatar_damage.mp3");
private static final Uri kSoundAvatarDeath =
Uri.parse("content://avatar_death.mp3");
+ private static final Uri kSoundAvatarWin =
Uri.parse("content://avatar_win.mp3");
private static final Uri kSoundEnemyDeath =
Uri.parse("content://enemy_death.mp3");
private static final float kViewLead = 1.0f;
private static final float kViewSpeed = 2.0f;
+ private static final float kWinTimer = 3.5f;
+ private static final float kWinZoom = 1.7f;
private static final float kZoomSpeed = 1.0f;
}

Modified: trunk/src/android/com/abb/LevelSelectActivity.java
==============================================================================
--- trunk/src/android/com/abb/LevelSelectActivity.java (original)
+++ trunk/src/android/com/abb/LevelSelectActivity.java Tue Apr 28 22:41:06
2009
@@ -30,6 +30,7 @@
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
+import junit.framework.Assert;


public class LevelSelectActivity extends ListActivity {
@@ -86,14 +87,23 @@
String level_path = kRootDirectory + "level_" + level_index + ".txt";
Uri level_path_uri = Uri.parse(level_path);
if (Content.exists(level_path_uri)) {
- String level_string = kRootDirectory + level_index;
+ String level_string = kRootDirectory + level_index;
+ String level_kills =
+ avatar_database.getStringValue(level_string + "_kills");
String level_health =
avatar_database.getStringValue(level_string + "_health");
String level_time =
avatar_database.getStringValue(level_string + "_time");

Level level = new Level();
- if (level_time == null) {
+
+ String level_description_path =
+ kRootDirectory + "description_" + level_index + ".txt";
+ String[] description =
+ Content.readUriLines(Uri.parse(level_description_path));
+ level.name = description[0];
+
+ if (level_kills == null) {
Assert.assertNull(level_health);
level.complete = false;
mLevels.add(level);
@@ -101,6 +111,7 @@
} else {
level.complete = true;
level.health = Float.valueOf(level_health);
+ level.kills = Integer.valueOf(level_kills);
level.time = Float.valueOf(level_time);
mLevels.add(level);
}
@@ -133,20 +144,17 @@

ImageView icon = (ImageView)row_view.findViewById(R.id.ROW_ICON);
TextView label = (TextView)row_view.findViewById(R.id.ROW_LABEL);
- TextView time = (TextView)row_view.findViewById(R.id.ROW_TIME);
+ TextView kills = (TextView)row_view.findViewById(R.id.ROW_KILLS);
TextView health = (TextView)row_view.findViewById(R.id.ROW_HEALTH);
+ TextView time = (TextView)row_view.findViewById(R.id.ROW_TIME);

- if (level.complete) {
- icon.setImageResource(R.drawable.level_old);
- }
label.setText("Stage " + (position + 1) + ": " + level.name);
if (level.complete) {
DecimalFormat formatter = new DecimalFormat("0.0");
time.setText(formatter.format(level.time) + "s");
- }
- if (level.complete) {
- DecimalFormat formatter = new DecimalFormat("0.0");
health.setText(formatter.format(100.0f * level.health) + "%");
+ kills.setText(Integer.toString(level.kills));
+ icon.setImageResource(R.drawable.level_old);
}
return row_view;
}
@@ -157,12 +165,14 @@
private class Level {
public boolean complete;
float health;
- float time;
+ int kills;
String name;
+ float time;
}

private LevelArrayAdapter mLevelArrayAdapter;
private ArrayList<Level> mLevels = new ArrayList<Level>();

- private final String kRootDirectory = "content:///The_Second_Wave/";
+ private final String kRootDirectory = "content:///Demo/";
+ //private final String kRootDirectory = "content:///The_Second_Wave/";
}

Modified: trunk/src/android/com/abb/Weapon.java
==============================================================================
--- trunk/src/android/com/abb/Weapon.java (original)
+++ trunk/src/android/com/abb/Weapon.java Tue Apr 28 22:41:06 2009
@@ -203,7 +203,8 @@
mDrawingMatrix.preRotate(
57.2958f * (float)Math.atan2(hand_ly - hand_ry, hand_lx -
hand_rx));
mDrawingMatrix.preTranslate(x_offset, y_offset);
- mDrawingMatrix.preScale(sprite_rect.width(), sprite_rect.height());
+ mDrawingMatrix.preScale(zoom * sprite_rect.width(),
+ zoom * sprite_rect.height());
graphics.drawImage(sprite_image, sprite_rect, mDrawingMatrix,
false, sprite_flipped_horizontal);
}

Reply all
Reply to author
Forward
0 new messages