-
Notifications
You must be signed in to change notification settings - Fork 0
/
Monster.java
102 lines (84 loc) · 2.65 KB
/
Monster.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package kr.ac.tukorea.sgp22.nerverendingjump.game;
import kr.ac.tukorea.sgp22.nerverendingjump.R;
import kr.ac.tukorea.sgp22.nerverendingjump.framework.BitmapPool;
import kr.ac.tukorea.sgp22.nerverendingjump.framework.CollisionHelper;
import kr.ac.tukorea.sgp22.nerverendingjump.framework.GameView;
import kr.ac.tukorea.sgp22.nerverendingjump.framework.Metrics;
import kr.ac.tukorea.sgp22.nerverendingjump.framework.Recycle;
import kr.ac.tukorea.sgp22.nerverendingjump.framework.Sprite;
public class Monster extends Sprite
{
private static MainGame game = null;
private static Doodle doodle = null;
public enum Type
{
hole(0.002f), monster(0.003f), COUNT(2.f);
private final float parcentage;
Type(float value)
{
parcentage = value;
}
public float getPercentage()
{
return parcentage;
}
}
private boolean attackable;
private Type type;
public Monster()
{
super(0, 0, Metrics.size(R.dimen.bullet_w), Metrics.size(R.dimen.bullet_h), R.mipmap.projectile);
game = MainGame.getInstance();
doodle = game.getDoodle();
}
public static Monster get(float x, float y, Type type)
{
Monster monster = (Monster) Recycle.get(Monster.class);
if (monster == null)
{
monster = new Monster();
}
monster.set(x, y, type);
return monster;
}
private void set(float x, float y, Type type)
{
this.x = x;
this.y = y;
this.type = type;
switch (this.type)
{
case hole:
this.bitmap = BitmapPool.get(R.mipmap.hole);
this.setDstRect(Metrics.size(R.dimen.hole_w), Metrics.size(R.dimen.hole_h));
attackable = false;
break;
case monster:
this.bitmap = BitmapPool.get(R.mipmap.monster);
this.setDstRect(Metrics.size(R.dimen.monster_w_1), Metrics.size(R.dimen.monster_h_1));
attackable = true;
break;
default:
attackable = false;
break;
}
}
@Override
public void update()
{
float t_dy = 0;
t_dy = game.getScrollVal();
this.y += t_dy;
dstRect.offset(0, t_dy);
if (CollisionHelper.CollisionCheck(this, doodle))
{
GameView.view.endGame();
GameView.view.changeScene(GameView.Scene.score);
}
else if (y > Metrics.height)
{
game.remove(MainGame.Layer.monster, this);
}
}
public boolean isAttackable() {return attackable;}
}