Listen for controller components and allow inputs from controllers

Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com>
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
main
sigonasr2 3 years ago
parent 9060e3aa96
commit 7387ced9e5
  1. 9
      src/sig/DrawLoop.java
  2. 7
      src/sig/RabiClone.java
  3. 7
      src/sig/engine/Action.java
  4. 245
      src/sig/engine/Key.java
  5. 80
      src/sig/engine/KeyBind.java
  6. 11
      src/sig/engine/Object.java
  7. 17
      src/sig/engine/Panel.java
  8. 43
      src/sig/objects/ConfigureControls.java

@ -68,6 +68,15 @@ public class DrawLoop {
}
}
public static void FillRect(byte[] p,byte col,double x,double y,double w,double h) {
for (int xx=0;xx<w;xx++) {
for (int yy=0;yy<h;yy++) {
int index = ((int)y+yy)*RabiClone.BASE_WIDTH+(int)x+xx;
Draw(p,index,col, Alpha.ALPHA0);
}
}
}
public static void Draw_Sprite(double x, double y, Sprite sprite){
Draw_Sprite_Partial(x,y,0,0,sprite.getWidth(),sprite.getHeight(),sprite,0,Transform.NONE );
}

@ -12,6 +12,7 @@ import java.util.List;
import sig.engine.Panel;
import sig.engine.Point;
import sig.map.Maps;
import sig.objects.ConfigureControls;
import sig.objects.EditorRenderer;
import sig.objects.Erinoah;
import sig.objects.LevelRenderer;
@ -116,6 +117,11 @@ public class RabiClone{
OBJ.add(level_renderer=new EditorRenderer(p));
}
}
if (Key.isKeyHeld(KeyEvent.VK_F3)) {
OBJ.clear();
ResetGame();
OBJ.add(new ConfigureControls(p));
}
for (int i=0;i<OBJ.size();i++) {
OBJ.get(i).update(updateMult);
@ -128,6 +134,7 @@ public class RabiClone{
private static void ResetGame() {
player=null;
level_renderer=null;
}
private static void StartGame() {

@ -4,7 +4,8 @@ import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.Arrays;
import net.java.games.input.Component;
import net.java.games.input.Controller;
import net.java.games.input.Component.Identifier;
public enum Action {
MOVE_RIGHT(new KeyBind(KeyEvent.VK_RIGHT),new KeyBind(KeyEvent.VK_D)),
@ -24,9 +25,9 @@ public enum Action {
Action(KeyBind...keybinds) {
KeyBind.KEYBINDS.put(this,new ArrayList<>(Arrays.asList(keybinds)));
}
Action(Component axis,float val) {
Action(Controller c, Identifier.Axis axis,float val) {
ArrayList<KeyBind> comps = new ArrayList<KeyBind>();
comps.add(new KeyBind(axis,val));
comps.add(new KeyBind(c,axis,val));
KeyBind.KEYBINDS.put(this,comps);
}
}

@ -3,117 +3,122 @@ package sig.engine;
import java.util.HashMap;
import java.awt.event.KeyEvent;
import net.java.games.input.Component;
import net.java.games.input.Component.Identifier;
public class Key implements Component{
public class Key extends Identifier{
public static HashMap<Integer,Identifier.Key> KEY_CONVERSION_MAP = new HashMap<>();
static HashMap<Component.Identifier.Key,Boolean> KEYS = new HashMap<>();
int keycode;
protected Key(String name) {
super(name);
}
Key(int keycode) {
protected Key(int keycode) {
super(KEY_CONVERSION_MAP.get(keycode).getName());
this.keycode=keycode;
}
public static HashMap<Integer,Identifier.Key> KEY_CONVERSION_MAP = new HashMap<>();
static HashMap<Identifier.Key,Boolean> KEYS = new HashMap<>();
int keycode;
public static void InitializeKeyConversionMap() {
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_0,Identifier.Key._0);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_1,Identifier.Key._1);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_2,Identifier.Key._2);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_3,Identifier.Key._3);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_4,Identifier.Key._4);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_5,Identifier.Key._5);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_6,Identifier.Key._6);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_7,Identifier.Key._7);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_8,Identifier.Key._8);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_9,Identifier.Key._9);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_A,Identifier.Key.A);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_B,Identifier.Key.B);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_C,Identifier.Key.C);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_D,Identifier.Key.D);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_E,Identifier.Key.E);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_F,Identifier.Key.F);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_G,Identifier.Key.G);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_H,Identifier.Key.H);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_I,Identifier.Key.I);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_J,Identifier.Key.J);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_K,Identifier.Key.K);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_L,Identifier.Key.L);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_M,Identifier.Key.M);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_N,Identifier.Key.N);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_O,Identifier.Key.O);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_P,Identifier.Key.P);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_Q,Identifier.Key.Q);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_R,Identifier.Key.R);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_S,Identifier.Key.S);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_T,Identifier.Key.T);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_U,Identifier.Key.U);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_V,Identifier.Key.V);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_W,Identifier.Key.W);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_X,Identifier.Key.X);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_Y,Identifier.Key.Y);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_Z,Identifier.Key.Z);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_MINUS,Identifier.Key.MINUS);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_EQUALS,Identifier.Key.EQUALS);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_BACK_QUOTE,Identifier.Key.GRAVE);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_OPEN_BRACKET,Identifier.Key.LBRACKET);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_CLOSE_BRACKET,Identifier.Key.RBRACKET);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_BACK_SLASH,Identifier.Key.BACKSLASH);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_BACK_SPACE,Identifier.Key.BACK);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_TAB,Identifier.Key.TAB);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_CAPS_LOCK,Identifier.Key.CAPITAL);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_SEMICOLON,Identifier.Key.SEMICOLON);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_ENTER,Identifier.Key.RETURN);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_SHIFT,Identifier.Key.LSHIFT);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_COMMA,Identifier.Key.COMMA);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_PERIOD,Identifier.Key.PERIOD);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_SLASH,Identifier.Key.SLASH);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_CONTROL,Identifier.Key.LCONTROL);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_ALT,Identifier.Key.LALT);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_SPACE,Identifier.Key.SPACE);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_WINDOWS,Identifier.Key.SYSRQ);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_CONTEXT_MENU,Identifier.Key.APPS);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_HOME,Identifier.Key.HOME);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_INSERT,Identifier.Key.INSERT);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_DELETE,Identifier.Key.DELETE);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_END,Identifier.Key.END);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_PAGE_UP,Identifier.Key.PAGEUP);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_PAGE_DOWN,Identifier.Key.PAGEDOWN);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_ESCAPE,Identifier.Key.ESCAPE);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_F1,Identifier.Key.F1);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_F2,Identifier.Key.F2);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_F3,Identifier.Key.F3);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_F4,Identifier.Key.F4);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_F5,Identifier.Key.F5);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_F6,Identifier.Key.F6);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_F7,Identifier.Key.F7);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_F8,Identifier.Key.F8);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_F9,Identifier.Key.F9);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_F10,Identifier.Key.F10);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_F11,Identifier.Key.F11);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_F12,Identifier.Key.F12);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_PRINTSCREEN,Identifier.Key.KANA);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_SCROLL_LOCK,Identifier.Key.SCROLL);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_PAUSE,Identifier.Key.PAUSE);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_LEFT,Identifier.Key.LEFT);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_RIGHT,Identifier.Key.RIGHT);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_UP,Identifier.Key.UP);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_DOWN,Identifier.Key.DOWN);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_NUM_LOCK,Identifier.Key.NUMLOCK);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_ASTERISK,Identifier.Key.AX);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_DIVIDE,Identifier.Key.DIVIDE);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_SUBTRACT,Identifier.Key.SUBTRACT);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_ADD,Identifier.Key.ADD);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_DECIMAL,Identifier.Key.DECIMAL);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_NUMPAD0,Identifier.Key.NUMPAD0);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_NUMPAD1,Identifier.Key.NUMPAD1);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_NUMPAD2,Identifier.Key.NUMPAD2);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_NUMPAD3,Identifier.Key.NUMPAD3);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_NUMPAD4,Identifier.Key.NUMPAD4);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_NUMPAD5,Identifier.Key.NUMPAD5);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_NUMPAD6,Identifier.Key.NUMPAD6);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_NUMPAD7,Identifier.Key.NUMPAD7);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_NUMPAD8,Identifier.Key.NUMPAD8);
Key.KEY_CONVERSION_MAP.put(KeyEvent.VK_NUMPAD9,Identifier.Key.NUMPAD9);
KEY_CONVERSION_MAP.put(KeyEvent.VK_0,Identifier.Key._0);
KEY_CONVERSION_MAP.put(KeyEvent.VK_1,Identifier.Key._1);
KEY_CONVERSION_MAP.put(KeyEvent.VK_2,Identifier.Key._2);
KEY_CONVERSION_MAP.put(KeyEvent.VK_3,Identifier.Key._3);
KEY_CONVERSION_MAP.put(KeyEvent.VK_4,Identifier.Key._4);
KEY_CONVERSION_MAP.put(KeyEvent.VK_5,Identifier.Key._5);
KEY_CONVERSION_MAP.put(KeyEvent.VK_6,Identifier.Key._6);
KEY_CONVERSION_MAP.put(KeyEvent.VK_7,Identifier.Key._7);
KEY_CONVERSION_MAP.put(KeyEvent.VK_8,Identifier.Key._8);
KEY_CONVERSION_MAP.put(KeyEvent.VK_9,Identifier.Key._9);
KEY_CONVERSION_MAP.put(KeyEvent.VK_A,Identifier.Key.A);
KEY_CONVERSION_MAP.put(KeyEvent.VK_B,Identifier.Key.B);
KEY_CONVERSION_MAP.put(KeyEvent.VK_C,Identifier.Key.C);
KEY_CONVERSION_MAP.put(KeyEvent.VK_D,Identifier.Key.D);
KEY_CONVERSION_MAP.put(KeyEvent.VK_E,Identifier.Key.E);
KEY_CONVERSION_MAP.put(KeyEvent.VK_F,Identifier.Key.F);
KEY_CONVERSION_MAP.put(KeyEvent.VK_G,Identifier.Key.G);
KEY_CONVERSION_MAP.put(KeyEvent.VK_H,Identifier.Key.H);
KEY_CONVERSION_MAP.put(KeyEvent.VK_I,Identifier.Key.I);
KEY_CONVERSION_MAP.put(KeyEvent.VK_J,Identifier.Key.J);
KEY_CONVERSION_MAP.put(KeyEvent.VK_K,Identifier.Key.K);
KEY_CONVERSION_MAP.put(KeyEvent.VK_L,Identifier.Key.L);
KEY_CONVERSION_MAP.put(KeyEvent.VK_M,Identifier.Key.M);
KEY_CONVERSION_MAP.put(KeyEvent.VK_N,Identifier.Key.N);
KEY_CONVERSION_MAP.put(KeyEvent.VK_O,Identifier.Key.O);
KEY_CONVERSION_MAP.put(KeyEvent.VK_P,Identifier.Key.P);
KEY_CONVERSION_MAP.put(KeyEvent.VK_Q,Identifier.Key.Q);
KEY_CONVERSION_MAP.put(KeyEvent.VK_R,Identifier.Key.R);
KEY_CONVERSION_MAP.put(KeyEvent.VK_S,Identifier.Key.S);
KEY_CONVERSION_MAP.put(KeyEvent.VK_T,Identifier.Key.T);
KEY_CONVERSION_MAP.put(KeyEvent.VK_U,Identifier.Key.U);
KEY_CONVERSION_MAP.put(KeyEvent.VK_V,Identifier.Key.V);
KEY_CONVERSION_MAP.put(KeyEvent.VK_W,Identifier.Key.W);
KEY_CONVERSION_MAP.put(KeyEvent.VK_X,Identifier.Key.X);
KEY_CONVERSION_MAP.put(KeyEvent.VK_Y,Identifier.Key.Y);
KEY_CONVERSION_MAP.put(KeyEvent.VK_Z,Identifier.Key.Z);
KEY_CONVERSION_MAP.put(KeyEvent.VK_MINUS,Identifier.Key.MINUS);
KEY_CONVERSION_MAP.put(KeyEvent.VK_EQUALS,Identifier.Key.EQUALS);
KEY_CONVERSION_MAP.put(KeyEvent.VK_BACK_QUOTE,Identifier.Key.GRAVE);
KEY_CONVERSION_MAP.put(KeyEvent.VK_OPEN_BRACKET,Identifier.Key.LBRACKET);
KEY_CONVERSION_MAP.put(KeyEvent.VK_CLOSE_BRACKET,Identifier.Key.RBRACKET);
KEY_CONVERSION_MAP.put(KeyEvent.VK_BACK_SLASH,Identifier.Key.BACKSLASH);
KEY_CONVERSION_MAP.put(KeyEvent.VK_BACK_SPACE,Identifier.Key.BACK);
KEY_CONVERSION_MAP.put(KeyEvent.VK_TAB,Identifier.Key.TAB);
KEY_CONVERSION_MAP.put(KeyEvent.VK_CAPS_LOCK,Identifier.Key.CAPITAL);
KEY_CONVERSION_MAP.put(KeyEvent.VK_SEMICOLON,Identifier.Key.SEMICOLON);
KEY_CONVERSION_MAP.put(KeyEvent.VK_ENTER,Identifier.Key.RETURN);
KEY_CONVERSION_MAP.put(KeyEvent.VK_SHIFT,Identifier.Key.LSHIFT);
KEY_CONVERSION_MAP.put(KeyEvent.VK_COMMA,Identifier.Key.COMMA);
KEY_CONVERSION_MAP.put(KeyEvent.VK_PERIOD,Identifier.Key.PERIOD);
KEY_CONVERSION_MAP.put(KeyEvent.VK_SLASH,Identifier.Key.SLASH);
KEY_CONVERSION_MAP.put(KeyEvent.VK_CONTROL,Identifier.Key.LCONTROL);
KEY_CONVERSION_MAP.put(KeyEvent.VK_ALT,Identifier.Key.LALT);
KEY_CONVERSION_MAP.put(KeyEvent.VK_SPACE,Identifier.Key.SPACE);
KEY_CONVERSION_MAP.put(KeyEvent.VK_WINDOWS,Identifier.Key.SYSRQ);
KEY_CONVERSION_MAP.put(KeyEvent.VK_CONTEXT_MENU,Identifier.Key.APPS);
KEY_CONVERSION_MAP.put(KeyEvent.VK_HOME,Identifier.Key.HOME);
KEY_CONVERSION_MAP.put(KeyEvent.VK_INSERT,Identifier.Key.INSERT);
KEY_CONVERSION_MAP.put(KeyEvent.VK_DELETE,Identifier.Key.DELETE);
KEY_CONVERSION_MAP.put(KeyEvent.VK_END,Identifier.Key.END);
KEY_CONVERSION_MAP.put(KeyEvent.VK_PAGE_UP,Identifier.Key.PAGEUP);
KEY_CONVERSION_MAP.put(KeyEvent.VK_PAGE_DOWN,Identifier.Key.PAGEDOWN);
KEY_CONVERSION_MAP.put(KeyEvent.VK_ESCAPE,Identifier.Key.ESCAPE);
KEY_CONVERSION_MAP.put(KeyEvent.VK_F1,Identifier.Key.F1);
KEY_CONVERSION_MAP.put(KeyEvent.VK_F2,Identifier.Key.F2);
KEY_CONVERSION_MAP.put(KeyEvent.VK_F3,Identifier.Key.F3);
KEY_CONVERSION_MAP.put(KeyEvent.VK_F4,Identifier.Key.F4);
KEY_CONVERSION_MAP.put(KeyEvent.VK_F5,Identifier.Key.F5);
KEY_CONVERSION_MAP.put(KeyEvent.VK_F6,Identifier.Key.F6);
KEY_CONVERSION_MAP.put(KeyEvent.VK_F7,Identifier.Key.F7);
KEY_CONVERSION_MAP.put(KeyEvent.VK_F8,Identifier.Key.F8);
KEY_CONVERSION_MAP.put(KeyEvent.VK_F9,Identifier.Key.F9);
KEY_CONVERSION_MAP.put(KeyEvent.VK_F10,Identifier.Key.F10);
KEY_CONVERSION_MAP.put(KeyEvent.VK_F11,Identifier.Key.F11);
KEY_CONVERSION_MAP.put(KeyEvent.VK_F12,Identifier.Key.F12);
KEY_CONVERSION_MAP.put(KeyEvent.VK_PRINTSCREEN,Identifier.Key.KANA);
KEY_CONVERSION_MAP.put(KeyEvent.VK_SCROLL_LOCK,Identifier.Key.SCROLL);
KEY_CONVERSION_MAP.put(KeyEvent.VK_PAUSE,Identifier.Key.PAUSE);
KEY_CONVERSION_MAP.put(KeyEvent.VK_LEFT,Identifier.Key.LEFT);
KEY_CONVERSION_MAP.put(KeyEvent.VK_RIGHT,Identifier.Key.RIGHT);
KEY_CONVERSION_MAP.put(KeyEvent.VK_UP,Identifier.Key.UP);
KEY_CONVERSION_MAP.put(KeyEvent.VK_DOWN,Identifier.Key.DOWN);
KEY_CONVERSION_MAP.put(KeyEvent.VK_NUM_LOCK,Identifier.Key.NUMLOCK);
KEY_CONVERSION_MAP.put(KeyEvent.VK_ASTERISK,Identifier.Key.AX);
KEY_CONVERSION_MAP.put(KeyEvent.VK_DIVIDE,Identifier.Key.DIVIDE);
KEY_CONVERSION_MAP.put(KeyEvent.VK_SUBTRACT,Identifier.Key.SUBTRACT);
KEY_CONVERSION_MAP.put(KeyEvent.VK_ADD,Identifier.Key.ADD);
KEY_CONVERSION_MAP.put(KeyEvent.VK_DECIMAL,Identifier.Key.DECIMAL);
KEY_CONVERSION_MAP.put(KeyEvent.VK_NUMPAD0,Identifier.Key.NUMPAD0);
KEY_CONVERSION_MAP.put(KeyEvent.VK_NUMPAD1,Identifier.Key.NUMPAD1);
KEY_CONVERSION_MAP.put(KeyEvent.VK_NUMPAD2,Identifier.Key.NUMPAD2);
KEY_CONVERSION_MAP.put(KeyEvent.VK_NUMPAD3,Identifier.Key.NUMPAD3);
KEY_CONVERSION_MAP.put(KeyEvent.VK_NUMPAD4,Identifier.Key.NUMPAD4);
KEY_CONVERSION_MAP.put(KeyEvent.VK_NUMPAD5,Identifier.Key.NUMPAD5);
KEY_CONVERSION_MAP.put(KeyEvent.VK_NUMPAD6,Identifier.Key.NUMPAD6);
KEY_CONVERSION_MAP.put(KeyEvent.VK_NUMPAD7,Identifier.Key.NUMPAD7);
KEY_CONVERSION_MAP.put(KeyEvent.VK_NUMPAD8,Identifier.Key.NUMPAD8);
KEY_CONVERSION_MAP.put(KeyEvent.VK_NUMPAD9,Identifier.Key.NUMPAD9);
}
public static void setKeyHeld(int keycode,boolean pressed) {
@ -126,37 +131,7 @@ public class Key implements Component{
}
public boolean isKeyHeld() {
return KEYS.getOrDefault(getIdentifier(),false);
}
@Override
public Identifier.Key getIdentifier() {
return KEY_CONVERSION_MAP.get(keycode);
}
@Override
public boolean isRelative() {
return false;
}
@Override
public boolean isAnalog() {
return false;
}
@Override
public float getDeadZone() {
return 0;
}
@Override
public float getPollData() {
return isKeyHeld()?1.0f:0.0f;
}
@Override
public String getName() {
return "Java System Keyboard - "+Key.KEY_CONVERSION_MAP.get(keycode).getName();
return KEYS.getOrDefault(KEY_CONVERSION_MAP.get(keycode),false);
}
}

@ -3,7 +3,7 @@ package sig.engine;
import java.util.HashMap;
import java.util.List;
import net.java.games.input.Component;
import net.java.games.input.Controller;
import net.java.games.input.Component.Identifier;
import net.java.games.input.Component.POV;
import sig.RabiClone;
@ -12,40 +12,61 @@ public class KeyBind {
public static HashMap<Action,List<KeyBind>> KEYBINDS = new HashMap<>();
static HashMap<Action,Boolean> KEYS = new HashMap<>();
public Component c;
public Controller c;
public Identifier id;
float val;
public KeyBind(Component c) {
public KeyBind(Controller c, Identifier id) {
this.c=c;
this.id=id;
}
public KeyBind(int keycode) {
this(new Key(keycode));
this(null,new Key(keycode));
}
public KeyBind(Component c, float val) {
public KeyBind(Controller c, Identifier id, float val) {
this.c=c;
this.id=id;
this.val=val;
}
public static boolean isKeyHeld(Action action) {
return KEYS.getOrDefault(action,false);
}
public boolean isKeyHeld() {
if (c instanceof Key) {
return ((Key)c).isKeyHeld();
} else if (c instanceof Identifier.Button) {
return c.getPollData()>0.0f;
if (id instanceof Key) {
return ((Key)id).isKeyHeld();
} else if (id instanceof Identifier.Button) {
return c.getComponent(id).getPollData()>0.0f;
} else
if (c.getComponent(id).getIdentifier()==Identifier.Axis.POV) {
if (val==POV.DOWN) {
return c.getComponent(id).getPollData()==POV.DOWN||
c.getComponent(id).getPollData()==POV.DOWN_LEFT||
c.getComponent(id).getPollData()==POV.DOWN_RIGHT;
} else
if (c.getIdentifier()==Identifier.Axis.POV) {
return c.getPollData()!=POV.CENTER;
if (val==POV.UP) {
return c.getComponent(id).getPollData()==POV.UP||
c.getComponent(id).getPollData()==POV.UP_LEFT||
c.getComponent(id).getPollData()==POV.UP_RIGHT;
} else
if (c.getIdentifier() instanceof Identifier.Axis) {
return Math.abs(c.getPollData())>=c.getDeadZone();
if (val==POV.RIGHT) {
return c.getComponent(id).getPollData()==POV.RIGHT||
c.getComponent(id).getPollData()==POV.UP_RIGHT||
c.getComponent(id).getPollData()==POV.DOWN_RIGHT;
} else
if (val==POV.LEFT) {
return c.getComponent(id).getPollData()==POV.LEFT||
c.getComponent(id).getPollData()==POV.DOWN_LEFT||
c.getComponent(id).getPollData()==POV.UP_LEFT;
} else {
System.err.println("Unexpected value for POV! Must be a cardinal direction! Given value: "+val);
return false;
}
} else
if (id instanceof Identifier.Axis) {
return Math.abs(c.getComponent(id).getPollData())>=c.getComponent(id).getDeadZone()&&Math.signum(c.getComponent(id).getPollData())==Math.signum(val);
}
else {
System.out.println("Could not find proper recognition for component "+c.getName());
System.out.println("Could not find proper recognition for component "+id.getName());
return false;
}
}
@ -68,11 +89,19 @@ public class KeyBind {
}
}
if (held) {
KEYBINDS.get(a).remove(cc);
KEYBINDS.get(a).add(0,cc);
if (KEYBINDS.get(a).get(0)!=cc) {
for (int i=0;i<KEYBINDS.get(a).size()-1;i++) {
KEYBINDS.get(a).set(i+1,KEYBINDS.get(a).get(i));
}
KEYBINDS.get(a).set(0,cc);
}
}
}
}
public static boolean isKeyHeld(Action action) {
return KEYS.getOrDefault(action,false);
}
private static void actionEventCheck(Action a, boolean held) {
if (KeyBind.isKeyHeld(a)&&!held) {
@ -96,4 +125,15 @@ public class KeyBind {
RabiClone.OBJ.get(i).KeyPressed(a);
}
}
public String getName() {
if (c!=null) {
return c.getComponent(id).getName();
} else
if (id instanceof Key) {
return ((Key)id).getName();
} else {
return "?";
}
}
}

@ -1,5 +1,6 @@
package sig.engine;
import java.awt.event.MouseEvent;
import sig.DrawLoop;
public abstract class Object implements GameEntity{
@ -57,6 +58,10 @@ public abstract class Object implements GameEntity{
DrawLoop.Draw(canvas, index, (byte)col.ordinal(), alpha);
}
protected void Draw_Rect(byte[] p,byte col,double x,double y,double w,double h) {
DrawLoop.FillRect(p, col, x, y, w, h);
}
protected void Draw_Sprite(double x, double y, Sprite sprite){
DrawLoop.Draw_Sprite(x,y,sprite);
}
@ -99,6 +104,12 @@ public abstract class Object implements GameEntity{
protected void KeyReleased(Action a) {
}
protected void MousePressed(MouseEvent e) {
}
protected void MouseReleased(MouseEvent e) {
}
protected boolean MouseHeld(int mb) {
return panel.MOUSE.getOrDefault(mb,false);
}

@ -96,12 +96,20 @@ public class Panel extends JPanel implements Runnable,KeyListener {
MOUSE.put(e.getButton(),true);
mousePos.set(e.getX()/RabiClone.SIZE_MULTIPLIER,e.getY()/RabiClone.SIZE_MULTIPLIER);
//System.out.println("Mouse List: "+MOUSE);
for(int i=0; i<RabiClone.OBJ.size();i++){
RabiClone.OBJ.get(i).MousePressed(e);
}
}
@Override
public void mouseReleased(MouseEvent e) {
MOUSE.put(e.getButton(),false);
mousePos.set(e.getX()/RabiClone.SIZE_MULTIPLIER,e.getY()/RabiClone.SIZE_MULTIPLIER);
for(int i=0; i<RabiClone.OBJ.size();i++){
RabiClone.OBJ.get(i).MouseReleased(e);
}
}
@Override
@ -215,15 +223,6 @@ public class Panel extends JPanel implements Runnable,KeyListener {
DrawLoop.drawGame(this);
}
public void FillRect(byte[] p,byte col,double x,double y,double w,double h) {
for (int xx=0;xx<w;xx++) {
for (int yy=0;yy<h;yy++) {
int index = ((int)y+yy)*getWidth()+(int)x+xx;
Draw(p,index,col);
}
}
}
public void FillCircle(byte[] p,byte col,double center_x,double center_y,double r) {
int counter=0;
Point[] points = new Point[CIRCLE_PRECISION];

@ -1,5 +1,8 @@
package sig.objects;
import java.awt.event.MouseEvent;
import java.util.List;
import net.java.games.input.Component;
import net.java.games.input.Event;
import sig.RabiClone;
@ -13,7 +16,10 @@ import sig.engine.Panel;
public class ConfigureControls extends Object{
protected ConfigureControls(Panel panel) {
Action selectedAction = Action.MOVE_RIGHT;
boolean assigningKey = false;
public ConfigureControls(Panel panel) {
super(panel);
RabiClone.BACKGROUND_COLOR = PaletteColor.WHITE;
}
@ -27,11 +33,16 @@ public class ConfigureControls extends Object{
for (int j=0;j<components.length;j++) {
//Component c = components[j];
//System.out.println(c.getName()+","+c.getIdentifier()+": "+c.getPollData());
}
//System.out.println("--------");
if (RabiClone.CONTROLLERS[i].getEventQueue().getNextEvent(e)) {
System.out.println(e.getComponent().getName()+" value: "+e.getValue());
if (assigningKey) {
List<KeyBind> clist = KeyBind.KEYBINDS.get(selectedAction);
clist.add(new KeyBind(RabiClone.CONTROLLERS[i],e.getComponent().getIdentifier(),e.getValue()));
KeyBind.KEYBINDS.put(selectedAction,clist);
assigningKey=false;
}
//System.out.println(e.getComponent().getName()+" value: "+e.getValue());
}
}
}
@ -39,17 +50,33 @@ public class ConfigureControls extends Object{
@Override
public void draw(byte[] p) {
int y = 4;
if (!assigningKey) {
for (Action a : Action.values()) {
Draw_Text_Ext(4,getY(),DisplayActionKeys(a),Font.PROFONT_12,Alpha.ALPHA0,PaletteColor.MIDNIGHT_BLUE);
if (RabiClone.MOUSE_POS.getY()>=getY()+y&&RabiClone.MOUSE_POS.getY()<getY()+y+Font.PROFONT_12.getGlyphHeight()+4) {
selectedAction=a;
Draw_Rect(p,(byte)PaletteColor.PEACH.ordinal(),0,getY()+y,RabiClone.BASE_WIDTH,Font.PROFONT_12.getGlyphHeight()+4);
}
Draw_Text_Ext(4,getY()+y,DisplayActionKeys(a),Font.PROFONT_12,Alpha.ALPHA0,PaletteColor.MIDNIGHT_BLUE);
y+=Font.PROFONT_12.getGlyphHeight()+4;
}
} else {
Draw_Text_Ext(4, 4, new StringBuilder("Press a key to assign to ").append(selectedAction), Font.PROFONT_12, Alpha.ALPHA0, PaletteColor.MIDNIGHT_BLUE);
}
}
@Override
protected void MousePressed(MouseEvent e) {
if (e.getButton()==MouseEvent.BUTTON1) {
assigningKey=true;
}
}
private StringBuilder DisplayActionKeys(Action a) {
StringBuilder sb = new StringBuilder(a.toString()).append(": ");
boolean first=true;
for (KeyBind c : KeyBind.KEYBINDS.get(a)) {
sb.append(c.isKeyHeld()?PaletteColor.YELLOW_GREEN:"").append(c.c.getName()).append(PaletteColor.MIDNIGHT_BLUE).append(!first?",":"");
sb.append("\n");
for (int i=0;i<KeyBind.KEYBINDS.get(a).size();i++) {
KeyBind c = KeyBind.KEYBINDS.get(a).get(i);
sb.append(c.isKeyHeld()?PaletteColor.YELLOW_GREEN:"").append(c.getName()).append(PaletteColor.MIDNIGHT_BLUE).append(i!=KeyBind.KEYBINDS.get(a).size()-1?",":"");
}
return sb;
}

Loading…
Cancel
Save