Display actions and keys assigned

Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com>
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
main
Nic0Nic0Nii 3 years ago
parent 6db59a796e
commit ec26ebadcc
  1. BIN
      RabiClone_0.0a.zip
  2. BIN
      bin/RabiClone.jar
  3. 2
      manifest
  4. 2
      src/sig/DrawLoop.java
  5. 6
      src/sig/RabiClone.java
  6. 47
      src/sig/engine/KeyBind.java
  7. 45
      src/sig/objects/ConfigureControls.java

Binary file not shown.

Binary file not shown.

@ -5,3 +5,5 @@ Main-Class: sig.RabiClone
Main-Class: sig.RabiClone Main-Class: sig.RabiClone
Main-Class: sig.RabiClone Main-Class: sig.RabiClone
Main-Class: sig.RabiClone Main-Class: sig.RabiClone
Main-Class: sig.RabiClone
Main-Class: sig.RabiClone

@ -19,7 +19,7 @@ public class DrawLoop {
for (int y=0;y<RabiClone.BASE_HEIGHT;y++) { for (int y=0;y<RabiClone.BASE_HEIGHT;y++) {
for (int x=0;x<RabiClone.BASE_WIDTH;x++) { for (int x=0;x<RabiClone.BASE_WIDTH;x++) {
p[y*RabiClone.BASE_WIDTH+x]=(byte)PaletteColor.DARK_ORCHID.ordinal();//RGB p[y*RabiClone.BASE_WIDTH+x]=(byte)RabiClone.BACKGROUND_COLOR.ordinal();//RGB
} }
} }

@ -5,6 +5,7 @@ import javax.swing.JFrame;
import net.java.games.input.Component; import net.java.games.input.Component;
import net.java.games.input.Controller; import net.java.games.input.Controller;
import net.java.games.input.ControllerEnvironment; import net.java.games.input.ControllerEnvironment;
import net.java.games.input.Controller.Type;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -19,6 +20,8 @@ import sig.objects.Player;
import sig.engine.Key; import sig.engine.Key;
import sig.engine.KeyBind; import sig.engine.KeyBind;
import sig.engine.Object; import sig.engine.Object;
import sig.engine.PaletteColor;
import java.awt.Toolkit; import java.awt.Toolkit;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
@ -37,6 +40,8 @@ public class RabiClone{
public static int SIZE_MULTIPLIER=1; public static int SIZE_MULTIPLIER=1;
public static Point MOUSE_POS; public static Point MOUSE_POS;
public static PaletteColor BACKGROUND_COLOR = PaletteColor.DARK_ORCHID;
public static LevelRenderer level_renderer; public static LevelRenderer level_renderer;
public static Player player; public static Player player;
@ -80,6 +85,7 @@ public class RabiClone{
CONTROLLERS = ControllerEnvironment.getDefaultEnvironment().getControllers(); CONTROLLERS = ControllerEnvironment.getDefaultEnvironment().getControllers();
for (int i=0;i<CONTROLLERS.length;i++) { for (int i=0;i<CONTROLLERS.length;i++) {
if (CONTROLLERS[i].poll()) { if (CONTROLLERS[i].poll()) {
//System.out.println(CONTROLLERS[i].getPortType()+" // "+CONTROLLERS[i].getType());
Component[] components = CONTROLLERS[i].getComponents(); Component[] components = CONTROLLERS[i].getComponents();
for (int j=0;j<components.length;j++) { for (int j=0;j<components.length;j++) {
//Component c = components[j]; //Component c = components[j];

@ -5,6 +5,7 @@ import java.util.List;
import net.java.games.input.Component; import net.java.games.input.Component;
import net.java.games.input.Component.Identifier; import net.java.games.input.Component.Identifier;
import net.java.games.input.Component.POV;
import sig.RabiClone; import sig.RabiClone;
public class KeyBind { public class KeyBind {
@ -27,20 +28,26 @@ public class KeyBind {
return KEYS.getOrDefault(action,false); return KEYS.getOrDefault(action,false);
} }
public static void setKeyPressed(Action action, boolean state) { public static boolean isKeyHeld(Component c) {
KEYS.put(action,state); if (c instanceof Key) {
/*if (c instanceof Key) {
return ((Key)c).isKeyHeld(); return ((Key)c).isKeyHeld();
} else } else if (c instanceof Identifier.Button) {
if (c instanceof Identifier.Button) {
return c.getPollData()>0.0f; return c.getPollData()>0.0f;
} else } else
if (c.getIdentifier()==Identifier.Axis.POV) { if (c.getIdentifier()==Identifier.Axis.POV) {
return val==c.getPollData(); return c.getPollData()!=POV.CENTER;
} else } else
if (c instanceof Identifier.Axis) { if (c.getIdentifier() instanceof Identifier.Axis) {
return c.getPollData()>=c.getDeadZone()&&Math.signum(c.getPollData())==Math.signum(val); return Math.abs(c.getPollData())>=c.getDeadZone();
}*/ }
else {
System.out.println("Could not find proper recognition for component "+c.getName());
return false;
}
}
public static void setKeyPressed(Action action, boolean state) {
KEYS.put(action,state);
} }
public static void poll() { public static void poll() {
@ -49,22 +56,8 @@ public class KeyBind {
boolean held = false; boolean held = false;
Component cc = null; Component cc = null;
for (Component c : KEYBINDS.get(a)) { for (Component c : KEYBINDS.get(a)) {
if (c instanceof Key) { held = isKeyHeld(c);
held = ((Key)c).isKeyHeld(); actionEventCheck(a,held);
actionEventCheck(a,held);
} else
if (c instanceof Identifier.Button) {
held = c.getPollData()>0.0f;
actionEventCheck(a,held);
} else
if (c.getIdentifier()==Identifier.Axis.POV) {
held = a.val==c.getPollData();
actionEventCheck(a,held);
} else
if (c.getIdentifier() instanceof Identifier.Axis) {
held = c.getPollData()>=c.getDeadZone()&&Math.signum(c.getPollData())==Math.signum(a.val);
actionEventCheck(a,held);
}
if (held) { if (held) {
cc=c; cc=c;
break; break;

@ -0,0 +1,45 @@
package sig.objects;
import net.java.games.input.Component;
import sig.RabiClone;
import sig.engine.Action;
import sig.engine.Alpha;
import sig.engine.Font;
import sig.engine.Key;
import sig.engine.KeyBind;
import sig.engine.Object;
import sig.engine.PaletteColor;
import sig.engine.Panel;
public class ConfigureControls extends Object{
protected ConfigureControls(Panel panel) {
super(panel);
RabiClone.BACKGROUND_COLOR = PaletteColor.WHITE;
}
@Override
public void update(double updateMult) {
// TODO Auto-generated method stub
}
@Override
public void draw(byte[] p) {
int y=4;
for (Action a : Action.values()) {
Draw_Text_Ext(4,getY(),DisplayActionKeys(a),Font.PROFONT_12,Alpha.ALPHA0,PaletteColor.MIDNIGHT_BLUE);
}
}
private StringBuilder DisplayActionKeys(Action a) {
StringBuilder sb = new StringBuilder(a.toString()).append(": ");
boolean first=true;
for (Component c : KeyBind.KEYBINDS.get(a)) {
sb.append(((Key)c).isKeyHeld()?PaletteColor.YELLOW_GREEN:PaletteColor.MIDNIGHT_BLUE).append(c.getName()).append(!first?",":"");
sb.append("\n");
}
return sb;
}
}
Loading…
Cancel
Save