⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bulletmanager.java

📁 J2ME 上的坦克大战的demo,欢迎大家用来学习使用
💻 JAVA
字号:
/*
 * 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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -