Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix interface issues #21

Merged
merged 4 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 32 additions & 37 deletions dev/catchPlate.pde
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ class CatchPlate{
private final color _fillColor = color(58, 201, 176, 120);
private final color _strokeColor = color(58, 201, 176);
// phisics var
private float _mass = 10;
private float _mass = 300;
private PVector _velocity = new PVector(0, 0, 0);
private PVector _force = new PVector(0, 0, 0);
private final float _forceSize = 5;
private final float _forceSize = 60000;
// area limitation var
public boolean moveAreaLimitation = false;
private PVector _moveArea = new PVector(0, 0, 0);
Expand Down Expand Up @@ -67,45 +67,40 @@ class CatchPlate{
_velocity.z = 0;
}
}
public void addForce(KeyState keyState){
_force = new PVector(0, 0, 0);
// wasd
if(keyState.get('w')){
_force.z += _forceSize;
}
if(keyState.get('a')){
_force.x -= _forceSize;
}
if(keyState.get('s')){
_force.z -= _forceSize;
}
if(keyState.get('d')){
_force.x += _forceSize;
}
// direction keys
// if(keyState.get(UP)){
// _force.z += _forceSize;
// }
// if(keyState.get(LEFT)){
// _force.x -= _forceSize;
// }
// if(keyState.get(DOWN)){
// _force.z -= _forceSize;
// }
// if(keyState.get(RIGHT)){
// _force.x += _forceSize;
// }
}
public void update(){
// add force to plate object
PVector a, dCoord;
// delta time = 1frame
float dt = 1.0;
_force = new PVector(0, 0, 0);
if(keyPressed){
// add force by pressed keys
switch(key){
// wasd
case 'w':
_force.x -= _forceSize;
break;
case 'a':
_force.z -= _forceSize;
break;
case 's':
_force.x += _forceSize;
break;
case 'd':
_force.z += _forceSize;
break;
// dir keys
case UP:
_force.x -= _forceSize;
break;
case LEFT:
_force.z -= _forceSize;
break;
case DOWN:
_force.x += _forceSize;
break;
case RIGHT:
_force.z += _forceSize;
break;
default:
break;
}
}
float dt = 1.0 / frameRate;
// a = F/m
a = PVector.div(_force, _mass);
// dx = v0*dt + 1/2*a*(dt^2)
Expand Down
28 changes: 17 additions & 11 deletions dev/dev.pde
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// ----------------------------------------------------
// game system variables
// ----------------------------------------------------
final int TotalCredits = 20;
final int TotalCredits = 50;
int appearedCredits = 0;
int gainedWeights = 0;
float GPA = 0;
Expand Down Expand Up @@ -39,6 +39,16 @@ CatchPlate plate = new CatchPlate(plateSize);
PVector cameraEye = new PVector(0, 0, 0);
PVector cameraPlace = new PVector(0, (float)MaxX * 1, -(float)MaxZ * 0.95);

// ----------------------------------------------------
// keyPress handller
// ----------------------------------------------------
KeyState keyState = new KeyState();
void keyPressed(){
keyState.set(keyCode, true);
}
void keyReleased() {
keyState.set(keyCode, false);
}

// ----------------------------------------------------
// rendering
Expand All @@ -54,7 +64,7 @@ void setup() {
// game score init
appearedCredits = HandleCreditCount;
// smooth();
sphereDetail(10);
sphereDetail(5);
hint(ENABLE_DEPTH_SORT); // for correct transparency rendering
// objects config
area.fogRendering(true);
Expand All @@ -81,9 +91,7 @@ void setup() {
}
void draw() {
background(0);


// // camera settings
// camera settings
// cameraEye.z = plate.getCoordinate().z;
camera(
cameraPlace.x, cameraPlace.y, cameraPlace.z,
Expand Down Expand Up @@ -132,9 +140,11 @@ void draw() {
textSize(10);
text(scoreInfo, -MaxX, -30, MaxZ);
popMatrix();


// play area
area.put(playAreaCenter);
//plate
plate.addForce(keyState);
plate.update();
// credits
for (int i = 0; i < HandleCreditCount; ++i) {
Expand Down Expand Up @@ -166,10 +176,6 @@ void draw() {
gainedWeights += credits[i].getMass();
}
}
// // update score
// print(gainedWeights, '/', TotalCredits, ',', appearedCredits, '\n');
// // print(credit1.getY(), '\n');

}

// ----------------------------------------------------
Expand Down
29 changes: 29 additions & 0 deletions dev/keyInterface.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class KeyState{
// class to check which key is pressed
private HashMap<Integer, Boolean> states;
public KeyState(){
states = new HashMap<Integer, Boolean>();
// init keyPressed variable of target keys
// states.put(UP, false);
// states.put(LEFT, false);
// states.put(DOWN, false);
// states.put(RIGHT, false);
states.put((int)'W', false);
states.put((int)'A', false);
states.put((int)'S', false);
states.put((int)'D', false);
}
public boolean get(int keycode){
// get state with keyCode integer
return states.get(keyCode);
}
public boolean get(char keyChar){
// get state with char of key
if(keyChar >= 'a')
keyChar -= 0x20;
return states.get((int)keyChar);
}
public void set(int keycode, boolean state){
states.put(keycode, state);
}
}