did all the things to prepare

This commit is contained in:
Makussu 2023-10-20 01:17:13 +02:00
parent ff4d996155
commit b269d39f62
6 changed files with 111 additions and 76 deletions

0
game/background.pde Normal file
View File

View File

@ -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--;
}
}

View File

@ -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;

View File

@ -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();
// if (ismenu) {
// mainMenu();
// } else if (isgame) {
// play();
// helper();
debug();
if (ismenu) {
mainMenu();
} else if (isgame) {
play();
} else if (iseditor) {
mapEditor();
}
// } 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);

View File

@ -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;

26
game/unused.pde Normal file
View File

@ -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 };