Compare commits
10
Commits
withOpenGL
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
406af7315b | ||
|
|
04c9b367ae | ||
|
|
da8f0df869 | ||
|
|
f09aba315e | ||
|
|
8ffa981d90 | ||
|
|
266b04bb45 | ||
|
|
0c24eff46b | ||
|
|
ae660adb4a | ||
|
|
13c401d818 | ||
|
|
de06fab9ba |
No files matched your search
@@ -0,0 +1,2 @@
|
|||||||
|
bin/
|
||||||
|
/bin
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,3 +0,0 @@
|
|||||||
# cache for current jar dependecy. DO NOT EDIT.
|
|
||||||
# format is <lastModified> <length> <SHA-1> <path>
|
|
||||||
# Encoding is UTF-8
|
|
||||||
Binary file not shown.
@@ -1,73 +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;
|
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 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 ic_launcher=0x7f020005;
|
|
||||||
public static final int inky=0x7f020006;
|
|
||||||
public static final int level1=0x7f020007;
|
|
||||||
public static final int pacmanta=0x7f020008;
|
|
||||||
public static final int pacmantaa=0x7f020009;
|
|
||||||
public static final int sfood=0x7f02000a;
|
|
||||||
public static final int streight=0x7f02000b;
|
|
||||||
}
|
|
||||||
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 pacman_walk=0x7f040001;
|
|
||||||
}
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 1023 B |
Binary file not shown.
|
After Width: | Height: | Size: 1.8 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 299 B |
Binary file not shown.
|
After Width: | Height: | Size: 4.0 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.5 KiB |
+4
-4
@@ -11,9 +11,9 @@ xxxxxx.xxxxx0xx0xxxxx.xxxxxx
|
|||||||
x.xxxxx0xx0xxxxx.x
|
x.xxxxx0xx0xxxxx.x
|
||||||
x.xx0000000000xx.x
|
x.xx0000000000xx.x
|
||||||
x.xx0xxx00xxx0xx.x
|
x.xx0xxx00xxx0xx.x
|
||||||
xxxxxx.xx0x000000x0xx.xxxxxx
|
x.xx0x000000x0xx.x
|
||||||
000000.000x000000x000.000000
|
x.000x000000x000.x
|
||||||
xxxxxx.xx0x000000x0xx.xxxxxx
|
x.xx0x000000x0xx.x
|
||||||
x.xx0xxxxxxxx0xx.x
|
x.xx0xxxxxxxx0xx.x
|
||||||
x.xx0000000000xx.x
|
x.xx0000000000xx.x
|
||||||
x.xx0xxxxxxxx0xx.x
|
x.xx0xxxxxxxx0xx.x
|
||||||
@@ -28,4 +28,4 @@ x......xx....xx....xx......x
|
|||||||
x.xxxxxxxxxx.xx.xxxxxxxxxx.x
|
x.xxxxxxxxxx.xx.xxxxxxxxxx.x
|
||||||
x.xxxxxxxxxx.xx.xxxxxxxxxx.x
|
x.xxxxxxxxxx.xx.xxxxxxxxxx.x
|
||||||
x..........................x
|
x..........................x
|
||||||
xxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
xxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||||
+13
-2
@@ -7,6 +7,11 @@ x..........................x
|
|||||||
x.xxxx.xx.xxxxxxxx.xx.xxxx.x
|
x.xxxx.xx.xxxxxxxx.xx.xxxx.x
|
||||||
x.xxxx.xx.xxxxxxxx.xx.xxxx.x
|
x.xxxx.xx.xxxxxxxx.xx.xxxx.x
|
||||||
x......xx....xx....xx......x
|
x......xx....xx....xx......x
|
||||||
|
x......xx....x x..........x
|
||||||
|
x.xxxx.xxxxx.x x xxxxx.xx.x
|
||||||
|
x.x x.x x.x x.x x.xx.x
|
||||||
|
x.xxxx.xxxxx.xxxx.xxxxx.xx.x
|
||||||
|
x......xx..........xx......x
|
||||||
xxxxxx.xxxxx0xx0xxxxx.xxxxxx
|
xxxxxx.xxxxx0xx0xxxxx.xxxxxx
|
||||||
x.xxxxx0xx0xxxxx.x
|
x.xxxxx0xx0xxxxx.x
|
||||||
x.xx0000000000xx.x
|
x.xx0000000000xx.x
|
||||||
@@ -17,7 +22,13 @@ xxxxxx.xx0x000000x0xx.xxxxxx
|
|||||||
x.xx0xxxxxxxx0xx.x
|
x.xx0xxxxxxxx0xx.x
|
||||||
x.xx0000000000xx.x
|
x.xx0000000000xx.x
|
||||||
x.xx0xxxxxxxx0xx.x
|
x.xx0xxxxxxxx0xx.x
|
||||||
xxxxxx.xx0xxxxxxxx0xx.xxxxxx
|
xxxxxx.xx0xxxx xx0xx.xxxxxx
|
||||||
|
x......xx....x x..........x
|
||||||
|
x.xxxx.xxxxx.x x xxxxx.xx.x
|
||||||
|
x.x x.x x.x x.x x.xx.x
|
||||||
|
x.xxxx.xxxxx.xxxx.xxxxx.xx.x
|
||||||
|
x......xx..........xx......x
|
||||||
|
xxxxxx.xx.xxxxxxxx.xx.xxxxxx
|
||||||
x............xx............x
|
x............xx............x
|
||||||
x.xxxx.xxxxx.xx.xxxxx.xxxx.x
|
x.xxxx.xxxxx.xx.xxxxx.xxxx.x
|
||||||
x.xxxx.xxxxx.xx.xxxxx.xxxx.x
|
x.xxxx.xxxxx.xx.xxxxx.xxxx.x
|
||||||
@@ -28,4 +39,4 @@ x......xx....xx....xx......x
|
|||||||
x.xxxxxxxxxx.xx.xxxxxxxxxx.x
|
x.xxxxxxxxxx.xx.xxxxxxxxxx.x
|
||||||
x.xxxxxxxxxx.xx.xxxxxxxxxx.x
|
x.xxxxxxxxxx.xx.xxxxxxxxxx.x
|
||||||
x..........................x
|
x..........................x
|
||||||
xxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
xxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
xxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||||
|
xo...xx...................ox
|
||||||
|
x.xx.xxxxx.xx.xx.xxxxx.xxx.x
|
||||||
|
x.xx.xxxxx.xx.xx.xxxxx.xxx.x
|
||||||
|
x.xx.......xx.xx.......xxx.x
|
||||||
|
x.xxxxxxxxxxx.xxxxx.xxxxxx.x
|
||||||
|
x.xxxxxxxxxxx.xxxxx.xxxxxx.x
|
||||||
|
x.xxxxxxxxxxx.xxxxx.xxxxxx.x
|
||||||
|
x.xxxxxxxxxxx0xxxxx0xxxxxx.x
|
||||||
|
x.xx..000000000000000...xx.x
|
||||||
|
x.xx.xx0xxxxx00xxxxx0xx....x
|
||||||
|
x....xx0xxxxx00xxxxx0xxxxx.x
|
||||||
|
x.xxxxx0xx00000000xx0xxxxx.x
|
||||||
|
x.xxxxx0xx00000000xx0xxxxx.x
|
||||||
|
x.xxxxx0xx00000000xx00.....x
|
||||||
|
x....xx0xxxxxxxxxxxx0xxxxxxx
|
||||||
|
x.xx.xx0xxxxxxxxxxxx0xxxxxxx
|
||||||
|
x.xx..0000000000000000.....x
|
||||||
|
x.xxxxxxx0xxxxxxxxx0xxxxxx.x
|
||||||
|
x.xxxxxxx.xxxxxxxxx.xxxxxx.x
|
||||||
|
x.xxx...............xx.....x
|
||||||
|
x.xxx.xxxxxxx.xxxxx.xx.xxxxx
|
||||||
|
x.xxx.xxxxxxx.xxxxx.xx.xxxxx
|
||||||
|
xo........................ox
|
||||||
|
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
|
||||||
|
x.xxxxxxxxx00000xx.xxxxxxx.x
|
||||||
|
x.xxxxxxxxxxxxxxxxoxxxxxxx.x
|
||||||
|
x.xxxxxxxxxxxxxxxx.xxxxxxx.x
|
||||||
|
x..........................x
|
||||||
|
x.xxxxxx.xxxxxxxxxxxxxxxxx.x
|
||||||
|
x.xxxxxx.xxxxxxxxxxxxxxxxx.x
|
||||||
|
x.xxxxxx.xxxxxxxxxxxxxxxxx.x
|
||||||
|
x..........................x
|
||||||
|
x.xxxxxxxxxxx.xxxxxxxxxxxx.x
|
||||||
|
x.xxxxxxxxxxx.xxxxxxxxxxxx.x
|
||||||
|
xo........................ox
|
||||||
|
xxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,186 +1,327 @@
|
|||||||
package com.android.game.pacman.game;
|
package com.android.game.pacman.game;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.graphics.BitmapFactory;
|
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.Matrix;
|
import android.graphics.Paint;
|
||||||
|
import android.hardware.Sensor;
|
||||||
|
import android.hardware.SensorEvent;
|
||||||
|
import android.hardware.SensorEventListener;
|
||||||
|
import android.hardware.SensorManager;
|
||||||
|
import android.os.CountDownTimer;
|
||||||
import android.os.Vibrator;
|
import android.os.Vibrator;
|
||||||
import android.util.Log;
|
|
||||||
import android.util.Pair;
|
|
||||||
import android.view.SurfaceHolder;
|
import android.view.SurfaceHolder;
|
||||||
import android.view.SurfaceView;
|
import android.view.SurfaceView;
|
||||||
|
|
||||||
import com.adroid.game.pacman.R;
|
import com.adroid.game.pacman.R;
|
||||||
import com.android.game.pacman.model.Block;
|
import com.android.game.pacman.model.*;
|
||||||
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.utils.GameEnum;
|
import com.android.game.pacman.utils.GameEnum;
|
||||||
|
|
||||||
public class GameLogic extends SurfaceView implements SurfaceHolder.Callback {
|
import java.util.LinkedList;
|
||||||
|
|
||||||
private PacMan pacman;
|
public class GameLogic extends SurfaceView implements SurfaceHolder.Callback,
|
||||||
private GameLoop loop;
|
SensorEventListener {
|
||||||
private ArrayList<Block> wall;
|
|
||||||
private ArrayList<Block> path;
|
|
||||||
private ArrayList<SolidObject> food;
|
|
||||||
private Board boardGame;
|
|
||||||
private SoundStuff ss;
|
|
||||||
private Bitmap background;
|
|
||||||
private Ghost ghost1;
|
|
||||||
private Ghost ghost2;
|
|
||||||
private Ghost ghost3;
|
|
||||||
private Ghost ghost4;
|
|
||||||
|
|
||||||
static int BOARD_TILE_SIZE = 17;
|
private PacMan pacman;
|
||||||
static int BOARD_HEIGHT = 31;
|
|
||||||
static int BOARD_WIDTH = 28;
|
|
||||||
|
|
||||||
public GameLogic(Context context) {
|
private LinkedList<Block> wall;
|
||||||
super(context);
|
private LinkedList<Block> path;
|
||||||
setFocusable(true);
|
private LinkedList<SolidObject> food;
|
||||||
getHolder().addCallback(this);
|
private LinkedList<Ghost> ghosts;
|
||||||
Bitmap tmpbackground = BitmapFactory.decodeResource(getResources(),
|
|
||||||
R.drawable.blue_gradien);
|
|
||||||
|
|
||||||
float scaleWidth = ((float) 480) / 256;
|
public GameLoop loop;
|
||||||
float scaleHeight = ((float) 800) / 256;
|
private Board boardGame;
|
||||||
Matrix matrix = new Matrix();
|
private SoundStuff ss;
|
||||||
matrix.postScale(scaleWidth, scaleHeight);
|
private CountDownTimer task;
|
||||||
background = Bitmap.createBitmap(tmpbackground, 0, 0,
|
private SensorManager sensorManager;
|
||||||
256, 256, matrix,
|
private Vibrator v;
|
||||||
false);
|
|
||||||
loop = new GameLoop(getHolder(), this);
|
|
||||||
ss = new SoundStuff(context);
|
|
||||||
|
|
||||||
}
|
private int points = 0;
|
||||||
|
private int eatInRow = 0; // mnoznik do zjedzonych duszkow
|
||||||
|
private boolean accOn;
|
||||||
|
private boolean start = false;
|
||||||
|
|
||||||
public void render(Canvas canvas) {
|
private final static Paint paint = new Paint();
|
||||||
canvas.drawBitmap(background, 0f, 0f, null);
|
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;
|
||||||
|
|
||||||
for (Block obj : wall) {
|
public GameLogic(Context context, int w, int h) {
|
||||||
obj.draw(canvas);
|
super(context);
|
||||||
}
|
setFocusable(true);
|
||||||
for (Block obj : path) {
|
getHolder().addCallback(this);
|
||||||
obj.draw(canvas);
|
|
||||||
}
|
|
||||||
for (SolidObject obj : food) {
|
|
||||||
obj.draw(canvas);
|
|
||||||
}
|
|
||||||
pacman.draw(canvas);
|
|
||||||
ghost1.draw(canvas);
|
|
||||||
ghost2.draw(canvas);
|
|
||||||
ghost3.draw(canvas);
|
|
||||||
ghost4.draw(canvas);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void prepareLevel() {
|
WIDTH = w;
|
||||||
// TODO generate level
|
HEIGHT = h;
|
||||||
}
|
|
||||||
|
|
||||||
public void update() {
|
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;
|
||||||
|
|
||||||
otherCollision();
|
@Override
|
||||||
handleCollsion();
|
public void onTick(long millisUntilFinished) {
|
||||||
pacman.update(System.currentTimeMillis(), getWidth(), getHeight());
|
|
||||||
ghost1.update(System.currentTimeMillis(), getWidth(), getHeight());
|
|
||||||
ghost2.update(System.currentTimeMillis(), getWidth(), getHeight());
|
|
||||||
ghost3.update(System.currentTimeMillis(), getWidth(), getHeight());
|
|
||||||
ghost4.update(System.currentTimeMillis(), getWidth(), getHeight());
|
|
||||||
|
|
||||||
}
|
if (!first) {
|
||||||
|
ID = SoundStuff.sp.play(SoundStuff.ghostSiren, 1, 1, 1, -1,
|
||||||
|
1);
|
||||||
|
|
||||||
public void doAi(GameEnum deficultiy) {
|
for (Ghost ghost : ghosts) {
|
||||||
switch (deficultiy) {
|
ghost.setEatable(true);
|
||||||
case EASY:
|
}
|
||||||
// todo
|
first = true;
|
||||||
break;
|
}
|
||||||
// todo
|
|
||||||
case NORMAL:
|
|
||||||
break;
|
|
||||||
case HARD:
|
|
||||||
// todo
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
if (times == 5)
|
||||||
|
for (Ghost ghost : ghosts) {
|
||||||
|
ghost.setBlinking(true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
times++;
|
||||||
|
}
|
||||||
|
|
||||||
private void otherCollision() {
|
@Override
|
||||||
for (SolidObject obj : food) {
|
public void onFinish() {
|
||||||
if (Collision.detectNormalCollision(pacman.getBoundingRect(),
|
for (Ghost ghost : ghosts) {
|
||||||
obj.getBoundingRect())) {
|
ghost.reset();
|
||||||
obj.setIsTouched(true);
|
}
|
||||||
}
|
SoundStuff.sp.stop(ID);
|
||||||
}
|
eatInRow = 0;
|
||||||
}
|
first = false;
|
||||||
|
times = 0;
|
||||||
|
|
||||||
private void handleCollsion() {
|
}
|
||||||
for (int i = 0; i < food.size(); i++) {
|
|
||||||
if (food.get(i).getIsTouched()) {
|
|
||||||
if (food.get(i).getKind() == GameEnum.FOODUP) {
|
|
||||||
Vibrator v = (Vibrator) getContext().getSystemService(
|
|
||||||
Context.VIBRATOR_SERVICE);
|
|
||||||
v.vibrate(100);
|
|
||||||
}
|
|
||||||
food.remove(i);
|
|
||||||
|
|
||||||
}
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
public void render(Canvas canvas) {
|
||||||
public boolean onTouchEvent(android.view.MotionEvent event) {
|
// 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);
|
||||||
|
|
||||||
pacman.dir(event);
|
for (Block obj : path) {
|
||||||
return true;
|
obj.draw(canvas);
|
||||||
}
|
}
|
||||||
|
for (SolidObject obj : food) {
|
||||||
|
obj.draw(canvas);
|
||||||
|
}
|
||||||
|
pacman.draw(canvas);
|
||||||
|
for (Ghost ghost : ghosts) {
|
||||||
|
ghost.draw(canvas);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
}
|
||||||
public void surfaceChanged(SurfaceHolder holder, int format, int width,
|
|
||||||
int height) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
public void loadNextLvl() {
|
||||||
|
task.cancel();
|
||||||
|
pacman.stop();
|
||||||
|
boardGame = new Board(getResources(), R.raw.lvl);
|
||||||
|
|
||||||
@Override
|
wall = boardGame.getWall();
|
||||||
public void surfaceCreated(SurfaceHolder holder) {
|
path = boardGame.getPath();
|
||||||
boardGame = new Board(BOARD_WIDTH, BOARD_HEIGHT, BOARD_TILE_SIZE,
|
food = boardGame.getbGame();
|
||||||
getResources());
|
pacman = new PacMan(getResources(), new Vect((BOARD_TILE_SIZE
|
||||||
wall = boardGame.getWall();
|
* BOARD_WIDTH / 2), BOARD_TILE_SIZE * 23), getContext(),
|
||||||
path = boardGame.getPath();
|
boardGame.getBlock(), 100f, 3);
|
||||||
food = boardGame.getbGame();
|
ghosts = new LinkedList<Ghost>();
|
||||||
pacman = new PacMan(getResources(), new Vect((int) (BOARD_TILE_SIZE
|
|
||||||
* BOARD_WIDTH / 2), BOARD_TILE_SIZE * 23), getContext(),
|
|
||||||
boardGame.getBlock(), 17, 5);
|
|
||||||
ghost1=new Ghost(17, 2, boardGame.getBlock(),getResources(),new Vect(12*BOARD_TILE_SIZE, 14*BOARD_TILE_SIZE));
|
|
||||||
ghost2=new Ghost(17, 2, boardGame.getBlock(),getResources(),new Vect(13*BOARD_TILE_SIZE, 14*BOARD_TILE_SIZE));
|
|
||||||
ghost3=new Ghost(17, 2, boardGame.getBlock(),getResources(),new Vect(14*BOARD_TILE_SIZE, 14*BOARD_TILE_SIZE));
|
|
||||||
ghost4=new Ghost(17, 2, boardGame.getBlock(),getResources(),new Vect(15*BOARD_TILE_SIZE, 14*BOARD_TILE_SIZE));
|
|
||||||
loop.setRunning(true);
|
|
||||||
loop.start();
|
|
||||||
|
|
||||||
}
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
public void update(double time) {
|
||||||
public void surfaceDestroyed(SurfaceHolder holder) {
|
|
||||||
boolean retry = true;
|
|
||||||
while (retry) {
|
|
||||||
try {
|
|
||||||
loop.join();
|
|
||||||
retry = false;
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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.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 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();
|
||||||
|
|
||||||
|
} else
|
||||||
|
points += FOOD_POINT;
|
||||||
|
|
||||||
|
food.remove(i);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onTouchEvent(android.view.MotionEvent event) {
|
||||||
|
|
||||||
|
pacman.dir(event);
|
||||||
|
|
||||||
|
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 surfaceCreated(SurfaceHolder holder) {
|
||||||
|
|
||||||
|
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<Ghost>();
|
||||||
|
|
||||||
|
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 onAccuracyChanged(Sensor arg0, int arg1) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSensorChanged(SensorEvent event) {
|
||||||
|
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER && start) {
|
||||||
|
|
||||||
|
pacman.dirAcc(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAccOn() {
|
||||||
|
return accOn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAccOn(boolean accOn) {
|
||||||
|
this.accOn = accOn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stop() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.android.game.pacman.game;
|
package com.android.game.pacman.game;
|
||||||
|
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.SurfaceHolder;
|
import android.view.SurfaceHolder;
|
||||||
|
|
||||||
public class GameLoop extends Thread {
|
public class GameLoop extends Thread {
|
||||||
@@ -19,21 +20,32 @@ public class GameLoop extends Thread {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
long lastFpsTime = 0;
|
||||||
|
long last = 0;
|
||||||
|
|
||||||
Canvas canvas;
|
Canvas canvas;
|
||||||
|
|
||||||
|
double delay;
|
||||||
while (running) {
|
while (running) {
|
||||||
canvas = null;
|
canvas = null;
|
||||||
|
last = System.currentTimeMillis();
|
||||||
|
delay = (last - lastFpsTime);
|
||||||
|
|
||||||
|
lastFpsTime = last;
|
||||||
try {
|
try {
|
||||||
canvas = this.surfaceHolder.lockCanvas();
|
canvas = this.surfaceHolder.lockCanvas();
|
||||||
synchronized (surfaceHolder) {
|
synchronized (surfaceHolder) {
|
||||||
gamePanel.update();
|
|
||||||
gamePanel.render(canvas);
|
gamePanel.render(canvas);
|
||||||
|
gamePanel.update(delay / 1000);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (canvas != null) {
|
if (canvas != null) {
|
||||||
surfaceHolder.unlockCanvasAndPost(canvas);
|
surfaceHolder.unlockCanvasAndPost(canvas);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRunning(Boolean looping) {
|
public void setRunning(Boolean looping) {
|
||||||
|
|||||||
@@ -4,19 +4,26 @@ import com.adroid.game.pacman.R;
|
|||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.util.DisplayMetrics;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
|
|
||||||
public class MainActivity extends Activity {
|
public class MainActivity extends Activity {
|
||||||
|
GameLogic game;
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||||
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||||
setContentView(new GameLogic(this));
|
DisplayMetrics metrics = new DisplayMetrics();
|
||||||
|
getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
||||||
|
int screenHeight = metrics.heightPixels;
|
||||||
|
int screenWidth = metrics.widthPixels;
|
||||||
|
game = new GameLogic(this,screenWidth,screenHeight);
|
||||||
|
setContentView(game);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,5 +33,16 @@ public class MainActivity extends Activity {
|
|||||||
getMenuInflater().inflate(R.menu.activity_main, menu);
|
getMenuInflater().inflate(R.menu.activity_main, menu);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
// @Override
|
||||||
|
// protected void onPause() {
|
||||||
|
// game.loop=null;
|
||||||
|
// super.onPause();
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
// @Override
|
||||||
|
// protected void onResume() {
|
||||||
|
// game.loop = new GameLoop(game.getHolder(), game);
|
||||||
|
// super.onResume();
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -3,39 +3,34 @@ package com.android.game.pacman.model;
|
|||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.graphics.Rect;
|
|
||||||
|
|
||||||
|
import com.android.game.pacman.game.GameLogic;
|
||||||
import com.android.game.pacman.utils.GameEnum;
|
import com.android.game.pacman.utils.GameEnum;
|
||||||
|
|
||||||
public class Block extends SolidObject {
|
public class Block extends SolidObject {
|
||||||
|
|
||||||
private boolean selected = false;
|
private boolean selected = false;
|
||||||
private int size;
|
static Paint paint = new Paint();
|
||||||
private Rect sourceRect;
|
|
||||||
|
|
||||||
|
public Block(int x, int y) {
|
||||||
|
super(x * GameLogic.BOARD_TILE_SIZE, y * GameLogic.BOARD_TILE_SIZE);
|
||||||
|
|
||||||
|
|
||||||
|
paint.setColor(Color.BLACK);
|
||||||
public Block(int x, int y, int size) {
|
paint.setStyle(Paint.Style.FILL);
|
||||||
super(x * size, y * size);
|
|
||||||
this.size = size;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void draw(Canvas canvas) {
|
public void draw(Canvas canvas) {
|
||||||
Paint paint = new Paint();
|
|
||||||
boundingRect.set(x, y, x + size, y + size);
|
|
||||||
if (kind == GameEnum.PATH) {
|
if (kind == GameEnum.PATH) {
|
||||||
paint.setColor(Color.BLACK);
|
if (selected) {
|
||||||
if (!isTouched)
|
paint.setColor(Color.RED);
|
||||||
paint.setStyle(Paint.Style.FILL);
|
}else
|
||||||
else {
|
paint.setColor(Color.BLACK);
|
||||||
paint.setStyle(Paint.Style.STROKE);
|
|
||||||
isTouched = false;
|
boundingRect.set((float) x - GameLogic.BOARD_TILE_SIZE / 2, (float) y - GameLogic.BOARD_TILE_SIZE / 2,
|
||||||
}
|
(float) x + GameLogic.BOARD_TILE_SIZE / 2 + GameLogic.BOARD_TILE_SIZE, (float) y + GameLogic.BOARD_TILE_SIZE / 2 + GameLogic.BOARD_TILE_SIZE);
|
||||||
canvas.drawRect(boundingRect, paint);
|
canvas.drawRect(boundingRect, paint);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,46 +5,42 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.LinkedList;
|
||||||
|
|
||||||
|
import android.R.integer;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.graphics.Canvas;
|
|
||||||
import android.graphics.Color;
|
|
||||||
import android.graphics.Paint;
|
|
||||||
import android.graphics.Path;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.util.Pair;
|
||||||
|
|
||||||
import com.adroid.game.pacman.R;
|
import com.adroid.game.pacman.R;
|
||||||
|
import com.android.game.pacman.game.GameLogic;
|
||||||
import com.android.game.pacman.utils.GameEnum;
|
import com.android.game.pacman.utils.GameEnum;
|
||||||
|
|
||||||
public class Board {
|
public class Board {
|
||||||
|
|
||||||
private ArrayList<SolidObject> bGame;
|
private LinkedList<SolidObject> bGame;
|
||||||
private int x;
|
|
||||||
private int y;
|
|
||||||
private int size;
|
private int size;
|
||||||
private char[][] lvl;
|
private char[][] lvl;
|
||||||
private ArrayList<Block> path;
|
private LinkedList<Block> path;
|
||||||
private ArrayList<Block> wall;
|
private LinkedList<Block> wall;
|
||||||
private Block[][] blockTab;
|
private Block[][] blockTab;
|
||||||
Resources res;
|
Resources res;
|
||||||
|
|
||||||
public Board(int x, int y, int size, Resources res) {
|
public Board(Resources res, int sourceLvl) {
|
||||||
this.x = x;
|
|
||||||
this.y = y;
|
|
||||||
this.size = size;
|
|
||||||
this.res = res;
|
|
||||||
blockTab = new Block[x][y];
|
|
||||||
bGame = new ArrayList<SolidObject>(x * y);
|
|
||||||
lvl = readLvl(x, y, res);
|
|
||||||
path = new ArrayList<Block>();
|
|
||||||
wall = new ArrayList<Block>();
|
|
||||||
// Bitmap bitmap=
|
|
||||||
for (int i = 0; i < y; i++) {
|
|
||||||
for (int j = 0; j < x; j++) {
|
|
||||||
|
|
||||||
blockTab[j][i] = new Block(j, i, size);
|
this.size = GameLogic.BOARD_TILE_SIZE;
|
||||||
|
lvl = readLvl(res, sourceLvl);
|
||||||
|
blockTab = new Block[GameLogic.WIDTH][GameLogic.BOARD_HEIGHT];
|
||||||
|
bGame = new LinkedList<SolidObject>();
|
||||||
|
|
||||||
|
path = new LinkedList<Block>();
|
||||||
|
wall = new LinkedList<Block>();
|
||||||
|
// Bitmap bitmap=
|
||||||
|
for (int i = 0; i < GameLogic.BOARD_HEIGHT; i++) {
|
||||||
|
for (int j = 0; j < GameLogic.BOARD_WIDTH; j++) {
|
||||||
|
|
||||||
|
blockTab[j][i] = new Block(j, i);
|
||||||
switch (lvl[j][i]) {
|
switch (lvl[j][i]) {
|
||||||
case 'x':
|
case 'x':
|
||||||
setBlock(j, i);
|
setBlock(j, i);
|
||||||
@@ -59,7 +55,7 @@ public class Board {
|
|||||||
break;
|
break;
|
||||||
case '.':
|
case '.':
|
||||||
setFood(j, i, res);
|
setFood(j, i, res);
|
||||||
|
|
||||||
blockTab[j][i].kind = GameEnum.PATH;
|
blockTab[j][i].kind = GameEnum.PATH;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -71,27 +67,27 @@ public class Board {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setBlock(int x, int y) {
|
private void setBlock(int x, int y) {
|
||||||
Block newB = new Block(x, y, size);
|
Block newB = new Block(x, y);
|
||||||
wall.add(newB);
|
wall.add(newB);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setPath(int x, int y) {
|
private void setPath(int x, int y) {
|
||||||
|
|
||||||
Block newB = new Block(x, y, size);
|
Block newB = new Block(x, y);
|
||||||
newB.kind = GameEnum.PATH;
|
newB.kind = GameEnum.PATH;
|
||||||
path.add(newB);
|
path.add(newB);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setFood(int x, int y, Resources res) {
|
private void setFood(int x, int y, Resources res) {
|
||||||
Food newF = new Food(x, y, res,GameEnum.FOOD);
|
Food newF = new Food(x, y, res);
|
||||||
bGame.add(newF);
|
bGame.add(newF);
|
||||||
setPath(x, y);
|
setPath(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setFoodUp(int x, int y, Resources res) {
|
private void setFoodUp(int x, int y, Resources res) {
|
||||||
Food newF = new Food(x, y, res,GameEnum.FOODUP);
|
FoodUp newF = new FoodUp(x, y, res);
|
||||||
|
|
||||||
bGame.add(newF);
|
bGame.add(newF);
|
||||||
setPath(x, y);
|
setPath(x, y);
|
||||||
|
|
||||||
@@ -101,45 +97,62 @@ public class Board {
|
|||||||
return blockTab;
|
return blockTab;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<SolidObject> getbGame() {
|
public LinkedList<SolidObject> getbGame() {
|
||||||
return bGame;
|
return bGame;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<Block> getPath() {
|
public LinkedList<Block> getPath() {
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<Block> getWall() {
|
public LinkedList<Block> getWall() {
|
||||||
return wall;
|
return wall;
|
||||||
}
|
}
|
||||||
|
|
||||||
public char[][] readLvl(int x, int y, Resources res) {
|
public char[][] readLvl(Resources res, int sourceLvl) {
|
||||||
|
Pair<char[][], Pair<Integer, Integer>> x_y = readl(res, sourceLvl);
|
||||||
|
GameLogic.BOARD_HEIGHT = x_y.second.second;
|
||||||
|
GameLogic.BOARD_WIDTH = x_y.second.first;
|
||||||
|
GameLogic.BOARD_TILE_SIZE = (int) ( GameLogic.WIDTH/x_y.second.first );
|
||||||
|
Log.v("dem",String.valueOf(GameLogic.BOARD_TILE_SIZE));
|
||||||
|
return x_y.first;
|
||||||
|
|
||||||
InputStream inputStream = res.openRawResource(R.raw.lvl);
|
}
|
||||||
|
|
||||||
|
public static Pair<char[][], Pair<Integer, Integer>> readl(Resources res,
|
||||||
|
int sourceLvl) {
|
||||||
|
InputStream inputStream = res.openRawResource(sourceLvl);
|
||||||
|
|
||||||
InputStreamReader inputreader = new InputStreamReader(inputStream);
|
InputStreamReader inputreader = new InputStreamReader(inputStream);
|
||||||
BufferedReader buffreader = new BufferedReader(inputreader);
|
BufferedReader buffreader = new BufferedReader(inputreader);
|
||||||
|
ArrayList<Character> tab = new ArrayList<Character>();
|
||||||
int r;
|
int r;
|
||||||
char[][] buf = new char[x][y];
|
|
||||||
int _x = 0, _y = 0;
|
int _x = 0, _y = 0;
|
||||||
try {
|
try {
|
||||||
while ((r = buffreader.read()) != -1) {
|
while ((r = buffreader.read()) != -1) {
|
||||||
if (r == 10) {
|
if (r == 10) {
|
||||||
|
|
||||||
_y++;
|
_y++;
|
||||||
_x = 0;
|
_x = 0;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
buf[_x][_y] = (char) r;
|
|
||||||
_x++;
|
_x++;
|
||||||
|
tab.add((char) r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
return null;
|
// return null;
|
||||||
}
|
}
|
||||||
|
_y++;
|
||||||
|
int index = 0;
|
||||||
|
|
||||||
|
char[][] buf = new char[_x][_y];
|
||||||
|
for (int i = 0; i < _y; i++) {
|
||||||
|
for (int j = 0; j < _x; j++) {
|
||||||
|
buf[j][i] = tab.get((index));
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
|
||||||
return buf;
|
}
|
||||||
|
return new Pair<char[][], Pair<Integer, Integer>>(buf,
|
||||||
|
new Pair<Integer, Integer>(_x, _y));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,15 +1,14 @@
|
|||||||
package com.android.game.pacman.model;
|
package com.android.game.pacman.model;
|
||||||
|
|
||||||
|
import android.graphics.Rect;
|
||||||
|
import android.graphics.RectF;
|
||||||
|
import android.util.Pair;
|
||||||
|
|
||||||
import com.android.game.pacman.utils.GameEnum;
|
import com.android.game.pacman.utils.GameEnum;
|
||||||
|
|
||||||
import android.R.integer;
|
|
||||||
import android.graphics.Rect;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.util.Pair;
|
|
||||||
|
|
||||||
public class Collision {
|
public class Collision {
|
||||||
//nie uzywane
|
//nie uzywane
|
||||||
static public Pair<GameEnum, Integer> wallDetectCollision(Rect one, Rect two) {
|
static public Pair<Integer, Integer> wallDetectCollision(Rect one, Rect two) {
|
||||||
double w = 0.5 * (one.width()-1 + two.width());
|
double w = 0.5 * (one.width()-1 + two.width());
|
||||||
double h = 0.5 * (one.height()-1 + two.height());
|
double h = 0.5 * (one.height()-1 + two.height());
|
||||||
double dx = one.exactCenterX() - two.exactCenterX();
|
double dx = one.exactCenterX() - two.exactCenterX();
|
||||||
@@ -23,29 +22,29 @@ public class Collision {
|
|||||||
if (wy > -hx) {
|
if (wy > -hx) {
|
||||||
/* collision at the top */
|
/* collision at the top */
|
||||||
|
|
||||||
return new Pair<GameEnum, Integer>(GameEnum.UP,
|
return new Pair<Integer, Integer>(GameEnum.UP,
|
||||||
Integer.valueOf((int)(one.exactCenterY() - two.exactCenterY())-17));
|
Integer.valueOf((int)(one.exactCenterY() - two.exactCenterY())-17));
|
||||||
} else
|
} else
|
||||||
/* on the left */
|
/* on the left */
|
||||||
return new Pair<GameEnum, Integer>(GameEnum.RIGHT,
|
return new Pair<Integer, Integer>(GameEnum.RIGHT,
|
||||||
Integer.valueOf((int)(two.exactCenterX() - one.exactCenterX())-17));
|
Integer.valueOf((int)(two.exactCenterX() - one.exactCenterX())-17));
|
||||||
|
|
||||||
else if (wy > -hx)
|
else if (wy > -hx)
|
||||||
/* on the right */
|
/* on the right */
|
||||||
return new Pair<GameEnum, Integer>(GameEnum.LEFT,
|
return new Pair<Integer, Integer>(GameEnum.LEFT,
|
||||||
Integer.valueOf((int)(two.exactCenterX() - one.exactCenterX())+17));
|
Integer.valueOf((int)(two.exactCenterX() - one.exactCenterX())+17));
|
||||||
|
|
||||||
else {
|
else {
|
||||||
/* at the bottom */
|
/* at the bottom */
|
||||||
return new Pair<GameEnum, Integer>(GameEnum.DOWN,
|
return new Pair<Integer, Integer>(GameEnum.DOWN,
|
||||||
Integer.valueOf((int)(one.exactCenterY() - two.exactCenterY())+17));
|
Integer.valueOf((int)(one.exactCenterY() - two.exactCenterY())+17));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new Pair<GameEnum, Integer>(GameEnum.NORMAL, Integer.valueOf(0));
|
return new Pair<Integer, Integer>(GameEnum.NORMAL, Integer.valueOf(0));
|
||||||
|
|
||||||
}
|
}
|
||||||
//nie uzwyane
|
//nie uzwyane
|
||||||
static public Pair<GameEnum, Double> pathDetectCollision(Rect one, Rect two,int size) {
|
static public Pair<Integer, Double> pathDetectCollision(Rect one, Rect two,int size) {
|
||||||
double w = 0.5 * (one.width()+size + two.width());
|
double w = 0.5 * (one.width()+size + two.width());
|
||||||
double h = 0.5 * (one.height()+size + two.height());
|
double h = 0.5 * (one.height()+size + two.height());
|
||||||
double dx = one.exactCenterX() - two.exactCenterX();
|
double dx = one.exactCenterX() - two.exactCenterX();
|
||||||
@@ -61,28 +60,28 @@ public class Collision {
|
|||||||
if (wy > -hx) {
|
if (wy > -hx) {
|
||||||
/* collision at the top */
|
/* collision at the top */
|
||||||
|
|
||||||
return new Pair<GameEnum, Double>(GameEnum.UP,
|
return new Pair<Integer, Double>(GameEnum.UP,
|
||||||
Double.valueOf(d));
|
Double.valueOf(d));
|
||||||
} else
|
} else
|
||||||
/* on the left */
|
/* on the left */
|
||||||
return new Pair<GameEnum, Double>(GameEnum.RIGHT,
|
return new Pair<Integer, Double>(GameEnum.RIGHT,
|
||||||
Double.valueOf(d));
|
Double.valueOf(d));
|
||||||
|
|
||||||
else if (wy > -hx)
|
else if (wy > -hx)
|
||||||
/* on the right */
|
/* on the right */
|
||||||
return new Pair<GameEnum, Double>(GameEnum.LEFT,
|
return new Pair<Integer, Double>(GameEnum.LEFT,
|
||||||
Double.valueOf(d));
|
Double.valueOf(d));
|
||||||
|
|
||||||
else {
|
else {
|
||||||
/* at the bottom */
|
/* at the bottom */
|
||||||
return new Pair<GameEnum, Double>(GameEnum.DOWN,
|
return new Pair<Integer, Double>(GameEnum.DOWN,
|
||||||
Double.valueOf(d));
|
Double.valueOf(d));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new Pair<GameEnum, Double>(GameEnum.NORMAL, Double.valueOf(0));
|
return new Pair<Integer, Double>(GameEnum.NORMAL, Double.valueOf(0));
|
||||||
|
|
||||||
}
|
}
|
||||||
public static boolean detectNormalCollision(Rect one,Rect two){
|
public static boolean detectNormalCollision(RectF one,RectF two){
|
||||||
return one.intersect(two);
|
return one.intersect(two);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,25 +1,29 @@
|
|||||||
package com.android.game.pacman.model;
|
package com.android.game.pacman.model;
|
||||||
|
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Rect;
|
|
||||||
|
|
||||||
|
import com.android.game.pacman.game.GameLogic;
|
||||||
import com.android.game.pacman.utils.GameEnum;
|
import com.android.game.pacman.utils.GameEnum;
|
||||||
|
|
||||||
public class Food extends SolidObject {
|
public class Food extends SolidObject {
|
||||||
|
|
||||||
|
|
||||||
|
private static Bitmap bitmap;
|
||||||
|
|
||||||
public Food(int x,int y,Resources res,GameEnum kind){
|
public Food(int x, int y, Resources res) {
|
||||||
super(x*17, y*17);
|
super(x * GameLogic.BOARD_TILE_SIZE, y * GameLogic.BOARD_TILE_SIZE);
|
||||||
if(kind ==GameEnum.FOOD)
|
kind = GameEnum.FOOD;
|
||||||
bitmap = BitmapFactory.decodeResource(res,
|
if (bitmap == null) {
|
||||||
com.adroid.game.pacman.R.drawable.food);
|
|
||||||
else
|
|
||||||
bitmap = BitmapFactory.decodeResource(res,
|
bitmap = BitmapFactory.decodeResource(res,
|
||||||
com.adroid.game.pacman.R.drawable.foodup);
|
com.adroid.game.pacman.R.drawable.food);
|
||||||
this.kind=kind;
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
public void draw(Canvas canvas) {
|
||||||
|
canvas.drawBitmap(bitmap, (float)x, (float)y, null);
|
||||||
|
boundingRect.set((float)x, (float)y, (float)x + bitmap.getWidth(),(float)y + bitmap.getHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package com.android.game.pacman.model;
|
||||||
|
|
||||||
|
import android.content.res.Resources;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
|
import android.graphics.Canvas;
|
||||||
|
|
||||||
|
import com.android.game.pacman.game.GameLogic;
|
||||||
|
import com.android.game.pacman.utils.GameEnum;
|
||||||
|
|
||||||
|
public class FoodUp extends SolidObject {
|
||||||
|
private static Bitmap bitmap;
|
||||||
|
|
||||||
|
public FoodUp(int x, int y, Resources res) {
|
||||||
|
super(x * GameLogic.BOARD_TILE_SIZE, y * GameLogic.BOARD_TILE_SIZE);
|
||||||
|
kind = GameEnum.FOODUP;
|
||||||
|
if (bitmap == null) {
|
||||||
|
bitmap = BitmapFactory.decodeResource(res,
|
||||||
|
com.adroid.game.pacman.R.drawable.foodup);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
public void draw(Canvas canvas) {
|
||||||
|
canvas.drawBitmap(bitmap, (float)x, (float)y, null);
|
||||||
|
boundingRect.set((float)x, (float)y, (float)x + bitmap.getWidth(),(float)y + bitmap.getHeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -4,136 +4,168 @@ import android.content.res.Resources;
|
|||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.util.Log;
|
import android.graphics.RectF;
|
||||||
|
|
||||||
|
import com.android.game.pacman.game.GameLogic;
|
||||||
import com.android.game.pacman.utils.GameEnum;
|
import com.android.game.pacman.utils.GameEnum;
|
||||||
|
|
||||||
public class GameObject {
|
public class GameObject {
|
||||||
|
|
||||||
|
public RectF boundingRect = new RectF();
|
||||||
|
public RectF destRect = new RectF();
|
||||||
|
|
||||||
protected Vect position;
|
protected Vect position;
|
||||||
protected Bitmap bitmap;
|
protected Bitmap bitmap;
|
||||||
Rect boundingRect = new Rect();
|
|
||||||
protected boolean isTouched = false;
|
protected boolean isTouched = false;
|
||||||
protected GameEnum dirToChange;
|
protected int dirToChange;
|
||||||
protected int speed;
|
protected double speed;
|
||||||
protected boolean rotate = false;
|
|
||||||
protected double angle = 0;
|
protected double angle = 0;
|
||||||
protected Vect direction;
|
protected Vect direction;
|
||||||
protected Vect target;
|
protected Vect target = new Vect(0, 0);
|
||||||
protected boolean stop;
|
protected boolean stop;
|
||||||
protected int size;
|
protected int nextDir;
|
||||||
private Block[][] board;
|
|
||||||
protected GameEnum nextDir;
|
|
||||||
protected Rect sourceRect; // the rectangle to be drawn from the animation
|
protected Rect sourceRect; // the rectangle to be drawn from the animation
|
||||||
protected int spriteWidth; // the width of the sprite to calculate the cut out
|
protected int spriteWidth; // the width of the sprite to calculate the cut
|
||||||
protected int spriteHeight;
|
protected int spriteHeight;
|
||||||
protected Resources res;
|
protected Resources res;
|
||||||
|
protected boolean targetReached = true;
|
||||||
|
|
||||||
|
private Block[][] board;
|
||||||
|
|
||||||
|
private Vect newdir = new Vect(0, 0);
|
||||||
|
|
||||||
public void update() {
|
public void update() {
|
||||||
|
|
||||||
}
|
}
|
||||||
public GameObject(int size,int speed,Block[][] board){
|
|
||||||
this.speed=speed;
|
public GameObject(double speed, Block[][] board) {
|
||||||
this.size=size;
|
this.speed = speed;
|
||||||
this.board=board;
|
this.board = board;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void rotate(double angle) {
|
public void rotate(double angle) {
|
||||||
rotate = true;
|
|
||||||
this.angle = angle;
|
this.angle = angle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void draw(Canvas canvas) {
|
public void draw(Canvas canvas) {
|
||||||
canvas.drawBitmap(bitmap, position.x, position.y, null);
|
boundingRect.set((float) position.x, (float) position.y,
|
||||||
boundingRect = new Rect(position.x, position.y, position.x
|
(float) position.x + spriteWidth, (float) position.y
|
||||||
+ bitmap.getWidth(), position.y + bitmap.getHeight());
|
+ spriteHeight);
|
||||||
|
canvas.drawBitmap(bitmap, sourceRect, boundingRect, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Rect getBoundingRect() {
|
synchronized public void move(double dt) {
|
||||||
return boundingRect;
|
|
||||||
}
|
|
||||||
synchronized public void move() {
|
|
||||||
|
|
||||||
if (dirToChange == GameEnum.UP) {
|
if (targetReached) {
|
||||||
direction = new Vect(0, -1);
|
if (dirToChange == GameEnum.UP) {
|
||||||
rotate(270);
|
direction.x=0;
|
||||||
}
|
direction.y=-1;
|
||||||
if (dirToChange == GameEnum.DOWN) {
|
angle=270;
|
||||||
direction = new Vect(0, 1);
|
}
|
||||||
rotate(90);
|
if (dirToChange == GameEnum.DOWN) {
|
||||||
}
|
direction.x=0;
|
||||||
if (dirToChange == GameEnum.LEFT) {
|
direction.y=1;
|
||||||
direction = new Vect(-1, 0);
|
angle=90;
|
||||||
rotate(180);
|
}
|
||||||
}
|
if (dirToChange == GameEnum.LEFT) {
|
||||||
if (dirToChange == GameEnum.RIGHT) {
|
direction.x=-1;
|
||||||
direction = new Vect(1, 0);
|
direction.y=0;
|
||||||
rotate(0);
|
angle=180;
|
||||||
}
|
}
|
||||||
if (target == null) {
|
if (dirToChange == GameEnum.RIGHT) {
|
||||||
|
direction.x=1;
|
||||||
|
direction.y=0;
|
||||||
|
angle=0;
|
||||||
|
}
|
||||||
if (canMove(position, direction)) {
|
if (canMove(position, direction)) {
|
||||||
stop = false;
|
stop = false;
|
||||||
|
targetReached = false;
|
||||||
target = position.add(direction.mulitply(size));
|
target = position.add(direction
|
||||||
|
.mulitply(GameLogic.BOARD_TILE_SIZE));
|
||||||
} else
|
} else
|
||||||
stop = true;
|
stop = true;
|
||||||
}
|
}
|
||||||
if (target != null) {
|
if (!targetReached) {
|
||||||
if (moveTowards(target))
|
if (moveTowards(target, dt))
|
||||||
target = null;
|
targetReached = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
private boolean moveTowards(Vect goal) {
|
|
||||||
if (position.equals(goal))
|
|
||||||
return true;
|
|
||||||
Vect dir = Vect.normalize(goal.subtract(position)); //kierunek ruchu
|
|
||||||
position = position.add(dir.mulitply(speed)); //nowa pozycja
|
|
||||||
|
|
||||||
if (Math.abs(Vect.dot(dir, Vect.normalize(goal.subtract(position))) + 1) < speed) //jezeli minął cel
|
|
||||||
position = goal;
|
|
||||||
|
|
||||||
return position.equals(goal);
|
private boolean moveTowards(Vect goal, double dt) {
|
||||||
|
|
||||||
|
if (position.equals(goal)) //jezeli obiekt osiagna cel
|
||||||
|
return true;
|
||||||
|
|
||||||
|
Vect dir = Vect.normalize(goal.subtract(position)); // kierunek ruchu
|
||||||
|
|
||||||
|
position = position.add(dir.mulitply(speed * dt)); // nowa pozycja
|
||||||
|
|
||||||
|
if (Math.abs(Vect.dot(dir, Vect.normalize(goal.subtract(position))) + 1) < speed* dt) //czy obiekt minol cel
|
||||||
|
position=goal;
|
||||||
|
return position.equals(goal);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean canMove(Vect position, Vect direction) {
|
private boolean canMove(Vect position, Vect direction) {
|
||||||
if (direction == null)
|
if (direction.x == 0 && direction.y == 0)
|
||||||
return false;
|
return false;
|
||||||
int nx = (int) (position.x / size) + (int) direction.x;
|
int nx = (int) (position.x / GameLogic.BOARD_TILE_SIZE)
|
||||||
int ny = (int) (position.y / size) + (int) direction.y;
|
+ (int) direction.x;
|
||||||
if (nx < 0 || ny < 0 || nx >= board.length
|
int ny = (int) (position.y / GameLogic.BOARD_TILE_SIZE)
|
||||||
|| ny >= board[0].length)
|
+ (int) direction.y;
|
||||||
|
if (nx < 0 || ny < 0 || nx >= GameLogic.BOARD_WIDTH
|
||||||
|
|| ny >= GameLogic.BOARD_HEIGHT)
|
||||||
return false;
|
return false;
|
||||||
return board[nx][ny].kind == GameEnum.PATH;
|
return board[nx][ny].kind == GameEnum.PATH;
|
||||||
|
|
||||||
}
|
}
|
||||||
private boolean check(GameEnum dir) {
|
//sprawdzanie czy jest mozliwosc zmiany kierunku na nowy
|
||||||
Vect newdir = null;
|
private boolean check(int dir) {
|
||||||
if (dir == GameEnum.UP)
|
newdir.x = 0;
|
||||||
newdir = new Vect(0, -1);
|
newdir.y = 0;
|
||||||
if (dir == GameEnum.DOWN)
|
|
||||||
newdir = new Vect(0, 1);
|
|
||||||
if (dir == GameEnum.LEFT)
|
|
||||||
newdir = new Vect(-1, 0);
|
|
||||||
if (dir == GameEnum.RIGHT)
|
|
||||||
newdir = new Vect(1, 0);
|
|
||||||
|
|
||||||
|
if (dir == GameEnum.UP) {
|
||||||
|
newdir.x = 0;
|
||||||
|
newdir.y = -1;
|
||||||
|
}
|
||||||
|
if (dir == GameEnum.DOWN) {
|
||||||
|
newdir.x = 0;
|
||||||
|
newdir.y = 1;
|
||||||
|
}
|
||||||
|
if (dir == GameEnum.LEFT) {
|
||||||
|
newdir.x = -1;
|
||||||
|
newdir.y = 0;
|
||||||
|
}
|
||||||
|
if (dir == GameEnum.RIGHT) {
|
||||||
|
newdir.x = 1;
|
||||||
|
newdir.y = 0;
|
||||||
|
}
|
||||||
return canMove(position, newdir);
|
return canMove(position, newdir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setDirection(int dir) {
|
||||||
public void setDirection(GameEnum dir) {
|
//jezeli obiekt jest wyrownany do plytki to zmien kierunek jezeli nie to zapamietaj ten kierunke na puxniej
|
||||||
|
if (position.x % GameLogic.BOARD_TILE_SIZE == 0
|
||||||
if (check(dir)) {
|
&& position.y % GameLogic.BOARD_TILE_SIZE == 0) {
|
||||||
dirToChange=dir;
|
if (check(dir))
|
||||||
|
dirToChange = dir;
|
||||||
} else
|
} else
|
||||||
nextDir = dir;
|
nextDir = dir;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
//sprawdza czy obiekt moze zmienic kierunke na nowy
|
||||||
public void canChangeDir() {
|
public void canChangeDir() {
|
||||||
if (check(nextDir)) {
|
if (position.x % GameLogic.BOARD_TILE_SIZE == 0
|
||||||
|
&& position.y % GameLogic.BOARD_TILE_SIZE == 0) {
|
||||||
dirToChange=nextDir;
|
if (check(nextDir)) {
|
||||||
nextDir = GameEnum.STOP;
|
dirToChange = nextDir;
|
||||||
|
nextDir = GameEnum.STOP;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setIsTouched(boolean state) {
|
||||||
|
isTouched = state;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,76 +1,187 @@
|
|||||||
package com.android.game.pacman.model;
|
package com.android.game.pacman.model;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
|
||||||
|
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Rect;
|
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 com.android.game.pacman.utils.GameEnum;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
|
||||||
public class Ghost extends GameObject {
|
public class Ghost extends GameObject {
|
||||||
private LinkedList<GameEnum> movement;
|
private LinkedList<GameEnum> movement;
|
||||||
private int lvl;// table of actual lvl importanto to do ai
|
private Rect sourceRect;
|
||||||
private Rect sourceRect;
|
// uzywane kied duszek jest do zjedzenia
|
||||||
private boolean eatable=false;
|
private int spriteEatHeight;
|
||||||
public Ghost(int size, int speed, Block[][] board, Resources res,Vect initPosition) {
|
private int spriteEatWidth;
|
||||||
super(size, speed, board);
|
private Rect sourceEatRect;
|
||||||
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);
|
|
||||||
dirToChange = GameEnum.STOP;
|
|
||||||
this.res = res;
|
|
||||||
position = initPosition;
|
|
||||||
nextDir = GameEnum.STOP;
|
|
||||||
direction = new Vect(0, 0);
|
|
||||||
this.size = size;
|
|
||||||
stop=false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void doAi() {
|
private Bitmap eyes;
|
||||||
|
private Bitmap eatableBitmap;
|
||||||
|
|
||||||
}
|
private boolean eatable = false;
|
||||||
|
private boolean onlyEyes = false;
|
||||||
|
private boolean blinking = false;
|
||||||
|
|
||||||
public void update(long gameTime, int canvasWidth, int canvasHeiht) {
|
private double frameTicker;
|
||||||
|
private double framePeriod = 0.5f;
|
||||||
|
private boolean swap;
|
||||||
|
|
||||||
move();
|
private double time; // do mrugania;
|
||||||
calculateSourceRect();
|
private int currentFrame;
|
||||||
canChangeDir();
|
|
||||||
|
|
||||||
}
|
public Ghost(double speed, Block[][] board, Resources res, Vect initPosition) {
|
||||||
|
super(speed, board);
|
||||||
|
|
||||||
@Override
|
bitmap = BitmapFactory.decodeResource(res,
|
||||||
public void draw(Canvas canvas) {
|
com.adroid.game.pacman.R.drawable.ghost);
|
||||||
Rect destRect = new Rect(position.x, position.y, position.x
|
|
||||||
+ spriteWidth, position.y + spriteHeight);
|
|
||||||
canvas.drawBitmap(bitmap, sourceRect, destRect, null);
|
|
||||||
boundingRect = destRect;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void calculateSourceRect() {
|
spriteHeight = bitmap.getHeight();
|
||||||
|
spriteWidth = bitmap.getWidth() / 4; // ilosc dostepnych klatek
|
||||||
|
sourceRect = new Rect(0, 0, spriteWidth, spriteHeight);
|
||||||
|
|
||||||
if (angle == 270) {// gora
|
eatableBitmap = BitmapFactory
|
||||||
sourceRect.left = 1 * spriteWidth;
|
.decodeResource(res, R.drawable.ghost_eat2);
|
||||||
sourceRect.right = sourceRect.left + spriteWidth;
|
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);
|
||||||
if (angle == 90) {// dol
|
|
||||||
sourceRect.left = 3 * spriteWidth;
|
|
||||||
sourceRect.right = sourceRect.left + spriteWidth;
|
|
||||||
|
|
||||||
}
|
dirToChange = GameEnum.STOP;
|
||||||
if (angle == 180) {// prawo
|
this.res = res;
|
||||||
sourceRect.left = 0 * spriteWidth;
|
position = initPosition;
|
||||||
sourceRect.right = sourceRect.left + spriteWidth;
|
nextDir = GameEnum.STOP;
|
||||||
|
direction = new Vect(0, 0);
|
||||||
|
stop = false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
public void doAi() {
|
||||||
if (angle == 0) {// lewo
|
|
||||||
sourceRect.left = 2 * spriteWidth;
|
|
||||||
sourceRect.right = sourceRect.left + spriteWidth;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public void update(double gameTime, int canvasWidth, int canvasHeiht) {
|
||||||
|
|
||||||
|
move(gameTime);
|
||||||
|
calculateSourceRect(gameTime);
|
||||||
|
canChangeDir();
|
||||||
|
if (eatable) {
|
||||||
|
if (isTouched) {
|
||||||
|
eatable = true;
|
||||||
|
onlyEyes = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 boolean isOnlyEyes() {
|
||||||
|
return onlyEyes;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void calculateSourceRect(double gameTime) {
|
||||||
|
|
||||||
|
if (!eatable) {
|
||||||
|
if (angle == 270) {// gora
|
||||||
|
sourceRect.left = 1 * spriteWidth;
|
||||||
|
sourceRect.right = sourceRect.left + spriteWidth;
|
||||||
|
|
||||||
|
}
|
||||||
|
if (angle == 90) {// dol
|
||||||
|
sourceRect.left = 3 * spriteWidth;
|
||||||
|
sourceRect.right = sourceRect.left + spriteWidth;
|
||||||
|
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
|
||||||
|
}
|
||||||
|
} 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,34 +1,45 @@
|
|||||||
package com.android.game.pacman.model;
|
package com.android.game.pacman.model;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
|
import android.hardware.SensorEvent;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
|
|
||||||
|
import com.android.game.pacman.game.GameLogic;
|
||||||
import com.android.game.pacman.utils.GameEnum;
|
import com.android.game.pacman.utils.GameEnum;
|
||||||
|
|
||||||
public class PacMan extends GameObject {
|
public class PacMan extends GameObject {
|
||||||
|
|
||||||
|
|
||||||
// rectangle
|
// rectangle
|
||||||
|
|
||||||
private int frameNr; // number of frames in animation
|
|
||||||
private int currentFrame = 0; // the current frame
|
private int currentFrame = 0; // the current frame
|
||||||
private double frameTicker; // the time of the last frame update
|
private double frameTicker; // the time of the last frame update
|
||||||
private int framePeriod; // milliseconds between each frame (1000/fps)
|
private double framePeriod; // milliseconds between each frame (1000/fps)
|
||||||
// the height of the sprite
|
// the height of the sprite
|
||||||
private Resources res;
|
|
||||||
private float x1, x2, y1, y2, dx, dy;
|
private double x1, x2, y1, y2, dx, dy;
|
||||||
private boolean isPlaying = false;
|
private boolean isPlaying = false;
|
||||||
boolean swap = false;
|
boolean swap = false;
|
||||||
|
private int soundID1 = -1;
|
||||||
|
private int soundID2 = -1;
|
||||||
|
private float xAcc;
|
||||||
|
private float yAcc;
|
||||||
|
private float xZero;
|
||||||
|
private float yZero;
|
||||||
|
private boolean first = true;
|
||||||
|
private boolean die = false;
|
||||||
|
private int life;
|
||||||
|
private double second = 0;
|
||||||
|
private Vect initVectl;
|
||||||
|
|
||||||
public PacMan(Resources res, Vect initPosition, Context context,
|
public PacMan(Resources res, Vect initPosition, Context context,
|
||||||
Block[][] board, int size, int speed) {
|
Block[][] board, double speed, int life) {
|
||||||
super(size, speed, board);
|
super(speed, board);
|
||||||
|
initVectl = initPosition;
|
||||||
|
this.life = life;
|
||||||
dirToChange = GameEnum.STOP;
|
dirToChange = GameEnum.STOP;
|
||||||
this.res = res;
|
this.res = res;
|
||||||
position = initPosition;
|
position = initPosition;
|
||||||
@@ -37,55 +48,74 @@ public class PacMan extends GameObject {
|
|||||||
spriteHeight = bitmap.getHeight();
|
spriteHeight = bitmap.getHeight();
|
||||||
spriteWidth = bitmap.getWidth() / 3; // ilosc dostepnych klatek
|
spriteWidth = bitmap.getWidth() / 3; // ilosc dostepnych klatek
|
||||||
sourceRect = new Rect(0, 0, spriteWidth, spriteHeight);
|
sourceRect = new Rect(0, 0, spriteWidth, spriteHeight);
|
||||||
frameNr = 6;
|
|
||||||
framePeriod = 1000 / 6;
|
|
||||||
|
|
||||||
SoundStuff.sp.play(SoundStuff.pacamnWalk, 1, 1, 1, -1, 1);
|
framePeriod = (double) (0.25) / 2;
|
||||||
|
do {
|
||||||
|
soundID1 = SoundStuff.sp
|
||||||
|
.play(SoundStuff.pacamnWalk, 1, 1, 1, -1, 1);
|
||||||
|
} while (soundID1 == 0);
|
||||||
|
|
||||||
nextDir = GameEnum.STOP;
|
nextDir = GameEnum.STOP;
|
||||||
|
|
||||||
direction = new Vect(0, 1);
|
direction = new Vect(0, 1);
|
||||||
|
|
||||||
this.size = size;
|
stop = true;
|
||||||
stop=true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Canvas canvas) {
|
public void draw(Canvas canvas) {
|
||||||
Rect destRect = new Rect(position.x, position.y, position.x
|
|
||||||
+ spriteWidth, position.y + spriteHeight);
|
|
||||||
if (rotate) {
|
|
||||||
canvas.save();
|
|
||||||
canvas.rotate((float) angle,
|
|
||||||
(float) position.x + (spriteWidth / 2), (float) position.y
|
|
||||||
+ (spriteHeight / 2));
|
|
||||||
|
|
||||||
canvas.drawBitmap(bitmap, sourceRect, destRect, null);
|
destRect.set((float) position.x - GameLogic.BOARD_TILE_SIZE / 2,
|
||||||
canvas.restore();
|
(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);
|
||||||
|
canvas.save();
|
||||||
|
canvas.rotate((float) angle, (float) position.x + (spriteWidth / 2),
|
||||||
|
(float) position.y + (spriteHeight / 2));
|
||||||
|
|
||||||
rotate = false;
|
canvas.drawBitmap(bitmap, sourceRect, destRect, null);
|
||||||
} else {
|
canvas.restore();
|
||||||
|
|
||||||
canvas.drawBitmap(bitmap, sourceRect, destRect, null);
|
|
||||||
|
|
||||||
}
|
|
||||||
boundingRect = destRect;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// the update method for ship
|
// the update method for ship
|
||||||
public void update(long gameTime, int canvasWidth, int canvasHeiht) {
|
public void update(double gameTime, int canvasWidth, int canvasHeiht) {
|
||||||
|
if (die) {
|
||||||
|
if (!stop) {
|
||||||
|
stop = true;
|
||||||
|
handleSound();
|
||||||
|
}
|
||||||
|
second += gameTime;
|
||||||
|
if (second >= 1) {
|
||||||
|
die = false;
|
||||||
|
life--;
|
||||||
|
second = 0;
|
||||||
|
position = initVectl;
|
||||||
|
targetReached = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
move(gameTime);
|
||||||
|
calculateSourceRect(gameTime);
|
||||||
|
handleSound();
|
||||||
|
canChangeDir();
|
||||||
|
|
||||||
move();
|
}
|
||||||
calculateSourceRect(gameTime);
|
|
||||||
borders();
|
|
||||||
handleSound();
|
|
||||||
canChangeDir();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void playSound(int kind) {
|
private void playDieSound() {
|
||||||
|
|
||||||
|
do {
|
||||||
|
soundID2 = SoundStuff.sp.play(SoundStuff.gameOver, 1, 1, 1, 0, 1);
|
||||||
|
} while (soundID2 == 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void dir(MotionEvent event) {
|
public void dir(MotionEvent event) {
|
||||||
|
|
||||||
switch (event.getAction()) {
|
switch (event.getAction()) {
|
||||||
@@ -123,29 +153,29 @@ public class PacMan extends GameObject {
|
|||||||
|
|
||||||
public void handleSound() {
|
public void handleSound() {
|
||||||
if (stop) {
|
if (stop) {
|
||||||
SoundStuff.sp.pause(SoundStuff.pacamnWalk);
|
SoundStuff.sp.pause(soundID1);
|
||||||
isPlaying = false;
|
isPlaying = false;
|
||||||
} else if (!isPlaying) {
|
} else if (!isPlaying) {
|
||||||
SoundStuff.sp.resume(SoundStuff.pacamnWalk);
|
SoundStuff.sp.resume(soundID1);
|
||||||
isPlaying = true;
|
isPlaying = true;
|
||||||
}
|
}
|
||||||
|
if(stop && die)
|
||||||
|
{
|
||||||
|
do {
|
||||||
|
soundID2 = SoundStuff.sp.play(SoundStuff.gameOver, 1, 1, 1, 0, 1);
|
||||||
|
} while (soundID2 == 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void borders() {
|
public void borders() {
|
||||||
if (position.x > 480 && position.y == 238) { // przejście przez sciane
|
|
||||||
// nie bedzie dzialac
|
|
||||||
// dla innych lvl!
|
|
||||||
position.x = -size;
|
|
||||||
}
|
|
||||||
if (position.x < -size && position.y == 238) {
|
|
||||||
position.x = 479;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void calculateSourceRect(long gameTime) {
|
private void calculateSourceRect(double gameTime) {
|
||||||
if (!stop) {
|
if (!stop) {
|
||||||
if (gameTime > frameTicker + framePeriod) {
|
frameTicker += gameTime;
|
||||||
frameTicker = gameTime;
|
if (frameTicker > framePeriod) {
|
||||||
|
frameTicker = 0;
|
||||||
// increment the frame
|
// increment the frame
|
||||||
if (!swap)
|
if (!swap)
|
||||||
currentFrame++;
|
currentFrame++;
|
||||||
@@ -153,6 +183,7 @@ public class PacMan extends GameObject {
|
|||||||
currentFrame--;
|
currentFrame--;
|
||||||
if (currentFrame == 0 || currentFrame == 2) {
|
if (currentFrame == 0 || currentFrame == 2) {
|
||||||
swap = !swap;
|
swap = !swap;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -163,4 +194,38 @@ public class PacMan extends GameObject {
|
|||||||
sourceRect.right = sourceRect.left + spriteWidth;
|
sourceRect.right = sourceRect.left + spriteWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void die() {
|
||||||
|
die = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void dirAcc(SensorEvent event) {
|
||||||
|
|
||||||
|
xAcc = event.values[0];
|
||||||
|
yAcc = event.values[1];
|
||||||
|
if (!first) {
|
||||||
|
// jezeli wartosc akcelometra jest wieksza od 1 lub -1
|
||||||
|
if (xAcc > xZero + 1) {
|
||||||
|
setDirection(GameEnum.LEFT);
|
||||||
|
} else if (xAcc < xZero - 1) {
|
||||||
|
setDirection(GameEnum.RIGHT);
|
||||||
|
} else if (yAcc > yZero + 1) {
|
||||||
|
setDirection(GameEnum.DOWN);
|
||||||
|
} else if (yAcc < yZero - 1) {
|
||||||
|
setDirection(GameEnum.UP);
|
||||||
|
}
|
||||||
|
} else {// zapamietanie pozycji poczatkowej poto aby wygodniej sie
|
||||||
|
// sterowalo
|
||||||
|
xZero = xAcc;
|
||||||
|
yZero = yAcc;
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stop() {
|
||||||
|
SoundStuff.sp.stop(soundID1);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -2,17 +2,17 @@ package com.android.game.pacman.model;
|
|||||||
|
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Rect;
|
import android.graphics.RectF;
|
||||||
|
|
||||||
import com.android.game.pacman.utils.GameEnum;
|
import com.android.game.pacman.utils.GameEnum;
|
||||||
|
|
||||||
public class SolidObject {
|
public class SolidObject {
|
||||||
protected int x;
|
protected double x;
|
||||||
protected int y;
|
protected double y;
|
||||||
protected Bitmap bitmap;
|
static Bitmap bitmap;
|
||||||
Rect boundingRect = new Rect();
|
public RectF boundingRect = new RectF();
|
||||||
protected boolean isTouched = false;
|
protected boolean isTouched = false;
|
||||||
protected GameEnum kind;
|
public int kind;
|
||||||
protected boolean rotate = false;
|
protected boolean rotate = false;
|
||||||
protected double angle = 0;
|
protected double angle = 0;
|
||||||
public SolidObject(int x, int y){
|
public SolidObject(int x, int y){
|
||||||
@@ -22,12 +22,10 @@ public class SolidObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void draw(Canvas canvas) {
|
public void draw(Canvas canvas) {
|
||||||
canvas.drawBitmap(bitmap, x, y, null);
|
canvas.drawBitmap(bitmap, (float)x, (float)y, null);
|
||||||
boundingRect = new Rect(x, y, x + bitmap.getWidth(),y + bitmap.getHeight());
|
boundingRect.set((float)x, (float)y, (float)x + bitmap.getWidth(),(float)y + bitmap.getHeight());
|
||||||
}
|
|
||||||
public Rect getBoundingRect() {
|
|
||||||
return boundingRect;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setIsTouched(boolean b) {
|
public void setIsTouched(boolean b) {
|
||||||
isTouched = b;
|
isTouched = b;
|
||||||
@@ -37,9 +35,8 @@ public class SolidObject {
|
|||||||
return isTouched;
|
return isTouched;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GameEnum getKind() {
|
|
||||||
return kind;
|
|
||||||
}
|
|
||||||
public void rotate(double angle) {
|
public void rotate(double angle) {
|
||||||
rotate = true;
|
rotate = true;
|
||||||
this.angle = angle;
|
this.angle = angle;
|
||||||
|
|||||||
@@ -7,18 +7,24 @@ import android.media.SoundPool;
|
|||||||
import com.adroid.game.pacman.R;
|
import com.adroid.game.pacman.R;
|
||||||
|
|
||||||
public class SoundStuff {
|
public class SoundStuff {
|
||||||
static SoundPool sp;
|
public static SoundPool sp;
|
||||||
static int pacamnWalk;
|
public static int pacamnWalk;
|
||||||
public SoundStuff(Context context){
|
public static int ghostSiren;
|
||||||
sp=new SoundPool(3,AudioManager.STREAM_MUSIC,0);
|
public static int gameStart;
|
||||||
pacamnWalk = sp.load(context,R.raw.pacman_walk, 1);
|
public static int gameOver;
|
||||||
|
public static int pacmanCherry;
|
||||||
|
public static int pacmanEatGhost;
|
||||||
}
|
|
||||||
public int getIdPacman(){
|
public SoundStuff(Context context) {
|
||||||
return pacamnWalk;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
sp = new SoundPool(3, AudioManager.STREAM_MUSIC, 0);
|
||||||
|
pacamnWalk = sp.load(context, R.raw.pacman_walk, 1);
|
||||||
|
ghostSiren = sp.load(context, R.raw.pacman_siren, 1);
|
||||||
|
gameStart = sp.load(context, R.raw.pacman_start, 1);
|
||||||
|
gameOver = sp.load(context, R.raw.pacmandie, 1);
|
||||||
|
pacmanCherry = sp.load(context, R.raw.pacman_cherry, 1);
|
||||||
|
pacmanEatGhost = sp.load(context, R.raw.pacman_ghost_eating, 1);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package com.android.game.pacman.model;
|
|
||||||
|
|
||||||
public class Stage {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -2,18 +2,19 @@ package com.android.game.pacman.model;
|
|||||||
|
|
||||||
public class Vect {
|
public class Vect {
|
||||||
|
|
||||||
public int x;
|
public double x;
|
||||||
public int y;
|
public double y;
|
||||||
|
|
||||||
public Vect(int x, int y) {
|
public Vect(double x, double y ) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vect add(Vect another) {
|
public Vect add(Vect another) {
|
||||||
return new Vect(x + another.x, y + another.y);
|
return new Vect(x+another.x,y+another.y);
|
||||||
|
|
||||||
}
|
}
|
||||||
public Vect mulitply(int speed){
|
public Vect mulitply(double speed){
|
||||||
x=x*speed;
|
x=x*speed;
|
||||||
y=y*speed;
|
y=y*speed;
|
||||||
return this;
|
return this;
|
||||||
@@ -27,8 +28,12 @@ public class Vect {
|
|||||||
public Vect subtract(Vect vect){
|
public Vect subtract(Vect vect){
|
||||||
return new Vect(x-vect.x,y-vect.y);
|
return new Vect(x-vect.x,y-vect.y);
|
||||||
}
|
}
|
||||||
|
public void set(double x,double y){
|
||||||
|
this.x=x;
|
||||||
|
this.y=y;
|
||||||
|
}
|
||||||
static public Vect normalize(Vect vect){
|
static public Vect normalize(Vect vect){
|
||||||
return new Vect((int)(vect.x/vect.getLength()), (int)(vect.y/vect.getLength()));
|
return new Vect((double)(vect.x/vect.getLength()), (double)(vect.y/vect.getLength()));
|
||||||
}
|
}
|
||||||
static public double dot(Vect one,Vect two){
|
static public double dot(Vect one,Vect two){
|
||||||
return one.x*two.x+one.y*two.y;
|
return one.x*two.x+one.y*two.y;
|
||||||
|
|||||||
@@ -1,5 +1,19 @@
|
|||||||
package com.android.game.pacman.utils;
|
package com.android.game.pacman.utils;
|
||||||
|
|
||||||
public enum GameEnum {
|
public class GameEnum {
|
||||||
NORMAL,EASY,HARD,UP,DOWN,LEFT,RIGHT,STOP,FOOD,FOODUP,BONUS,WALL,PATH,CORNER,STRAIGHT
|
public final static int NORMAL=0;
|
||||||
|
public final static int EASY=1;
|
||||||
|
public final static int HARD=2;
|
||||||
|
public final static int UP=3;
|
||||||
|
public final static int DOWN=4;
|
||||||
|
public final static int LEFT=5;
|
||||||
|
public final static int RIGHT=6;
|
||||||
|
public final static int STOP=7;
|
||||||
|
public final static int FOOD=8;
|
||||||
|
public final static int FOODUP=9;
|
||||||
|
public final static int BONUS=10;
|
||||||
|
public final static int WALL=11;
|
||||||
|
public final static int PATH=12;
|
||||||
|
public final static int CORNER=13;
|
||||||
|
public final static int STRAIGHT=14;
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user