code quality
This commit is contained in:
parent
175c0d238e
commit
a527307ee1
@ -1,5 +1,4 @@
|
|||||||
// } else if (key == 'l') {
|
// Here are all the keys that are used
|
||||||
// println(loadJSONArray("../map/map.json"));
|
|
||||||
|
|
||||||
boolean iseditorModeRect = true;
|
boolean iseditorModeRect = true;
|
||||||
boolean iseditorModeSpike = false;
|
boolean iseditorModeSpike = false;
|
||||||
@ -45,11 +44,12 @@ void keyPressed () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add tiles in editor mode
|
||||||
int runnerRect = 0;
|
int runnerRect = 0;
|
||||||
void mouseReleased() {
|
void mouseReleased() {
|
||||||
if(iseditor) {
|
if(iseditor) {
|
||||||
if(iseditorModeRect) {
|
if (mouseButton == LEFT) {
|
||||||
if (mouseButton == LEFT) {
|
if(iseditorModeRect) {
|
||||||
level[runnerRect][0] = mouseX+screenx;
|
level[runnerRect][0] = mouseX+screenx;
|
||||||
level[runnerRect][1] = mouseY;
|
level[runnerRect][1] = mouseY;
|
||||||
level[runnerRect][2] = 100;
|
level[runnerRect][2] = 100;
|
||||||
@ -58,7 +58,6 @@ void mouseReleased() {
|
|||||||
println("generated");
|
println("generated");
|
||||||
runnerRect = runnerRect + 1;
|
runnerRect = runnerRect + 1;
|
||||||
println(runnerRect);
|
println(runnerRect);
|
||||||
}
|
|
||||||
} else if (iseditorModeSpike) {
|
} else if (iseditorModeSpike) {
|
||||||
level[runnerRect][0] = mouseX+screenx;
|
level[runnerRect][0] = mouseX+screenx;
|
||||||
level[runnerRect][1] = mouseY;
|
level[runnerRect][1] = mouseY;
|
||||||
@ -68,6 +67,7 @@ void mouseReleased() {
|
|||||||
println("generated");
|
println("generated");
|
||||||
runnerRect = runnerRect + 1;
|
runnerRect = runnerRect + 1;
|
||||||
println(runnerRect);
|
println(runnerRect);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,22 +3,9 @@ void setup() {
|
|||||||
frameRate(60);
|
frameRate(60);
|
||||||
smooth(4);
|
smooth(4);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
level = loadJson("./saves/save.json");
|
level = loadJson("./saves/save.json");
|
||||||
}
|
}
|
||||||
|
|
||||||
// not done yet
|
|
||||||
void saveFileChecker() {
|
|
||||||
File f = dataFile("./saves/save.json");
|
|
||||||
String filePath = f.getPath();
|
|
||||||
boolean exist = f.isFile();
|
|
||||||
println(filePath, exist);
|
|
||||||
if (!exist) {
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
void draw() {
|
void draw() {
|
||||||
// debug();
|
// debug();
|
||||||
|
|
||||||
@ -36,7 +23,7 @@ boolean ismenu = true;
|
|||||||
boolean isgame = false;
|
boolean isgame = false;
|
||||||
boolean iseditor = false;
|
boolean iseditor = false;
|
||||||
|
|
||||||
|
// This is the start screen and main menu. It has a few Buttons
|
||||||
void mainMenu() {
|
void mainMenu() {
|
||||||
background(14, 181, 59);
|
background(14, 181, 59);
|
||||||
// go to game
|
// go to game
|
||||||
@ -73,6 +60,7 @@ void menuButton() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Map Editor Mode
|
||||||
void mapEditor() {
|
void mapEditor() {
|
||||||
background(255);
|
background(255);
|
||||||
baseRect();
|
baseRect();
|
||||||
@ -81,6 +69,7 @@ void mapEditor() {
|
|||||||
menuButton();
|
menuButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Rectangle with editor colission
|
||||||
boolean drawRectWithMouseColission(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);
|
||||||
@ -94,19 +83,21 @@ boolean drawRectWithMouseColission(int x, int y, int rectwidth, int rectheight)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Triangle with editor colission
|
||||||
boolean drawTriangleWithMouseColission(int x, int y, int rectwidth, int rectheight) {
|
boolean drawTriangleWithMouseColission(int x, int y, int rectwidth, int rectheight) {
|
||||||
// Draw A Rect
|
// Draw A Rect
|
||||||
rectMode(CENTER);
|
rectMode(CENTER);
|
||||||
triangle();
|
triangle(x - rectwidth/2, y, x + rectwidth/2, y, x, y - rectheight);
|
||||||
|
|
||||||
// Check it for collission
|
// Check it for collission
|
||||||
if(dist(mouseX, mouseY, x+rectwidth/2, y-rectheight/2) > rectheight/2) {
|
if(dist(mouseX, mouseY, x+rectwidth/2, y-rectheight/2) < rectheight/1.5) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// These are my Debugger Functions
|
||||||
void debug() {
|
void debug() {
|
||||||
// println(screenoffset);
|
// println(screenoffset);
|
||||||
// println(level[0][0]);
|
// println(level[0][0]);
|
||||||
|
|||||||
23
game/map.pde
23
game/map.pde
@ -1,8 +1,12 @@
|
|||||||
// BUG level editor x position bleibt ingame
|
// BUG level editor x position bleibt ingame
|
||||||
|
// TODO Completly rework colission
|
||||||
|
// TODO Die when touching triangle
|
||||||
|
// moveTilesBack() and High Score Tracking
|
||||||
|
// No Unlimited Jumping
|
||||||
|
|
||||||
int screenx = 0;
|
int screenx = 0;
|
||||||
|
|
||||||
// level generation
|
// level generation for playable
|
||||||
void generate_tiles() {
|
void generate_tiles() {
|
||||||
stroke(0);
|
stroke(0);
|
||||||
for (int i = 0; i < level.length; i++ ) {
|
for (int i = 0; i < level.length; i++ ) {
|
||||||
@ -14,13 +18,10 @@ void generate_tiles() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void generate_spikes() {
|
// Generate the tiles for Editor View (tiles that are deletable with mouse)
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
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(level[i][4] == 0) {
|
if(level[i][4] == 0) {
|
||||||
if (drawRectWithMouseColission(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) {
|
||||||
@ -54,7 +55,7 @@ void baseRect() {
|
|||||||
fill(255);
|
fill(255);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Background
|
// Draws all the Background elements like sea and Beach
|
||||||
void drawBackground() {
|
void drawBackground() {
|
||||||
color sky = color(94, 218, 252);
|
color sky = color(94, 218, 252);
|
||||||
color sand = color(235, 218, 174);
|
color sand = color(235, 218, 174);
|
||||||
@ -93,11 +94,12 @@ void drawBackground() {
|
|||||||
drawPalm(400, 700);
|
drawPalm(400, 700);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// No Clouds yet
|
||||||
void drawCloud() {
|
void drawCloud() {
|
||||||
ellipse(224, 184, 220, 220);
|
ellipse(224, 184, 220, 220);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Draws a slightly randomised Palm
|
||||||
void drawPalm(int startingpoint_x, int startingpoint_y) {
|
void drawPalm(int startingpoint_x, int startingpoint_y) {
|
||||||
fill(108, 88, 51);
|
fill(108, 88, 51);
|
||||||
float randomnumber = int(random(10, 16));
|
float randomnumber = int(random(10, 16));
|
||||||
@ -115,10 +117,9 @@ void drawPalm(int startingpoint_x, int startingpoint_y) {
|
|||||||
|
|
||||||
|
|
||||||
//// This Handles loading and saving the level
|
//// 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;
|
JSONArray json;
|
||||||
|
|
||||||
|
// This saves the Current save to file
|
||||||
int savetofile(String filename) {
|
int savetofile(String filename) {
|
||||||
json = new JSONArray();
|
json = new JSONArray();
|
||||||
|
|
||||||
@ -141,6 +142,7 @@ boolean checkSaveFile(String filepath) {
|
|||||||
return new File(dataPath(filepath)).exists();
|
return new File(dataPath(filepath)).exists();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if there already is a safefile and load it if it is possible. If not load empty array
|
||||||
int[][] loadJson(String jsonfile) {
|
int[][] loadJson(String jsonfile) {
|
||||||
if (checkSaveFile("./saves/save.json")) {
|
if (checkSaveFile("./saves/save.json")) {
|
||||||
JSONArray values = loadJSONArray(jsonfile);
|
JSONArray values = loadJSONArray(jsonfile);
|
||||||
@ -158,7 +160,6 @@ int[][] loadJson(String jsonfile) {
|
|||||||
int rectheight = jsontoarray.getInt(3);
|
int rectheight = jsontoarray.getInt(3);
|
||||||
int isspike = jsontoarray.getInt(4);
|
int isspike = jsontoarray.getInt(4);
|
||||||
|
|
||||||
// arrayfromjson_x[i] = x;
|
|
||||||
arrayfromjson[i][0] = x;
|
arrayfromjson[i][0] = x;
|
||||||
arrayfromjson[i][1] = y;
|
arrayfromjson[i][1] = y;
|
||||||
arrayfromjson[i][2] = rectwidth;
|
arrayfromjson[i][2] = rectwidth;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user