package
javagame;
import
org.newdawn.slick.*;
import
org.newdawn.slick.state.*;
import
org.lwjgl.input.Mouse;
public
class
Menu extends
BasicGameState
{
Image playNow;
Image exitGame;
public
Menu(int
State)
{
}
public
void
init(GameContainer gc,StateBasedGame sbg) throws
SlickException
{
playNow
= new
Image("res/playNow.png");
exitGame
= new
Image("res/exitGame.png");
}
public
void
render(GameContainer gc,StateBasedGame sbg, Graphics g) throws
SlickException
{
g.drawString("Welcome
to My RPG Game",100,50);
playNow.draw(100,100);
exitGame.draw(100,200);
}
public
void
update(GameContainer gc,StateBasedGame sbg, int
delta) throws
SlickException
{
int
posX = Mouse.getX();
int
posY = Mouse.getY();
//play
now button
if((posX>100
&& posX<311) && (posY>209 &&
posY<260)){ → 根據你的圖片像素
if(Mouse.isButtonDown(0)){
sbg.enterState(1);
}
}
//exit
button
if((posX>100
&& posX<311) && (posY>109 &&
posY<160)){
if(Mouse.isButtonDown(0)){
System.exit(0);
→ 遊戲將退出並關閉程序
}
}
}
public
int
getID()
{
return
0;
}
}
沒有留言:
張貼留言