这个爆炸的效果怎么出不来大神给看看
源码太多,qq530651341 希望大神们帮帮我你们留qq 我加你们也可以package demo;
import java.util.Random;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.LayerManager;
import javax.microedition.lcdui.game.TiledLayer;
public class Scene {
private TiledLayer m_TLayer; //跑道格子
private PlayerCar m_Player; //玩家赛车
private CarSprite m_aComCar[]; //电脑赛车
private LayerManager m_Manager; //层管理器
private Random m_Random; //随机数
private ExplosionSprite m_aExplosion[]; //爆炸对象
public Scene( int scrWidth, int scrHeight ){
m_aExplosion = new ExplosionSprite[3];
try{
//读取跑道格子
Image img = Image.createImage("/demo/grid.png");
m_TLayer = new TiledLayer( 7, 100, img, 20, 20 );
m_TLayer.setPosition( scrWidth/2 - m_TLayer.getWidth()/2, 0);
//读取赛车图像
Image imgcar = Image.createImage("/demo/car.png");
m_Player = new PlayerCar( imgcar, 17, 29 );
m_aComCar = new CarSprite[3];
for( int n = 0; n < m_aComCar.length; n ++ )
m_aComCar[n] = new CarSprite( imgcar, 17, 29);
img = Image.createImage("/demo/explosion.png");
for( int m = 0; m < m_aExplosion.length; m ++ ){
m_aExplosion[m] = new ExplosionSprite( img, 21, 17 );
}
//将所有图层添加到层管理器
m_Manager = new LayerManager();
for( int n = 0; n < m_aComCar.length; n ++ )
m_Manager.append(m_aComCar[n]);
m_Manager.append(m_Player);
m_Manager.append(m_TLayer);
for( int m = 0; m < m_aExplosion.length; m ++ )
{
m_Manager.append(m_aExplosion[m]);
}
m_Random = new Random();
}
catch(Exception e){}
}
//重新开局
public void Reset(){
//设置跑道
for( int col = 0; col < m_TLayer.getColumns(); col ++ ){
for( int row = 0; row < m_TLayer.getRows(); row ++ ){
m_TLayer.setCell(col, row, col%2 + 1);
}
}
for( int col = 0; col < m_TLayer.getColumns(); col ++ ){
m_TLayer.setCell(col, 2, 3);
m_TLayer.setCell(col, m_TLayer.getRows()-2, 3);
}
//设置各个赛车的位置
int width = m_TLayer.getCellWidth();
int dis = m_TLayer.getCellWidth()/2 - m_Player.getWidth()/2;
int y = m_TLayer.getHeight() - 30;
m_Player.setPosition(m_TLayer.getX() + 2 * width + dis, y);
m_aComCar[0].setPosition(m_TLayer.getX() + dis, y);
m_aComCar[0].setFrame(1);
m_aComCar[1].setPosition(m_TLayer.getX() + 4 * width + dis, y);
m_aComCar[1].setFrame(2);
m_aComCar[2].setPosition(m_TLayer.getX() + 6 * width + dis, y);
m_aComCar[2].setFrame(3);
}
//设置游戏画面的显示区域
public void SetViewWindow( int scrWidth, int scrHeight ){
if( m_Manager == null )
return;
//根据英雄的位置,设置游戏画面的显示区域
int nY = m_Player.getRefPixelY() - scrHeight/2;
if( nY < 0 )
nY = 0;
else if( nY > m_TLayer.getHeight() - scrHeight )
nY = m_TLayer.getHeight() - scrHeight;
m_Manager.setViewWindow( 0, nY, scrWidth, scrHeight );
}
//处理按键的输入,参数keyStates为按键状态
public void Input(int keyStates){
m_Player.Input(keyStates);
}
//逻辑操作,参数scrWidth、scrHeight分别是屏幕的宽和高
//返回-1表示游戏失败,返回1表示游戏胜利
public int Logic(int scrWidth, int scrHeight)
{
m_Player.Logic(null);
boolean bHasCar = false; //是否有汽车到达了终点
for( int n = 0; n < m_aComCar.length; n ++ ){
m_aComCar[n].Logic(m_Random);
if( m_aComCar[n].collidesWith(m_Player, true) )
{//如果和游戏者赛车相撞
CreateExplosion(m_Player.getRefPixelY(), m_Player.getRefPixelX());
m_Player.setVisible( false );
}
//如果超出跑道范围
if( m_aComCar[n].getX() < m_TLayer.getX() )
m_aComCar[n].MoveBack(false);
if( m_aComCar[n].getX() + m_aComCar[n].getWidth() >
m_TLayer.getX() + m_TLayer.getWidth() )
m_aComCar[n].MoveBack(false);
if( m_aComCar[n].getRefPixelY() < 40 )
{//如果到达终点
m_aComCar[n].Stop();
bHasCar = true;
}
}
//设置可视区域
SetViewWindow(scrWidth, scrHeight);
if( m_Player.getRefPixelY() < 40 )
{//如果到达终点
if( bHasCar )
return -1;
else
return 1;
}
return 0;
}
//显示图像
public void Paint(Graphics g){
m_Manager.paint(g, 0, 0);
}
public void CreateExplosion( int nX, int nY ){
for( int m = 0; m < m_aExplosion.length; m ++ ){
if( m_aExplosion[m].isVisible() )
continue;
m_aExplosion[m].Start( nX, nY );
break;
}
}
}
--------------------编程问答-------------------- --------------------编程问答-------------------- 在这里等高手答案。学习中
补充:Java , J2ME