-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathController.java
More file actions
134 lines (108 loc) · 3.5 KB
/
Copy pathController.java
File metadata and controls
134 lines (108 loc) · 3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package Game;
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import javax.swing.JPanel;
public class Controller implements KeyListener,MouseListener,MouseMotionListener,MouseWheelListener{
private JPanel gamePanel;
static boolean mousePressed = false;
static Point mousePosition = new Point(0,0);
public void setGamePanel(JPanel panelRef) {
gamePanel = panelRef;
gamePanel.addKeyListener(this);
gamePanel.addMouseListener(this);
gamePanel.addMouseMotionListener(this);
gamePanel.addMouseWheelListener(this);
}
public void mouseWheelMoved(MouseWheelEvent arg0) {
// TODO Auto-generated method stub
}
public void mouseDragged(MouseEvent e) {
mousePosition.x = (int) e.getPoint().getX();
mousePosition.y = (int) e.getPoint().getY();
}
public void mouseMoved(MouseEvent e) {
mousePosition.x = (int) e.getPoint().getX();
mousePosition.y = (int) e.getPoint().getY();
// TODO Auto-generated method stub
}
public void mouseClicked(MouseEvent arg0) {
// TODO Auto-generated method stub
}
public void mouseEntered(MouseEvent arg0) {
// TODO Auto-generated method stub
}
public void mouseExited(MouseEvent arg0) {
// TODO Auto-generated method stub
}
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
mousePressed = true;
mousePosition.x = (int) e.getPoint().getX();
mousePosition.y = (int) e.getPoint().getY();
}
public void mouseReleased(MouseEvent arg0) {
// TODO Auto-generated method stub
mousePressed = false;
}
public void keyPressed(KeyEvent e) {
if(e.getKeyCode()==KeyEvent.VK_M){
if(GamePanel.showMap){
GamePanel.showMap=false;
}
else{
GamePanel.showMap=true;
}
}
if(e.getKeyCode()==KeyEvent.VK_G){
if(GamePanel.godmode){
GamePanel.godmode=false;
}
else{
GamePanel.godmode=true;
}
}
if(GamePanel.godmode){
if(e.getKeyCode()==KeyEvent.VK_1){
if(GamePanel.player.movementSpeed>0){
GamePanel.player.movementSpeed-=.05;
}
}
if(e.getKeyCode()==KeyEvent.VK_2){
GamePanel.player.movementSpeed+=.05;
}
if(e.getKeyCode()==KeyEvent.VK_UP){
GamePanel.levels.get(GamePanel.currentLevel).seed++;
GamePanel.levels.get(GamePanel.currentLevel).generateMap();
GamePanel.levels.get(GamePanel.currentLevel).updateTileMapArt();
}
if(e.getKeyCode()==KeyEvent.VK_DOWN){
GamePanel.levels.get(GamePanel.currentLevel).seed--;
GamePanel.levels.get(GamePanel.currentLevel).generateMap();
GamePanel.levels.get(GamePanel.currentLevel).updateTileMapArt();
}
}
}
public void keyReleased(KeyEvent arg0) {
// TODO Auto-generated method stub
}
public void keyTyped(KeyEvent e) {
}
public static void checkKeys(){
//check if mouse was pressed
if(mousePressed){
//Point temp = MouseEvent.getPoint();
if(mousePressed){
GamePanel.player.destination.x=(int)GamePanel.player.xpos+mousePosition.x-((ApplicationUI.windowWidth/2)-16);
GamePanel.player.destination.y=(int)GamePanel.player.ypos+mousePosition.y-((ApplicationUI.windowHeight/2)-16);
}
//System.out.println("destination: "+GamePanel.player.destination.x+","+GamePanel.player.destination.y);
}
}
}