Merge branch 'master' of github.com:jokerx3/prp

This commit is contained in:
feschi55
2014-11-14 10:36:53 +01:00
18 changed files with 792 additions and 137 deletions
+2 -1
View File
@@ -3,6 +3,7 @@ package de.heatup.audio;
public class Main {
public static void main(String[] args) {
new WavePlayer("<filetpath>").start();
Sound.BOMB.play();
}
}
+58
View File
@@ -0,0 +1,58 @@
package de.heatup.audio;
import java.io.File;
import java.io.IOException;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.Line;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
public enum Sound {
BOMB("src/de/heatup/resources/audio/" + "bomb.wav");
private Clip clip;
Sound(String soundFileName) {
File f = new File(soundFileName);
if(!f.exists()) {
System.err.println("File not found : " + f.getAbsolutePath());
return;
}
try {
Line.Info linfo = new Line.Info(Clip.class);
Line line = AudioSystem.getLine(linfo);
clip = (Clip) line;
AudioInputStream inputStream = AudioSystem.getAudioInputStream(f);
clip.open(inputStream);
} catch(UnsupportedAudioFileException e) {
e.printStackTrace();
} catch(IOException e) {
e.printStackTrace();
} catch(LineUnavailableException e) {
e.printStackTrace();
} catch(Exception e) {
e.printStackTrace();
}
}
public void play() {
try {
new Thread() {
public void run() {
clip.start();
}
}.start();
} catch(Throwable e) {
e.printStackTrace();
}
}
}
@@ -1,99 +0,0 @@
package de.heatup.audio;
import java.io.File;
import java.io.IOException;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.FloatControl;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.SourceDataLine;
import javax.sound.sampled.UnsupportedAudioFileException;
public class WavePlayer extends Thread {
private String filename;
private Position curPosition;
private final int EXTERNAL_BUFFER_SIZE = 524288; // 128Kb
enum Position {
LEFT, RIGHT, NORMAL
};
public WavePlayer(String wavfile) {
filename = wavfile;
curPosition = Position.NORMAL;
}
public WavePlayer(String wavfile, Position p) {
filename = wavfile;
curPosition = p;
}
public void run() {
File soundFile = new File(filename);
if (!soundFile.exists()) {
System.err.println("Wave file not found: " + filename);
return;
}
AudioInputStream audioInputStream = null;
try {
audioInputStream = AudioSystem.getAudioInputStream(soundFile);
} catch (UnsupportedAudioFileException e1) {
e1.printStackTrace();
return;
} catch (IOException e1) {
e1.printStackTrace();
return;
}
AudioFormat format = audioInputStream.getFormat();
SourceDataLine auline = null;
DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
try {
auline = (SourceDataLine) AudioSystem.getLine(info);
auline.open(format);
} catch (LineUnavailableException e) {
e.printStackTrace();
return;
} catch (Exception e) {
e.printStackTrace();
return;
}
if (auline.isControlSupported(FloatControl.Type.PAN)) {
FloatControl pan = (FloatControl) auline
.getControl(FloatControl.Type.PAN);
if (curPosition == Position.RIGHT)
pan.setValue(1.0f);
else if (curPosition == Position.LEFT)
pan.setValue(-1.0f);
}
auline.start();
int nBytesRead = 0;
byte[] abData = new byte[EXTERNAL_BUFFER_SIZE];
try {
while (nBytesRead != -1) {
nBytesRead = audioInputStream.read(abData, 0, abData.length);
if (nBytesRead >= 0)
auline.write(abData, 0, nBytesRead);
}
} catch (IOException e) {
e.printStackTrace();
return;
} finally {
auline.drain();
auline.close();
}
}
}
+5
View File
@@ -4,6 +4,11 @@ package de.heatup.cfg;
* Bitte hier eure Magicnumbers eintragen
*/
public class Config {
/*
* Attribute
* de.heatup.ui.GameLoop
*/
public static int currentTickNr = 0;
/*
* Attribute
* de.heatup.mapengine.*
@@ -1,9 +1,13 @@
package de.heatup.mapengine;
import java.util.ArrayList;
import de.heatup.logging.Logger;
import de.heatup.testing.Opponent;
import de.heatup.testing.Player;
public class CollisionHandler {
private static ArrayList<Player> movingObjects = new ArrayList<Player>();
/**
* Prüfe ob eine Kollision vorliegt
* @param movingObject Kann alles sein, dass sich bewegt. Spieler oder KI.
@@ -11,29 +15,101 @@ public class CollisionHandler {
* @return
*/
public static boolean checkCollision(Player movingObject, char d) {
if (movingObject == (movingObjects.get(0))) {
// return normalCheck(movingObject, d);
// if (movingObject.equals(movingObjects.get(0))) {
// enemyCollision(movingObject, d);
hardwareCollision(movingObject, d);
return normalCheck(movingObject, d);
} else {
// playerCollision(movingObject, d);
return normalCheck(movingObject, d);
}
// switch (d) {
// case 'l':
// if (MapGrid.getGridCell(movingObject.getGridLocation().x-1, movingObject.getGridLocation().y).isPath() && MapGrid.getGridCell(movingObject.getGridLocation().x-1, movingObject.getGridLocation().y).isTrigger()) {
// Logger.write("Collision with trigger of hardware ID: " + MapGrid.getGridCell(movingObject.getGridLocation().x-1, movingObject.getGridLocation().y).getCorrespondingHardwareToTrigger());
// }
// return MapGrid.getGridCell(movingObject.getGridLocation().x-1, movingObject.getGridLocation().y).isPath();
// case 'r':
// if (MapGrid.getGridCell(movingObject.getGridLocation().x+1, movingObject.getGridLocation().y).isPath() && MapGrid.getGridCell(movingObject.getGridLocation().x+1, movingObject.getGridLocation().y).isTrigger()) {
// Logger.write("Collision with trigger of hardware ID: " + MapGrid.getGridCell(movingObject.getGridLocation().x+1, movingObject.getGridLocation().y).getCorrespondingHardwareToTrigger());
// }
// return MapGrid.getGridCell(movingObject.getGridLocation().x+1, movingObject.getGridLocation().y).isPath();
// case 'd':
// if (MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y+1).isPath() && MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y+1).isTrigger()) {
// Logger.write("Collision with trigger of hardware ID: " + MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y+1).getCorrespondingHardwareToTrigger());
// }
// return MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y+1).isPath();
// case 'u':
// if (MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y-1).isPath() && MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y-1).isTrigger()) {
// Logger.write("Collision with trigger of hardware ID: " + MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y-1).getCorrespondingHardwareToTrigger());
// }
// return MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y-1).isPath();
// default:
// return true;
// }
}
private static void playerCollision(Player movingObject, char d) {
// if (movingObject.getGridLocation().x== movingObjects.get(0).getGridLocation().x && movingObject.getGridLocation().y == movingObjects.get(0).getGridLocation().y) {
//// System.exit(-1);
// }
}
private static void enemyCollision(Player movingObject, char d ) {
// for (int i=1; i<movingObjects.size();i++) {
// if (movingObject.getGridLocation().x== movingObjects.get(i).getGridLocation().x && movingObject.getGridLocation().y == movingObjects.get(i).getGridLocation().y) {
//// System.exit(-1);
// }
// }
}
public static void tick() {
for (int i=1; i<movingObjects.size();i++) {
if (movingObjects.get(0).getGridLocation().x== movingObjects.get(i).getGridLocation().x && movingObjects.get(0).getGridLocation().y == movingObjects.get(i).getGridLocation().y) {
Logger.write("COLLISION WITH ENEMY");
}
}
}
private static void hardwareCollision(Player movingObject, char d) {
switch (d) {
case 'l':
if (MapGrid.getGridCell(movingObject.getGridLocation().x-1, movingObject.getGridLocation().y).isPath() && MapGrid.getGridCell(movingObject.getGridLocation().x-1, movingObject.getGridLocation().y).isTrigger()) {
Logger.write("Collision with trigger of hardware ID: " + MapGrid.getGridCell(movingObject.getGridLocation().x-1, movingObject.getGridLocation().y).getCorrespondingHardwareToTrigger());
}
return MapGrid.getGridCell(movingObject.getGridLocation().x-1, movingObject.getGridLocation().y).isPath();
case 'r':
if (MapGrid.getGridCell(movingObject.getGridLocation().x+1, movingObject.getGridLocation().y).isPath() && MapGrid.getGridCell(movingObject.getGridLocation().x+1, movingObject.getGridLocation().y).isTrigger()) {
Logger.write("Collision with trigger of hardware ID: " + MapGrid.getGridCell(movingObject.getGridLocation().x+1, movingObject.getGridLocation().y).getCorrespondingHardwareToTrigger());
}
return MapGrid.getGridCell(movingObject.getGridLocation().x+1, movingObject.getGridLocation().y).isPath();
case 'd':
if (MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y+1).isPath() && MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y+1).isTrigger()) {
Logger.write("Collision with trigger of hardware ID: " + MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y+1).getCorrespondingHardwareToTrigger());
}
return MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y+1).isPath();
case 'u':
if (MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y-1).isPath() && MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y-1).isTrigger()) {
Logger.write("Collision with trigger of hardware ID: " + MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y-1).getCorrespondingHardwareToTrigger());
}
default:
}
}
private static boolean normalCheck(Player movingObject, char d) {
switch (d) {
case 'l':
return MapGrid.getGridCell(movingObject.getGridLocation().x-1, movingObject.getGridLocation().y).isPath();
case 'r':
return MapGrid.getGridCell(movingObject.getGridLocation().x+1, movingObject.getGridLocation().y).isPath();
case 'd':
return MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y+1).isPath();
case 'u':
return MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y-1).isPath();
default:
return true;
return true; // should not happen
}
}
public static void addMovingObject(Player movingObject) {
movingObjects.add(movingObject);
}
}
Binary file not shown.
@@ -0,0 +1,24 @@
################################
################################
################################
################################
################################
################################
################################
################################
################################
################################
################################
################################
################################
################################
################################
################################
################################
################################
################################
################################
################################
################################
################################
################################
@@ -0,0 +1,24 @@
--------------------------------
-##############################-
-##############################-
-##############################-
-##############################-
-##############################-
-##############################-
-##############################-
-##############################-
-##############################-
-##############################-
-##############################-
-##############################-
-##############################-
-##############################-
-##############################-
-##############################-
-##############################-
-##############################-
-##############################-
-##############################-
-##############################-
-##############################-
--------------------------------
+61 -9
View File
@@ -8,20 +8,26 @@ import java.awt.Point;
import javax.swing.JFrame;
import javax.swing.JPanel;
import de.heatup.cfg.Config;
import de.heatup.logging.Logger;
import de.heatup.mapengine.CollisionHandler;
import de.heatup.mapengine.MapEngine;
import de.heatup.mapengine.MapGrid;
import de.heatup.mapengine.SpawnAssistant;
import de.heatup.objects.StaticObject;
import de.heatup.timers.HardwareResetTimers;
import de.heatup.ui.KeyBindings;
import de.heatup.ui.StatusPanelAdder;
import de.heatup.ui.actionPanel.ActionControl;
import de.heatup.ui.actionPanel.ActionWatcher;
public class GameLoopD extends JFrame implements Runnable {
private static final long serialVersionUID = 1L;
private boolean running = false;
private static boolean pause = false;
private Thread thread;
@@ -36,6 +42,9 @@ public class GameLoopD extends JFrame implements Runnable {
public static Opponent opponent01;
public static Opponent opponent02;
public static Opponent opponent03;
public static Opponent opponent04;
public static Opponent opponent05;
public static Opponent opponent06;
public static void main(String[] args) {
@@ -66,12 +75,12 @@ public class GameLoopD extends JFrame implements Runnable {
gamePanel = new JPanel();
gamePanel.setLayout(null);
gamePanel.setPreferredSize(new Dimension(800,600));
gamePanel.setFocusable(true);
actionPanel = new JPanel();
actionPanel.setLayout(new GridLayout(1,1));
actionPanel.setPreferredSize(new Dimension(800,80));
actionPanel.setFocusable(false);
actionPanel.setFocusable(true);
outerPanel.add(statusPanel,BorderLayout.NORTH);
outerPanel.add(gamePanel,BorderLayout.CENTER);
@@ -84,8 +93,12 @@ public class GameLoopD extends JFrame implements Runnable {
// StatusPanel bauen
StatusPanelAdder.setPanel(statusPanel);
StatusPanelAdder.createPanel();
// ActionPanel bauen
ActionControl.setPanel(actionPanel);
player01 = new Player();
player01 = new Player(); // !!! PLAYER IMMER ZUERST INSTANZIIEREN, DANACH OPPONENTS !!!
// Query.setPlayer(player01);
gamePanel.add(player01);
player01.setBounds(25,25,25, 25); // !!! MUSS DRIN BLEIBEN TROTZ NACHTRÄGLICHES SPAWN UMSETZEN !!!
@@ -103,11 +116,24 @@ public class GameLoopD extends JFrame implements Runnable {
gamePanel.add(opponent03);
opponent03.setBounds(550,450,25,25);
opponent04 = new Opponent();
gamePanel.add(opponent04);
opponent04.setBounds(50,50,25,25);
opponent05 = new Opponent();
gamePanel.add(opponent05);
opponent05.setBounds(150,150,25,25);
opponent06 = new Opponent();
gamePanel.add(opponent06);
opponent06.setBounds(550,450,25,25);
gamePanel.setFocusable(true);
kb = new KeyBindings(player01);
gamePanel.addKeyListener(kb);
MapEngine me = new MapEngine(1);
me.addAllToPanel(gamePanel);
@@ -120,6 +146,12 @@ public class GameLoopD extends JFrame implements Runnable {
opponent02.spawnAt(spawnPoint3);
Point spawnPoint4 = SpawnAssistant.getPathLocationOnGrid();
opponent03.spawnAt(spawnPoint4);
Point spawnPoint5 = SpawnAssistant.getPathLocationOnGrid();
opponent04.spawnAt(spawnPoint5);
Point spawnPoint6 = SpawnAssistant.getPathLocationOnGrid();
opponent05.spawnAt(spawnPoint6);
Point spawnPoint7 = SpawnAssistant.getPathLocationOnGrid();
opponent06.spawnAt(spawnPoint7);
actionPanel.setVisible(true);
outerPanel.setVisible(true);
@@ -135,12 +167,19 @@ public class GameLoopD extends JFrame implements Runnable {
* ende
*/
frame.repaint();
frame.start();
}
private synchronized void start() {
public static synchronized void pause() {
if (pause) {
pause = false;
} else {
pause = true;
}
}
public synchronized void start() {
if (running) {
return;
}
@@ -151,7 +190,7 @@ public class GameLoopD extends JFrame implements Runnable {
}
private synchronized void stop() {
public synchronized void stop() {
if (!running) {
return;
}
@@ -182,7 +221,9 @@ public class GameLoopD extends JFrame implements Runnable {
delta += (now-lastTime) / ns;
lastTime = now;
if (delta >= 1) {
if (!pause) {
tick();
}
updates++;
delta--;
}
@@ -209,12 +250,23 @@ public class GameLoopD extends JFrame implements Runnable {
}
// alles was geupdatet werden muss hier rein
private void tick() {
if (Config.currentTickNr >= 60) {
Config.currentTickNr = 0;
} else {
Config.currentTickNr++;
}
kb.checkKeyActivity();
ActionWatcher.tick();
ActionControl.actionControl();
HardwareResetTimers.tick();
player01.tick();
opponent01.tick();
opponent02.tick();
opponent03.tick();
opponent04.tick();
opponent05.tick();
opponent06.tick();
CollisionHandler.tick();
}
// alles was animiert wird hier rein (paints)
private void render() {
+63 -20
View File
@@ -8,13 +8,12 @@ import javax.imageio.ImageIO;
import de.heatup.cfg.Config;
import de.heatup.logging.Logger;
import de.heatup.mapengine.CollisionHandler;
import de.heatup.mapengine.MapGrid;
import de.heatup.mapengine.MapGridCell;
public class Opponent extends Player {
/**
*
*/
private static final long serialVersionUID = 1L;
private boolean redecide = true; // Nötig sobald der Schritt in die gewollte Richtung erfolgt ist
private Random rand = new Random();
@@ -26,7 +25,13 @@ public class Opponent extends Player {
private int prevX;
private int prevY;
private boolean blocked = false;
private boolean move = false;
private int blockedCounter = 0;
private char charDir;
public Opponent() {
CollisionHandler.addMovingObject(this);
}
@Override protected void loadBufferedImage() {
try {
@@ -37,17 +42,9 @@ public class Opponent extends Player {
}
@Override public void tick() {
if ( redecide ) {
while ( true ) {
this.d = (rand.nextInt(10) <= 4) ? 'x' : 'y';
this.i = (rand.nextInt(10) <= 4) ? 1 : -1;
// Sicher stellen das man nicht in die Richtung geht aus der man gekommen ist.
if ( redecide && this.d == this.prevd && this.i != this.previ ) {
this.i *= -1;
}
// Blockade Erkennung
if ( this.prevX == this.getGridLocation().x & this.prevY == this.getGridLocation().y ) {
this.blockedCounter++;
@@ -58,12 +55,47 @@ public class Opponent extends Player {
this.prevX = this.getGridLocation().x;
this.prevY = this.getGridLocation().y;
//TODO: Bei Kreuzung umentscheiden
if ( d == 'x' ) {
if ( CollisionHandler.checkCollision(this, 'd') ) {
this.move = false;
}
if ( CollisionHandler.checkCollision(this, 'u') ) {
this.move = false;
}
}
if ( d == 'y' ) {
if ( CollisionHandler.checkCollision(this, 'l') ) {
this.move = false;
}
if ( CollisionHandler.checkCollision(this, 'r') ) {
this.move = false;
}
}
// Umentscheiden oder weiter in die vorgegeben Richtung
if ( ! this.move ) {
//Logger.write("Redeciding...");
this.d = (rand.nextInt(10) <= 4) ? 'x' : 'y';
this.i = (rand.nextInt(10) <= 4) ? 1 : -1;
// Sicher stellen das man nicht in die Richtung geht aus der man gekommen ist.
if ( redecide && this.d == this.prevd && this.i != this.previ ) {
this.i *= -1;
}
} else {
//Logger.write("Moving...");
}
this.move = true;
// Blockade auflösen, gehe doch in die Richtung aus man gekommen ist
if ( this.blocked ) {
Logger.write("Warning: Block detected!");
//Logger.write("Warning: Block detected!");
this.i *= -1;
this.move = false;
this.blocked = false;
this.blockedCounter = 0;
}
@@ -77,8 +109,17 @@ public class Opponent extends Player {
testX=this.getGridLocation().x;
}
// Testen ob die gewählte Richtung begehbar ist
if (MapGrid.getGridCell(testX,testY).isPath()) {
if ( d == 'x' && i == -1 ) {
charDir = 'l';
} else if ( d == 'x' && i == 1 ) {
charDir = 'r';
} else if ( d == 'y' && i == -1 ) {
charDir = 'u';
} else if ( d == 'y' && i == 1 ) {
charDir = 'd';
}
if (CollisionHandler.checkCollision(this, charDir)) {
this.setGridLocation(testX, testY);
this.prevd = d;
this.previ = i;
@@ -86,7 +127,6 @@ public class Opponent extends Player {
animate = true;
break;
}
}
}
@@ -94,7 +134,8 @@ public class Opponent extends Player {
int newx = this.getX();
int newy = this.getY();
for (int s = 0; s < this.speedMultiplicator; s++) { // speed multiplikator
// Speed Multiplikator
for (int s = 0; s < this.speedMultiplicator; s++) {
if (d == 'x' && i == -1) {
newx = newx - 1;
} else if (d == 'x' && i == 1) {
@@ -111,13 +152,15 @@ public class Opponent extends Player {
animate = false;
break;
}
}
if (stepCounter <= 0) {
stepCounter = 25;
redecide = true;
}
animate = false;
} else {
animate = true;
}
}
}
}
+5
View File
@@ -14,6 +14,7 @@ import javax.swing.JComponent;
import de.heatup.cfg.Config;
import de.heatup.logging.Logger;
import de.heatup.mapengine.CollisionHandler;
public class Player extends JComponent {
private static final long serialVersionUID = 1L;
@@ -33,6 +34,10 @@ public class Player extends JComponent {
int stepCounter = 25;
private Point currentGridPosition;
public Player() {
CollisionHandler.addMovingObject(this);
}
public void setSpeedMultiplicator(int factor) {
this.speedMultiplicator *= factor;
}
@@ -0,0 +1,36 @@
package de.heatup.timers;
import java.util.HashMap;
import java.util.Map;
import de.heatup.cfg.Config;
import de.heatup.logging.Logger;
import de.heatup.ui.actionPanel.HardewareManipulate;
public class HardwareResetTimers {
private static int tickCount = 0;
private static int tickRoundMax = 10000;
private static int nrOfTicksUntilReset = 900; // entspricht 15 sekunden ingame zeit (nicht unbedingt echtzeit!); berechnet durch 15*targetTickRate im Gameloop.
private static Map<Character, Integer> HardwareResetTickstamps = new HashMap<Character, Integer>();
public static void tick() {
tickCount++;
if (tickCount>=tickRoundMax) {
tickCount = 0;
}
for (char i = Config.firstHardwareChar; i<=Config.lastHardwareChar; i++) {
if (HardwareResetTickstamps.containsKey(i)) {
if (HardwareResetTickstamps.get(i).equals(tickCount)) {
Logger.write("Hardware "+i+" reset");
HardewareManipulate.resetHardware(i);
}
}
}
}
public static void setManipulated(char c) {
int resetTimestamp = tickCount+nrOfTicksUntilReset;
if (resetTimestamp > tickRoundMax) {
resetTimestamp = resetTimestamp % tickRoundMax;
}
HardwareResetTickstamps.put(c, resetTimestamp);
}
}
+66
View File
@@ -3,8 +3,14 @@ package de.heatup.ui;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import sun.awt.resources.awt;
import de.heatup.mapengine.CollisionHandler;
import de.heatup.mapengine.MapGrid;
import de.heatup.testing.GameLoopD;
import de.heatup.testing.Player;
import de.heatup.ui.actionPanel.ActionControl;
import de.heatup.ui.actionPanel.ActionWatcher;
import de.heatup.ui.actionPanel.HardewareManipulate;
public class KeyBindings extends KeyAdapter {
@@ -12,6 +18,7 @@ public class KeyBindings extends KeyAdapter {
private boolean right = false;
private boolean up = false;
private boolean down = false;
private boolean esc = false;
private Player player;
public KeyBindings(Player player) {
@@ -34,6 +41,9 @@ public class KeyBindings extends KeyAdapter {
case KeyEvent.VK_DOWN:
down = false;
break;
case KeyEvent.VK_ESCAPE:
esc = false;
break;
}
}
@@ -53,6 +63,55 @@ public class KeyBindings extends KeyAdapter {
case KeyEvent.VK_DOWN:
down = true;
break;
case KeyEvent.VK_ESCAPE:
esc = true;
break;
case KeyEvent.VK_A:
if(MapGrid.getGridCell(GameLoopD.player01.getGridLocation().x, GameLoopD.player01.getGridLocation().y).isTrigger()
&& !HardewareManipulate.getHardware(MapGrid.getGridCell(GameLoopD.player01.getGridLocation().x, GameLoopD.player01.getGridLocation().y).getCorrespondingHardwareToTrigger())){
ActionWatcher.setAction(true);
}
break;
case KeyEvent.VK_Q:
if(ActionWatcher.getAction()&&ActionControl.getSmash()=='Q'){
if(ActionControl.getOption()){
ActionControl.count++;
}else{
//ActionControl.setQ();
//ActionControl.count++;
}
}
break;
case KeyEvent.VK_W:
if(ActionWatcher.getAction()&&ActionControl.getSmash()=='W'){
if(ActionControl.getOption()){
ActionControl.count++;
}else{
//ActionControl.setW();
//ActionControl.count++;
}
}
break;
case KeyEvent.VK_E:
if(ActionWatcher.getAction()&&ActionControl.getSmash()=='E'){
if(ActionControl.getOption()){
ActionControl.count++;
}else{
//ActionControl.setE();
//ActionControl.count++;
}
}
break;
case KeyEvent.VK_R:
if(ActionWatcher.getAction()&&ActionControl.getSmash()=='R'){
if(ActionControl.getOption()){
ActionControl.count++;
}else{
//ActionControl.setR();
//ActionControl.count++;
}
}
break;
}
}
@@ -90,6 +149,10 @@ public class KeyBindings extends KeyAdapter {
}
player.animate = true;
}
if (isESC()) {
System.out.println("ESC pressed.");
GameLoopD.pause();
}
}
public boolean isLeft() {
@@ -107,4 +170,7 @@ public class KeyBindings extends KeyAdapter {
public boolean isDown() {
return down;
}
public boolean isESC() {
return esc;
}
}
@@ -0,0 +1,113 @@
package de.heatup.ui.actionPanel;
import java.awt.Color;
import java.awt.Font;
import javax.swing.*;
import javax.swing.border.LineBorder;
import de.heatup.mapengine.MapGrid;
import de.heatup.testing.GameLoopD;
public class ActionControl{
public static int count =0;
private static long afterTime=0;
static long beforeTime =0;
static boolean time =true;
private static boolean Q=false;
private static boolean W=false;
private static boolean E=false;
private static boolean R=false;
private static boolean option;
private static char chr='0';
private static char arr[];
private static Smashing smashing;
private static Keysequence keysequence;
private static JPanel panel;
protected static JLabel actionLabel;
public static void setPanel(JPanel newPanel){
panel = newPanel;
smashing = new Smashing();
keysequence = new Keysequence();
actionLabel = new JLabel();
actionLabel.setFont(new Font("Arial", Font.CENTER_BASELINE, 16));
actionLabel.setBorder(new LineBorder(Color.BLACK, 1));
actionLabel.setSize(100,10);
panel.add(actionLabel);
wishPanel();
}
public static void setAction(int rd){
if(true){
option=true;
setSmash(smashing.getKey());
String str= "Bitte die Taste "+getSmash()+" so schnell wie moeglich druecken";
actionLabel.setText(str);
/*}else{
option=false;
setSequence(keysequence.getKeySequence());
String str="Bitte diese Tastenkombination \"";
for(int i=0;i<keysequence.getLength();i++){
str=str+getSequence()[i]+" ";
}
str=str + "\" "+"so schnell wie moeglich eingeben";
actionLabel.setText(str);*/
}
}
public static void actionControl(){
if(ActionWatcher.getAction()){
if(option){
if(count<30){
if(time){
time = !time;
beforeTime=System.nanoTime();
}
}else{
afterTime=System.nanoTime()-beforeTime;
if(afterTime>8_000_000_000L){
actionLabel.setText("Fehlgeschlagen");
}else{
actionLabel.setText("Manipulation erfolgreich!");
count=0;
time=!time;
ActionWatcher.setAction(false);
HardewareManipulate.setHardware(MapGrid.getGridCell(GameLoopD.player01.getGridLocation().x, GameLoopD.player01.getGridLocation().y).getCorrespondingHardwareToTrigger());
}
}
}else{
//
}
}
}
public static void setQ(){
Q=true;
}
public static void setW(){
W=true;
}
public static void setE(){
E=true;
}
public static void setR(){
R=true;
}
public static boolean getOption(){
return option;
}
private static void setSmash(char c){
chr=c;
}
private static void setSequence(char c[]){
arr=c;
}
public static char getSmash(){
return chr;
}
private static char[] getSequence(){
return arr;
}
public static void wishPanel(){
actionLabel.setText("");
}
}
@@ -0,0 +1,55 @@
package de.heatup.ui.actionPanel;
import java.awt.Component;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.Random;
import javax.swing.JLabel;
import de.heatup.mapengine.MapEngine;
import de.heatup.mapengine.MapGrid;
import de.heatup.mapengine.MapGridCell;
import de.heatup.testing.GameLoopD;
public class ActionWatcher{
private static boolean action = false;
private static boolean setaction = false;
private static Random rdm = new Random();
public static void setAction(boolean b){
action = b;
}
public static boolean getAction(){
return action;
}
public static void tick(){
//Taucht auf, falls man in der Näche von einem Hardwareteil steht
if(MapGrid.getGridCell(GameLoopD.player01.getGridLocation().x, GameLoopD.player01.getGridLocation().y).isTrigger() && !action && !setaction){
if(!HardewareManipulate.getHardware(MapGrid.getGridCell(GameLoopD.player01.getGridLocation().x, GameLoopD.player01.getGridLocation().y).getCorrespondingHardwareToTrigger())){
ActionControl.actionLabel.setText("Taste A druecken");
}else{
ActionControl.actionLabel.setText("Bereits Manipuliert");
}
}
//Entfernt jeglichen Text wenn man sich von dem Hardwarestück entfernt und noch nicht A gedrückt hat
if(!MapGrid.getGridCell(GameLoopD.player01.getGridLocation().x, GameLoopD.player01.getGridLocation().y).isTrigger() && !action && !setaction){
ActionControl.wishPanel();
}
//Nach dem man A gedrueckt hat kommt entweder Smashing oder Keysequence Text.
if(action&&!setaction){
setaction = !setaction;
ActionControl.actionLabel.setText("");
ActionControl.setAction(rdm.nextInt(2)+1);
}
//Entfernt jeglichen Text wenn man sich von dem Hardwarestück entfernt und setzt Booleans wieder auf ausganssituation
if(!MapGrid.getGridCell(GameLoopD.player01.getGridLocation().x, GameLoopD.player01.getGridLocation().y).isTrigger() && setaction){
ActionControl.wishPanel();
ActionControl.count=0;
ActionControl.time=true;
ActionControl.beforeTime=0;
setaction = !setaction;
action = !action;
}
}
}
@@ -0,0 +1,132 @@
package de.heatup.ui.actionPanel;
import de.heatup.timers.HardwareResetTimers;
public class HardewareManipulate {
private static boolean h00=false;
private static boolean h01=false;
private static boolean h02=false;
private static boolean h03=false;
private static boolean h04=false;
private static boolean h05=false;
private static boolean h06=false;
private static boolean h07=false;
private static boolean h08=false;
private static boolean h09=false;
public static void setHardware(char c){
switch(c){
case '0':
h00=true;
HardwareResetTimers.setManipulated(c);
break;
case '1':
h01=true;
HardwareResetTimers.setManipulated(c);
break;
case '2':
h02=true;
HardwareResetTimers.setManipulated(c);
break;
case '3':
h03=true;
HardwareResetTimers.setManipulated(c);
break;
case '4':
h04=true;
HardwareResetTimers.setManipulated(c);
break;
case '5':
h05=true;
HardwareResetTimers.setManipulated(c);
break;
case '6':
h06=true;
HardwareResetTimers.setManipulated(c);
break;
case '7':
h07=true;
HardwareResetTimers.setManipulated(c);
break;
case '8':
h08=true;
HardwareResetTimers.setManipulated(c);
break;
case '9':
h09=true;
HardwareResetTimers.setManipulated(c);
break;
}
}
public static void resetHardware(char c){
switch(c){
case '0':
h00=false;
break;
case '1':
h01=false;
break;
case '2':
h02=false;
break;
case '3':
h03=false;
break;
case '4':
h04=false;
break;
case '5':
h05=false;
break;
case '6':
h06=false;
break;
case '7':
h07=false;
break;
case '8':
h08=false;
break;
case '9':
h09=false;
break;
}
}
public static boolean getHardware(char c){
switch(c){
case '0':
return h00;
case '1':
return h01;
case '2':
return h02;
case '3':
return h03;
case '4':
return h04;
case '5':
return h05;
case '6':
return h06;
case '7':
return h07;
case '8':
return h08;
case '9':
return h09;
default:
return false;
}
}
public static void reinitialisieren(){
h00=false;
h01=false;
h02=false;
h03=false;
h04=false;
h05=false;
h06=false;
h07=false;
h08=false;
h09=false;
}
}
@@ -0,0 +1,35 @@
package de.heatup.ui.actionPanel;
import java.util.Random;
public class Keysequence {
private int length =8;
private char[] key_sq;
private Random rdm;
public Keysequence(){
rdm = new Random();
key_sq=new char[length];
}
public int getLength(){
return length;
}
protected char[] getKeySequence(){
for(int i=0;i<length;i++){
switch(rdm.nextInt(4)+1){
case 1:
key_sq[i]='Q';
break;
case 2:
key_sq[i]='W';
break;
case 3:
key_sq[i]='E';
break;
case 4:
key_sq[i]='R';
break;
}
}
return key_sq;
}
}
@@ -0,0 +1,29 @@
package de.heatup.ui.actionPanel;
import java.util.Random;
public class Smashing {
char key;
Random rdm;
public Smashing(){
rdm = new Random();
}
public char getKey(){
switch(rdm.nextInt(4)+1){
case 1:
key='Q';
break;
case 2:
key='W';
break;
case 3:
key='E';
break;
case 4:
key='R';
break;
}
return key;
}
}