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

📄 bullet.java

📁 本j2me坦克游戏是在Nokia平台下开发的
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * @(#)Bullet.java	0.20 02/11/07 * Copyright (c) 2002 InterScape Creations. All Rights Reserved. */import javax.microedition.lcdui.*;class Bullet implements Runnable {    private static Graphics G = null;	boolean alive;    int posX, posY;    int BposX, BposY;	int mapBlock;    int direction;    int speed;    int frameNum;	int bombCount;	Image bulletImage;	Image bulletLeft;	Image bulletRight;	Image bulletUp;	Image bulletDown;	Image bombImage;	Image drawBullet;	boolean bombFlag = false;    boolean ironPaint = false;    boolean grassPaint = false;    boolean homeover = false;    boolean isbomb = false;    int frameWidth, frameHeight;    int starNum;    Bullet() {        starNum = 0;		// Load the object images        try {        	bulletImage = Image.createImage("/bullet.png");        	frameWidth = bulletImage.getWidth()/4;        	frameHeight = bulletImage.getHeight();            bulletLeft = Image.createImage(frameWidth, frameHeight);            G = bulletLeft.getGraphics();            G.drawImage(bulletImage, 0, 0, 20);            bulletRight = Image.createImage(frameWidth, frameHeight);            G = bulletRight.getGraphics();            G.drawImage(bulletImage, -frameWidth*1, 0, 20);            bulletUp = Image.createImage(frameWidth, frameHeight);            G = bulletUp.getGraphics();            G.drawImage(bulletImage, -frameWidth*2, 0, 20);            bulletDown = Image.createImage(frameWidth, frameHeight);            G = bulletDown.getGraphics();            G.drawImage(bulletImage, -frameWidth*3, 0, 20);            G = null;	       	drawBullet = bulletUp;			bombImage = Image.createImage("/explode.png");        }        catch(Exception exception) {            System.out.println(exception);        }    }	public void run() {	}    synchronized void paint(Graphics g) {    	int fillposX = posX;    	int fillposY = posY;    	int fillwidth = frameWidth;    	int fillheigh = frameHeight;    	int blockX = 0;    	int blockY = 0;		int i;		int tileW = SuperTank.canvas.tileW;        switch(starNum){            case 0:                speed = SuperTank.canvas.tileW;                break;            case 1:                speed = SuperTank.canvas.tileW+1;                break;            case 2:                speed = SuperTank.canvas.tileW+2;                break;            case 3:                speed = SuperTank.canvas.tileW+3;                break;            default:                break;        }		if (!bombFlag){            ironPaint = false;            grassPaint = false;            if (ismapCollide()) {                g.fillRect(posX, posY, frameWidth, frameHeight);                if (mapBlock < 0x0ffff) {                    // Destroy the blocks                    switch (direction) {                        case 1: //left                            for (i = 0; i < 4; i++) {                                if ( (SuperTank.canvas.mapInfo[mapBlock] > 0) &&                                    (SuperTank.canvas.mapInfo[mapBlock] < 4)) {                                    if (SuperTank.canvas.mapInfo[mapBlock] == 2 &&                                        starNum != 3) {                                        ironPaint = true;                                    }                                    if (SuperTank.canvas.mapInfo[mapBlock] != 2) {                                        blockY = mapBlock /                                            (SuperTank.canvas.mapWidth / tileW);                                        blockX = mapBlock -                                            blockY *                                            (SuperTank.canvas.mapWidth / tileW);                                        g.setColor(0x0);                                        g.fillRect(blockX * tileW +                                            SuperTank.canvas.mapOffsetX,                                            blockY * tileW +                                            SuperTank.canvas.mapOffsetY, tileW, tileW);                                        SuperTank.canvas.mapInfo[mapBlock] = 0;                                    }                                    else { //rid the iron layer                                        if (starNum == 3) {                                            blockY = mapBlock /                                                (SuperTank.canvas.mapWidth / tileW);                                            blockX = mapBlock -                                                blockY *                                                (SuperTank.canvas.mapWidth / tileW);                                            g.setColor(0x0);                                            g.fillRect(blockX * tileW +                                                SuperTank.canvas.mapOffsetX,                                                blockY * tileW +                                                SuperTank.canvas.mapOffsetY, tileW, tileW);                                            SuperTank.canvas.mapInfo[mapBlock] = 0;                                        }                                    }                                }                                else if (SuperTank.canvas.mapInfo[mapBlock] >=                                         4) {                                    SuperTank.canvas.gameLose = true;                                    SuperTank.canvas.overtimer.timeCounter = 0;                                    g.setColor(0x0);                                    homeover = true;                                    g.fillRect(SuperTank.canvas.mapOffsetX +                                               SuperTank.canvas.mapWidth / 2 - tileW*2,                                               SuperTank.canvas.mapOffsetY +                                               SuperTank.canvas.mapHeight - tileW*4, tileW*4,                                               tileW*4);                                }                                mapBlock += (SuperTank.canvas.mapWidth / tileW);                                if (mapBlock >=                                    ( (SuperTank.canvas.mapWidth / tileW) *                                     (SuperTank.canvas.mapHeight / tileW)))                                    break;                            }                            break;                        case 2: //right                            for (i = 0; i < 4; i++) {                                if ( (SuperTank.canvas.mapInfo[mapBlock] > 0) &&                                    (SuperTank.canvas.mapInfo[mapBlock] < 4)) {                                    if (SuperTank.canvas.mapInfo[mapBlock] == 2 &&                                        starNum != 3) {                                        ironPaint = true;                                    }                                    if (SuperTank.canvas.mapInfo[mapBlock] != 2) {                                        blockY = mapBlock /                                            (SuperTank.canvas.mapWidth / tileW);                                        blockX = mapBlock -                                            blockY *                                            (SuperTank.canvas.mapWidth / tileW);                                        g.setColor(0x0);                                        g.fillRect(blockX * tileW +                                            SuperTank.canvas.mapOffsetX,                                            blockY * tileW +                                            SuperTank.canvas.mapOffsetY, tileW, tileW);                                        SuperTank.canvas.mapInfo[mapBlock] = 0;                                    }                                    else { //rid the iron layer                                        if (starNum == 3) {                                            blockY = mapBlock /                                                (SuperTank.canvas.mapWidth / tileW);                                            blockX = mapBlock -                                                blockY *                                                (SuperTank.canvas.mapWidth / tileW);                                            g.setColor(0x0);                                            g.fillRect(blockX * tileW +                                                SuperTank.canvas.mapOffsetX,                                                blockY * tileW +                                                SuperTank.canvas.mapOffsetY, tileW, tileW);                                            SuperTank.canvas.mapInfo[mapBlock] = 0;                                        }                                    }                                }                                else if (SuperTank.canvas.mapInfo[mapBlock] >=                                         4) {                                    SuperTank.canvas.gameLose = true;                                    SuperTank.canvas.overtimer.timeCounter = 0;                                    g.setColor(0x0);                                    homeover = true;                                    g.fillRect(SuperTank.canvas.mapOffsetX +                                               SuperTank.canvas.mapWidth / 2 - tileW*2,                                               SuperTank.canvas.mapOffsetY +                                               SuperTank.canvas.mapHeight - tileW*4, tileW*4,                                               tileW*4);                                }                                mapBlock += (SuperTank.canvas.mapWidth / tileW);                                if (mapBlock >=                                    ( (SuperTank.canvas.mapWidth / tileW) *                                     (SuperTank.canvas.mapHeight / tileW)))                                    break;                            }                            break;                        case 3: //up                            for (i = 0; i < 4; i++) {                                if ( (SuperTank.canvas.mapInfo[mapBlock] > 0) &&                                    (SuperTank.canvas.mapInfo[mapBlock] < 4)) {                                    if (SuperTank.canvas.mapInfo[mapBlock] == 2 &&                                        starNum != 3) {                                        ironPaint = true;                                   //     System.out.println(ironPaint);                                    }                                    if (SuperTank.canvas.mapInfo[mapBlock] != 2) {                                        blockY = mapBlock /                                            (SuperTank.canvas.mapWidth / tileW);                                        blockX = mapBlock -                                            blockY *                                            (SuperTank.canvas.mapWidth / tileW);                                        g.setColor(0x0);                                        g.fillRect(blockX * tileW +                                            SuperTank.canvas.mapOffsetX,                                            blockY * tileW +                                            SuperTank.canvas.mapOffsetY, tileW, tileW);                                        SuperTank.canvas.mapInfo[mapBlock] = 0;                                    }                                    else {                                        if (starNum == 3) {                                            blockY = mapBlock /                                                (SuperTank.canvas.mapWidth / tileW);                                            blockX = mapBlock -                                                blockY *                                                (SuperTank.canvas.mapWidth / tileW);                                            g.setColor(0x0);                                            g.fillRect(blockX * tileW +                                                SuperTank.canvas.mapOffsetX,                                                blockY * tileW +

⌨️ 快捷键说明

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