|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
package ciel;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Point;
import java.util.Scanner;
import com.rupeng.game.GameCore;
import java.awt.event.KeyEvent;
public class game2 implements Runnable
{
public static void main(String[] args)
{
GameCore.start(new game2());
}
public void run()
{
int [] x_pos = {101,256,355,472,564,694,782};
int [] y_pos = {328,171,524,219,475,235,111};
boolean [] g_tf = new boolean [x_pos.length];
GameCore.loadBgView("46905.jpg");
GameCore.setGameTitle("夏培鑫的第一个游戏");
for (int i=0;i<g_tf.length;i++)
{
GameCore.createSprite(i, "coin");
GameCore.setSpritePosition(i,x_pos[i],y_pos[i]);
GameCore.playSpriteAnimate(i,"rotate",true);
}
int mlid = 999; int txid = 777;
GameCore.createSprite(mlid, "mario");
GameCore.setSpritePosition(mlid,50,20);
GameCore.playSpriteAnimate(mlid,"walk",true);
Dimension mlbig =GameCore.getSpriteSize(mlid);
int mlw = mlbig.width;
int mlh = mlbig.height;
GameCore.createText(txid,"金币数量:0");
GameCore.setTextPosition(txid,777,20);
GameCore.setTextColor(txid,Color.yellow);
for (;;)
{
int kc = GameCore.getPressedKeyCode();
Point pos = GameCore.getSpritePosition(mlid);
if (kc==KeyEvent.VK_UP)
{
GameCore.setSpritePosition(mlid,pos.x,pos.y-20);
}
if (kc==KeyEvent.VK_DOWN)
{
GameCore.setSpritePosition(mlid,pos.x,pos.y+20);
}
if (kc==KeyEvent.VK_LEFT)
{
GameCore.setSpriteFlipX(mlid,false);
GameCore.setSpritePosition(mlid,pos.x-20,pos.y);
}
if (kc==KeyEvent.VK_RIGHT)
{
GameCore.setSpriteFlipX(mlid,true);
GameCore.setSpritePosition(mlid,pos.x+20,pos.y);
}
GameCore.pause(50);
for (int i=0;i<g_tf.length;i++)
{
if (g_tf[i])
{
continue;
}
Dimension gbig =GameCore.getSpriteSize(i);
int gw = gbig.width;
int gh = gbig.height;
int gmidx = x_pos[i]+gw/2;
int gmidy = y_pos[i]+gh/2;
int mlmidx =pos.x+mlw/2;
int mlmidy =pos.y+mlh/2;
double magjl =Math.pow((gmidx-mlmidx)*(gmidx-mlmidx)+(gmidy-mlmidy)*(gmidy-mlmidy),0.5);
if (magjl<30)
{
GameCore.hideSprite(i);
g_tf[i]=true;
int count = 0;
for (int s=0;s<g_tf.length;s++)
{
if (g_tf[s])
{
count++;
}
}
GameCore.setText(txid,"金币数量:"+count);
if (count==7)
{
GameCore.alert("游戏结束");
break;
}
}
}
}
|
|