将图片设置为随机坐标?

时间:2014-02-09 04:37:50

标签: java image slick2d

所以我试图像硬币收集器游戏一样写一个飞扬的鸟,当我试图将硬币图像坐标设置为随机数时,屏幕会冻结。有帮助吗?

继承我的球员课程:

package gamepackage;
import java.util.Random;

import org.newdawn.slick.*;
import org.newdawn.slick.geom.Rectangle;
import org.newdawn.slick.state.*;
public class Playing extends BasicGameState{
Image coin;
Image guy;
int coincounter = 0;
float x = 30, y = 90;
int coiny = 20, coinx= 1000;

public Playing(int state){


}

public void init(GameContainer gc, StateBasedGame sbg)throws SlickException{
    guy = new Image("res/PlaneMovie1.gif");
    coin = new Image("res/coin.gif");


}
public void render(GameContainer gc, StateBasedGame sbg, Graphics g)throws     SlickException{
    g.drawString("Coins:" + coincounter, 70, 70);
    g.drawImage(coin, coinx, coiny);
    g.drawImage(guy, x, y);
}
public void update(GameContainer gc, StateBasedGame sbg, int delta)throws SlickException{

Input input = gc.getInput();

coinx --;
if(input.isKeyDown(Input.KEY_SPACE)){   y -= 1 ; }
if(input.isKeyDown(Input.KEY_SPACE) == false){  y += .5;}
 if(y == coiny){ coincounter += 1;coinx = 1000; coiny -= 20;}
 if(coinx == -175){coinx = 1000; coiny += 20;}


}
public int getID(){
return 1;
}
}

0 个答案:

没有答案