mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-08 04:41:51 +09:00
Former-commit-id: 1647fa32ef6894bd7db44f741f07c2f4dcdf9054 Former-commit-id: 0e5810dcfbe1fd59b13e7cabe9f1e93c5542da2d
103 lines
3.3 KiB
Java
103 lines
3.3 KiB
Java
package org.newdawn.slick.tests;
|
|
|
|
import org.newdawn.slick.AppGameContainer;
|
|
import org.newdawn.slick.BasicGame;
|
|
import org.newdawn.slick.GameContainer;
|
|
import org.newdawn.slick.Graphics;
|
|
import org.newdawn.slick.Input;
|
|
import org.newdawn.slick.SlickException;
|
|
import org.newdawn.slick.command.BasicCommand;
|
|
import org.newdawn.slick.command.Command;
|
|
import org.newdawn.slick.command.ControllerButtonControl;
|
|
import org.newdawn.slick.command.ControllerDirectionControl;
|
|
import org.newdawn.slick.command.InputProvider;
|
|
import org.newdawn.slick.command.InputProviderListener;
|
|
import org.newdawn.slick.command.KeyControl;
|
|
import org.newdawn.slick.command.MouseButtonControl;
|
|
|
|
/**
|
|
* A test for abstract input via InputProvider
|
|
*
|
|
* @author kevin
|
|
*/
|
|
public class InputProviderTest extends BasicGame implements InputProviderListener {
|
|
/** The command for attack */
|
|
private Command attack = new BasicCommand("attack");
|
|
/** The command for jump */
|
|
private Command jump = new BasicCommand("jump");
|
|
/** The command for jump */
|
|
private Command run = new BasicCommand("run");
|
|
/** The input provider abstracting input */
|
|
private InputProvider provider;
|
|
/** The message to be displayed */
|
|
private String message = "";
|
|
|
|
/**
|
|
* Create a new image rendering test
|
|
*/
|
|
public InputProviderTest() {
|
|
super("InputProvider Test");
|
|
}
|
|
|
|
/**
|
|
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
|
*/
|
|
public void init(GameContainer container) throws SlickException {
|
|
provider = new InputProvider(container.getInput());
|
|
provider.addListener(this);
|
|
|
|
provider.bindCommand(new KeyControl(Input.KEY_LEFT), run);
|
|
provider.bindCommand(new KeyControl(Input.KEY_A), run);
|
|
provider.bindCommand(new ControllerDirectionControl(0, ControllerDirectionControl.LEFT), run);
|
|
provider.bindCommand(new KeyControl(Input.KEY_UP), jump);
|
|
provider.bindCommand(new KeyControl(Input.KEY_W), jump);
|
|
provider.bindCommand(new ControllerDirectionControl(0, ControllerDirectionControl.UP), jump);
|
|
provider.bindCommand(new KeyControl(Input.KEY_SPACE), attack);
|
|
provider.bindCommand(new MouseButtonControl(0), attack);
|
|
provider.bindCommand(new ControllerButtonControl(0, 1), attack);
|
|
}
|
|
|
|
/**
|
|
* @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
|
*/
|
|
public void render(GameContainer container, Graphics g) {
|
|
g.drawString("Press A, W, Left, Up, space, mouse button 1,and gamepad controls",10,50);
|
|
g.drawString(message,100,150);
|
|
}
|
|
|
|
/**
|
|
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
|
*/
|
|
public void update(GameContainer container, int delta) {
|
|
}
|
|
|
|
/**
|
|
* @see org.newdawn.slick.command.InputProviderListener#controlPressed(org.newdawn.slick.command.Command)
|
|
*/
|
|
public void controlPressed(Command command) {
|
|
message = "Pressed: "+command;
|
|
}
|
|
|
|
/**
|
|
* @see org.newdawn.slick.command.InputProviderListener#controlReleased(org.newdawn.slick.command.Command)
|
|
*/
|
|
public void controlReleased(Command command) {
|
|
message = "Released: "+command;
|
|
}
|
|
|
|
/**
|
|
* Entry point to our test
|
|
*
|
|
* @param argv The arguments to pass into the test
|
|
*/
|
|
public static void main(String[] argv) {
|
|
try {
|
|
AppGameContainer container = new AppGameContainer(new InputProviderTest());
|
|
container.setDisplayMode(800,600,false);
|
|
container.start();
|
|
} catch (SlickException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|