Compare commits
No commits in common. "main" and "new" have entirely different histories.
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 4.3 KiB |
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 507 B |
Binary file not shown.
|
Before Width: | Height: | Size: 4.3 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 4.5 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 236 B |
Binary file not shown.
Binary file not shown.
Binary file not shown.
18
collect.pde
18
collect.pde
@ -1,12 +1,10 @@
|
|||||||
// Tarek
|
|
||||||
class Collectable {
|
class Collectable {
|
||||||
float cwidth, cheight;
|
float x, y, cwidth, cheight;
|
||||||
boolean is_attached = false;
|
boolean is_attached = false;
|
||||||
PVector pos = new PVector();
|
|
||||||
|
|
||||||
Collectable(float xpos, float ypos, float cw, float ch) {
|
Collectable(float xpos, float ypos, float cw, float ch) {
|
||||||
pos.x = xpos;
|
x = xpos;
|
||||||
pos.y = ypos;
|
y = ypos;
|
||||||
cwidth = cw;
|
cwidth = cw;
|
||||||
cheight = ch;
|
cheight = ch;
|
||||||
}
|
}
|
||||||
@ -20,7 +18,10 @@ class Saw extends Collectable {
|
|||||||
|
|
||||||
void drawSaw() {
|
void drawSaw() {
|
||||||
if (!is_attached) {
|
if (!is_attached) {
|
||||||
image(saw_sprite, pos.x, pos.y);
|
stroke(0);
|
||||||
|
fill(210, 210, 0);
|
||||||
|
rect(x, y, cwidth, cheight);
|
||||||
|
fill(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -33,7 +34,10 @@ class Bob extends Collectable {
|
|||||||
|
|
||||||
void drawBob() {
|
void drawBob() {
|
||||||
if (!is_attached) {
|
if (!is_attached) {
|
||||||
image(bob_sprite, pos.x, pos.y);
|
stroke(0);
|
||||||
|
fill(255, 209, 152);
|
||||||
|
rect(x, y, cwidth, cheight);
|
||||||
|
fill(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
34
files.pde
34
files.pde
@ -1,34 +0,0 @@
|
|||||||
// Marla
|
|
||||||
class Files {
|
|
||||||
|
|
||||||
boolean checkSaveFile(String filepath) {
|
|
||||||
return new File(dataPath(filepath)).exists();
|
|
||||||
}
|
|
||||||
|
|
||||||
void loadJson(String jsonfile) {
|
|
||||||
// if (!checkSaveFile(jsonfile)) {
|
|
||||||
try {
|
|
||||||
JSONArray values = loadJSONArray(jsonfile);
|
|
||||||
|
|
||||||
stats_menu.best_game_time = values.getInt(0);
|
|
||||||
stats_menu.trees_sawed = values.getInt(1);
|
|
||||||
stats_menu.game_time = values.getInt(2);
|
|
||||||
println("Savefile found");
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
println("Savefile not found");
|
|
||||||
stats_menu.best_game_time = 90000;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
JSONArray json;
|
|
||||||
void savetofile(String filename) {
|
|
||||||
json = new JSONArray();
|
|
||||||
|
|
||||||
json.setInt(0, stats_menu.best_game_time);
|
|
||||||
json.setInt(1, stats_menu.trees_sawed);
|
|
||||||
json.setInt(2, millis() + stats_menu.game_time);
|
|
||||||
saveJSONArray(json,"./saves/" + filename + ".json");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
66
kek2.pde
Normal file
66
kek2.pde
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
|
||||||
|
|
||||||
|
float checkDistance(Log log, Ship ship) {
|
||||||
|
float testX = ship.x;
|
||||||
|
float testY = ship.y;
|
||||||
|
|
||||||
|
// which edge is closest?
|
||||||
|
if (ship.x < log.x) testX = log.x;
|
||||||
|
else if (ship.x > log.x+log.logwidth) testX = log.x+log.logwidth;
|
||||||
|
if (ship.y < log.y) testY = log.y;
|
||||||
|
else if (ship.y > log.y+log.logheight) testY = log.y+log.logheight;
|
||||||
|
|
||||||
|
// get distant
|
||||||
|
float distX = ship.x-testX;
|
||||||
|
float distY = ship.y-testY;
|
||||||
|
float distance = sqrt( (distX*distX) + (distY*distY) );
|
||||||
|
|
||||||
|
line(testX, testY, ship_zero.x, ship_zero.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) };
|
||||||
|
|
||||||
|
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() {
|
||||||
|
background(50);
|
||||||
|
|
||||||
|
|
||||||
|
for(int i = 0; i < logs.length; i++) {
|
||||||
|
logs[i].drawLog(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// for(int i = 0; i < trees.length; i++) {
|
||||||
|
// trees[i].draw();
|
||||||
|
// }
|
||||||
|
|
||||||
|
ship_zero.draw();
|
||||||
|
saw_zero.drawSaw();
|
||||||
|
ship_zero.collect(saw_zero);
|
||||||
|
bob.drawBob();
|
||||||
|
ship_zero.collect(bob);
|
||||||
|
|
||||||
|
for(int i = 0; i < logs.length; i++) {
|
||||||
|
logs[i].strokecolor = logs[i].logcolor;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
logs[ship_zero.nextLog].strokecolor = color(255, 0, 0);
|
||||||
|
|
||||||
|
}
|
||||||
23
keys.pde
23
keys.pde
@ -1,11 +1,8 @@
|
|||||||
boolean NORTH, SOUTH, ROTATEL, ROTATER;
|
boolean NORTH, SOUTH, ROTATEL, ROTATER;
|
||||||
|
|
||||||
// Julia, Max
|
|
||||||
void keyPressed() {
|
void keyPressed() {
|
||||||
if (key == CODED) {
|
if (key == CODED) {
|
||||||
if(keyCode == UP) {
|
if(keyCode == UP) {
|
||||||
NORTH = true;
|
NORTH = true;
|
||||||
if(!idle_motor.isPlaying()) idle_motor.play();
|
|
||||||
} else if (keyCode == DOWN) {
|
} else if (keyCode == DOWN) {
|
||||||
SOUTH = true;
|
SOUTH = true;
|
||||||
} else if (keyCode == LEFT) {
|
} else if (keyCode == LEFT) {
|
||||||
@ -15,32 +12,16 @@ void keyPressed() {
|
|||||||
}
|
}
|
||||||
} else if (key == 's') { // SAW
|
} else if (key == 's') { // SAW
|
||||||
if (ship_zero.hasSaw) {
|
if (ship_zero.hasSaw) {
|
||||||
Log target_log = logs[ship_zero.nextLog];
|
if(checkDistance(logs[ship_zero.nextLog], ship_zero) < 40) {
|
||||||
if(checkDistance(target_log, ship_zero) < 40) {
|
logs[ship_zero.nextLog].sawed = true;
|
||||||
target_log.sawed = true;
|
|
||||||
stats_menu.trees_sawed = stats_menu.trees_sawed + 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Marla
|
|
||||||
// Pause menu
|
|
||||||
} else if (keyCode == ESC){
|
|
||||||
key = 0;
|
|
||||||
if (isgame) {
|
|
||||||
isgame = false;
|
|
||||||
ispause = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Julia
|
|
||||||
void keyReleased() {
|
void keyReleased() {
|
||||||
if(keyCode == UP) {NORTH = false; }
|
if(keyCode == UP) {NORTH = false; }
|
||||||
else if (keyCode == DOWN) SOUTH = false;
|
else if (keyCode == DOWN) SOUTH = false;
|
||||||
else if (keyCode == LEFT) {ROTATEL = false; }
|
else if (keyCode == LEFT) {ROTATEL = false; }
|
||||||
else if (keyCode == RIGHT) {ROTATER = false; }
|
else if (keyCode == RIGHT) {ROTATER = false; }
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean mouse_released = false;
|
|
||||||
void mouseReleased() {
|
|
||||||
mouse_released = true;
|
|
||||||
}
|
|
||||||
|
|||||||
17
level.pde
17
level.pde
@ -1,17 +0,0 @@
|
|||||||
// Julia, Max
|
|
||||||
|
|
||||||
// Outside wall
|
|
||||||
Log[] walls = {new Log(-30, 275, 40, 275, false, true), new Log(-30, 600, 40, 275, false, true)};
|
|
||||||
|
|
||||||
void create_level(int logcount) {
|
|
||||||
logs = new Log[logcount];
|
|
||||||
randomSeed((int)random(0, 30));
|
|
||||||
for (int i = 1; i < logs.length; i++) {
|
|
||||||
logs[i] = new Log((int) random(20, width), (int) random(0, height), 20, 60 + random(0, 40), true, false);
|
|
||||||
}
|
|
||||||
// 2nd slide entry
|
|
||||||
logs[0] = new Log(-15, 325, 10, 50, false, true);
|
|
||||||
|
|
||||||
// debug log
|
|
||||||
logs[1] = new Log(-300, 100, 20, 100, true, false);
|
|
||||||
}
|
|
||||||
39
logs.pde
39
logs.pde
@ -1,58 +1,55 @@
|
|||||||
// Tarek
|
|
||||||
class Log {
|
class Log {
|
||||||
float x, y, logwidth, logheight;
|
float x, y, logwidth, logheight;
|
||||||
boolean sawed = false;
|
boolean sawed = false;
|
||||||
boolean is_tree = false;
|
boolean is_tree = false;
|
||||||
boolean is_wall = false;
|
|
||||||
float a = 0;
|
|
||||||
boolean render_log = true;
|
|
||||||
|
|
||||||
color logcolor;
|
color logcolor;
|
||||||
color strokecolor = logcolor;
|
color strokecolor = logcolor;
|
||||||
|
|
||||||
Log (float xpos, float ypos, float logw, float logh, boolean ist, boolean isw) {
|
Log (float xpos, float ypos, float logw, float logh, boolean ist) {
|
||||||
x = xpos;
|
x = xpos;
|
||||||
y = ypos;
|
y = ypos;
|
||||||
logwidth = logw;
|
logwidth = logw;
|
||||||
logheight = logh;
|
logheight = logh;
|
||||||
is_tree = ist;
|
is_tree = ist;
|
||||||
is_wall = isw;
|
|
||||||
//draw();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawLog(int logtext) {
|
void drawLog(int logtext) {
|
||||||
|
|
||||||
if (sawed) {
|
if (sawed) {
|
||||||
logcolor = color(128, 88, 60);
|
logcolor = color(128, 88, 60);
|
||||||
if (a > -90) a = a - 1;
|
|
||||||
if (a == -90) render_log = false;
|
|
||||||
} else if (is_wall) {
|
|
||||||
logcolor = color(0, 0, 0);
|
|
||||||
} else {
|
} else {
|
||||||
logcolor = color(133, 79, 51);
|
logcolor = color(133, 79, 51);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (render_log) {
|
|
||||||
pushMatrix();
|
|
||||||
translate(x, y);
|
|
||||||
rotate(radians(a));
|
|
||||||
stroke(strokecolor); // Set stroke color for the log
|
stroke(strokecolor); // Set stroke color for the log
|
||||||
strokeWeight(1); // Set stroke weight for the log
|
strokeWeight(1); // Set stroke weight for the log
|
||||||
fill(logcolor); // Set fill color for the log
|
fill(logcolor); // Set fill color for the log
|
||||||
rect(0, 0, logwidth, -logheight); // Draw the log as a rectangle
|
// rectMode(CENTER);
|
||||||
// text(logtext, x, y);
|
rect(x, y, logwidth, logheight); // Draw the log as a rectangle
|
||||||
|
text(logtext, x, y);
|
||||||
|
// rectMode(CORNER);
|
||||||
strokeWeight(1);
|
strokeWeight(1);
|
||||||
stroke(0);
|
stroke(0);
|
||||||
|
|
||||||
// Bush
|
|
||||||
if(is_tree) {
|
if(is_tree) {
|
||||||
color bushes = color(107, 117, 48);
|
color bushes = color(107, 117, 48);
|
||||||
fill(bushes);
|
fill(bushes);
|
||||||
ellipse(0 + logwidth/2, 0 - logheight, 170*0.3, 160*0.3);
|
ellipse(x+logwidth/2, y+5, 170*0.3, 160*0.3);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
popMatrix();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
175
menu.pde
175
menu.pde
@ -1,175 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Julia
|
|
||||||
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;
|
|
||||||
ispause = false;
|
|
||||||
isgame = true;
|
|
||||||
}
|
|
||||||
fill(0);
|
|
||||||
textAlign(CENTER, CENTER);
|
|
||||||
textSize(32);
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
fill(0);
|
|
||||||
textAlign(CENTER, CENTER);
|
|
||||||
textSize(32);
|
|
||||||
text("Stats", x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
void drawMenu() {
|
|
||||||
background(40);
|
|
||||||
// color maincolor = color(100, 100, 100);
|
|
||||||
playButton(300, 300, 150, 50);
|
|
||||||
statsButton(300, 400, 150, 50);
|
|
||||||
|
|
||||||
textSize(100);
|
|
||||||
textAlign(CENTER, CENTER);
|
|
||||||
text("Save Bob", 300, 200);
|
|
||||||
}
|
|
||||||
|
|
||||||
void draw() {
|
|
||||||
println("test");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class EndMenu extends Menus {
|
|
||||||
|
|
||||||
void menuButton(float x, float y, float w, float h) {
|
|
||||||
fill(100, 100, 100);
|
|
||||||
if(drawRectWithMouseColission(x, y, w, h) && mousePressed) {
|
|
||||||
ismenu = true;
|
|
||||||
ispause = false;
|
|
||||||
isgame = false;
|
|
||||||
}
|
|
||||||
fill(0);
|
|
||||||
textAlign(CENTER, CENTER);
|
|
||||||
textSize(32);
|
|
||||||
text("Menu", x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
void drawMenu() {
|
|
||||||
background(40);
|
|
||||||
// color maincolor = color(100, 100, 100);
|
|
||||||
menuButton(300, 350, 150, 50);
|
|
||||||
|
|
||||||
textSize(100);
|
|
||||||
textAlign(CENTER, CENTER);
|
|
||||||
if (ship_zero.health < 1) {
|
|
||||||
text("You Died", 300, 200);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Julia, Max, Marla, Chris
|
|
||||||
class Stats extends Menus {
|
|
||||||
int trees_sawed = 0;
|
|
||||||
int best_game_time = 0;
|
|
||||||
int game_time = 0;
|
|
||||||
|
|
||||||
void menuButton() {
|
|
||||||
fill(100, 100, 100);
|
|
||||||
if(drawRectWithMouseColission(300, 300, 150, 50) && mouse_released) {
|
|
||||||
ismenu = true;
|
|
||||||
isgame = false;
|
|
||||||
isstats = false;
|
|
||||||
}
|
|
||||||
fill(0);
|
|
||||||
textSize(32);
|
|
||||||
textAlign(CENTER, CENTER);
|
|
||||||
text("Main Menu", 300, 300);
|
|
||||||
}
|
|
||||||
|
|
||||||
void draw() {
|
|
||||||
background(50);
|
|
||||||
menuButton();
|
|
||||||
|
|
||||||
textAlign(LEFT);
|
|
||||||
textSize(24);
|
|
||||||
text("Best Game Time", 100, 50);
|
|
||||||
text(best_game_time, 500, 50);
|
|
||||||
text("Trees Sawed: " , 100, 70);
|
|
||||||
text(trees_sawed, 500, 70);
|
|
||||||
text("Insgesamt Spielzeit", 100, 90);
|
|
||||||
int sek = game_time/1000;
|
|
||||||
int min = game_time/1000/60;
|
|
||||||
int minsek = sek % 60;
|
|
||||||
text(min + ":" + minsek, 500, 90);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Chris
|
|
||||||
class StopWatchTimer {
|
|
||||||
int startTime = 0, stopTime = 0, pauseTime = 0;
|
|
||||||
boolean running = false;
|
|
||||||
boolean pause = false;
|
|
||||||
|
|
||||||
|
|
||||||
void start() {
|
|
||||||
startTime = millis();
|
|
||||||
running = true;
|
|
||||||
}
|
|
||||||
void stop() {
|
|
||||||
stopTime = millis();
|
|
||||||
running = false;
|
|
||||||
}
|
|
||||||
void pause_start() {
|
|
||||||
if (!pause) {
|
|
||||||
pauseTime = millis();
|
|
||||||
pause = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void resume() {
|
|
||||||
if (pause) {
|
|
||||||
startTime = startTime + (millis() - pauseTime);
|
|
||||||
pauseTime = 0;
|
|
||||||
pause = 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,199 +0,0 @@
|
|||||||
import processing.sound.*;
|
|
||||||
|
|
||||||
// Tarek
|
|
||||||
float checkDistance(Log log, Ship ship) {
|
|
||||||
float testX = ship.pos.x;
|
|
||||||
float testY = ship.pos.y;
|
|
||||||
|
|
||||||
// which edge is closest?
|
|
||||||
if (ship.pos.x < log.x) testX = log.x;
|
|
||||||
else if (ship.pos.x > log.x+log.logwidth) testX = log.x+log.logwidth;
|
|
||||||
if (ship.pos.y < log.y - log.logheight) testY = log.y - log.logheight;
|
|
||||||
else if (ship.pos.y > log.y) testY = log.y;
|
|
||||||
|
|
||||||
// get distant
|
|
||||||
float distX = ship.pos.x-testX;
|
|
||||||
float distY = ship.pos.y-testY;
|
|
||||||
float distance = sqrt( (distX*distX) + (distY*distY) );
|
|
||||||
|
|
||||||
// Debug Lines
|
|
||||||
// line(testX, testY, ship.pos.x, ship.pos.y);
|
|
||||||
|
|
||||||
// if the distance is less than the radius, collision!
|
|
||||||
return distance;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Main Game entry
|
|
||||||
// Chris, Julia, Marla, Tarek, Max
|
|
||||||
void play() {
|
|
||||||
background(75, 105, 47);
|
|
||||||
|
|
||||||
|
|
||||||
// Timer
|
|
||||||
fill(0);
|
|
||||||
textSize(24);
|
|
||||||
text(playtime.second(), 40, 20);
|
|
||||||
text(playtime.second(), -580, 20);
|
|
||||||
|
|
||||||
// Tutorial
|
|
||||||
textAlign(LEFT);
|
|
||||||
textSize(16);
|
|
||||||
text("You are a robot that has to save Bob. He is stuck in the forest.", -570, 160);
|
|
||||||
text("Here is a chainsaw to get through", -570, 180);
|
|
||||||
|
|
||||||
ship_zero.draw();
|
|
||||||
saw_zero.drawSaw();
|
|
||||||
ship_zero.collect(saw_zero);
|
|
||||||
bob.drawBob();
|
|
||||||
ship_zero.collect(bob);
|
|
||||||
|
|
||||||
// draw wall
|
|
||||||
for(int i = 0; i < walls.length; i++) {
|
|
||||||
walls[i].drawLog(i);
|
|
||||||
}
|
|
||||||
// draw log
|
|
||||||
for(int i = 0; i < logs.length; i++) {
|
|
||||||
logs[i].drawLog(i);
|
|
||||||
}
|
|
||||||
// log normal stroke
|
|
||||||
for(int i = 0; i < logs.length; i++) {
|
|
||||||
logs[i].strokecolor = logs[i].logcolor;
|
|
||||||
}
|
|
||||||
// nearest log stroke (debug)
|
|
||||||
logs[ship_zero.nextLog].strokecolor = color(255, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----
|
|
||||||
|
|
||||||
|
|
||||||
// global state
|
|
||||||
boolean isgame = false;
|
|
||||||
boolean ismenu = true;
|
|
||||||
boolean isend = false;
|
|
||||||
boolean isstats = false;
|
|
||||||
boolean ispause = false;
|
|
||||||
boolean start_slide = true;
|
|
||||||
|
|
||||||
// ----- Objectives
|
|
||||||
MainMenu main_menu = new MainMenu();
|
|
||||||
Stats stats_menu = new Stats();
|
|
||||||
EndMenu end_menu = new EndMenu();
|
|
||||||
|
|
||||||
Log[] logs;
|
|
||||||
|
|
||||||
// player
|
|
||||||
Ship ship_zero;
|
|
||||||
|
|
||||||
// collectables
|
|
||||||
Saw saw_zero;
|
|
||||||
Bob bob;
|
|
||||||
|
|
||||||
// stopwatch
|
|
||||||
StopWatchTimer playtime = new StopWatchTimer();
|
|
||||||
Files savefile = new Files();
|
|
||||||
|
|
||||||
|
|
||||||
PImage player_sprite;
|
|
||||||
PImage player_sprite_bob;
|
|
||||||
PImage saw_sprite;
|
|
||||||
PImage bob_sprite;
|
|
||||||
|
|
||||||
SoundFile idle_motor;
|
|
||||||
SoundFile music;
|
|
||||||
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
size(600, 600);
|
|
||||||
textAlign(CENTER, CENTER);
|
|
||||||
|
|
||||||
create_level(30);
|
|
||||||
println(logs[1]);
|
|
||||||
|
|
||||||
ship_zero = new Ship();
|
|
||||||
saw_zero = new Saw(-width+100, 100, 20, 50);
|
|
||||||
bob = new Bob(500, 400, 20, 40);
|
|
||||||
|
|
||||||
// Marla
|
|
||||||
player_sprite = loadImage("./assets/Sprite-robi.png");
|
|
||||||
player_sprite_bob = loadImage("./assets/Sprite-robiwithbob.png");
|
|
||||||
saw_sprite = loadImage("./assets/Sprite-saege.png");
|
|
||||||
bob_sprite = loadImage("./assets/Sprite-bob.png");
|
|
||||||
|
|
||||||
idle_motor = new SoundFile(this, "./assets/idle_motor.mp3");
|
|
||||||
music = new SoundFile(this, "./assets/main_music.wav");
|
|
||||||
|
|
||||||
savefile.loadJson("./saves/save.json");
|
|
||||||
|
|
||||||
music.loop(1, 0.5);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Chris, Max
|
|
||||||
void draw() {
|
|
||||||
// time debug
|
|
||||||
// println(millis(), " start: ", playtime.startTime, " pause: ", playtime.pauseTime);
|
|
||||||
|
|
||||||
// game state
|
|
||||||
if (isgame) {
|
|
||||||
|
|
||||||
|
|
||||||
// Go to second or first slide
|
|
||||||
if(ship_zero.pos.x > 0) {
|
|
||||||
start_slide = false;
|
|
||||||
} else {
|
|
||||||
start_slide = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// actually move the camera
|
|
||||||
if(start_slide) {
|
|
||||||
translate(600, 0);
|
|
||||||
} else {
|
|
||||||
translate(0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Main Entry
|
|
||||||
play();
|
|
||||||
|
|
||||||
// Timer
|
|
||||||
if (playtime.running) {} else playtime.start();
|
|
||||||
if (playtime.pause) playtime.resume();
|
|
||||||
|
|
||||||
// Win
|
|
||||||
if(bob.is_attached && dist(ship_zero.pos.x, ship_zero.pos.y ,-400, 300) < 100) {
|
|
||||||
isgame = false;
|
|
||||||
isend = true;
|
|
||||||
}
|
|
||||||
fill(150, 0, 0, 50);
|
|
||||||
ellipse(-400, 300, 200, 200);
|
|
||||||
|
|
||||||
} 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
|
|
||||||
end_menu.drawMenu();
|
|
||||||
|
|
||||||
// get into right state
|
|
||||||
ship_zero.health = 150;
|
|
||||||
ship_zero.pos.x = -width/2;
|
|
||||||
ship_zero.pos.y = height/2;
|
|
||||||
bob.is_attached = false;
|
|
||||||
saw_zero.is_attached = false;
|
|
||||||
create_level(30);
|
|
||||||
ship_zero.hasSaw = false;
|
|
||||||
|
|
||||||
|
|
||||||
// save
|
|
||||||
if(ship_zero.health > 0) if(playtime.second() < stats_menu.best_game_time) stats_menu.best_game_time = playtime.second();
|
|
||||||
savefile.savetofile("save");
|
|
||||||
} else if (ispause) {
|
|
||||||
main_menu.drawMenu();
|
|
||||||
|
|
||||||
if (playtime.running && playtime.pause == false) playtime.pause_start();
|
|
||||||
}
|
|
||||||
|
|
||||||
mouse_released = false;
|
|
||||||
}
|
|
||||||
@ -1,5 +0,0 @@
|
|||||||
[
|
|
||||||
0,
|
|
||||||
13,
|
|
||||||
205455
|
|
||||||
]
|
|
||||||
152
ship.pde
152
ship.pde
@ -1,177 +1,121 @@
|
|||||||
class Ship {
|
class Ship {
|
||||||
// Movement
|
float x, y, a;
|
||||||
PVector pos = new PVector(-width/2, height/2); // position
|
|
||||||
PVector speed = new PVector(0, 0); // The speed of movement
|
|
||||||
PVector acceleration = new PVector();
|
|
||||||
float a; // angle
|
|
||||||
|
|
||||||
// For the collision
|
|
||||||
PVector newPos = new PVector(width/2, height/2);
|
|
||||||
|
|
||||||
float newX, newY;
|
float newX, newY;
|
||||||
boolean colliding = false;
|
boolean colliding = false;
|
||||||
boolean colliding_logs = false;
|
boolean colliding2 = false;
|
||||||
boolean hasSaw = false;
|
boolean hasSaw = false;
|
||||||
|
float rotationSpeed = 4; // The speed of rotation
|
||||||
|
float movementSpeed = 4; // The speed of movement
|
||||||
int nextLog;
|
int nextLog;
|
||||||
|
|
||||||
int health = 150;
|
|
||||||
|
|
||||||
Ship() {
|
Ship() {
|
||||||
// pos.x = width/2;
|
x = width / 2;
|
||||||
// pos.y = height/2;
|
y = height / 2;
|
||||||
|
a = -90;
|
||||||
a = 0;
|
|
||||||
newX = width/2;
|
|
||||||
newY = height/2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tarek
|
|
||||||
void draw() {
|
void draw() {
|
||||||
nextLog = returnIndexOfNearestLog();
|
nextLog = returnIndexOfNearestLog();
|
||||||
|
|
||||||
logCollide(logs);
|
logCollide(logs);
|
||||||
logCollide(walls);
|
// logCollide(trees);
|
||||||
|
|
||||||
|
|
||||||
sawIndicator();
|
sawIndicator();
|
||||||
simulate();
|
simulate();
|
||||||
render();
|
render();
|
||||||
|
// println(colliding);
|
||||||
|
|
||||||
// println(newX, " : ", newY);
|
ship_zero.colliding2 = false;
|
||||||
|
|
||||||
if (health == 0) {
|
|
||||||
isgame = false;
|
|
||||||
isend = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
colliding_logs = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Max, julia
|
|
||||||
void sawIndicator() {
|
void sawIndicator() {
|
||||||
if (hasSaw) {
|
if (hasSaw) {
|
||||||
if (checkDistance(logs[nextLog], ship_zero) < 40) {
|
if (checkDistance(logs[nextLog], ship_zero) < 40) {
|
||||||
fill(204, 102, 0);
|
fill(204, 102, 0);
|
||||||
circle(pos.x, pos.y -20, 20);
|
circle(x, y -20, 20);
|
||||||
fill(0);
|
fill(0);
|
||||||
textSize(32);
|
textSize(32);
|
||||||
textAlign(CENTER, CENTER);
|
textAlign(CENTER, CENTER);
|
||||||
text("s", pos.x, pos.y - 27);
|
text("s", x, y - 27);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Max
|
|
||||||
int returnIndexOfNearestLog() {
|
int returnIndexOfNearestLog() {
|
||||||
float shortest_distance_log_distance = checkDistance(logs[0], ship_zero);
|
float shortest_distance_log_distance = checkDistance(logs[0], ship_zero);
|
||||||
int shortest_distance_log = 0;
|
int shortest_distance_log = 0;
|
||||||
for(int i = 0; i < logs.length; i++) {
|
for(int i = 0; i < logs.length; i++) {
|
||||||
// only logs that are not sawed already
|
|
||||||
if (!logs[i].sawed) {
|
|
||||||
if(checkDistance(logs[i], ship_zero) < shortest_distance_log_distance) {
|
if(checkDistance(logs[i], ship_zero) < shortest_distance_log_distance) {
|
||||||
shortest_distance_log = i;
|
shortest_distance_log = i;
|
||||||
shortest_distance_log_distance = checkDistance(logs[i], ship_zero);
|
shortest_distance_log_distance = checkDistance(logs[i], ship_zero);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return shortest_distance_log;
|
return shortest_distance_log;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Max
|
|
||||||
void simulate() {
|
void simulate() {
|
||||||
// First do the Math but dont move something
|
if(newX > 0 && newX < width && newY > 0 && newY < height) {
|
||||||
|
colliding = false;
|
||||||
|
} else {
|
||||||
|
colliding = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Rotate PLayer
|
|
||||||
if (ROTATEL) {
|
if (ROTATEL) {
|
||||||
a -= 0.03;
|
a -= rotationSpeed;
|
||||||
}
|
}
|
||||||
if (ROTATER) {
|
if (ROTATER) {
|
||||||
a += 0.03;
|
a += rotationSpeed;
|
||||||
}
|
|
||||||
PVector direction = new PVector();
|
|
||||||
direction.x = cos(a);
|
|
||||||
direction.y = sin(a);
|
|
||||||
direction.mult(0.07);
|
|
||||||
|
|
||||||
|
|
||||||
acceleration = direction;
|
|
||||||
|
|
||||||
// add speed if pressing NORTH
|
|
||||||
if(NORTH) {
|
|
||||||
speed.add(acceleration);
|
|
||||||
speed.limit(1.3);
|
|
||||||
} else if (SOUTH) {
|
|
||||||
speed.mult(0.80);
|
|
||||||
} else { // decrease it if not
|
|
||||||
speed.mult(0.90);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (NORTH) {
|
||||||
// Check new pos
|
newX = x + cos(radians(a)) * movementSpeed;
|
||||||
newPos = pos.add(speed);
|
newY = y + sin(radians(a)) * movementSpeed;
|
||||||
|
|
||||||
// Collide with outside walls
|
|
||||||
if( newPos.x > width || newPos.y < 0 || newPos.y > height) {
|
|
||||||
colliding = true;
|
|
||||||
// println("collide");
|
|
||||||
} else {
|
|
||||||
colliding = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if the new position is within the bounds of the screen
|
// Check if the new position is within the bounds of the screen
|
||||||
// - Handle it more like https://processing.org/examples/circlecollision.html
|
if(colliding == false && colliding2 == false) {
|
||||||
if(colliding == false && colliding_logs == false) {
|
x = newX;
|
||||||
pos.add(speed);
|
y = newY;
|
||||||
} else {
|
}
|
||||||
speed.limit(0);
|
} else if (SOUTH) {
|
||||||
speed.sub(acceleration);
|
newX = x - cos(radians(a)) * movementSpeed;
|
||||||
pos.add(0, 0);
|
newY = y - sin(radians(a)) * movementSpeed;
|
||||||
pos.add(speed.mult(2));
|
|
||||||
|
// Check if the new position is within the bounds of the screen
|
||||||
health = health - 1;
|
if(colliding == false && colliding2 == false) {
|
||||||
|
x = newX;
|
||||||
|
y = newY;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// println(speed);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tarek
|
void logCollide(Log[] logs) {
|
||||||
void logCollide(Log[] loggers) {
|
for(int i = 0; i < logs.length; i++) {
|
||||||
for(int i = 0; i < loggers.length; i++) {
|
if(logs[i].sawed == false) {
|
||||||
if(loggers[i].sawed == false) {
|
if (newX+10 > logs[i].x && newX-10 < logs[i].x + logs[i].logwidth && newY+10 > logs[i].y && newY-10 < logs[i].y + logs[i].logheight) {
|
||||||
if (newPos.x+10 > loggers[i].x && newPos.x-10 < loggers[i].x + loggers[i].logwidth && newPos.y+10 > loggers[i].y - loggers[i].logheight && newPos.y-10 < loggers[i].y) {
|
colliding2 = true;
|
||||||
colliding_logs = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tarek, Marla
|
|
||||||
void collect(Collectable c) {
|
void collect(Collectable c) {
|
||||||
if (pos.dist(c.pos) < 20) {
|
if (newX > c.x && newX < c.x + c.cwidth && newY > c.y && newY < c.y + c.cheight) {
|
||||||
if (c.getClass() == Saw.class ) hasSaw = true;
|
if (c.getClass() == Saw.class ) hasSaw = true;
|
||||||
c.is_attached = true;
|
c.is_attached = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void render() {
|
void render() {
|
||||||
|
|
||||||
pushMatrix();
|
pushMatrix();
|
||||||
translate(pos.x, pos.y);
|
translate(x, y);
|
||||||
rotate(a);
|
rotate(radians(a + 90));
|
||||||
stroke(255);
|
stroke(255);
|
||||||
noFill();
|
noFill();
|
||||||
// line(0, -10, 10, 10);
|
line(0, -10, 10, 10);
|
||||||
// line(10, 10, 0, 5);
|
line(10, 10, 0, 5);
|
||||||
// line(0, 5, -10, 10);
|
line(0, 5, -10, 10);
|
||||||
// line(-10, 10, 0, -10);
|
line(-10, 10, 0, -10);
|
||||||
// triangle(- 5, - 5, - 5, 5, 10, 0);
|
|
||||||
imageMode(CENTER);
|
|
||||||
if(bob.is_attached) {
|
|
||||||
image(player_sprite_bob, 0, 0);
|
|
||||||
} else {
|
|
||||||
image(player_sprite, 0, 0);
|
|
||||||
}
|
|
||||||
if(hasSaw) {
|
if(hasSaw) {
|
||||||
image(saw_sprite, 20, 0);
|
rect(0+2, 0-45, 20, 50);
|
||||||
}
|
}
|
||||||
popMatrix();
|
popMatrix();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user