Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package potikgame;
- import java.util.ArrayList;
- import org.lwjgl.input.Mouse;
- import org.newdawn.slick.GameContainer;
- import org.newdawn.slick.Graphics;
- import org.newdawn.slick.Image;
- import org.newdawn.slick.Input;
- import org.newdawn.slick.SlickException;
- import org.newdawn.slick.geom.Polygon;
- import org.newdawn.slick.state.BasicGameState;
- import org.newdawn.slick.state.GameState;
- import org.newdawn.slick.state.StateBasedGame;
- import org.newdawn.slick.state.transition.FadeInTransition;
- import org.newdawn.slick.state.transition.FadeOutTransition;
- public class game extends BasicGameState{
- boolean debug;
- Image background;
- Image eButton;
- ArrayList<Polygon> butPol=new ArrayList<Polygon>();
- ArrayList<String> butStr=new ArrayList<String>();
- Polygon mousePoly;
- networking net;
- StateBasedGame par1;
- private boolean begin=false;
- public game(int game) {
- }
- public void init(GameContainer gc, StateBasedGame sbg)throws SlickException {
- mousePoly=new Polygon(new float[]{Mouse.getX(),768-Mouse.getY()});
- background=new Image("res/backround.png");
- eButton=new Image("res/nupuPohi.png");
- net=new networking("25.163.75.92");
- }
- public void render(GameContainer gc, StateBasedGame sbg, Graphics g)throws SlickException {
- background.draw(0, 0);
- renderButton(g);
- if(debug){
- g.drawString("X "+mousePoly.getX(), 100, 50);
- g.drawString("Y "+mousePoly.getY(), 100, 70);
- g.drawString(""+mouseOverButton(), 100, 90);
- }
- }
- public void update(GameContainer gc, StateBasedGame sbg, int delta)throws SlickException {
- updateMousePoly();
- par1 = sbg;
- debug=mainGame.debug;
- if(!begin){
- System.out.println("run");
- net.startRunning();
- begin=true;
- net.sendMessage("test message");
- }
- }
- public int getID() {
- return 1;
- }
- private void buttonDoAction(StateBasedGame sbg) {//tegeleb nupu vajutustega
- if(mouseOverButton()!=null){
- try{
- switch(Integer.parseInt(mouseOverButton())){
- case 0: buttonTextBoolean(0, "Debug:Sees", "Debug:Väljas"); break;
- case 1: break;
- case 2: sbg.enterState(0, new FadeOutTransition(),new FadeInTransition()); break;
- }
- }catch(Exception err){
- System.out.println("Lol,you fucked up");
- }
- }
- }
- public void updateMousePoly(){//uuendab hiire asukoha markerit
- mousePoly.setX(Mouse.getX());
- mousePoly.setY(768-Mouse.getY());
- }
- public void createButton(int X,int Y,String txt){//teeb uue nupu
- butStr.add(txt);
- Polygon poly=new Polygon(new float[]{X,Y,
- X+200,Y,
- X+200,Y+80,
- X,Y+80
- });
- butPol.add(poly);
- System.out.printf("state %d nupp X:%d Y:%d txt:%s \n", getID(),X,Y,txt);
- }
- public void renderButton(Graphics g){//kuvab nupud
- for (int i=0;i<butPol.size();i++) {
- eButton.draw(butPol.get(i).getMinX(), butPol.get(i).getMinY());
- if(debug){g.draw(butPol.get(i));g.drawString(""+i, butPol.get(i).getX(), butPol.get(i).getY());}
- g.drawString(""+butStr.get(i),butPol.get(i).getMinX()+20, butPol.get(i).getMinY()+30);
- }
- }
- public String mouseOverButton(){//tagastab nupu Stringi mille kohal hiir on
- for(int i=0;i<butPol.size();i++){
- if (butPol.get(i).contains(mousePoly)){
- return ""+i;
- }
- }
- return null;
- }
- public void buttonTextBoolean(int i,String on,String off){//muudab nupu teksti sellele vajutades
- if(butStr.get(i)==on){
- butStr.set(i, off);
- }else
- if(butStr.get(i)==off){
- butStr.set(i, on);
- }
- }
- public void mouseClicked(int button,int x,int y,int clickCount){//kutsutakse kui hiirt vajutatakse
- buttonDoAction(par1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement