various changes
This commit is contained in:
parent
497de07028
commit
80a3e06e84
78
files.pde
Normal file
78
files.pde
Normal file
@ -0,0 +1,78 @@
|
||||
class Files {
|
||||
|
||||
boolean checkSaveFile(String filepath) {
|
||||
return new File(dataPath(filepath)).exists();
|
||||
}
|
||||
|
||||
int[] loadJson(String jsonfile) {
|
||||
if (!checkSaveFile(jsonfile)) {
|
||||
JSONArray values = loadJSONArray(jsonfile);
|
||||
|
||||
int[] arrayfromjson = new int[values.size()];
|
||||
return arrayfromjson;
|
||||
} else {
|
||||
int[] arrayfromjson = new int[100];
|
||||
return arrayfromjson;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
//// This Handles loading and saving the level
|
||||
JSONArray json;
|
||||
|
||||
// This saves the Current save to file
|
||||
int savetofile(String filename) {
|
||||
json = new JSONArray();
|
||||
|
||||
for (int i = 0; i < level.length; i++) {
|
||||
|
||||
JSONArray mapsave = new JSONArray();
|
||||
mapsave.setInt(0, level[i][0]);
|
||||
mapsave.setInt(1, level[i][1]);
|
||||
mapsave.setInt(2, level[i][2]);
|
||||
mapsave.setInt(3, level[i][3]);
|
||||
mapsave.setInt(4, level[i][4]);
|
||||
|
||||
json.setJSONArray(i, mapsave);
|
||||
}
|
||||
saveJSONArray(json,"./saves/" + filename + ".json");
|
||||
return 1;
|
||||
}
|
||||
|
||||
boolean checkSaveFile(String filepath) {
|
||||
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) {
|
||||
if (!checkSaveFile("./saves/save.json")) {
|
||||
JSONArray values = loadJSONArray(jsonfile);
|
||||
// println(values.size());
|
||||
|
||||
int[][] arrayfromjson = new int[values.size()][values.size()];
|
||||
|
||||
for (int i = 0; i < values.size(); i++) {
|
||||
|
||||
JSONArray jsontoarray = values.getJSONArray(i);
|
||||
|
||||
int x = jsontoarray.getInt(0);
|
||||
int y = jsontoarray.getInt(1);
|
||||
int rectwidth = jsontoarray.getInt(2);
|
||||
int rectheight = jsontoarray.getInt(3);
|
||||
int isspike = jsontoarray.getInt(4);
|
||||
|
||||
arrayfromjson[i][0] = x;
|
||||
arrayfromjson[i][1] = y;
|
||||
arrayfromjson[i][2] = rectwidth;
|
||||
arrayfromjson[i][3] = rectheight;
|
||||
arrayfromjson[i][4] = isspike;
|
||||
}
|
||||
return arrayfromjson;
|
||||
} else {
|
||||
int[][] arrayfromjson = new int[100][5];
|
||||
return arrayfromjson;
|
||||
}
|
||||
}
|
||||
*/
|
||||
95
kek2.pde
95
kek2.pde
@ -2,7 +2,7 @@
|
||||
|
||||
// Statistikseite: Spielzeit, Bäume gefällt, Zeit gestoppt
|
||||
// Wir brauchen Geräusche
|
||||
// Roboter muss abprallen, kaputt gehen
|
||||
// Robi muss noch beschleunigen können
|
||||
|
||||
float checkDistance(Log log, Ship ship) {
|
||||
float testX = ship.x;
|
||||
@ -19,35 +19,18 @@ float checkDistance(Log log, Ship ship) {
|
||||
float distY = ship.y-testY;
|
||||
float distance = sqrt( (distX*distX) + (distY*distY) );
|
||||
|
||||
line(testX, testY, ship_zero.x, ship_zero.y);
|
||||
line(testX, testY, ship.x, ship.y);
|
||||
|
||||
// if the distance is less than the radius, collision!
|
||||
return distance;
|
||||
}
|
||||
|
||||
// -----
|
||||
boolean isColliding = false;
|
||||
|
||||
Ship ship_zero;
|
||||
Saw saw_zero;
|
||||
Bob bob;
|
||||
|
||||
Log[] logs = {new Log(100, 200, 100, 100, false), new Log(500, 200, 200, 100, false), new Log(400, 400, 20, 100, true) };
|
||||
//Log log_zero = new Log(100,200,100,100,false);
|
||||
void setup() {
|
||||
size(600, 600);
|
||||
ship_zero = new Ship();
|
||||
saw_zero = new Saw(100, 100, 20, 50);
|
||||
bob = new Bob(100, 400, 20, 40);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
// Main Game entry
|
||||
void play() {
|
||||
background(50);
|
||||
|
||||
|
||||
for(int i = 0; i < logs.length; i++) {
|
||||
logs[i].drawLog(i);
|
||||
}
|
||||
|
||||
text(playtime.second(), 20, 20);
|
||||
println(playtime.second());
|
||||
|
||||
|
||||
// for(int i = 0; i < trees.length; i++) {
|
||||
@ -60,6 +43,11 @@ void draw() {
|
||||
bob.drawBob();
|
||||
ship_zero.collect(bob);
|
||||
|
||||
|
||||
for(int i = 0; i < logs.length; i++) {
|
||||
logs[i].drawLog(i);
|
||||
}
|
||||
|
||||
for(int i = 0; i < logs.length; i++) {
|
||||
logs[i].strokecolor = logs[i].logcolor;
|
||||
}
|
||||
@ -69,5 +57,62 @@ void draw() {
|
||||
|
||||
// println(ship_zero.newX, " : ", ship_zero.newY);
|
||||
|
||||
println("x: ", ship_zero.x, " : ", ship_zero.newX);
|
||||
// println("x: ", ship_zero.x, " : ", ship_zero.y);
|
||||
}
|
||||
|
||||
// -----
|
||||
MainMenu main_menu = new MainMenu();
|
||||
Stats stats_menu = new Stats();
|
||||
|
||||
//Log log_zero = new Log(100,200,100,100,false);
|
||||
void setup() {
|
||||
// size(1280, 720);
|
||||
size(600, 600);
|
||||
textAlign(CENTER, CENTER);
|
||||
|
||||
// surface.setResizable(true);
|
||||
|
||||
ship_zero = new Ship();
|
||||
saw_zero = new Saw(100, 100, 20, 50);
|
||||
bob = new Bob(100, 400, 20, 40);
|
||||
}
|
||||
|
||||
|
||||
// global state
|
||||
boolean isgame = false;
|
||||
boolean ismenu = true;
|
||||
boolean isend = false;
|
||||
boolean isstats = false;
|
||||
|
||||
Log[] logs = {new Log(100, 200, 100, 100, false), new Log(500, 200, 200, 100, false), new Log(400, 400, 20, 100, true) };
|
||||
Ship ship_zero;
|
||||
Saw saw_zero;
|
||||
Bob bob;
|
||||
|
||||
// stopwatch
|
||||
StopWatchTimer playtime = new StopWatchTimer();
|
||||
|
||||
void draw() {
|
||||
|
||||
|
||||
if (isgame) {
|
||||
play();
|
||||
|
||||
if(keyPressed) {
|
||||
println(mouseX, " : ", mouseY);
|
||||
}
|
||||
|
||||
if (playtime.running) {} else playtime.start();
|
||||
} else if (ismenu){
|
||||
// menu code
|
||||
// play();
|
||||
main_menu.drawMenu();
|
||||
if (playtime.running) playtime.stop();
|
||||
} else if (isstats) {
|
||||
stats_menu.draw();
|
||||
} else if (isend) {
|
||||
// end screen code
|
||||
}
|
||||
|
||||
mouse_released = false;
|
||||
}
|
||||
|
||||
5
keys.pde
5
keys.pde
@ -25,3 +25,8 @@ void keyReleased() {
|
||||
else if (keyCode == LEFT) {ROTATEL = false; }
|
||||
else if (keyCode == RIGHT) {ROTATER = false; }
|
||||
}
|
||||
|
||||
boolean mouse_released = false;
|
||||
void mouseReleased() {
|
||||
mouse_released = true;
|
||||
}
|
||||
|
||||
22
logs.pde
22
logs.pde
@ -26,10 +26,8 @@ class Log {
|
||||
stroke(strokecolor); // Set stroke color for the log
|
||||
strokeWeight(1); // Set stroke weight for the log
|
||||
fill(logcolor); // Set fill color for the log
|
||||
// rectMode(CENTER);
|
||||
rect(x, y, logwidth, logheight); // Draw the log as a rectangle
|
||||
text(logtext, x, y);
|
||||
// rectMode(CORNER);
|
||||
strokeWeight(1);
|
||||
stroke(0);
|
||||
|
||||
@ -55,15 +53,15 @@ class Log {
|
||||
|
||||
}
|
||||
|
||||
class Tree extends Log {
|
||||
Tree (float x, float y, float logw, float logh, boolean hasC) {
|
||||
super(x, y, logw, logh, hasC);
|
||||
}
|
||||
void draw() {
|
||||
color treecolor = color(133, 79, 51);
|
||||
// class Tree extends Log {
|
||||
// Tree (float x, float y, float logw, float logh, boolean hasC) {
|
||||
// super(x, y, logw, logh, hasC);
|
||||
// }
|
||||
// void draw() {
|
||||
// color treecolor = color(133, 79, 51);
|
||||
|
||||
// rectMode(CENTER);
|
||||
drawLog(1);
|
||||
// // rectMode(CENTER);
|
||||
// drawLog(1);
|
||||
|
||||
}
|
||||
}
|
||||
// }
|
||||
// }
|
||||
|
||||
106
menu.pde
Normal file
106
menu.pde
Normal file
@ -0,0 +1,106 @@
|
||||
class Menus {
|
||||
|
||||
boolean drawRectWithMouseColission(float x, float y, float rectwidth, float rectheight) {
|
||||
// Draw A Rect
|
||||
rectMode(CENTER);
|
||||
rect(x, y, rectwidth, rectheight);
|
||||
rectMode(CORNER);
|
||||
|
||||
// Check it for collission
|
||||
if((mouseX > x - rectwidth/2 && mouseX < x + rectwidth/2) && (mouseY > y - rectheight/2 && mouseY < y + rectheight/2)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class MainMenu extends Menus {
|
||||
|
||||
void playButton(float x, float y, float w, float h) {
|
||||
fill(100, 100, 100);
|
||||
if(drawRectWithMouseColission(x, y, w, h) && mousePressed) {
|
||||
ismenu = false;
|
||||
isgame = true;
|
||||
}
|
||||
text("Play", x, y);
|
||||
}
|
||||
|
||||
void statsButton(float x, float y, float w, float h) {
|
||||
fill(100, 100, 100);
|
||||
if(drawRectWithMouseColission(x, y, w, h) && mousePressed) {
|
||||
ismenu = false;
|
||||
isstats = true;
|
||||
}
|
||||
text("Stats", x, y);
|
||||
}
|
||||
|
||||
void drawMenu() {
|
||||
// color maincolor = color(100, 100, 100);
|
||||
playButton(300, 300, 150, 50);
|
||||
statsButton(300, 400, 150, 50);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
println("test");
|
||||
}
|
||||
}
|
||||
|
||||
class Stats extends Menus {
|
||||
int trees_sawed = 0;
|
||||
|
||||
void menuButton() {
|
||||
fill(100, 100, 100);
|
||||
if(drawRectWithMouseColission(300, 300, 150, 50) && mouse_released) {
|
||||
ismenu = true;
|
||||
isgame = false;
|
||||
isstats = false;
|
||||
}
|
||||
fill(0);
|
||||
text("Main Menu", 300, 300);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(50);
|
||||
menuButton();
|
||||
|
||||
text("Best Game Time", 50, 50);
|
||||
text("Trees Sawed", 50, 70);
|
||||
text("Insgesamt Spielzeit", 50, 90);
|
||||
}
|
||||
}
|
||||
|
||||
class StopWatchTimer {
|
||||
int startTime = 0, stopTime = 0;
|
||||
boolean running = false;
|
||||
|
||||
|
||||
void start() {
|
||||
startTime = millis();
|
||||
running = true;
|
||||
}
|
||||
void stop() {
|
||||
stopTime = millis();
|
||||
running = false;
|
||||
}
|
||||
int getElapsedTime() {
|
||||
int elapsed;
|
||||
if (running) {
|
||||
elapsed = (millis() - startTime);
|
||||
}
|
||||
else {
|
||||
elapsed = (stopTime - startTime);
|
||||
}
|
||||
return elapsed;
|
||||
}
|
||||
int second() {
|
||||
return (getElapsedTime() / 1000) % 60;
|
||||
}
|
||||
int minute() {
|
||||
return (getElapsedTime() / (1000*60)) % 60;
|
||||
}
|
||||
int hour() {
|
||||
return (getElapsedTime() / (1000*60*60)) % 24;
|
||||
}
|
||||
}
|
||||
12
ship.pde
12
ship.pde
@ -1,3 +1,5 @@
|
||||
// Roboter muss abprallen, kaputt gehen
|
||||
|
||||
class Ship {
|
||||
float x, y, a;
|
||||
float newX, newY;
|
||||
@ -8,10 +10,14 @@ class Ship {
|
||||
float movementSpeed = 2; // The speed of movement
|
||||
int nextLog;
|
||||
|
||||
int health;
|
||||
|
||||
Ship() {
|
||||
x = width / 2;
|
||||
y = height / 2;
|
||||
a = -90;
|
||||
// newX = width/2;
|
||||
// newY = height/2;
|
||||
}
|
||||
|
||||
void draw() {
|
||||
@ -25,7 +31,7 @@ class Ship {
|
||||
|
||||
// println(newX, " : ", newY);
|
||||
|
||||
ship_zero.colliding2 = false;
|
||||
colliding2 = false;
|
||||
}
|
||||
|
||||
void sawIndicator() {
|
||||
@ -78,8 +84,8 @@ class Ship {
|
||||
} else {
|
||||
float richtungX = x-newX;
|
||||
float richtungY = y-newY;
|
||||
x = (10*richtungX) + x;
|
||||
y = (10*richtungY) + y;
|
||||
x = (7*richtungX) + x;
|
||||
y = (7*richtungY) + y;
|
||||
}
|
||||
} else if (SOUTH) {
|
||||
newX = x - cos(radians(a)) * movementSpeed;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user