Results 1 to 2 of 2

Thread: Slick Troubles

  1. #1
    madtaffy is offline Member
    Join Date
    May 2014
    Posts
    23
    Rep Power
    0

    Default Slick Troubles

    I can't tell if this is a logic error or if something is going wrong with the library.

    This is my first time using the Slick library, so I'd appreciate any help.

    Basically, everything works, except, when I get to the Play class. The image appears, but if I click the snare drum, the game takes me back to the explain class, and if I then click play (again) from that class, nothing happens within the play class but the sounds for the drums. Furthermore, if I click the bass drum the first time the Play class is run, it just closes the program and says "AL lib: (EE) alc_cleanup: 1 device not closed."

    Here is my code:

    Menu Class:

    Java Code:
    package javaGame;
    
    import org.lwjgl.input.Mouse;
    import javax.swing.ImageIcon;
    import javax.swing.JLabel;
    
    import org.newdawn.slick.*;
    import org.newdawn.slick.state.*;
    
    public class Menu extends BasicGameState{
    	
    	public String mouse = "No input yet.";
    	public Image menuBackground;
    	public Image playButton;
    	public Image exitButton;
    	public Image highScoreButton;
    	
    	public Menu(int state){
    		
    	}
    	
    	public void init(GameContainer gc, StateBasedGame sbg) throws SlickException{
    		menuBackground = new Image("res/drumMenuBackground.png");
    		playButton = new Image("res/playButton.png");
    		exitButton = new Image("res/exitButton.png");
    		highScoreButton = new Image("res/highScoreButton.png");		
    	}
    	
    	public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException{
    		g.drawString(mouse, 50, 50);
    		g.drawImage(menuBackground, 0, 0);
    		g.drawImage(playButton, 400, 50);
    		g.drawImage(highScoreButton, 400, 150);
    		g.drawImage(exitButton, 400, 250);
    	}
    	
    	public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException{
    		int xposPlay = Mouse.getX();
    		int yposPlay = Mouse.getY();
    		
    		Input input = gc.getInput();
    		
    		if((xposPlay > 403 && xposPlay < 583) && (yposPlay > 235 && yposPlay < 310)){
    			//this is the bit of code that is going to run when the mouse is inside the circle
    			//check if they clicked to change state
    			if(input.isMouseButtonDown(0)){
    				sbg.enterState(1);
    			}
    		}
    		
    		if((xposPlay > 403 && xposPlay < 583) && (yposPlay > 207 && yposPlay < 136)){
    			if(input.isMouseButtonDown(0)){
    				sbg.enterState(5);
    			}
    		}
    		
    		if((xposPlay > 403 && xposPlay < 583) && (yposPlay > 35 && yposPlay < 108)){
    			if(input.isMouseButtonDown(0)){
    				System.exit(0);
    			}
    		}
    		
    	}
    	
    	public int getID(){
    		return 0;
    	}
    	
    	
    }
    Play Class:

    Java Code:
    package javaGame;
    
    import org.lwjgl.input.Mouse;
    import org.newdawn.slick.*;
    import org.newdawn.slick.state.*;
    
    public class Play extends BasicGameState{
    	
    	public Image firstLevelBackground;
    	
    	private Sound snareDrum;
    	private Sound bassDrum;
    	public int[] sample = {'1', '1', '1', '0', '0', '1', '1', '0', '0', '1', '1', '1', '1', '1', '0'};
    	public int drumValue;
    	public int life = 3;
    	public boolean checkIfRight;
    	public int arrayCount = 0;
    	public String lifeCounter = "Lives: " + life;
    	
    	public Play(int state){
    		
    	}
    	
    	public void init(GameContainer gc, StateBasedGame sbg) throws SlickException{
    		firstLevelBackground = new Image("res/firstLevel.png");
    		snareDrum = new Sound("res/snareDrumSound.wav");
    		bassDrum = new Sound("res/bassDrum.wav");
    	}
    	
    	public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException{
    		g.drawImage(firstLevelBackground, 0, 0);
    		g.drawString(lifeCounter, 50, 50);
    	}
    	
    	public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException{
    		int xDrumPos = Mouse.getX();
    		int yDrumPos = Mouse.getY();
    	
    		Input input = gc.getInput();
    				
    		if((xDrumPos > 115 && xDrumPos < 230) && (yDrumPos > 130 && yDrumPos < 200)){
    			if(input.isMouseButtonDown(0)){				
    				snareDrum.play();
    				drumValue = 1;
    				if(drumValue == sample[arrayCount]){
    					arrayCount++;
    				}
    				else{
    					life--;
    					if(life == 0){
    						sbg.enterState(4);
    					}
    				}
    				
    			}
    		}
    		
    		if((xDrumPos > 297 && xDrumPos < 460) && (yDrumPos > 5 && yDrumPos < 170)){
    			if(input.isMouseButtonDown(0)){
    				bassDrum.play();
    				drumValue = 0;
    				
    				if(drumValue == sample[arrayCount]){
    					arrayCount++;
    				}
    				else{
    					life--;
    					if(life == 0){
    						sbg.enterState(4);
    					}
    				}
    				
    			}
    		}
    	}
    	
    	
    	public int getID(){
    		return 2;
    	}
    	
    	
    }
    Explain Class:
    Java Code:
    package javaGame;
    
    import org.lwjgl.input.Mouse;
    import org.newdawn.slick.*;
    import org.newdawn.slick.state.BasicGameState;
    import org.newdawn.slick.state.StateBasedGame;
    
    
    public class Explain extends BasicGameState{
    
    	public Image playButton;
    	public Image exitButton;
    	public Image background;
    	
    	public String mouse;
    	
    	public Explain(int state){
    		
    	}
    	
    	public void init(GameContainer gc, StateBasedGame sbg) throws SlickException{
    		background = new Image("res/explainMenu.png");
    		playButton = new Image("res/playButton.png");
    		exitButton = new Image("res/exitButton.png");
    	}
    	
    	public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException{
    		g.drawImage(background, 0, 0);
    		g.drawImage(playButton, 70, 250);
    		g.drawImage(exitButton, 362, 250);
    		
    	}
    	
    	public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException{
    		int xpos = Mouse.getX();
    		int ypos = Mouse.getY();
    		
    		Input input = gc.getInput();
    		
    		if((xpos > 70 && xpos < 250) && (ypos > 35 && ypos < 107)){
    			if(input.isMouseButtonDown(0)){
    				sbg.enterState(2);
    			}		
    		}
    		
    		if((xpos > 360 && xpos < 545) && (ypos > 35 && ypos < 107)){
    			if(input.isMouseButtonDown(0)){
    				System.exit(0);
    			}
    			
    		}
    		
    	}
    	
    	public int getID(){
    		return 1;
    	}
    }
    Finally, my highscore button doesnt click, but my play and quit buttons do. Any suggestions on that as well?
    Last edited by madtaffy; 01-26-2016 at 03:28 AM.

  2. #2
    madtaffy is offline Member
    Join Date
    May 2014
    Posts
    23
    Rep Power
    0

    Default Re: Slick Troubles

    I figured out the highscore button thing. A stupid mistake on my part.

Similar Threads

  1. slick-util transparent texture rendering weird
    By josh_iz_besat96 in forum Advanced Java
    Replies: 0
    Last Post: 10-21-2014, 03:43 AM
  2. Slick - Text with border
    By HoverCatz in forum New To Java
    Replies: 4
    Last Post: 06-17-2014, 03:51 PM
  3. Slick: what does this line of code do?
    By krazyk in forum New To Java
    Replies: 1
    Last Post: 12-02-2012, 02:58 PM
  4. [Slick] Animating a GIF?
    By SX16 in forum Java 2D
    Replies: 0
    Last Post: 11-27-2011, 03:52 AM
  5. Replies: 6
    Last Post: 07-25-2011, 01:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •