diff --git a/game/background.pde b/game/background.pde new file mode 100644 index 0000000..e69de29 diff --git a/game/game.pde b/game/game.pde index 5ccd8bd..b4521fe 100644 --- a/game/game.pde +++ b/game/game.pde @@ -5,6 +5,9 @@ // - Find a way to make menus //- Movement berechnen mit move = gravitation - speed // - Jump als Zahl, die langsam kleiner wird +// +// Make Colission better: +// - https://happycoding.io/tutorials/processing/collision-detection // jumping related float speed = 20; @@ -14,23 +17,23 @@ float jumpcooldown = 12; // for moving x-axis (mostly depracted) // But dont delete yet!! -PVector direction = new PVector(0,0); +// PVector direction = new PVector(0,0); PVector pos = new PVector(220, 50); int playerRadius = 25; -float actualPos; +// float actualPos; PVector tilesize = new PVector(50, 50); int[][] level; +int tilesmoved = 0; +int tilespeed = 3; - - int test = 0; // The actual game void play() { // calculate actual position on ground - actualPos = height - pos.y; + // actualPos = height - pos.y; background(255); @@ -38,30 +41,52 @@ void play() { rectMode(CENTER); rect(pos.x, pos.y, playerRadius, playerRadius); - moveTiles(); - baseline(); - // jumpToJumpheight(); + moveTiles(tilespeed); + baseRect(); newJump(); collisionTest(); - generate_tiles(); helper(); - // moveTiles(); menuButton(); fill(0); - text(test, 700, 50); - test = test+3; + text(tilesmoved, 700, 50); + tilesmoved = tilesmoved + tilespeed; fill(255); } +void moveTiles(int tilesspeed) { + for (int i = 0; i < level.length; i++) { + level[i][0] = level[i][0] - tilesspeed; + } +} +void moveTilesBack(int tilespeed) { + for (int i = 0; i < level.length; i++) { + level[i][0] = level[i][0] + tilesmoved; + } + tilesmoved = 0; +} + +// Handles Jumping +float movement; +float jumpspeed; +void newJump() { + movement = gravitation - jumpspeed; + pos.set(pos.x, pos.y + movement); + if (jumpspeed > 0) { + jumpspeed--; + } +} + +// This is an absolute mess + // 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); + if ( pos.y > 0.875*height - playerRadius/2 ) { + pos.set(pos.x, 0.875*height - playerRadius/2); } // Collision with all the tiles bottom site @@ -79,35 +104,3 @@ void collisionTest() { } } } - -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--; - } -} - - diff --git a/game/keys.pde b/game/keys.pde index ad08dd6..2d4e8e9 100644 --- a/game/keys.pde +++ b/game/keys.pde @@ -5,15 +5,15 @@ void keyPressed () { if (ismenu) { } else if (isgame) { if (key == CODED) { - if (keyCode == RIGHT) { - direction.x = +1; - pos.x = pos.x + direction.x * speed; - } else if (keyCode == LEFT) { - direction.x = -1; - pos.x = pos.x + direction.x * speed; - } + // if (keyCode == RIGHT) { + // direction.x = +1; + // pos.x = pos.x + direction.x * speed; + // } else if (keyCode == LEFT) { + // direction.x = -1; + // pos.x = pos.x + direction.x * speed; + // } } else if (key == ' ') { - jumpspeed =+ 25; + jumpspeed =+ 30; } } else if (iseditor) { if (key == 's') { @@ -39,7 +39,7 @@ void mouseReleased() { if (mouseButton == LEFT) { level[runnerRect][0] = mouseX+screenx; level[runnerRect][1] = mouseY; - level[runnerRect][2] = 50; + level[runnerRect][2] = 100; level[runnerRect][3] = 50; println("generated"); runnerRect = runnerRect + 1; diff --git a/game/main.pde b/game/main.pde index 88c547e..5a23404 100644 --- a/game/main.pde +++ b/game/main.pde @@ -2,11 +2,13 @@ void setup() { size(800,800); frameRate(60); smooth(4); - // saveFileChecker(); - level = loadJson("./saves/save.json"); + + drawBackground(); + // level = loadJson("./saves/save.json"); } +// not done yet void saveFileChecker() { File f = dataFile("./saves/save.json"); String filePath = f.getPath(); @@ -16,20 +18,17 @@ void saveFileChecker() { } }; + void draw() { + // debug(); - // play(); - // helper(); - debug(); - - if (ismenu) { - mainMenu(); - } else if (isgame) { - play(); - } else if (iseditor) { - mapEditor(); - } - + // if (ismenu) { + // mainMenu(); + // } else if (isgame) { + // play(); + // } else if (iseditor) { + // mapEditor(); + // } } boolean ismenu = true; @@ -39,40 +38,49 @@ boolean iseditor = false; void mainMenu() { background(14, 181, 59); - if (drawRectWithColission(width/2, height/2, 100, 100)) { + // go to game + if (drawRectWithMouseColission(width/2, height/2, 100, 100)) { if (mousePressed) { ismenu = false; isgame = true; } } - if (drawRectWithColission(width/2, height/2+200, 100, 100)) { + // go to menu + if (drawRectWithMouseColission(width/2, height/2+200, 100, 100)) { if (mousePressed) { ismenu = false; iseditor = true; } } + // exit game + if (drawRectWithMouseColission(50, 50, 80, 40)) { + if (mousePressed) { + exit(); + } + } } void menuButton() { - if (drawRectWithColission(50, 50, 80, 40)) { + if (drawRectWithMouseColission(50, 50, 80, 40)) { if (mousePressed) { ismenu = true; iseditor = false; isgame = false; - moveTilesBack(); + moveTilesBack(tilespeed); + savetofile("save"); } } } void mapEditor() { background(255); - baseline(); + baseRect(); generate_editor_tiles(); // generate_tiles(); menuButton(); } -boolean drawRectWithColission(int x, int y, int rectwidth, int rectheight) { +boolean drawRectWithMouseColission(int x, int y, int rectwidth, int rectheight) { // Draw A Rect rectMode(CENTER); rect(x, y, rectwidth, rectheight); diff --git a/game/map.pde b/game/map.pde index 8196921..de45f25 100644 --- a/game/map.pde +++ b/game/map.pde @@ -1,5 +1,6 @@ int screenx = 0; +// level generation void generate_tiles() { for (int i = 0; i < level.length; i++ ) { rect(level[i][0]-screenx, level[i][1], level[i][2], level[i][3]); @@ -9,7 +10,7 @@ void generate_tiles() { void generate_editor_tiles() { for (int i = 0; i < 100; i++ ) { rect(level[i][0]-screenx, level[i][1], level[i][2], level[i][3]); - if (drawRectWithColission(level[i][0]-screenx, level[i][1], level[i][2], level[i][3])) { + if (drawRectWithMouseColission(level[i][0]-screenx, level[i][1], level[i][2], level[i][3])) { if (mousePressed && iseditor) { if (mouseButton == RIGHT) { level[i][0] = 0; @@ -22,7 +23,14 @@ void generate_editor_tiles() { } } +void baseRect() { + line(0, 0.875*height, width, 0.875*height); + fill(100); + quad(0, 0.875*height, width, 0.875*height, width, height, 0, height); + fill(255); +} +//// This Handles loading and saving the level // TODO Check if json is empty. If it is generate level // int[][] level = new int[100][4]; JSONArray json; diff --git a/game/unused.pde b/game/unused.pde new file mode 100644 index 0000000..155e8ba --- /dev/null +++ b/game/unused.pde @@ -0,0 +1,26 @@ +void rectWithText(float rectX, float rectY, float rectWidth, float rectHeight, String rectText, float ts) { + // rect + rectMode(CENTER); + rect(rectX, rectY, rectWidth, rectHeight); + + // text + textSize(ts); + textAlign(CENTER,CENTER); + fill(0); + text(rectText, rectX, rectY); + + // stop painting + noFill(); + +} + +void menu() { + rectWithText(width/2, height/2, 100, 50, "test", 40); +} + + +// This is basically the Level file: +// It consists out of an array, that spawns tiles +// It is also checked in collisionTest() +int[] tiles_x = { 300, 50, 600, 50}; +int[] tiles_y = { 500, 50, 600, 200 };