114 lines
2.4 KiB
Plaintext
114 lines
2.4 KiB
Plaintext
//TODO
|
|
//- 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
|
|
|
|
// jumping related
|
|
float speed = 20;
|
|
float gravitation = 9.81;
|
|
float jumpheight;
|
|
float jumpcooldown = 12;
|
|
|
|
// for moving x-axis (mostly depracted)
|
|
// But dont delete yet!!
|
|
PVector direction = new PVector(0,0);
|
|
PVector pos = new PVector(220, 50);
|
|
int playerRadius = 25;
|
|
|
|
float actualPos;
|
|
|
|
PVector tilesize = new PVector(50, 50);
|
|
|
|
int[][] level;
|
|
|
|
|
|
|
|
int test = 0;
|
|
// The actual game
|
|
void play() {
|
|
// calculate actual position on ground
|
|
actualPos = height - pos.y;
|
|
|
|
background(255);
|
|
|
|
// player
|
|
rectMode(CENTER);
|
|
rect(pos.x, pos.y, playerRadius, playerRadius);
|
|
|
|
moveTiles();
|
|
baseline();
|
|
// jumpToJumpheight();
|
|
newJump();
|
|
collisionTest();
|
|
|
|
generate_tiles();
|
|
|
|
helper();
|
|
// moveTiles();
|
|
menuButton();
|
|
|
|
fill(0);
|
|
text(test, 700, 50);
|
|
test = test+3;
|
|
fill(255);
|
|
}
|
|
|
|
|
|
// TODO Collision erweitern wie in https://happycoding.io/tutorials/processing/collision-detection
|
|
void collisionTest() {
|
|
// Collision with baseline
|
|
if ( pos.y > baseline_y - playerRadius/2 ) {
|
|
pos.set(pos.x, baseline_y - playerRadius/2);
|
|
}
|
|
|
|
// Collision with all the tiles bottom site
|
|
for (int i = 0; i < level.length; i++) {
|
|
boolean xSideEdges = pos.x > level[i][0] - tilesize.x/2 && pos.x < level[i][0] + tilesize.x/2;
|
|
boolean ySideEdges = pos.y < level[i][1] + tilesize.y/2 && pos.y > level[i][1] - tilesize.y/2;
|
|
|
|
// Bottom
|
|
if ( (xSideEdges) && (ySideEdges)) {
|
|
pos.set(pos.x, level[i][1] + tilesize.y/2);
|
|
}
|
|
// Top
|
|
if ( (xSideEdges) && (pos.y < level[i][1] + tilesize.y/2 && pos.y > level[i][1] - tilesize.y/2 - playerRadius)) {
|
|
pos.set(pos.x, level[i][1] - tilesize.y/2 - 15);
|
|
}
|
|
}
|
|
}
|
|
|
|
int screenoffset = 0;
|
|
|
|
void moveTiles() {
|
|
for (int i = 0; i < level.length; i++) {
|
|
level[i][0] = level[i][0] - 3;
|
|
screenoffset++;
|
|
}
|
|
}
|
|
void moveTilesBack() {
|
|
for (int i = 0; i < level.length; i++) {
|
|
level[i][0] = level[i][0] + test;
|
|
}
|
|
test = 0;
|
|
}
|
|
|
|
int baseline_y = 700;
|
|
void baseline() {
|
|
line(0, baseline_y, width, baseline_y);
|
|
}
|
|
|
|
float movement;
|
|
float jumpspeed;
|
|
void newJump() {
|
|
movement = gravitation - jumpspeed;
|
|
pos.set(pos.x, pos.y + movement);
|
|
if (jumpspeed > 0) {
|
|
jumpspeed--;
|
|
}
|
|
}
|
|
|
|
|