From c3f03901608f75d573f78c43e4924852688f904d Mon Sep 17 00:00:00 2001 From: Makussu Date: Thu, 5 Oct 2023 14:13:17 +0200 Subject: [PATCH] refactor --- program.pde | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/program.pde b/program.pde index c3ee5c5..465307f 100644 --- a/program.pde +++ b/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() {