Skip to content

Commit

Permalink
Redesign in game user interface
Browse files Browse the repository at this point in the history
  • Loading branch information
tbarthel-fr committed May 29, 2014
1 parent 49aa1ea commit 18a4349
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.RectF;
import android.graphics.drawable.BitmapDrawable;

import fr.tvbarthel.games.chasewhisply.R;
Expand All @@ -25,6 +26,8 @@ public class GameViewStandard extends GameView {
protected final Bitmap[] mBlondGhostBitmap;
protected final Bitmap[] mBlondTargetedBitmap;
protected final Bitmap mAmmoBitmap;
protected final Bitmap mTimerBitmap;
protected final Bitmap mScoreBitmap;
protected final Bitmap mBulletHoleBitmap;
protected final Bitmap mBabyGhostBitmap;
protected final Bitmap mTargetedBabyGhostBitmap;
Expand Down Expand Up @@ -55,7 +58,9 @@ public GameViewStandard(Context c, GameEngineStandard gameEngine) {
BitmapFactory.decodeResource(res, R.drawable.blond_ghost_in_tears_targeted),
BitmapFactory.decodeResource(res, R.drawable.blond_ghost_targeted),
};
mAmmoBitmap = BitmapFactory.decodeResource(res, R.drawable.ammo);
mAmmoBitmap = BitmapFactory.decodeResource(res, R.drawable.ic_ammo);
mTimerBitmap = BitmapFactory.decodeResource(res, R.drawable.ic_timer);
mScoreBitmap = BitmapFactory.decodeResource(res, R.drawable.ic_score);
mBulletHoleBitmap = BitmapFactory.decodeResource(res, R.drawable.bullethole);
mBabyGhostBitmap = BitmapFactory.decodeResource(res, R.drawable.baby_ghost);
mTargetedBabyGhostBitmap = BitmapFactory.decodeResource(res, R.drawable.baby_ghost_targeted);
Expand Down Expand Up @@ -198,8 +203,14 @@ protected void drawCrossHair(Canvas canvas) {
*/
protected void drawAmmo(Canvas canvas) {
final int currentAmmunition = mGameEngine.getCurrentAmmunition();
final String ammo = String.valueOf(currentAmmunition);
final int radius = Math.max(mAmmoBitmap.getWidth(), mAmmoBitmap.getHeight()) + (int) mPadding;
resetPainter();

//draw transparent overlay
useTransparentBlackPainter();
canvas.drawOval(new RectF(mScreenWidth - radius, mScreenHeight - radius, mScreenWidth + radius, mScreenHeight + radius), mPaint);

if (currentAmmunition == 0) {
useRedPainter();
final String noAmmoMessage = getResources().getString(R.string.in_game_no_ammo_message);
Expand All @@ -209,16 +220,17 @@ protected void drawAmmo(Canvas canvas) {
(mScreenHeight + mCrossHairs.getHeight()) / 2 + mBounds.height(),
mPaint);
} else {
useGreenPainter();
useWhitePainter();
}

canvas.drawBitmap(mAmmoBitmap, (float) (mScreenWidth - mAmmoBitmap.getWidth() - mPadding),
(float) (getHeight() - mAmmoBitmap.getHeight() - mPadding), mPaint);
canvas.drawBitmap(mAmmoBitmap, (float) (mScreenWidth - mAmmoBitmap.getWidth()),
(float) (getHeight() - mAmmoBitmap.getHeight()), mPaint);

mPaint.setTextSize(mAmmoBitmap.getHeight() / 2);
canvas.drawText(String.valueOf(currentAmmunition)
, mScreenWidth - mAmmoBitmap.getWidth() - mPaint.getTextSize() / 2 - mPadding
, mScreenHeight - (mAmmoBitmap.getHeight() / 4)
mPaint.getTextBounds(ammo, 0, ammo.length(), mBounds);
canvas.drawText(ammo
, mScreenWidth - radius
, mScreenHeight - radius + mBounds.height() / 2
, mPaint);
}

Expand Down Expand Up @@ -248,13 +260,22 @@ protected void drawCombo(Canvas canvas) {
*/
protected void drawScore(Canvas canvas) {
resetPainter();
useGreenPainter();
final String score = String.format(mScoreString, mGameEngine.getCurrentScore());
final String score = String.valueOf(mGameEngine.getCurrentScore());
final int radius = Math.max(mScoreBitmap.getWidth(), mScoreBitmap.getHeight()) + (int) mPadding;

//draw transparent overlay
useTransparentBlackPainter();
canvas.drawOval(new RectF(-radius, mScreenHeight - radius, radius, mScreenHeight + radius), mPaint);

//draw score icon
useWhitePainter();
canvas.drawBitmap(mScoreBitmap, 0, mScreenHeight - mScoreBitmap.getHeight(), mPaint);

//draw score
mPaint.getTextBounds(score, 0, score.length(), mBounds);
canvas.drawText(score
, mBounds.width() / 2 + mPadding
, mScreenHeight - mPaint.getTextSize()
, radius + mBounds.width() / 2
, mScreenHeight - radius + mBounds.height() / 2
, mPaint);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.RectF;

import fr.tvbarthel.games.chasewhisply.mechanics.engine.GameEngineTime;

Expand All @@ -28,13 +29,23 @@ public void onDrawing(Canvas c) {
protected void drawTimer(Canvas canvas) {
final long millis = mGameEngine.getCurrentTime();
final int seconds = (int) (millis / 1000);
final String remainingTime = String.format(mTimeString, seconds);
final String remainingTime = String.valueOf(seconds);
final int radius = Math.max(mTimerBitmap.getWidth(), mTimerBitmap.getHeight()) + (int) mPadding;
resetPainter();
useGreenPainter();

//draw transparent overlay
useTransparentBlackPainter();
canvas.drawOval(new RectF(-radius, -radius, radius, radius), mPaint);

//draw icon
useWhitePainter();
canvas.drawBitmap(mTimerBitmap, 0, 0, mPaint);

//draw time
mPaint.getTextBounds(remainingTime, 0, remainingTime.length(), mBounds);
canvas.drawText(remainingTime
, mPadding + mBounds.width() / 2
, mPadding + mPaint.getTextSize()
, mPadding + radius
, radius
, mPaint);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.RectF;

import fr.tvbarthel.games.chasewhisply.mechanics.engine.GameEngineTime;
import fr.tvbarthel.games.chasewhisply.mechanics.engine.GameEngineTwentyInARow;
Expand All @@ -19,16 +20,27 @@ public void onDrawing(Canvas c) {
drawCurrentStack(c);
}

@Override
protected void drawScore(Canvas canvas) {
//don't draw score
}

protected void drawCurrentStack(Canvas canvas) {
final int currentStack = ((GameEngineTwentyInARow) mGameEngine).getCurrentStack();
final String currentStackStr = String.valueOf(currentStack);
resetPainter();
useGreenPainter();
mPaint.getTextBounds(currentStackStr, 0, currentStackStr.length(), mBounds);
final int stackLength = currentStackStr.length();
final int radius = Math.max(mScreenWidth / (12 - stackLength), mScreenHeight / (12 - stackLength));

//draw transparent overlay
useTransparentBlackPainter();
canvas.drawOval(new RectF(-radius, mScreenHeight - radius, radius, mScreenHeight + radius), mPaint);

//draw Score
useWhitePainter();
mPaint.getTextBounds(currentStackStr, 0, currentStackStr.length(), mBounds);
canvas.drawText(currentStackStr
, mBounds.width() / 2 + mPadding
, mScreenHeight - mPaint.getTextSize() * 2 - mPadding
, mBounds.width() / 2 + radius / 4
, mScreenHeight - radius / 4
, mPaint);

}
Expand Down

0 comments on commit 18a4349

Please sign in to comment.