Skip to content

Commit 39b21c2

Browse files
authored
Merge pull request #21 from tenk-9/fix_interface_issues
Fix interface issues
2 parents d521a16 + 62a7633 commit 39b21c2

File tree

3 files changed

+78
-48
lines changed

3 files changed

+78
-48
lines changed

dev/catchPlate.pde

+32-37
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ class CatchPlate{
55
private final color _fillColor = color(58, 201, 176, 120);
66
private final color _strokeColor = color(58, 201, 176);
77
// phisics var
8-
private float _mass = 10;
8+
private float _mass = 300;
99
private PVector _velocity = new PVector(0, 0, 0);
1010
private PVector _force = new PVector(0, 0, 0);
11-
private final float _forceSize = 5;
11+
private final float _forceSize = 60000;
1212
// area limitation var
1313
public boolean moveAreaLimitation = false;
1414
private PVector _moveArea = new PVector(0, 0, 0);
@@ -67,45 +67,40 @@ class CatchPlate{
6767
_velocity.z = 0;
6868
}
6969
}
70+
public void addForce(KeyState keyState){
71+
_force = new PVector(0, 0, 0);
72+
// wasd
73+
if(keyState.get('w')){
74+
_force.z += _forceSize;
75+
}
76+
if(keyState.get('a')){
77+
_force.x -= _forceSize;
78+
}
79+
if(keyState.get('s')){
80+
_force.z -= _forceSize;
81+
}
82+
if(keyState.get('d')){
83+
_force.x += _forceSize;
84+
}
85+
// direction keys
86+
// if(keyState.get(UP)){
87+
// _force.z += _forceSize;
88+
// }
89+
// if(keyState.get(LEFT)){
90+
// _force.x -= _forceSize;
91+
// }
92+
// if(keyState.get(DOWN)){
93+
// _force.z -= _forceSize;
94+
// }
95+
// if(keyState.get(RIGHT)){
96+
// _force.x += _forceSize;
97+
// }
98+
}
7099
public void update(){
71100
// add force to plate object
72101
PVector a, dCoord;
73102
// delta time = 1frame
74-
float dt = 1.0;
75-
_force = new PVector(0, 0, 0);
76-
if(keyPressed){
77-
// add force by pressed keys
78-
switch(key){
79-
// wasd
80-
case 'w':
81-
_force.x -= _forceSize;
82-
break;
83-
case 'a':
84-
_force.z -= _forceSize;
85-
break;
86-
case 's':
87-
_force.x += _forceSize;
88-
break;
89-
case 'd':
90-
_force.z += _forceSize;
91-
break;
92-
// dir keys
93-
case UP:
94-
_force.x -= _forceSize;
95-
break;
96-
case LEFT:
97-
_force.z -= _forceSize;
98-
break;
99-
case DOWN:
100-
_force.x += _forceSize;
101-
break;
102-
case RIGHT:
103-
_force.z += _forceSize;
104-
break;
105-
default:
106-
break;
107-
}
108-
}
103+
float dt = 1.0 / frameRate;
109104
// a = F/m
110105
a = PVector.div(_force, _mass);
111106
// dx = v0*dt + 1/2*a*(dt^2)

dev/dev.pde

+17-11
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// ----------------------------------------------------
44
// game system variables
55
// ----------------------------------------------------
6-
final int TotalCredits = 20;
6+
final int TotalCredits = 50;
77
int appearedCredits = 0;
88
int gainedWeights = 0;
99
float GPA = 0;
@@ -39,6 +39,16 @@ CatchPlate plate = new CatchPlate(plateSize);
3939
PVector cameraEye = new PVector(0, 0, 0);
4040
PVector cameraPlace = new PVector(0, (float)MaxX * 1, -(float)MaxZ * 0.95);
4141

42+
// ----------------------------------------------------
43+
// keyPress handller
44+
// ----------------------------------------------------
45+
KeyState keyState = new KeyState();
46+
void keyPressed(){
47+
keyState.set(keyCode, true);
48+
}
49+
void keyReleased() {
50+
keyState.set(keyCode, false);
51+
}
4252

4353
// ----------------------------------------------------
4454
// rendering
@@ -54,7 +64,7 @@ void setup() {
5464
// game score init
5565
appearedCredits = HandleCreditCount;
5666
// smooth();
57-
sphereDetail(10);
67+
sphereDetail(5);
5868
hint(ENABLE_DEPTH_SORT); // for correct transparency rendering
5969
// objects config
6070
area.fogRendering(true);
@@ -81,9 +91,7 @@ void setup() {
8191
}
8292
void draw() {
8393
background(0);
84-
85-
86-
// // camera settings
94+
// camera settings
8795
// cameraEye.z = plate.getCoordinate().z;
8896
camera(
8997
cameraPlace.x, cameraPlace.y, cameraPlace.z,
@@ -132,9 +140,11 @@ void draw() {
132140
textSize(10);
133141
text(scoreInfo, -MaxX, -30, MaxZ);
134142
popMatrix();
135-
136-
143+
144+
// play area
137145
area.put(playAreaCenter);
146+
//plate
147+
plate.addForce(keyState);
138148
plate.update();
139149
// credits
140150
for (int i = 0; i < HandleCreditCount; ++i) {
@@ -166,10 +176,6 @@ void draw() {
166176
gainedWeights += credits[i].getMass();
167177
}
168178
}
169-
// // update score
170-
// print(gainedWeights, '/', TotalCredits, ',', appearedCredits, '\n');
171-
// // print(credit1.getY(), '\n');
172-
173179
}
174180

175181
// ----------------------------------------------------

dev/keyInterface.pde

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
class KeyState{
2+
// class to check which key is pressed
3+
private HashMap<Integer, Boolean> states;
4+
public KeyState(){
5+
states = new HashMap<Integer, Boolean>();
6+
// init keyPressed variable of target keys
7+
// states.put(UP, false);
8+
// states.put(LEFT, false);
9+
// states.put(DOWN, false);
10+
// states.put(RIGHT, false);
11+
states.put((int)'W', false);
12+
states.put((int)'A', false);
13+
states.put((int)'S', false);
14+
states.put((int)'D', false);
15+
}
16+
public boolean get(int keycode){
17+
// get state with keyCode integer
18+
return states.get(keyCode);
19+
}
20+
public boolean get(char keyChar){
21+
// get state with char of key
22+
if(keyChar >= 'a')
23+
keyChar -= 0x20;
24+
return states.get((int)keyChar);
25+
}
26+
public void set(int keycode, boolean state){
27+
states.put(keycode, state);
28+
}
29+
}

0 commit comments

Comments
 (0)