package com.swift; import java.awt.Point; import com.rupeng.game.GameCore;//导入游戏引擎包 public class Game_RuPeng implements Runnable { public static void main(String[] args) { GameCore.start(new Game_RuPeng());//生成游戏对象,并让引擎启动它 } //覆写接口中的run()方法,控制游戏 @Override public void run() { GameCore.setGameSize(1024, 768);//设置游戏窗口大小 GameCore.setGameTitle("游戏窗口");//设置游戏窗口标题 //使用精灵 int spriteNum=0; GameCore.createSprite(spriteNum, "robot"); GameCore.setSpritePosition(spriteNum, 100, 100); GameCore.playSpriteAnimate(spriteNum, "run", true); int spriteNum1=1; GameCore.createSprite(spriteNum1, "butterflygirl"); GameCore.setSpritePosition(spriteNum1, 200, 200); GameCore.playSpriteAnimate(spriteNum1, "kungfu1", true); int marioNum=2; GameCore.createSprite(marioNum, "mario");//创建精灵 GameCore.setSpritePosition(marioNum, 300, 300); GameCore.playSpriteAnimate(marioNum, "walk", true); GameCore.alert("摔倒"); GameCore.playSpriteAnimate(marioNum, "shuaidao", true); GameCore.alert("发呆"); GameCore.playSpriteAnimate(marioNum, "idle", true); GameCore.alert("晕倒"); GameCore.playSpriteAnimate(marioNum, "yundao", true); GameCore.playSpriteAnimate(marioNum, "walk", true); GameCore.alert("向右走"); GameCore.setSpriteFlipX(marioNum, true); //获取马里奥的位置 Point p=GameCore.getSpritePosition(marioNum);//获取马里奥游戏窗口中的位置 for(int i=p.x;i<=1000;i++) { GameCore.setSpritePosition(marioNum, i, p.y++);//向右下移动 GameCore.pause(20); } System.out.println(GameCore.getSpritePositionOnScreen(marioNum));//你的电脑屏幕的位置 GameCore.pause(30000000);//设置游戏窗口停留3秒 } }
精灵图片下载地址:
http://static.rupeng.com/upload/images/201510/F5FBA6FBCED7506695B67B1A551D3E80%E7%B2%BE%E7%81%B5.zip