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

📄 hero.java

📁 本j2me坦克游戏是在Nokia平台下开发的
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			            System.out.println(exception);			        }					posX = SuperTank.canvas.mapOffsetX + SuperTank.canvas.mapWidth/2 - (SuperTank.canvas.tileWidth*2+2) - frameWidth - 2;                    posY = SuperTank.canvas.mapOffsetY + SuperTank.canvas.mapHeight - frameHeight - 2;			    	status = 0;					count = 40;					direction = 3;			       	drawHero = heroUp;				} else {					if(overstart){					    posX = -1000;					    posY = -1000;                                            SuperTank.canvas.life --;		   			    SuperTank.canvas.gameLose = true;		   			    SuperTank.canvas.overtimer.timeCounter = 0;		   			    overstart = false;		   			}				}			}		} else {            if(capped){                if ( (count & 1) > 0 ){                    switch (direction & 0x0f) {                        case 1: //left                            g.drawImage(heroLeft2, posX, posY, g.TOP | g.LEFT);                            break;                        case 2: //right                            g.drawImage(heroRight2, posX, posY, g.TOP | g.LEFT);                            break;                        case 3: //up                            g.drawImage(heroUp2, posX, posY, g.TOP | g.LEFT);                            break;                        case 4: //down                            g.drawImage(heroDown2, posX, posY, g.TOP | g.LEFT);                        default:                            break;                    }                }else{                    switch (direction & 0x0f) {                        case 1: //left                            g.drawImage(heroLeft1, posX, posY, g.TOP | g.LEFT);                            break;                        case 2: //right                            g.drawImage(heroRight1, posX, posY, g.TOP | g.LEFT);                            break;                        case 3: //up                            g.drawImage(heroUp1, posX, posY, g.TOP | g.LEFT);                            break;                        case 4: //down                            g.drawImage(heroDown1, posX, posY, g.TOP | g.LEFT);                        default:                            break;                    }                }                count++;            }else{                switch (direction & 0x0f) {                    case 1: //left//                dg.drawImage(drawHero, posX, posY, g.TOP|g.LEFT, DirectGraphics.ROTATE_90);                        g.drawImage(heroLeft, posX, posY, g.TOP | g.LEFT);                        break;                    case 2: //right//                dg.drawImage(drawHero, posX, posY, g.TOP|g.LEFT, DirectGraphics.ROTATE_270);                        g.drawImage(heroRight, posX, posY, g.TOP | g.LEFT);                        break;                    case 3: //up//                g.drawImage(drawHero, posX, posY, g.TOP|g.LEFT);                        g.drawImage(heroUp, posX, posY, g.TOP | g.LEFT);                        break;                    case 4: //down//                dg.drawImage(drawHero, posX, posY, g.TOP|g.LEFT, DirectGraphics.ROTATE_180);                        g.drawImage(heroDown, posX, posY, g.TOP | g.LEFT);                    default:                        break;                }            }            //modified by johnson here????? is it redudant????	//		g.drawImage(drawHero, posX, posY, g.TOP|g.LEFT);		}        if(grassPaint){            SuperTank.canvas.grassPaint = true;         //   SuperTank.canvas.reDraw(3,g);        }    }    boolean ismapCollide() {    	boolean collFlag = false;    	int collX, collY;    	int i;    	int tileW = SuperTank.canvas.tileW;		collX = posX-SuperTank.canvas.mapOffsetX;		collY = posY-SuperTank.canvas.mapOffsetY;        int pos = 0;        boolean movable = false;        boolean upCol = true;        boolean leftCol = true;		switch(direction & 0x0f) {	        case 1:		//left	        	collX = collX - speed;		        if ( collX <= 0 )		        	collFlag = true;		        else {		        	collFlag = false;		        	for ( i = (collY/tileW * (SuperTank.canvas.mapWidth/tileW) + collX/tileW); i <= ((collY + frameHeight)/tileW * (SuperTank.canvas.mapWidth/tileW) + collX/tileW); i += (SuperTank.canvas.mapWidth/tileW) ){                        if (SuperTank.canvas.mapInfo[i] == 3) {                            grassPaint = true;                        }                        if ( SuperTank.canvas.mapInfo[i] != 0 && SuperTank.canvas.mapInfo[i] != 3){			        		collFlag = true;                            pos = i - (collY/tileW * (SuperTank.canvas.mapWidth/tileW) + collX/tileW);                            if(pos <= (frameHeight/8)/tileW * (SuperTank.canvas.mapWidth/tileW)){                                upCol = true;                                if (SuperTank.canvas.mapInfo[ ( (collY +                                    frameHeight / 8) / tileW *                                    (SuperTank.canvas.mapWidth / tileW) + collX / tileW)] !=                                    0                                    &&                                    SuperTank.canvas.mapInfo[ ( (collY +                                    frameHeight / 8) / tileW *                                    (SuperTank.canvas.mapWidth / tileW) + collX / tileW)] !=                                    3) {                                    movable = false;                                }                                else {                                    movable = true;                                }                            }else if(pos >= (7*frameHeight/8)/tileW * (SuperTank.canvas.mapWidth/tileW)){                                movable = true;                                upCol = false;                            }else{                                movable = false;                            }			        		break;			        	}			        }                    if(collFlag&&movable){                        if(upCol){                            posY = posY +1;                        }else{                            posY = posY -1;                        }                    }	        	}	            break;	        case 2:		//right	        	collX = collX + frameWidth+ speed;		        if (collX >= SuperTank.canvas.mapWidth)			        collFlag = true;			    else {		        	collFlag = false;		        	for ( i = (collY/tileW * (SuperTank.canvas.mapWidth/tileW) + collX/tileW); i <= ((collY + frameHeight)/tileW * (SuperTank.canvas.mapWidth/tileW) + collX/tileW); i += (SuperTank.canvas.mapWidth/tileW) ){                        if (SuperTank.canvas.mapInfo[i] == 3) {                            grassPaint = true;                        }                        if ( SuperTank.canvas.mapInfo[i] != 0 && SuperTank.canvas.mapInfo[i] != 3){			        		collFlag = true;                            pos = i - (collY/tileW * (SuperTank.canvas.mapWidth/tileW) + collX/tileW);                            if(pos <= (frameHeight/8)/tileW * (SuperTank.canvas.mapWidth/tileW)){                                upCol = true;                                if(SuperTank.canvas.mapInfo[((collY + frameHeight/8)/tileW * (SuperTank.canvas.mapWidth/tileW) + collX/tileW)]!=0                                   && SuperTank.canvas.mapInfo[((collY + frameHeight/8)/tileW * (SuperTank.canvas.mapWidth/tileW) + collX/tileW)]!=3){                                    movable = false;                                }else{                                    movable = true;                                }                            }else if(pos >= (7*frameHeight/8)/tileW * (SuperTank.canvas.mapWidth/tileW)){                                movable = true;                                upCol = false;                            }else{                                movable = false;                            }			        		break;			        	}			        }                    if(collFlag&& movable){                        if(upCol){                            posY = posY +1;                        }else{                            posY = posY -1;                        }                    }	        	}    	        break;	        case 3:		//up	        	collY = collY - speed;		        if (collY <= 0)		        	collFlag = true;		        else {		        	collFlag = false;		        	for ( i = (collY/tileW * (SuperTank.canvas.mapWidth/tileW) + collX/tileW); i <= (collY/tileW * (SuperTank.canvas.mapWidth/tileW) + (collX + frameWidth)/tileW); i ++ ){                        if (SuperTank.canvas.mapInfo[i] == 3) {                            grassPaint = true;                        }                        if ( SuperTank.canvas.mapInfo[i] != 0 && SuperTank.canvas.mapInfo[i] != 3){			        		collFlag = true;                            pos = i - (collY/tileW * (SuperTank.canvas.mapWidth/tileW) + collX/tileW);                            if(pos <= (frameWidth/8)/tileW){                                leftCol = true;                                if (SuperTank.canvas.mapInfo[ (collY / tileW *                                    (SuperTank.canvas.mapWidth / tileW) +                                    (collX + frameWidth / 8) / tileW)] != 0                                    &&                                    SuperTank.canvas.mapInfo[ (collY / tileW *                                    (SuperTank.canvas.mapWidth / tileW) +                                    (collX + frameWidth / 8) / tileW)] != 3) {                                    movable = false;                                }                                else {                                    movable = true;                                    }                            }else if(pos >= (7*frameWidth/8)/tileW){                                leftCol = false;                                movable = true;                            }else{                                movable = false;                            }			        		break;			        	}			        }                    if(collFlag&&movable){                        if (leftCol) {                            posX = posX + 1;                        }                        else {                            posX = posX - 1;                        }                    }	        	}        	    break;	        case 4:		//down	        	collY = collY + frameHeight+ speed;		        if (collY >= SuperTank.canvas.mapHeight)			        collFlag = true;			    else {		        	collFlag = false;		        	for ( i = (collY/tileW * (SuperTank.canvas.mapWidth/tileW) + collX/tileW); i <= (collY/tileW * (SuperTank.canvas.mapWidth/tileW) + (collX + frameWidth)/tileW); i ++ ){                        if (SuperTank.canvas.mapInfo[i] == 3) {                            grassPaint = true;                        }                        if ( SuperTank.canvas.mapInfo[i] != 0 && SuperTank.canvas.mapInfo[i] != 3 ){			        		collFlag = true;                            pos = i - (collY/tileW * (SuperTank.canvas.mapWidth/tileW) + collX/tileW);                            if(pos <= (frameWidth/8)/tileW){                                leftCol = true;                                if (SuperTank.canvas.mapInfo[ (collY / tileW *                                    (SuperTank.canvas.mapWidth / tileW) +                                    (collX + frameWidth / 8) / tileW)] != 0                                    &&                                    SuperTank.canvas.mapInfo[ (collY / tileW *                                    (SuperTank.canvas.mapWidth / tileW) +                                    (collX + frameWidth / 8) / tileW)] != 3) {                                    movable = false;                                }                                else {                                    movable = true;                                    }                            }else if(pos >= (7*frameWidth/8)/tileW){                                leftCol = false;                                movable = true;                            }else{                                movable = false;                            }			        		break;			        	}			        }                    if(collFlag&&movable){                        if (leftCol) {                            posX = posX + 1;                        }                        else {                            posX = posX - 1;                        }                    }	        	}	        default:	            break;		}    	return collFlag;    }    boolean isobjCollide( int objX, int objY, int objWidth,int objHeight) {        boolean collFlag = false;        int collX, collY;        int i;        collX = posX;        collY = posY;        switch(direction & 0x0f) {            case 1:		//left                collX = collX - speed;                break;            case 2:		//right                collX = collX + speed;                break;            case 3:		//up                collY = collY - speed;                break;            case 4:		//down                collY = collY + speed;            default:                break;        }        if ( collX < (objX + objWidth) && (collX + frameWidth) > objX &&                collY < (objY + objHeight) && (collY + frameHeight) > objY )            collFlag = true;        return collFlag;    }}

⌨️ 快捷键说明

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