18fdda8744848b484fdfb8828c85df87667e81bd
1 package code
.kalter
.longflight
.game
;
3 import code
.kalter
.longflight
.Loader
;
4 import code
.kalter
.longflight
.game
.bullet
.Collisionable
;
5 import code
.kalter
.longflight
.game
.bullet
.Gun
;
6 import java
.io
.IOException
;
7 import javax
.microedition
.lcdui
.Graphics
;
8 import javax
.microedition
.lcdui
.Image
;
15 public class Bullet
implements Gun
{
17 private final int SIZE
= 128;
18 private final int screenH
;
20 private final Image
[] gfx
;
22 private final int[] positionX
;
23 private final int[] positionY
;
24 private final int[] type
;
26 private Collisionable
[] object
;
28 public Bullet(int screenH
) throws IOException
{
29 this.screenH
= screenH
;
30 positionX
= new int[SIZE
];
31 positionY
= new int[SIZE
];
33 Loader imageLoader
= Loader
.getInstance();
35 imageLoader
.getImage("/gfx/bullet/0.png"),
36 imageLoader
.getImage("/gfx/bullet/1.png")
40 // магия - все пули исчезают
41 public void setNull() {
42 for (int i
= 0; i
< SIZE
; i
++) {
47 public void setCollisionable(Collisionable
[] object
) {
51 public void update() {
52 for (int i
= 0; i
< SIZE
; i
++) {
53 if (type
[i
] == NULL
) {
57 positionY
[i
] += (type
[i
] * 2 - 1) * 5;
58 if ((positionY
[i
] < -10) || (positionY
[i
] > screenH
)) {
64 public void paint(Graphics graphics
) {
65 for (int i
= 0; i
< SIZE
; i
++) {
66 if (type
[i
] == NULL
) {
69 graphics
.drawImage(gfx
[type
[i
]], positionX
[i
], positionY
[i
], 0);
74 public void fire(int type
, int positionX
, int positionY
) {
75 for (int i
= 0; i
< SIZE
; i
++) {
76 if (this.type
[i
] != NULL
) {
80 this.positionX
[i
] = positionX
;
81 this.positionY
[i
] = positionY
;
86 private void collision(int i
) {
87 for (int j
= 0; j
< object
.length
; j
++) {
88 if (type
[i
] == object
[j
].getType()) {
91 if (object
[j
].isCollisionOfBullet(positionX
[i
], positionY
[i
])) {
92 object
[j
].boomOfBullet();