[alienbloodbath commit] r73 - in trunk: . content_package res/layout res/values src/android/com/abb

3 views
Skip to first unread message

codesite...@google.com

unread,
Feb 21, 2009, 5:47:15 PM2/21/09
to alien-blood-b...@googlegroups.com
Author: matt.burkhart
Date: Sat Feb 21 14:36:43 2009
New Revision: 73

Removed:
trunk/content_package/weapons.png
Modified:
trunk/build.xml
trunk/content_package/jump.humanoid.animation
trunk/content_package/stand.humanoid.animation
trunk/res/layout/main.xml
trunk/res/values/strings.xml
trunk/src/android/com/abb/AlienBloodBathMain.java
trunk/src/android/com/abb/GameState.java
trunk/src/android/com/abb/GameView.java
trunk/src/android/com/abb/Map.java
trunk/src/android/com/abb/Weapon.java

Log:
Fixed weapon drawing. Updated avatar animations. Added loading progress
dialog box when loading. Improved loading performance. Removed background
drawing. Fixed orientation change bug.

Modified: trunk/build.xml
==============================================================================
--- trunk/build.xml (original)
+++ trunk/build.xml Sat Feb 21 14:36:43 2009
@@ -2,14 +2,14 @@
<!-- SDK Locations -->
<property name="sdk-folder" value="/usr/local/android-sdk" />
<property name="android-tools" value="/usr/local/android-sdk/tools" />
-
+
<!-- Application Package Name -->
<property name="application-package" value="android.com.abb" />

<!-- The intermediates directory -->
<!-- Eclipse uses "bin" for its own output, so we do the same. -->
<property name="outdir" value="bin" />
-
+
<!--
*************************************************************************************
-->
<!-- No user servicable parts below. -->


Modified: trunk/content_package/jump.humanoid.animation
==============================================================================
--- trunk/content_package/jump.humanoid.animation (original)
+++ trunk/content_package/jump.humanoid.animation Sat Feb 21 14:36:43 2009
@@ -15,8 +15,8 @@
shoulder_r 0.0 -110
shoulder_l 0.0 -110

-arm_r 0.0 140
-arm_l 0.0 135
+arm_r 0.0 240
+arm_l 0.0 120

farm_r 0.0 -95
farm_l 0.0 -90

Modified: trunk/content_package/stand.humanoid.animation
==============================================================================
--- trunk/content_package/stand.humanoid.animation (original)
+++ trunk/content_package/stand.humanoid.animation Sat Feb 21 14:36:43 2009
@@ -22,7 +22,7 @@
shoulder_l 2.0 200

arm_r 0.0 -110
-arm_l 0.0 140
+arm_l 0.0 160

farm_r 0.0 -110
-farm_l 0.0 -80
+farm_l 0.0 -75

Modified: trunk/res/layout/main.xml
==============================================================================
--- trunk/res/layout/main.xml (original)
+++ trunk/res/layout/main.xml Sat Feb 21 14:36:43 2009
@@ -2,26 +2,11 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
-
+
<android.com.abb.GameView
android:id="@+id/GAME_VIEW"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:focusableInTouchMode="true"/>

- <RelativeLayout
- android:layout_width="fill_parent"
- android:layout_height="fill_parent" >
- <TextView
- android:id="@+id/TEXT_VIEW"
- android:text="@string/title_text"
- android:visibility="visible"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_centerInParent="true"
- android:layout_alignParentTop="true"
- android:gravity="center"
- android:textColor="#eeffffff"
- android:textSize="14sp"/>
- </RelativeLayout>
</FrameLayout>

Modified: trunk/res/values/strings.xml
==============================================================================
--- trunk/res/values/strings.xml (original)
+++ trunk/res/values/strings.xml Sat Feb 21 14:36:43 2009
@@ -1,13 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Alien Blood Bath</string>
- <string name="title_text">
- Goal: Find the red flag, shoot aliens on the way!\n
- <b>Move left - a\n
- Move right - s\n
- Shoot - j\n
- Jump - k</b>\n
- \n
- <i>For game options, press 'Menu'.</i>
- </string>
</resources>

