diff --git a/bin/Pacman.apk b/bin/Pacman.apk index 105fb53..d0e498d 100644 Binary files a/bin/Pacman.apk and b/bin/Pacman.apk differ diff --git a/bin/classes.dex b/bin/classes.dex index 15a0a8d..e396b63 100644 Binary files a/bin/classes.dex and b/bin/classes.dex differ diff --git a/bin/resources.ap_ b/bin/resources.ap_ index 6ef6c11..8b688a0 100644 Binary files a/bin/resources.ap_ and b/bin/resources.ap_ differ diff --git a/gen/com/adroid/game/pacman/R.java b/gen/com/adroid/game/pacman/R.java index dc24c89..bc4711f 100644 --- a/gen/com/adroid/game/pacman/R.java +++ b/gen/com/adroid/game/pacman/R.java @@ -1,85 +1,5 @@ -/* AUTO-GENERATED FILE. DO NOT MODIFY. - * - * This class was automatically generated by the - * aapt tool from the resource data it found. It - * should not be modified by hand. - */ - package com.adroid.game.pacman; +/* This stub is for using by IDE only. It is NOT the R class actually packed into APK */ public final class R { - public static final class attr { - } - public static final class drawable { - public static final int blue_gradien=0x7f020000; - public static final int corner=0x7f020001; - public static final int food=0x7f020002; - public static final int foodup=0x7f020003; - public static final int ghost=0x7f020004; - public static final int ghost_eat=0x7f020005; - public static final int ghost_eat2=0x7f020006; - public static final int ghost_eye=0x7f020007; - public static final int ic_launcher=0x7f020008; - public static final int inky=0x7f020009; - public static final int level1=0x7f02000a; - public static final int pacman=0x7f02000b; - public static final int pacman_final1=0x7f02000c; - public static final int pacmanta=0x7f02000d; - public static final int pacmantaa=0x7f02000e; - public static final int sfood=0x7f02000f; - public static final int streight=0x7f020010; - } - public static final class id { - public static final int menu_settings=0x7f080000; - } - public static final class layout { - public static final int activity_main=0x7f030000; - } - public static final class menu { - public static final int activity_main=0x7f070000; - } - public static final class raw { - public static final int lvl=0x7f040000; - public static final int lvl0=0x7f040001; - public static final int pacman_cherry=0x7f040002; - public static final int pacman_die=0x7f040003; - public static final int pacman_ghost_eating=0x7f040004; - public static final int pacman_siren=0x7f040005; - public static final int pacman_start=0x7f040006; - public static final int pacman_walk=0x7f040007; - public static final int pacmandie=0x7f040008; - } - public static final class string { - public static final int app_name=0x7f050000; - public static final int hello_world=0x7f050001; - public static final int menu_settings=0x7f050002; - } - public static final class style { - /** - Base application theme, dependent on API level. This theme is replaced - by AppBaseTheme from res/values-vXX/styles.xml on newer devices. - - - Theme customizations available in newer API levels can go in - res/values-vXX/styles.xml, while customizations related to - backward-compatibility can go here. - - - Base application theme for API 11+. This theme completely replaces - AppBaseTheme from res/values/styles.xml on API 11+ devices. - - API 11 theme customizations can go here. - - Base application theme for API 14+. This theme completely replaces - AppBaseTheme from BOTH res/values/styles.xml and - res/values-v11/styles.xml on API 14+ devices. - - API 14 theme customizations can go here. - */ - public static final int AppBaseTheme=0x7f060000; - /** Application theme. - All customizations that are NOT specific to a particular API-level can go here. - */ - public static final int AppTheme=0x7f060001; - } -} +} \ No newline at end of file diff --git a/res/raw/lvl0 b/res/raw/lvl0 index 49354e4..7b6afd4 100644 --- a/res/raw/lvl0 +++ b/res/raw/lvl0 @@ -19,13 +19,13 @@ x.xx..0000000000000000.....x x.xxxxxxx0xxxxxxxxx0xxxxxx.x x.xxxxxxx.xxxxxxxxx.xxxxxx.x x.xxx...............xx.....x -x.xxx.xxxxxxxx.xxxx.xx.xxxxx -x.xxx.xxxxxxxx.xxxx.xx.xxxxx +x.xxx.xxxxxxx.xxxxx.xx.xxxxx +x.xxx.xxxxxxx.xxxxx.xx.xxxxx xo........................ox -x.xxxxxxxxxxxx.xxxx.xxxxxx.x -x.xxxxxxxxxxxx.xxxx.xxxxxx.x -x.xxxxxxxxxxxx.xxxx.xxxxxx.x -x.xxxxxxxxxxxx.xxxx.xxxxxx.x +x.xxxxxxxxxxx.xxxxx.xxxxxx.x +x.xxxxxxxxxxx.xxxxx.xxxxxx.x +x.xxxxxxxxxxx.xxxxx.xxxxxx.x +x.xxxxxxxxxxx.xxxxx.xxxxxx.x x....xx.o..................x x.xx.xx.xxxxxxxxxx.xxxxxxx.x x.xx....xxxxxxxxxx.xxxxxxx.x diff --git a/src/com/android/game/pacman/game/GameLogic.java b/src/com/android/game/pacman/game/GameLogic.java index 09ea5b7..5930ab3 100644 --- a/src/com/android/game/pacman/game/GameLogic.java +++ b/src/com/android/game/pacman/game/GameLogic.java @@ -1,14 +1,8 @@ package com.android.game.pacman.game; -import java.util.LinkedList; -import java.util.Timer; - import android.content.Context; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Color; -import android.graphics.Matrix; import android.graphics.Paint; import android.hardware.Sensor; import android.hardware.SensorEvent; @@ -16,324 +10,318 @@ import android.hardware.SensorEventListener; import android.hardware.SensorManager; import android.os.CountDownTimer; import android.os.Vibrator; -import android.util.DisplayMetrics; -import android.util.Log; import android.view.SurfaceHolder; import android.view.SurfaceView; - import com.adroid.game.pacman.R; -import com.android.game.pacman.model.Block; -import com.android.game.pacman.model.Board; -import com.android.game.pacman.model.Collision; -import com.android.game.pacman.model.Ghost; -import com.android.game.pacman.model.PacMan; -import com.android.game.pacman.model.SolidObject; -import com.android.game.pacman.model.SoundStuff; -import com.android.game.pacman.model.Vect; +import com.android.game.pacman.model.*; import com.android.game.pacman.utils.GameEnum; +import java.util.LinkedList; + public class GameLogic extends SurfaceView implements SurfaceHolder.Callback, - SensorEventListener { + SensorEventListener { - private PacMan pacman; + private PacMan pacman; - private LinkedList wall; - private LinkedList path; - private LinkedList food; - private LinkedList ghosts; + private LinkedList wall; + private LinkedList path; + private LinkedList food; + private LinkedList ghosts; - public GameLoop loop; - private Board boardGame; - private SoundStuff ss; - private CountDownTimer task; - private SensorManager sensorManager; - private Vibrator v; + public GameLoop loop; + private Board boardGame; + private SoundStuff ss; + private CountDownTimer task; + private SensorManager sensorManager; + private Vibrator v; - private int points = 0; - private int eatInRow = 0; // mnoznik do zjedzonych duszkow - private boolean accOn; - private boolean start = false; + private int points = 0; + private int eatInRow = 0; // mnoznik do zjedzonych duszkow + private boolean accOn; + private boolean start = false; - private final static Paint paint = new Paint(); - public static int BOARD_TILE_SIZE; - public static int BOARD_HEIGHT; - public static int BOARD_WIDTH; - public final static int GHOST_EAT_POINT = 200; - public final static int FOODUP_POINT = 150; - public final static int FOOD_POINT = 50; - public static int WIDTH; - public static int HEIGHT; + private final static Paint paint = new Paint(); + public static int BOARD_TILE_SIZE; + public static int BOARD_HEIGHT; + public static int BOARD_WIDTH; + public final static int GHOST_EAT_POINT = 200; + public final static int FOODUP_POINT = 150; + public final static int FOOD_POINT = 50; + public static int WIDTH; + public static int HEIGHT; - public GameLogic(Context context, int w, int h) { - super(context); - setFocusable(true); - getHolder().addCallback(this); + public GameLogic(Context context, int w, int h) { + super(context); + setFocusable(true); + getHolder().addCallback(this); - WIDTH = w; - HEIGHT = h; + WIDTH = w; + HEIGHT = h; - loop = new GameLoop(getHolder(), this); - ss = new SoundStuff(context); - paint.setStyle(Paint.Style.FILL); - // przez 10 sek po 5 zaczna mrugac duchy - task = new CountDownTimer(10000, 1000) { - private boolean first = false; - private int ID; - int times = 0; + loop = new GameLoop(getHolder(), this); + ss = new SoundStuff(context); + paint.setStyle(Paint.Style.FILL); + // przez 10 sek po 5 zaczna mrugac duchy + task = new CountDownTimer(10000, 1000) { + private boolean first = false; + private int ID; + int times = 0; - @Override - public void onTick(long millisUntilFinished) { + @Override + public void onTick(long millisUntilFinished) { - if (!first) { - ID = SoundStuff.sp.play(SoundStuff.ghostSiren, 1, 1, 1, -1, - 1); + if (!first) { + ID = SoundStuff.sp.play(SoundStuff.ghostSiren, 1, 1, 1, -1, + 1); - for (Ghost ghost : ghosts) { - ghost.setEatable(true); - } - first = true; - } + for (Ghost ghost : ghosts) { + ghost.setEatable(true); + } + first = true; + } - if (times == 5) - for (Ghost ghost : ghosts) { - ghost.setBlinking(true); - } - else - times++; - } + if (times == 5) + for (Ghost ghost : ghosts) { + ghost.setBlinking(true); + } + else + times++; + } - @Override - public void onFinish() { - for (Ghost ghost : ghosts) { - ghost.reset(); - } - SoundStuff.sp.stop(ID); - eatInRow = 0; - first = false; - times = 0; + @Override + public void onFinish() { + for (Ghost ghost : ghosts) { + ghost.reset(); + } + SoundStuff.sp.stop(ID); + eatInRow = 0; + first = false; + times = 0; - } + } - }; + }; - } + } - public void render(Canvas canvas) { - // tlo - paint.setColor(Color.BLUE); - canvas.drawRect(0, 0, WIDTH, HEIGHT, paint); - // napis z punktami - paint.setColor(Color.WHITE); - paint.setTextSize(30); - canvas.drawText("Points: " + points, 10, getHeight() - 40, paint); + public void render(Canvas canvas) { + // tlo + paint.setColor(Color.BLUE); + canvas.drawRect(0, 0, WIDTH, HEIGHT, paint); + // napis z punktami + paint.setColor(Color.WHITE); + paint.setTextSize(30); + canvas.drawText("Points: " + points, 10, getHeight() - 40, paint); - for (Block obj : path) { - obj.draw(canvas); - } - for (SolidObject obj : food) { - obj.draw(canvas); - } - pacman.draw(canvas); - for (Ghost ghost : ghosts) { - ghost.draw(canvas); - } + for (Block obj : path) { + obj.draw(canvas); + } + for (SolidObject obj : food) { + obj.draw(canvas); + } + pacman.draw(canvas); + for (Ghost ghost : ghosts) { + ghost.draw(canvas); + } - } + } - public void loadNextLvl() { - task.cancel(); - pacman.stop(); - boardGame = new Board(getResources(), R.raw.lvl); + public void loadNextLvl() { + task.cancel(); + pacman.stop(); + boardGame = new Board(getResources(), R.raw.lvl); - wall = boardGame.getWall(); - path = boardGame.getPath(); - food = boardGame.getbGame(); - pacman = new PacMan(getResources(), new Vect((BOARD_TILE_SIZE - * BOARD_WIDTH / 2), BOARD_TILE_SIZE * 23), getContext(), - boardGame.getBlock(), 100f, 3); - ghosts = new LinkedList(); + wall = boardGame.getWall(); + path = boardGame.getPath(); + food = boardGame.getbGame(); + pacman = new PacMan(getResources(), new Vect((BOARD_TILE_SIZE + * BOARD_WIDTH / 2), BOARD_TILE_SIZE * 23), getContext(), + boardGame.getBlock(), 100f, 3); + ghosts = new LinkedList(); - ghosts.add(new Ghost(2, boardGame.getBlock(), getResources(), new Vect( - 11 * BOARD_TILE_SIZE, 14 * BOARD_TILE_SIZE))); - ghosts.add(new Ghost(2, boardGame.getBlock(), getResources(), new Vect( - 13 * BOARD_TILE_SIZE, 14 * BOARD_TILE_SIZE))); - ghosts.add(new Ghost(2, boardGame.getBlock(), getResources(), new Vect( - 15 * BOARD_TILE_SIZE, 14 * BOARD_TILE_SIZE))); - ghosts.add(new Ghost(2, boardGame.getBlock(), getResources(), new Vect( - 17 * BOARD_TILE_SIZE, 14 * BOARD_TILE_SIZE))); - int id = -1; - do { - id = SoundStuff.sp.play(SoundStuff.gameStart, 1, 1, 1, 0, 1); - } while (id == 0); - } + ghosts.add(new Ghost(2, boardGame.getBlock(), getResources(), new Vect( + 11 * BOARD_TILE_SIZE, 14 * BOARD_TILE_SIZE))); + ghosts.add(new Ghost(2, boardGame.getBlock(), getResources(), new Vect( + 13 * BOARD_TILE_SIZE, 14 * BOARD_TILE_SIZE))); + ghosts.add(new Ghost(2, boardGame.getBlock(), getResources(), new Vect( + 15 * BOARD_TILE_SIZE, 14 * BOARD_TILE_SIZE))); + ghosts.add(new Ghost(2, boardGame.getBlock(), getResources(), new Vect( + 17 * BOARD_TILE_SIZE, 14 * BOARD_TILE_SIZE))); + int id = -1; + do { + id = SoundStuff.sp.play(SoundStuff.gameStart, 1, 1, 1, 0, 1); + } while (id == 0); + } - public void update(double time) { + public void update(double time) { - pacman.update(time, getWidth(), getHeight()); - for (Ghost ghost : ghosts) { - ghost.update(time, getWidth(), getHeight()); - } - otherCollision(); - handleCollsion(); - if (food.isEmpty()) { - loadNextLvl(); - } + pacman.update(time, getWidth(), getHeight()); + for (Ghost ghost : ghosts) { + ghost.update(time, getWidth(), getHeight()); + } + otherCollision(); + handleCollsion(); + if (food.isEmpty()) { + loadNextLvl(); + } - } + } - public void doAi(int deficultiy) { - switch (deficultiy) { - case GameEnum.EASY: - // todo - break; - // todo - case GameEnum.NORMAL: - break; - case GameEnum.HARD: - // todo - break; - } + public void doAi(int deficultiy) { + switch (deficultiy) { + case GameEnum.EASY: + // todo + break; + // todo + case GameEnum.NORMAL: + break; + case GameEnum.HARD: + // todo + break; + } - } + } - private void otherCollision() { - for (SolidObject obj : food) { - if (Collision.detectNormalCollision(pacman.boundingRect, - obj.boundingRect)) { - obj.setIsTouched(true); + private void otherCollision() { + for (SolidObject obj : food) { + if (Collision.detectNormalCollision(pacman.boundingRect, + obj.boundingRect)) { + obj.setIsTouched(true); - } - } - for (Ghost ghost : ghosts) { - if (Collision.detectNormalCollision(pacman.boundingRect, - ghost.boundingRect)) { - if (ghost.isEatable()) { - ghost.setIsTouched(true); - eatInRow++; - points += GHOST_EAT_POINT * eatInRow; - SoundStuff.sp.play(SoundStuff.pacmanEatGhost, 1, 1, 1, 0, - 1f); - v.vibrate(100); + } + } + for (Ghost ghost : ghosts) { + if (Collision.detectNormalCollision(pacman.boundingRect, + ghost.boundingRect)) { + if (ghost.isEatable() && !ghost.isOnlyEyes()) { + ghost.setIsTouched(true); + ghost.reset(); + ghost.setEyes(true); + eatInRow++; + points += GHOST_EAT_POINT * eatInRow; + SoundStuff.sp.play(SoundStuff.pacmanEatGhost, 1, 1, 1, 0, + 1f); + v.vibrate(100); - } else - pacman.die(); - } - } + } else if (!ghost.isOnlyEyes()) + pacman.die(); + } + } - } + } - private void handleCollsion() { - for (int i = 0; i < food.size(); i++) { - if (food.get(i).getIsTouched()) { - if (food.get(i).kind == GameEnum.FOODUP) { - points += FOODUP_POINT; - v.vibrate(100); - task.onFinish(); - task.start(); + private void handleCollsion() { + for (int i = 0; i < food.size(); i++) { + if (food.get(i).getIsTouched()) { + if (food.get(i).kind == GameEnum.FOODUP) { + points += FOODUP_POINT; + v.vibrate(100); + task.onFinish(); + task.start(); - } else - points += FOOD_POINT; + } else + points += FOOD_POINT; - food.remove(i); + food.remove(i); - } + } - } - } + } + } - @Override - public boolean onTouchEvent(android.view.MotionEvent event) { + @Override + public boolean onTouchEvent(android.view.MotionEvent event) { - pacman.dir(event); + pacman.dir(event); - return true; - } + return true; + } - @Override - public void surfaceChanged(SurfaceHolder holder, int format, int width, - int height) { - WIDTH = width; - HEIGHT = height; - BOARD_TILE_SIZE = (int) (WIDTH / BOARD_WIDTH); + @Override + public void surfaceChanged(SurfaceHolder holder, int format, int width, + int height) { + WIDTH = width; + HEIGHT = height; + BOARD_TILE_SIZE = (int) (WIDTH / BOARD_WIDTH); - } + } - @Override - public void surfaceCreated(SurfaceHolder holder) { + @Override + public void surfaceCreated(SurfaceHolder holder) { - boardGame = new Board(getResources(), R.raw.lvl0); + boardGame = new Board(getResources(), R.raw.lvl0); - wall = boardGame.getWall(); - path = boardGame.getPath(); - food = boardGame.getbGame(); - pacman = new PacMan(getResources(), new Vect((BOARD_TILE_SIZE - * BOARD_WIDTH / 2), BOARD_TILE_SIZE * 23), getContext(), - boardGame.getBlock(), 100f, 3); - ghosts = new LinkedList(); + wall = boardGame.getWall(); + path = boardGame.getPath(); + food = boardGame.getbGame(); + pacman = new PacMan(getResources(), new Vect((BOARD_TILE_SIZE + * BOARD_WIDTH / 2), BOARD_TILE_SIZE * 23), getContext(), + boardGame.getBlock(), 100f, 3); + ghosts = new LinkedList(); - ghosts.add(new Ghost(2, boardGame.getBlock(), getResources(), new Vect( - 11 * BOARD_TILE_SIZE, 14 * BOARD_TILE_SIZE))); - ghosts.add(new Ghost(2, boardGame.getBlock(), getResources(), new Vect( - 13 * BOARD_TILE_SIZE, 14 * BOARD_TILE_SIZE))); - ghosts.add(new Ghost(2, boardGame.getBlock(), getResources(), new Vect( - 15 * BOARD_TILE_SIZE, 14 * BOARD_TILE_SIZE))); - ghosts.add(new Ghost(2, boardGame.getBlock(), getResources(), new Vect( - 17 * BOARD_TILE_SIZE, 14 * BOARD_TILE_SIZE))); - int id = -1; - do { - id = SoundStuff.sp.play(SoundStuff.gameStart, 1, 1, 1, 0, 1); - } while (id == 0); - sensorManager = (SensorManager) getContext().getSystemService( - getContext().SENSOR_SERVICE); - // add listener. The listener will be HelloAndroid (this) class - sensorManager.registerListener(this, - sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), - SensorManager.SENSOR_DELAY_GAME); - v = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE); - loop.setRunning(true); - loop.start(); - start = true; + ghosts.add(new Ghost(2, boardGame.getBlock(), getResources(), new Vect( + 11 * BOARD_TILE_SIZE, 14 * BOARD_TILE_SIZE))); + ghosts.add(new Ghost(2, boardGame.getBlock(), getResources(), new Vect( + 13 * BOARD_TILE_SIZE, 14 * BOARD_TILE_SIZE))); + ghosts.add(new Ghost(2, boardGame.getBlock(), getResources(), new Vect( + 15 * BOARD_TILE_SIZE, 14 * BOARD_TILE_SIZE))); + ghosts.add(new Ghost(2, boardGame.getBlock(), getResources(), new Vect( + 17 * BOARD_TILE_SIZE, 14 * BOARD_TILE_SIZE))); + int id = -1; + do { + id = SoundStuff.sp.play(SoundStuff.gameStart, 1, 1, 1, 0, 1); + } while (id == 0); + sensorManager = (SensorManager) getContext().getSystemService( + getContext().SENSOR_SERVICE); + // add listener. The listener will be HelloAndroid (this) class + sensorManager.registerListener(this, + sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), + SensorManager.SENSOR_DELAY_GAME); + v = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE); + loop.setRunning(true); + loop.start(); + start = true; - } + } - @Override - public void surfaceDestroyed(SurfaceHolder holder) { - boolean retry = true; - while (retry) { - try { - loop.join(); - retry = false; - } catch (InterruptedException e) { - } - } + @Override + public void surfaceDestroyed(SurfaceHolder holder) { + boolean retry = true; + while (retry) { + try { + loop.join(); + retry = false; + } catch (InterruptedException e) { + } + } - } + } - @Override - public void onAccuracyChanged(Sensor arg0, int arg1) { - // TODO Auto-generated method stub + @Override + public void onAccuracyChanged(Sensor arg0, int arg1) { + // TODO Auto-generated method stub - } + } - @Override - public void onSensorChanged(SensorEvent event) { - if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER && start) { + @Override + public void onSensorChanged(SensorEvent event) { + if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER && start) { - pacman.dirAcc(event); - } + pacman.dirAcc(event); + } - } + } - public boolean isAccOn() { - return accOn; - } + public boolean isAccOn() { + return accOn; + } - public void setAccOn(boolean accOn) { - this.accOn = accOn; - } + public void setAccOn(boolean accOn) { + this.accOn = accOn; + } - public void stop() { + public void stop() { - } + } } diff --git a/src/com/android/game/pacman/model/Ghost.java b/src/com/android/game/pacman/model/Ghost.java index 35927f6..c55eeb7 100644 --- a/src/com/android/game/pacman/model/Ghost.java +++ b/src/com/android/game/pacman/model/Ghost.java @@ -1,179 +1,187 @@ package com.android.game.pacman.model; -import java.util.LinkedList; - import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Rect; - import com.adroid.game.pacman.R; import com.android.game.pacman.game.GameLogic; import com.android.game.pacman.utils.GameEnum; +import java.util.LinkedList; + public class Ghost extends GameObject { - private LinkedList movement; - private Rect sourceRect; - // uzywane kied duszek jest do zjedzenia - private int spriteEatHeight; - private int spriteEatWidth; - private Rect sourceEatRect; + private LinkedList movement; + private Rect sourceRect; + // uzywane kied duszek jest do zjedzenia + private int spriteEatHeight; + private int spriteEatWidth; + private Rect sourceEatRect; - private Bitmap eyes; - private Bitmap eatableBitmap; + private Bitmap eyes; + private Bitmap eatableBitmap; - private boolean eatable = false; - private boolean onlyEyes = false; - private boolean blinking = false; + private boolean eatable = false; + private boolean onlyEyes = false; + private boolean blinking = false; - private double frameTicker; - private double framePeriod = 0.5f; - private boolean swap; + private double frameTicker; + private double framePeriod = 0.5f; + private boolean swap; - private double time; // do mrugania; - private int currentFrame; + private double time; // do mrugania; + private int currentFrame; - public Ghost(double speed, Block[][] board, Resources res, Vect initPosition) { - super(speed, board); + public Ghost(double speed, Block[][] board, Resources res, Vect initPosition) { + super(speed, board); - bitmap = BitmapFactory.decodeResource(res, - com.adroid.game.pacman.R.drawable.ghost); + bitmap = BitmapFactory.decodeResource(res, + com.adroid.game.pacman.R.drawable.ghost); - spriteHeight = bitmap.getHeight(); - spriteWidth = bitmap.getWidth() / 4; // ilosc dostepnych klatek - sourceRect = new Rect(0, 0, spriteWidth, spriteHeight); + spriteHeight = bitmap.getHeight(); + spriteWidth = bitmap.getWidth() / 4; // ilosc dostepnych klatek + sourceRect = new Rect(0, 0, spriteWidth, spriteHeight); - eatableBitmap = BitmapFactory - .decodeResource(res, R.drawable.ghost_eat2); - spriteEatHeight = eatableBitmap.getHeight(); - spriteEatWidth = eatableBitmap.getWidth() / 2; // ilosc dostepnych - // klatek - sourceEatRect = new Rect(0, 0, spriteWidth, spriteHeight); + eatableBitmap = BitmapFactory + .decodeResource(res, R.drawable.ghost_eat2); + spriteEatHeight = eatableBitmap.getHeight(); + spriteEatWidth = eatableBitmap.getWidth() / 2; // ilosc dostepnych + // klatek + sourceEatRect = new Rect(0, 0, spriteWidth, spriteHeight); - eyes = BitmapFactory.decodeResource(res, R.drawable.ghost_eye); + eyes = BitmapFactory.decodeResource(res, R.drawable.ghost_eye); - dirToChange = GameEnum.STOP; - this.res = res; - position = initPosition; - nextDir = GameEnum.STOP; - direction = new Vect(0, 0); - stop = false; - } + dirToChange = GameEnum.STOP; + this.res = res; + position = initPosition; + nextDir = GameEnum.STOP; + direction = new Vect(0, 0); + stop = false; + } - public void doAi() { + public void doAi() { - } + } - public void update(double gameTime, int canvasWidth, int canvasHeiht) { + public void update(double gameTime, int canvasWidth, int canvasHeiht) { - move(gameTime); - calculateSourceRect(gameTime); - canChangeDir(); - if (eatable) { - if (isTouched) { - eatable = false; - onlyEyes = true; - } + move(gameTime); + calculateSourceRect(gameTime); + canChangeDir(); + if (eatable) { + if (isTouched) { + eatable = true; + onlyEyes = true; + } - } - } + } + } - public void draw(Canvas canvas) { + public void draw(Canvas canvas) { - destRect.set((float) position.x - GameLogic.BOARD_TILE_SIZE / 2, - (float) position.y - GameLogic.BOARD_TILE_SIZE / 2, - (float) position.x + spriteWidth / 2 + spriteWidth, - (float) position.y + spriteHeight / 2 + spriteHeight); - boundingRect.set((float) position.x, (float) position.y, - (float) position.x + spriteWidth, (float) position.y - + spriteHeight); - if (eatable) { - boundingRect.set((float) position.x, (float) position.y, - (float) position.x + spriteEatWidth, (float) position.y - + spriteEatHeight); - destRect.set((float) position.x - GameLogic.BOARD_TILE_SIZE / 2, - (float) position.y - GameLogic.BOARD_TILE_SIZE / 2, - (float) position.x + spriteWidth / 2 + spriteWidth, - (float) position.y + spriteHeight / 2 + spriteHeight); - canvas.drawBitmap(eatableBitmap, sourceEatRect, destRect, null); - } else if (onlyEyes) - canvas.drawBitmap(eyes, (float) position.x, (float) position.y, - null); - else - canvas.drawBitmap(bitmap, sourceRect, destRect, null); - } + destRect.set((float) position.x - GameLogic.BOARD_TILE_SIZE / 2, + (float) position.y - GameLogic.BOARD_TILE_SIZE / 2, + (float) position.x + spriteWidth / 2 + spriteWidth, + (float) position.y + spriteHeight / 2 + spriteHeight); + boundingRect.set((float) position.x, (float) position.y, + (float) position.x + spriteWidth, (float) position.y + + spriteHeight); + if (eatable) { + boundingRect.set((float) position.x, (float) position.y, + (float) position.x + spriteEatWidth, (float) position.y + + spriteEatHeight); + destRect.set((float) position.x - GameLogic.BOARD_TILE_SIZE / 2, + (float) position.y - GameLogic.BOARD_TILE_SIZE / 2, + (float) position.x + spriteWidth / 2 + spriteWidth, + (float) position.y + spriteHeight / 2 + spriteHeight); + canvas.drawBitmap(eatableBitmap, sourceEatRect, destRect, null); + } else if (onlyEyes) + canvas.drawBitmap(eyes, (float) position.x, (float) position.y, + null); + else + canvas.drawBitmap(bitmap, sourceRect, destRect, null); + } - public void setEatable(boolean eat) { - eatable = eat; + public void setEatable(boolean eat) { + eatable = eat; - } - public void reset(){ - time = 0; - currentFrame = 0; - framePeriod = 0.5f; - blinking = false; - eatable = false; - frameTicker = 0; - swap=false; - } + } - public boolean isEatable() { - return eatable; - } + public void reset() { + time = 0; + currentFrame = 0; + framePeriod = 0.5f; + blinking = false; + eatable = false; + frameTicker = 0; + swap = false; + } - private void calculateSourceRect(double gameTime) { + public boolean isEatable() { + return eatable; + } - if (!eatable) { - if (angle == 270) {// gora - sourceRect.left = 1 * spriteWidth; - sourceRect.right = sourceRect.left + spriteWidth; + public boolean isOnlyEyes() { + return onlyEyes; + } - } - if (angle == 90) {// dol - sourceRect.left = 3 * spriteWidth; - sourceRect.right = sourceRect.left + spriteWidth; + private void calculateSourceRect(double gameTime) { - } - if (angle == 180) {// prawo - sourceRect.left = 0 * spriteWidth; - sourceRect.right = sourceRect.left + spriteWidth; + if (!eatable) { + if (angle == 270) {// gora + sourceRect.left = 1 * spriteWidth; + sourceRect.right = sourceRect.left + spriteWidth; - } - if (angle == 0) {// lewo - sourceRect.left = 2 * spriteWidth; - sourceRect.right = sourceRect.left + spriteWidth; + } + if (angle == 90) {// dol + sourceRect.left = 3 * spriteWidth; + sourceRect.right = sourceRect.left + spriteWidth; - } - } else if (eatable && blinking) { - frameTicker += gameTime; - time += gameTime; - if (frameTicker > framePeriod) { - frameTicker = 0; - // increment the frame - if (!swap) - currentFrame++; - else - currentFrame--; - if (currentFrame == 0 || currentFrame == 1) { - swap = !swap; - if (time > 1) { - time = 0; - framePeriod -= 0.08; - } - } + } + if (angle == 180) {// prawo + sourceRect.left = 0 * spriteWidth; + sourceRect.right = sourceRect.left + spriteWidth; - } + } + if (angle == 0) {// lewo + sourceRect.left = 2 * spriteWidth; + sourceRect.right = sourceRect.left + spriteWidth; - } - // define the rectangle to cut out sprite - sourceEatRect.left = currentFrame * spriteEatWidth; - sourceEatRect.right = sourceEatRect.left + spriteEatWidth; - } + } + } else if (eatable && blinking && !onlyEyes) { + frameTicker += gameTime; + time += gameTime; + if (frameTicker > framePeriod) { + frameTicker = 0; + // increment the frame + if (!swap) + currentFrame++; + else + currentFrame--; + if (currentFrame == 0 || currentFrame == 1) { + swap = !swap; + if (time > 1) { + time = 0; + framePeriod -= 0.08; + } + } - public void setBlinking(boolean blinking) { - this.blinking = blinking; + } - } + } + // define the rectangle to cut out sprite + sourceEatRect.left = currentFrame * spriteEatWidth; + sourceEatRect.right = sourceEatRect.left + spriteEatWidth; + } + + public void setEyes(boolean set) { + onlyEyes = set; + } + + public void setBlinking(boolean blinking) { + this.blinking = blinking; + + } }