Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
vbarthel-fr committed May 29, 2014
2 parents dc9ce9f + 7c2674c commit a5790e1
Show file tree
Hide file tree
Showing 18 changed files with 83 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,21 @@ protected void useRedPainter() {
mPaint.setShadowLayer(5, 5, 5, R.color.holo_dark_red);
}

protected void useTransparentBlackPainter() {
mPaint.setColor(getResources().getColor(R.color.transparent_grey));
mPaint.setShadowLayer(0, 0, 0, R.color.transparent_grey);
}

protected void useTransparentGreenPainter() {
mPaint.setColor(getResources().getColor(R.color.transparent_green));
mPaint.setShadowLayer(0, 0, 0, R.color.transparent_green);
}

protected void useWhitePainter() {
mPaint.setColor(getResources().getColor(R.color.white));
mPaint.setShadowLayer(5, 5, 5, R.color.alpha_shadow);
}

protected float getTextSizeFromStyle(Context context, int styleId) {
final TextView textView = new TextView(context);
textView.setTextAppearance(context, styleId);
Expand Down
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 @@ -41,6 +41,7 @@ protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
}


/**
* draw time, in red if time < 10 sec else in green
*
Expand All @@ -53,12 +54,7 @@ protected void drawTimer(Canvas canvas) {
resetPainter();
if (seconds > 5) {
if (!mRedCountDownTextView.getText().equals("")) mRedCountDownTextView.setText("");
useGreenPainter();
mPaint.getTextBounds(remainingTime, 0, remainingTime.length(), mBounds);
canvas.drawText(remainingTime
, mPadding + mBounds.width() / 2
, mPadding + mPaint.getTextSize()
, mPaint);
super.drawTimer(canvas);
} else if (seconds >= 0) {
final Animation currentAnimation = mRedCountDownTextView.getAnimation();
final String mayBeANewValue = String.valueOf(seconds);
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ChaseWhisply/src/main/res/drawable-mdpi/ic_ammo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions ChaseWhisply/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@
<color name="holo_dark_red">#CC0000</color>
<color name="background_grey">#e5e5e5</color>
<color name="text_view_grey">#888888</color>
<color name="transparent_grey">#AA666666</color>
<color name="transparent_green">#668a9d20</color>
</resources>

0 comments on commit a5790e1

Please sign in to comment.