bulletmanager.java

来自「J2ME 上的坦克大战的demo,欢迎大家用来学习使用」· Java 代码 · 共 52 行

JAVA
52
字号
/*
 * Created on 2006-2-4
 * Author: Xuefeng, Copyright (C) 2006, Xuefeng.
 */
package com.javaeedev.j2megame.tank;

import java.util.*;

import javax.microedition.lcdui.*;

public class BulletManager {

    private GameMap map;
    private Vector bullets = new Vector();

    public BulletManager(GameMap map) {
        this.map = map;
    }

    public void paint(Graphics g) {
        g.setColor(0xffffff);
        int n=0;
        while(n<bullets.size()) {
            Bullet bullet = (Bullet)bullets.elementAt(n);
            if(bullet.move()) {
                bullets.removeElementAt(n);
                continue;
            }
            if(!map.canPass(bullet.direction, bullet.getX(), bullet.getY())) {
                // check if collide:
                bullets.removeElementAt(n);
                continue;
            }
            //if(!hit(sprite, bullet.getX(), bullet.getY())) {
            //    bullets.removeElementAt(n);
            //    continue;
            //}
            n++;
            // draw it:
            g.fillRect(bullet.getX()-1, bullet.getY()-1, 1, 1);
        }
//        if(bullets.size()==0)
//            System.out.println("All bullets are removed!");
    }

    public void newBullet(Bullet bullet) {
        if(bullet!=null)
            bullets.addElement(bullet);
    }

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?