| C:\eclipse\workspace\Epsilon_03\src\GameSprite.java |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 class GameSprite {
22
23 public int x;
24 public int y;
25
26 public int w;
27 public int h;
28
29 public int vx;
30 public int vy;
31
32 public short energy;
33 public short energyMax;
34
35 public short damage;
36 public short score;
37
38 public byte spriteId;
39
40 public byte imageId;
41
42 public byte frameId;
43 public byte frameIdMax;
44
45 public byte fire_cooldown_frames_counter;
46
47
48
49 public static final byte[] spriteImageFrameWidths =
50 {
51 26,
52 4,
53 45,
54 20,
55 20,
56 20,
57 20,
58 };
59
60 public static final byte SPRITE_DATA_INDEX_IMG_ID = 0;
61 public static final byte SPRITE_DATA_INDEX_MAX_ENERGY = 1;
62 public static final byte SPRITE_DATA_INDEX_DAMAGE = 2;
63 public static final byte SPRITE_DATA_INDEX_SCORE = 3;
64
65
66 public static final short[][] spriteData = {
67 { GameCanvas.SPRITE_IMAGE_PLAYER, 200, 20, 0 },
68 { GameCanvas.SPRITE_IMAGE_ENEMY1, 40, 30, 20 },
69 { GameCanvas.SPRITE_IMAGE_ENEMY1, 40, 30, 40 },
70 { GameCanvas.SPRITE_IMAGE_ENEMY2, 20, 20, 10 },
71 { GameCanvas.SPRITE_IMAGE_ENEMY2, 20, 20, 20 },
72 { GameCanvas.SPRITE_IMAGE_ENEMY3, 60, 40, 30 },
73 { GameCanvas.SPRITE_IMAGE_BOSS1, 200, 100, 100 },
74 { GameCanvas.SPRITE_IMAGE_EXPLOSION, 0, 0, 0 },
75 { GameCanvas.SPRITE_IMAGE_FIRE, 0, 20, 0 },
76 { GameCanvas.SPRITE_IMAGE_FIRE, 0, 20, 0 },
77 { GameCanvas.SPRITE_IMAGE_FIRE, 0, 10, 0 },
78 };
79
80 public static final byte EXPLOSION_FRAME_SMOKE_START = 2;
81
82 GameSprite( byte sprite_id )
83 {
84 spriteId = sprite_id;
85 imageId = (byte) spriteData[sprite_id][SPRITE_DATA_INDEX_IMG_ID];
86 w = spriteImageFrameWidths[imageId];
87 h = GameCanvas.spriteImages[imageId].getHeight();
88 frameId = 0;
89 frameIdMax = (byte) (GameCanvas.spriteImages[imageId].getWidth() / w - 1);
90 vx = 4;
91 vy = 4;
92 energyMax = spriteData[sprite_id][SPRITE_DATA_INDEX_MAX_ENERGY];;
93 energy = energyMax;
94
95 damage = (byte) spriteData[sprite_id][SPRITE_DATA_INDEX_DAMAGE];
96 score = (byte) spriteData[sprite_id][SPRITE_DATA_INDEX_SCORE];
97 }
98
99 public boolean collidesWith(GameSprite sprite)
100 {
101 return (x+w > sprite.x) && (x < sprite.x + sprite.w) &&
102 (y+h > sprite.y) && (y < sprite.y + sprite.h);
103 }
104 }
105