did all the things to prepare
This commit is contained in:
parent
ff4d996155
commit
b269d39f62
0
game/background.pde
Normal file
0
game/background.pde
Normal file
@ -5,6 +5,9 @@
|
|||||||
// - Find a way to make menus
|
// - Find a way to make menus
|
||||||
//- Movement berechnen mit move = gravitation - speed
|
//- Movement berechnen mit move = gravitation - speed
|
||||||
// - Jump als Zahl, die langsam kleiner wird
|
// - Jump als Zahl, die langsam kleiner wird
|
||||||
|
//
|
||||||
|
// Make Colission better:
|
||||||
|
// - https://happycoding.io/tutorials/processing/collision-detection
|
||||||
|
|
||||||
// jumping related
|
// jumping related
|
||||||
float speed = 20;
|
float speed = 20;
|
||||||
@ -14,23 +17,23 @@ float jumpcooldown = 12;
|
|||||||
|
|
||||||
// for moving x-axis (mostly depracted)
|
// for moving x-axis (mostly depracted)
|
||||||
// But dont delete yet!!
|
// But dont delete yet!!
|
||||||
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);
|
PVector tilesize = new PVector(50, 50);
|
||||||
|
|
||||||
int[][] level;
|
int[][] level;
|
||||||
|
|
||||||
|
int tilesmoved = 0;
|
||||||
|
int tilespeed = 3;
|
||||||
|
|
||||||
|
|
||||||
int test = 0;
|
|
||||||
// The actual game
|
// The actual game
|
||||||
void play() {
|
void play() {
|
||||||
// calculate actual position on ground
|
// calculate actual position on ground
|
||||||
actualPos = height - pos.y;
|
// actualPos = height - pos.y;
|
||||||
|
|
||||||
background(255);
|
background(255);
|
||||||
|
|
||||||
@ -38,30 +41,52 @@ void play() {
|
|||||||
rectMode(CENTER);
|
rectMode(CENTER);
|
||||||
rect(pos.x, pos.y, playerRadius, playerRadius);
|
rect(pos.x, pos.y, playerRadius, playerRadius);
|
||||||
|
|
||||||
moveTiles();
|
moveTiles(tilespeed);
|
||||||
baseline();
|
baseRect();
|
||||||
// jumpToJumpheight();
|
|
||||||
newJump();
|
newJump();
|
||||||
collisionTest();
|
collisionTest();
|
||||||
|
|
||||||
generate_tiles();
|
generate_tiles();
|
||||||
|
|
||||||
helper();
|
helper();
|
||||||
// moveTiles();
|
|
||||||
menuButton();
|
menuButton();
|
||||||
|
|
||||||
fill(0);
|
fill(0);
|
||||||
text(test, 700, 50);
|
text(tilesmoved, 700, 50);
|
||||||
test = test+3;
|
tilesmoved = tilesmoved + tilespeed;
|
||||||
fill(255);
|
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
|
// TODO Collision erweitern wie in https://happycoding.io/tutorials/processing/collision-detection
|
||||||
void collisionTest() {
|
void collisionTest() {
|
||||||
// Collision with baseline
|
// Collision with baseline
|
||||||
if ( pos.y > baseline_y - playerRadius/2 ) {
|
if ( pos.y > 0.875*height - playerRadius/2 ) {
|
||||||
pos.set(pos.x, baseline_y - playerRadius/2);
|
pos.set(pos.x, 0.875*height - playerRadius/2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collision with all the tiles bottom site
|
// 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--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -5,15 +5,15 @@ void keyPressed () {
|
|||||||
if (ismenu) {
|
if (ismenu) {
|
||||||
} else if (isgame) {
|
} else if (isgame) {
|
||||||
if (key == CODED) {
|
if (key == CODED) {
|
||||||
if (keyCode == RIGHT) {
|
// if (keyCode == RIGHT) {
|
||||||
direction.x = +1;
|
// direction.x = +1;
|
||||||
pos.x = pos.x + direction.x * speed;
|
// pos.x = pos.x + direction.x * speed;
|
||||||
} else if (keyCode == LEFT) {
|
// } else if (keyCode == LEFT) {
|
||||||
direction.x = -1;
|
// direction.x = -1;
|
||||||
pos.x = pos.x + direction.x * speed;
|
// pos.x = pos.x + direction.x * speed;
|
||||||
}
|
// }
|
||||||
} else if (key == ' ') {
|
} else if (key == ' ') {
|
||||||
jumpspeed =+ 25;
|
jumpspeed =+ 30;
|
||||||
}
|
}
|
||||||
} else if (iseditor) {
|
} else if (iseditor) {
|
||||||
if (key == 's') {
|
if (key == 's') {
|
||||||
@ -39,7 +39,7 @@ void mouseReleased() {
|
|||||||
if (mouseButton == LEFT) {
|
if (mouseButton == LEFT) {
|
||||||
level[runnerRect][0] = mouseX+screenx;
|
level[runnerRect][0] = mouseX+screenx;
|
||||||
level[runnerRect][1] = mouseY;
|
level[runnerRect][1] = mouseY;
|
||||||
level[runnerRect][2] = 50;
|
level[runnerRect][2] = 100;
|
||||||
level[runnerRect][3] = 50;
|
level[runnerRect][3] = 50;
|
||||||
println("generated");
|
println("generated");
|
||||||
runnerRect = runnerRect + 1;
|
runnerRect = runnerRect + 1;
|
||||||
|
|||||||
@ -2,11 +2,13 @@ void setup() {
|
|||||||
size(800,800);
|
size(800,800);
|
||||||
frameRate(60);
|
frameRate(60);
|
||||||
smooth(4);
|
smooth(4);
|
||||||
// saveFileChecker();
|
|
||||||
|
|
||||||
level = loadJson("./saves/save.json");
|
|
||||||
|
drawBackground();
|
||||||
|
// level = loadJson("./saves/save.json");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// not done yet
|
||||||
void saveFileChecker() {
|
void saveFileChecker() {
|
||||||
File f = dataFile("./saves/save.json");
|
File f = dataFile("./saves/save.json");
|
||||||
String filePath = f.getPath();
|
String filePath = f.getPath();
|
||||||
@ -16,20 +18,17 @@ void saveFileChecker() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
void draw() {
|
void draw() {
|
||||||
|
// debug();
|
||||||
|
|
||||||
|
// if (ismenu) {
|
||||||
|
// mainMenu();
|
||||||
|
// } else if (isgame) {
|
||||||
// play();
|
// play();
|
||||||
// helper();
|
// } else if (iseditor) {
|
||||||
debug();
|
// mapEditor();
|
||||||
|
// }
|
||||||
if (ismenu) {
|
|
||||||
mainMenu();
|
|
||||||
} else if (isgame) {
|
|
||||||
play();
|
|
||||||
} else if (iseditor) {
|
|
||||||
mapEditor();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean ismenu = true;
|
boolean ismenu = true;
|
||||||
@ -39,40 +38,49 @@ boolean iseditor = false;
|
|||||||
|
|
||||||
void mainMenu() {
|
void mainMenu() {
|
||||||
background(14, 181, 59);
|
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) {
|
if (mousePressed) {
|
||||||
ismenu = false;
|
ismenu = false;
|
||||||
isgame = true;
|
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) {
|
if (mousePressed) {
|
||||||
ismenu = false;
|
ismenu = false;
|
||||||
iseditor = true;
|
iseditor = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// exit game
|
||||||
|
if (drawRectWithMouseColission(50, 50, 80, 40)) {
|
||||||
|
if (mousePressed) {
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void menuButton() {
|
void menuButton() {
|
||||||
if (drawRectWithColission(50, 50, 80, 40)) {
|
if (drawRectWithMouseColission(50, 50, 80, 40)) {
|
||||||
if (mousePressed) {
|
if (mousePressed) {
|
||||||
ismenu = true;
|
ismenu = true;
|
||||||
iseditor = false;
|
iseditor = false;
|
||||||
isgame = false;
|
isgame = false;
|
||||||
moveTilesBack();
|
moveTilesBack(tilespeed);
|
||||||
|
savetofile("save");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void mapEditor() {
|
void mapEditor() {
|
||||||
background(255);
|
background(255);
|
||||||
baseline();
|
baseRect();
|
||||||
generate_editor_tiles();
|
generate_editor_tiles();
|
||||||
// generate_tiles();
|
// generate_tiles();
|
||||||
menuButton();
|
menuButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean drawRectWithColission(int x, int y, int rectwidth, int rectheight) {
|
boolean drawRectWithMouseColission(int x, int y, int rectwidth, int rectheight) {
|
||||||
// Draw A Rect
|
// Draw A Rect
|
||||||
rectMode(CENTER);
|
rectMode(CENTER);
|
||||||
rect(x, y, rectwidth, rectheight);
|
rect(x, y, rectwidth, rectheight);
|
||||||
|
|||||||
10
game/map.pde
10
game/map.pde
@ -1,5 +1,6 @@
|
|||||||
int screenx = 0;
|
int screenx = 0;
|
||||||
|
|
||||||
|
// level generation
|
||||||
void generate_tiles() {
|
void generate_tiles() {
|
||||||
for (int i = 0; i < level.length; i++ ) {
|
for (int i = 0; i < level.length; i++ ) {
|
||||||
rect(level[i][0]-screenx, level[i][1], level[i][2], level[i][3]);
|
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() {
|
void generate_editor_tiles() {
|
||||||
for (int i = 0; i < 100; i++ ) {
|
for (int i = 0; i < 100; i++ ) {
|
||||||
rect(level[i][0]-screenx, level[i][1], level[i][2], level[i][3]);
|
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 (mousePressed && iseditor) {
|
||||||
if (mouseButton == RIGHT) {
|
if (mouseButton == RIGHT) {
|
||||||
level[i][0] = 0;
|
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
|
// TODO Check if json is empty. If it is generate level
|
||||||
// int[][] level = new int[100][4];
|
// int[][] level = new int[100][4];
|
||||||
JSONArray json;
|
JSONArray json;
|
||||||
|
|||||||
26
game/unused.pde
Normal file
26
game/unused.pde
Normal 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 };
|
||||||
Loading…
x
Reference in New Issue
Block a user