refactor
This commit is contained in:
parent
c5d00cdfc2
commit
c3f0390160
39
program.pde
39
program.pde
@ -2,6 +2,7 @@
|
||||
//- Start Screen
|
||||
//- Level Editor (click with mouse spawns or deletes tiles)
|
||||
// - Hotkey to slide the window right and left
|
||||
// - Find a way to make menus
|
||||
//- Movement berechnen mit move = gravitation - speed
|
||||
// - Jump als Zahl, die langsam kleiner wird
|
||||
|
||||
@ -87,6 +88,7 @@ void play() {
|
||||
generate_tiles();
|
||||
|
||||
helper();
|
||||
// moveTiles();
|
||||
}
|
||||
|
||||
// This is basically the Level file:
|
||||
@ -106,44 +108,33 @@ void collisionTest() {
|
||||
if ( pos.y > baseline_y - playerRadius ) {
|
||||
pos.set(pos.x, baseline_y - playerRadius);
|
||||
}
|
||||
|
||||
// Collision with all the tiles bottom site
|
||||
for (int i = 0; i < tiles_x.length; i++) {
|
||||
if ((pos.x > tiles_x[i] - tilesize.x/2 && pos.x < tiles_x[i]+tilesize.x/2) && (pos.y < tiles_y[i] + tilesize.y/2 && pos.y > tiles_y[i] - tilesize.y/2)) {
|
||||
boolean xSideEdges = pos.x > tiles_x[i] - tilesize.x/2 && pos.x < tiles_x[i]+tilesize.x/2;
|
||||
boolean ySideEdges = pos.y < tiles_y[i] + tilesize.y/2 && pos.y > tiles_y[i] - tilesize.y/2;
|
||||
|
||||
|
||||
if ( (xSideEdges) && (ySideEdges)) {
|
||||
pos.set(pos.x, tiles_y[i] + tilesize.y/2);
|
||||
}
|
||||
if ((pos.x > tiles_x[i] - tilesize.x/2 && pos.x < tiles_x[i]+tilesize.x/2) && (pos.y < tiles_y[i] + tilesize.y/2 && pos.y > tiles_y[i] -tilesize.y/2 - playerRadius)) {
|
||||
if ( (xSideEdges) && (pos.y < tiles_y[i] + tilesize.y/2 && pos.y > tiles_y[i] -tilesize.y/2 - playerRadius)) {
|
||||
pos.set(pos.x, tiles_y[i] - tilesize.y/2 - 20);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void moveTiles() {
|
||||
for (int i = 0; i < tiles_x.length; i++) {
|
||||
tiles_x[i] = tiles_x[i] - 1;
|
||||
}
|
||||
}
|
||||
|
||||
int baseline_y = 700;
|
||||
void baseline() {
|
||||
line(0, baseline_y, width, baseline_y);
|
||||
}
|
||||
|
||||
|
||||
// ##### Movement related
|
||||
//
|
||||
// all there is to jumping
|
||||
void jumpToJumpheight() {
|
||||
// control gravitation
|
||||
pos.set(pos.x, pos.y + gravitation);
|
||||
// turn gravity of if we are jumping
|
||||
if (actualPos < jumpheight) {
|
||||
gravitation = 0;
|
||||
} else {
|
||||
gravitation = 9.81;
|
||||
}
|
||||
|
||||
if (actualPos < jumpheight) {
|
||||
pos.y = pos.y - speed;
|
||||
jumpcooldown = 40;
|
||||
} else {
|
||||
jumpheight = 0;
|
||||
}
|
||||
}
|
||||
|
||||
float movement;
|
||||
float jumpspeed;
|
||||
void newJump() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user