Modified: trunk/src/android/com/abb/AlienBloodBathMain.java
==============================================================================
--- trunk/src/android/com/abb/AlienBloodBathMain.java (original)
+++ trunk/src/android/com/abb/AlienBloodBathMain.java Sat Feb 21 14:36:43
2009
@@ -21,7 +21,6 @@
import android.view.MenuItem;
import android.view.Window;
import android.view.WindowManager;
-import android.widget.TextView;


public class AlienBloodBathMain extends Activity {
@@ -37,13 +36,12 @@

mGameState = new GameState((Context)this);
mGameView = (GameView)findViewById(R.id.GAME_VIEW);
- mGameView.setTitleView((TextView)findViewById(R.id.TEXT_VIEW));
mGameView.setGame(mGameState);

if (saved_instance_state != null) {

mGameState.loadStateBundle(saved_instance_state.getBundle("mGameState"));
} else {
- mGameState.map.setUri(Uri.parse(kStartupMap));
+ mGameState.map.loadFromUri(Uri.parse(kStartupMap));
mGameState.reset();
}
}

Modified: trunk/src/android/com/abb/GameState.java
==============================================================================
--- trunk/src/android/com/abb/GameState.java (original)
+++ trunk/src/android/com/abb/GameState.java Sat Feb 21 14:36:43 2009
@@ -53,7 +53,6 @@
/** Initialize the game state structure. Upon returning the game state
should
* be in a state representing a new game "life". */
public void reset() {
- map.reload();
particles.clear();
projectiles.clear();
enemies.clear();
@@ -126,6 +125,7 @@
}
mDeathTimer -= time_step;
if (mDeathTimer < 0) {
+ map.reload();
reset();
}
}

Modified: trunk/src/android/com/abb/GameView.java
==============================================================================
--- trunk/src/android/com/abb/GameView.java (original)
+++ trunk/src/android/com/abb/GameView.java Sat Feb 21 14:36:43 2009
@@ -11,18 +11,9 @@

package android.com.abb;

+import android.app.ProgressDialog;
import android.content.Context;
-import android.content.res.Resources;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.graphics.Canvas;
-import android.graphics.Paint;
-import android.graphics.RectF;
-import android.graphics.drawable.Drawable;
-import android.os.Bundle;
import android.os.Debug;
-import android.os.Handler;
-import android.os.Message;
import android.util.AttributeSet;
import android.util.Log;
import android.view.KeyEvent;
@@ -30,7 +21,6 @@
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
-import android.widget.TextView;
import java.lang.Math;
import java.lang.System;
import java.lang.Thread;
@@ -39,12 +29,16 @@

