Compare commits
No commits in common. "c5d00cdfc2476bcdd3786e46539b01acd5243d10" and "73cb60941d4d820c05cabb84781c6b27f2347cfa" have entirely different histories.
c5d00cdfc2
...
73cb60941d
44
program.pde
44
program.pde
@ -2,8 +2,6 @@
|
|||||||
//- Start Screen
|
//- Start Screen
|
||||||
//- Level Editor (click with mouse spawns or deletes tiles)
|
//- Level Editor (click with mouse spawns or deletes tiles)
|
||||||
// - Hotkey to slide the window right and left
|
// - Hotkey to slide the window right and left
|
||||||
//- Movement berechnen mit move = gravitation - speed
|
|
||||||
// - Jump als Zahl, die langsam kleiner wird
|
|
||||||
|
|
||||||
// jumping related
|
// jumping related
|
||||||
float speed = 20;
|
float speed = 20;
|
||||||
@ -13,13 +11,13 @@ float jumpcooldown = 12;
|
|||||||
|
|
||||||
// for moving x-axis (mostly depracted)
|
// for moving x-axis (mostly depracted)
|
||||||
// But dont delete yet!!
|
// But dont delete yet!!
|
||||||
|
PVector movement = new PVector(0,0);
|
||||||
PVector direction = new PVector(0,0);
|
PVector direction = new PVector(0,0);
|
||||||
PVector pos = new PVector(220, 50);
|
PVector pos = new PVector(220, 50);
|
||||||
int playerRadius = 25;
|
int playerRadius = 25;
|
||||||
|
|
||||||
float actualPos;
|
float actualPos;
|
||||||
|
|
||||||
PVector tilesize = new PVector(50, 50);
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
size(800,800);
|
size(800,800);
|
||||||
@ -38,8 +36,8 @@ void draw() {
|
|||||||
// noFill();
|
// noFill();
|
||||||
|
|
||||||
|
|
||||||
// menu();
|
menu();
|
||||||
play();
|
// play();
|
||||||
helper();
|
helper();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,9 +78,9 @@ void play() {
|
|||||||
rect(pos.x, pos.y, playerRadius, playerRadius);
|
rect(pos.x, pos.y, playerRadius, playerRadius);
|
||||||
|
|
||||||
baseline();
|
baseline();
|
||||||
// jumpToJumpheight();
|
|
||||||
newJump();
|
|
||||||
collisionTest();
|
collisionTest();
|
||||||
|
cooldown();
|
||||||
|
jumpToJumpheight();
|
||||||
|
|
||||||
generate_tiles();
|
generate_tiles();
|
||||||
|
|
||||||
@ -92,12 +90,12 @@ void play() {
|
|||||||
// This is basically the Level file:
|
// This is basically the Level file:
|
||||||
// It consists out of an array, that spawns tiles
|
// It consists out of an array, that spawns tiles
|
||||||
// It is also checked in collisionTest()
|
// It is also checked in collisionTest()
|
||||||
int[] tiles_x = { 300, 50, 600, 50};
|
int[] tiles_x = { 300, 50, 600 };
|
||||||
int[] tiles_y = { 500, 50, 600, 200 };
|
int[] tiles_y = { 500, 50, 600 };
|
||||||
|
|
||||||
void generate_tiles() {
|
void generate_tiles() {
|
||||||
for (int i = 0; i < tiles_x.length; i++ ) {
|
for (int i = 0; i < tiles_x.length; i++ ) {
|
||||||
rect(tiles_x[i], tiles_y[i], tilesize.x, tilesize.y);
|
rect(tiles_x[i], tiles_y[i], 50, 50);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO Collision erweitern wie in https://happycoding.io/tutorials/processing/collision-detection
|
// TODO Collision erweitern wie in https://happycoding.io/tutorials/processing/collision-detection
|
||||||
@ -106,13 +104,10 @@ void collisionTest() {
|
|||||||
if ( pos.y > baseline_y - playerRadius ) {
|
if ( pos.y > baseline_y - playerRadius ) {
|
||||||
pos.set(pos.x, baseline_y - playerRadius);
|
pos.set(pos.x, baseline_y - playerRadius);
|
||||||
}
|
}
|
||||||
// Collision with all the tiles bottom site
|
// Collision with all the tiles top site
|
||||||
for (int i = 0; i < tiles_x.length; i++) {
|
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)) {
|
if ((pos.x > tiles_x[i]-25 && pos.x < tiles_x[i]+25) && pos.y < tiles_y[i] - playerRadius) {
|
||||||
pos.set(pos.x, tiles_y[i] + tilesize.y/2);
|
pos.set(pos.x, tiles_y[i] - playerRadius);
|
||||||
}
|
|
||||||
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)) {
|
|
||||||
pos.set(pos.x, tiles_y[i] - tilesize.y/2 - 20);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -143,17 +138,12 @@ void jumpToJumpheight() {
|
|||||||
jumpheight = 0;
|
jumpheight = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// count down jumping cooldown
|
||||||
float movement;
|
void cooldown() {
|
||||||
float jumpspeed;
|
if (jumpcooldown > 0) {
|
||||||
void newJump() {
|
jumpcooldown = jumpcooldown-1;
|
||||||
movement = gravitation - jumpspeed;
|
|
||||||
pos.set(pos.x, pos.y + movement);
|
|
||||||
if (jumpspeed > 0) {
|
|
||||||
jumpspeed--;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// actions for moving
|
// actions for moving
|
||||||
void keyPressed() {
|
void keyPressed() {
|
||||||
if (key == CODED)
|
if (key == CODED)
|
||||||
@ -170,10 +160,10 @@ void keyPressed() {
|
|||||||
pos.x = pos.x + direction.x * speed;
|
pos.x = pos.x + direction.x * speed;
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
if (keyCode == UP)
|
if (keyCode == UP && jumpcooldown == 0)
|
||||||
{
|
{
|
||||||
//if (directionY<0) {
|
//if (directionY<0) {
|
||||||
jumpspeed =+ 25;
|
jumpheight += 400;
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
// else if (keyCode == DOWN)
|
// else if (keyCode == DOWN)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user