public class GameView extends SurfaceView implements
SurfaceHolder.Callback {
class GameThread extends Thread {
- public GameThread(SurfaceHolder surface_holder) {
+ public GameThread(Context context, SurfaceHolder surface_holder) {
+ mContext = context;
+ mPaused = false;
+ mRunning = true;
mSurfaceHolder = surface_holder;
}

@Override
public void run() {
+ Log.d("GameThread::run", "Starting game thread...");
synchronized (this) {
while (mGame == null && mRunning) {
try {
@@ -115,7 +109,6 @@
time_step = Math.max(time_step, kMinTimeStep);
time_step = Math.min(time_step, kMaxTimeStep);

- Canvas canvas = null;
try {
synchronized (this) {
mGraphics.beginFrame();
@@ -124,8 +117,11 @@
} finally {
mGraphics.endFrame();
}
+ hideLoadingDialog();
}
+ Log.d("GameThread::run", "Freeing graphics resources...");
mGraphics.destroy();
+ Log.d("GameThread::run", "Finished game thread.");
}

synchronized public void setGame(Game game) {
@@ -150,15 +146,17 @@
notifyAll();
}

- boolean mRunning = true;
- boolean mPaused = false;
- Game mGame;
- Graphics mGraphics;
- SurfaceHolder mSurfaceHolder;
+ private Context mContext;
+ private Game mGame;
+ private Graphics mGraphics;
+ private boolean mPaused;
+ private boolean mRunning;
+ private SurfaceHolder mSurfaceHolder;
}

public GameView(Context context, AttributeSet attrs) {
super(context, attrs);
+ mContext = context;
getHolder().addCallback(this);
getHolder().setType(SurfaceHolder.SURFACE_TYPE_GPU);
}
@@ -170,20 +168,9 @@
}
}

- /** Set up the android widget for the title screen to be displayed until
any
- * key is pressed. */
- public void setTitleView(TextView title_view) {
- mTitleView = title_view;
- }
-
/** Standard override to get key-press events. */
@Override
public boolean onKeyDown(int key_code, KeyEvent msg) {
- if (!mTitleViewHidden) {
- mTitleView.setText("");
- mTitleViewHidden = true;
- }
-
if (key_code == kProfileKey) {
if (!mProfiling) {
Debug.startMethodTracing(kProfilePath);
@@ -213,18 +200,10 @@
@Override
public void onWindowFocusChanged(boolean window_has_focus) {
super.onWindowFocusChanged(window_has_focus);
- if (mGameThread != null) {
- mGameThread.pause(!window_has_focus);
- }
}

@Override
public boolean onTouchEvent(MotionEvent event) {
- if (!mTitleViewHidden) {
- mTitleView.setText("");
- mTitleViewHidden = true;
- }
-
synchronized (mGame) {
mGame.onMotionEvent(event);
}
@@ -234,13 +213,17 @@
/** Callback invoked when the Surface has been created and is ready to be
* used. */
public void surfaceCreated(SurfaceHolder holder) {
+ Log.d("GameView::surfaceCreated", "Creating new game thread...");
+ showLoadingDialog();
+
// Make sure we get key events and register our interest in hearing
about
// surface changes.
setFocusable(true);
getHolder().addCallback(this);
getHolder().setType(SurfaceHolder.SURFACE_TYPE_GPU);

- mGameThread = new GameThread(holder);
+ Assert.assertTrue(mGameThread == null);
+ mGameThread = new GameThread(mContext, holder);
mGameThread.setGame(mGame);
mGameThread.start();
mGameThreadStarted = true;
@@ -266,12 +249,27 @@
}
}

+ synchronized private void showLoadingDialog() {
+ if (mLoadingDialog == null) {
+ mLoadingDialog = ProgressDialog.show(
+ mContext, null, "Loading...", true, false);
+ mLoadingDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
+ }
+ }
+
+ synchronized private void hideLoadingDialog() {
+ if (mLoadingDialog != null) {
+ mLoadingDialog.dismiss();
+ mLoadingDialog = null;
+ }
+ }
+
+ private Context mContext;
private Game mGame;
private GameThread mGameThread;
private boolean mGameThreadStarted = false;
+ private ProgressDialog mLoadingDialog;
private boolean mProfiling = false;
- private TextView mTitleView;
- private boolean mTitleViewHidden = false;

private static final int kProfileKey = KeyEvent.KEYCODE_T;
private static final String kProfilePath = "abb.trace";

Modified: trunk/src/android/com/abb/Map.java
==============================================================================
--- trunk/src/android/com/abb/Map.java (original)
+++ trunk/src/android/com/abb/Map.java Sat Feb 21 14:36:43 2009
@@ -37,19 +37,12 @@
mGameState = game_state;
}

- public void setUri(Uri base_uri) {
- mBaseUri = base_uri;
- mLevelOffset = 0;
+ public void advanceLevel() {
+ mLevelOffset += 1;
}

public void reload() {
- if (mBaseUri != null) {
- loadFromUri(mBaseUri, mLevelOffset);
- }
- }
-
- public void advanceLevel() {
- mLevelOffset += 1;
+ loadFromUri(mBaseUri, mLevelOffset);
}

public void loadFromUri(Uri base_uri) {
@@ -82,16 +75,6 @@
String tiles_path = Content.getTemporaryFilePath(tiles_uri);
loadTilesFromFile(tiles_path);

- // Load background image.
- Uri background_uri =
- Uri.withAppendedPath(mBaseUri, "background_" + mLevelOffset
+ ".jpg");
- if (!Content.exists(background_uri))
- background_uri =
Uri.withAppendedPath(mBaseUri, "background_default.jpg");
- if (Content.exists(background_uri)) {
- String background_path =
Content.getTemporaryFilePath(background_uri);
- mBackgroundBitmap = BitmapFactory.decodeFile(background_path);
- }
-
// Load tile effects.
Uri effects_uri =
Uri.withAppendedPath(mBaseUri, "effects_" + mLevelOffset + ".txt");
@@ -349,35 +332,13 @@
mTilesImage = graphics.loadImageFromBitmap(mTilesBitmap);
mTilesBitmap = null;
}
- if (graphics.hasHardwareAcceleration() && mBackgroundBitmap != null) {
- graphics.freeImage(mBackgroundImage);
- mBackgroundImage = graphics.loadImageFromBitmap(mBackgroundBitmap);
- mBackgroundBitmap = null;
- }
-
- // Draw background.
- int canvas_width = graphics.getWidth();
- int canvas_height = graphics.getHeight();
- if (graphics.hasHardwareAcceleration() && mBackgroundImage != -1) {
- float scaled_background_size = kBackgroundScale * kBackgroundSize;
- mRectSource.left = mRectSource.top = 0;
- mRectSource.right = mRectSource.bottom = kBackgroundSize;
-
- mRectDest.left = -center_x / (kTileSize * kMapWidth) *
- (scaled_background_size - canvas_width);
- mRectDest.top = -center_y / (kTileSize * kMapHeight) *
- (scaled_background_size - canvas_height);
- mRectDest.right = mRectDest.left + scaled_background_size;
- mRectDest.bottom = mRectDest.top + scaled_background_size;
-
- graphics.drawImage(
- mBackgroundImage, mRectSource, mRectDest, false, false);
- }

// Draw tiles.
mRectSource.top = mRectSource.left = 0;
mRectSource.right = mRectSource.bottom = kTileSize;

+ int canvas_width = graphics.getWidth();
+ int canvas_height = graphics.getHeight();
int half_canvas_width = canvas_width / 2;
int half_canvas_height = canvas_height / 2;
float x_min = center_x - half_canvas_width / zoom;
@@ -457,8 +418,6 @@
return saved_instance_state;
}

- private Bitmap mBackgroundBitmap;
- private int mBackgroundImage = -1;
private Uri mBaseUri;
private boolean[] mEffectsDeath;
private boolean[] mEffectsExplode;
@@ -475,8 +434,6 @@
private int mTilesImage = -1;
private String[] mTriggers;

- private static final float kBackgroundScale = 2.0f;
- private static final int kBackgroundSize = 512;
private static final char kBaseValue = 'a';
private static final int kEndingTile = 11;
private static final int kExplodeVibrateLength = 40;

Modified: trunk/src/android/com/abb/Weapon.java
==============================================================================
--- trunk/src/android/com/abb/Weapon.java (original)
+++ trunk/src/android/com/abb/Weapon.java Sat Feb 21 14:36:43 2009
@@ -109,10 +109,10 @@
mPhase += 10.0f;

float shot_angle;
- float shot_distance = sprite_rect.width() / 2;
+ float shot_distance = 3 * sprite_rect.width() / 4;
float shot_velocity = mVelocity;
float x_offset = shot_distance;
- float y_offset = 0.0f;
+ float y_offset = -10.0f;

if (!has_ground_contact) {
shot_angle = mPhase;
@@ -161,12 +161,15 @@
// coordinates, not world coordinates. They are set via the
// setHandsPositions method.
if (sprite_image != -1) {
- mDrawingMatrix.setTranslate(hand_lx, hand_ly);
+ int x_offset = -sprite_rect.width() / 4;
+ int y_offset = -sprite_rect.height() / 2;
+ mDrawingMatrix.setTranslate(hand_rx, hand_ry);
mDrawingMatrix.preRotate(
- 57.2958f * (float)Math.atan2(hand_ry - hand_ly, hand_rx -
hand_lx));
+ 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());
graphics.drawImage(sprite_image, sprite_rect, mDrawingMatrix,
- sprite_flipped_horizontal,
sprite_flipped_vertical);
+ false, sprite_flipped_horizontal);
}
}

codesite...@google.com

unread,
Feb 21, 2009, 5:47:15 PM2/21/09
to alien-blood-b...@googlegroups.com

codesite...@google.com

unread,
Feb 21, 2009, 5:47:15 PM2/21/09
to alien-blood-b...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages