all the features

This commit is contained in:
Makussu 2023-12-11 00:03:26 +01:00
parent 81cd7e0a8f
commit a365254312
5 changed files with 235 additions and 183 deletions

43
collect.pde Normal file
View File

@ -0,0 +1,43 @@
class Collectable {
float x, y, cwidth, cheight;
boolean is_attached = false;
Collectable(float xpos, float ypos, float cw, float ch) {
x = xpos;
y = ypos;
cwidth = cw;
cheight = ch;
}
}
class Saw extends Collectable {
Saw(float x, float y, float cw, float ch) {
super(x, y, cw, ch);
}
void drawSaw() {
if (!is_attached) {
stroke(0);
fill(210, 210, 0);
rect(x, y, cwidth, cheight);
fill(0);
}
}
}
class Bob extends Collectable {
Bob(float x, float y, float cw, float ch) {
super(x, y, cw, ch);
}
void drawBob() {
if (!is_attached) {
stroke(0);
fill(255, 209, 152);
rect(x, y, cwidth, cheight);
fill(0);
}
}
}

194
kek2.pde
View File

@ -1,171 +1,4 @@
class Ship {
float x, y, a;
float newX, newY;
boolean colliding = false;
boolean colliding2 = false;
boolean hasSaw = true;
float rotationSpeed = 4; // The speed of rotation
float movementSpeed = 4; // The speed of movement
Ship() {
x = width / 2;
y = height / 2;
a = -90;
}
void draw() {
logCollide(logs);
logCollide(trees);
sawIndicator();
simulate();
render();
// println(colliding);
ship_zero.colliding2 = false;
}
void sawIndicator() {
if (hasSaw) {
if (checkDistance(logs[returnIndexOfNearestLog()], ship_zero) < 40) {
fill(204, 102, 0);
circle(x, y -20, 20);
fill(0);
textSize(32);
textAlign(CENTER, CENTER);
text("s", x, y - 27);
}
}
}
int returnIndexOfNearestLog() {
int longest_distance_log = 0;
float longest_distance_log_distance = 0;
for(int i = 0; i < logs.length; i++) {
if(checkDistance(logs[i], ship_zero) > longest_distance_log_distance) {
println(checkDistance(logs[i], ship_zero), " other ",longest_distance_log_distance);
longest_distance_log = i;
longest_distance_log_distance = checkDistance(logs[i], ship_zero);
}
}
return longest_distance_log;
}
void simulate() {
if(newX > 0 && newX < width && newY > 0 && newY < height) {
colliding = false;
} else {
colliding = true;
}
if (ROTATEL) {
a -= rotationSpeed;
}
if (ROTATER) {
a += rotationSpeed;
}
if (NORTH) {
newX = x + cos(radians(a)) * movementSpeed;
newY = y + sin(radians(a)) * movementSpeed;
// Check if the new position is within the bounds of the screen
if(colliding == false && colliding2 == false) {
x = newX;
y = newY;
}
} else if (SOUTH) {
newX = x - cos(radians(a)) * movementSpeed;
newY = y - sin(radians(a)) * movementSpeed;
// Check if the new position is within the bounds of the screen
if(colliding == false && colliding2 == false) {
x = newX;
y = newY;
}
}
}
void logCollide(Log[] logs) {
for(int i = 0; i < logs.length; i++) {
if(logs[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) {
colliding2 = true;
}
}
}
}
// void treeCollide(Tree[] trees) {
// for(int i = 0; i < trees.length; i++) {
// }
// }
void render() {
pushMatrix();
translate(x, y);
rotate(radians(a + 90));
stroke(255);
noFill();
line(0, -10, 10, 10);
line(10, 10, 0, 5);
line(0, 5, -10, 10);
line(-10, 10, 0, -10);
popMatrix();
}
}
class Log {
float x, y, logwidth, logheight;
boolean sawed = false;
color logcolor;
color strokecolor = logcolor;
Log (float xpos, float ypos, float logw, float logh, boolean hasC) {
x = xpos;
y = ypos;
logwidth = logw;
logheight = logh;
}
void drawLog(int logtext) {
if (sawed) {
logcolor = color(128, 88, 60);
} else {
logcolor = color(133, 79, 51);
}
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);
}
}
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);
color bushes = color(107, 117, 48);
// rectMode(CENTER);
fill(treecolor);
rect(x, y, logwidth, logheight);
fill(bushes);
ellipse(x, (y-40), 170*0.3, 160*0.3);
// rectMode(CORNER);
}
}
float checkDistance(Log log, Ship ship) { float checkDistance(Log log, Ship ship) {
float testX = ship.x; float testX = ship.x;
@ -192,14 +25,16 @@ float checkDistance(Log log, Ship ship) {
boolean isColliding = false; boolean isColliding = false;
Ship ship_zero; Ship ship_zero;
Saw saw_zero;
Bob bob;
Log log_zero; Log[] logs = {new Log(100, 200, 100, 100, false), new Log(500, 200, 200, 100, false), new Log(400, 400, 20, 100, true) };
Log[] logs = {new Log(100, 200, 100, 100, true), new Log(500, 200, 200, 100, true) };
Tree[] trees = {new Tree(50, 50, 15, 40, true), new Tree(400, 420, 15, 40, true) };
void setup() { void setup() {
size(600, 600); size(600, 600);
ship_zero = new Ship(); ship_zero = new Ship();
saw_zero = new Saw(100, 100, 20, 50);
bob = new Bob(100, 400, 20, 40);
} }
void draw() { void draw() {
@ -211,24 +46,21 @@ void draw() {
} }
for(int i = 0; i < trees.length; i++) { // for(int i = 0; i < trees.length; i++) {
trees[i].draw(); // trees[i].draw();
} // }
// println(ship_zero.newX, ", ", ship_zero.newY);
// println(ship_zero.returnIndexOfNearestLog());
ship_zero.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++) { for(int i = 0; i < logs.length; i++) {
logs[i].strokecolor = logs[i].logcolor; logs[i].strokecolor = logs[i].logcolor;
} }
logs[ship_zero.returnIndexOfNearestLog()].strokecolor = color(255, 0, 0); logs[ship_zero.nextLog].strokecolor = color(255, 0, 0);
// println(checkDistance(logs[0], ship_zero), " other ", checkDistance(logs[1], ship_zero) );
// println(ship_zero.returnIndexOfNearestLog());
} }

View File

@ -12,8 +12,8 @@ void keyPressed() {
} }
} else if (key == 's') { // SAW } else if (key == 's') { // SAW
if (ship_zero.hasSaw) { if (ship_zero.hasSaw) {
if(checkDistance(logs[1], ship_zero) < 40) { if(checkDistance(logs[ship_zero.nextLog], ship_zero) < 40) {
logs[1].sawed = true; logs[ship_zero.nextLog].sawed = true;
} }
} }
} }

55
logs.pde Normal file
View File

@ -0,0 +1,55 @@
class Log {
float x, y, logwidth, logheight;
boolean sawed = false;
boolean is_tree = false;
color logcolor;
color strokecolor = logcolor;
Log (float xpos, float ypos, float logw, float logh, boolean ist) {
x = xpos;
y = ypos;
logwidth = logw;
logheight = logh;
is_tree = ist;
}
void drawLog(int logtext) {
if (sawed) {
logcolor = color(128, 88, 60);
} else {
logcolor = color(133, 79, 51);
}
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);
if(is_tree) {
color bushes = color(107, 117, 48);
fill(bushes);
ellipse(x+logwidth/2, y+5, 170*0.3, 160*0.3);
}
}
}
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);
}
}

122
ship.pde Normal file
View File

@ -0,0 +1,122 @@
class Ship {
float x, y, a;
float newX, newY;
boolean colliding = false;
boolean colliding2 = false;
boolean hasSaw = false;
float rotationSpeed = 4; // The speed of rotation
float movementSpeed = 4; // The speed of movement
int nextLog;
Ship() {
x = width / 2;
y = height / 2;
a = -90;
}
void draw() {
nextLog = returnIndexOfNearestLog();
logCollide(logs);
// logCollide(trees);
sawIndicator();
simulate();
render();
// println(colliding);
ship_zero.colliding2 = false;
}
void sawIndicator() {
if (hasSaw) {
if (checkDistance(logs[nextLog], ship_zero) < 40) {
fill(204, 102, 0);
circle(x, y -20, 20);
fill(0);
textSize(32);
textAlign(CENTER, CENTER);
text("s", x, y - 27);
}
}
}
int returnIndexOfNearestLog() {
float shortest_distance_log_distance = checkDistance(logs[0], ship_zero);
int shortest_distance_log = 0;
for(int i = 0; i < logs.length; i++) {
if(checkDistance(logs[i], ship_zero) < shortest_distance_log_distance) {
shortest_distance_log = i;
shortest_distance_log_distance = checkDistance(logs[i], ship_zero);
}
}
return shortest_distance_log;
}
void simulate() {
if(newX > 0 && newX < width && newY > 0 && newY < height) {
colliding = false;
} else {
colliding = true;
}
if (ROTATEL) {
a -= rotationSpeed;
}
if (ROTATER) {
a += rotationSpeed;
}
if (NORTH) {
newX = x + cos(radians(a)) * movementSpeed;
newY = y + sin(radians(a)) * movementSpeed;
// Check if the new position is within the bounds of the screen
if(colliding == false && colliding2 == false) {
x = newX;
y = newY;
}
} else if (SOUTH) {
newX = x - cos(radians(a)) * movementSpeed;
newY = y - sin(radians(a)) * movementSpeed;
// Check if the new position is within the bounds of the screen
if(colliding == false && colliding2 == false) {
x = newX;
y = newY;
}
}
}
void logCollide(Log[] logs) {
for(int i = 0; i < logs.length; i++) {
if(logs[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) {
colliding2 = true;
}
}
}
}
void collect(Collectable c) {
if (newX > c.x && newX < c.x + c.cwidth && newY > c.y && newY < c.y + c.cheight) {
if (c.getClass() == Saw.class ) hasSaw = true;
c.is_attached = true;
}
}
void render() {
pushMatrix();
translate(x, y);
rotate(radians(a + 90));
stroke(255);
noFill();
line(0, -10, 10, 10);
line(10, 10, 0, 5);
line(0, 5, -10, 10);
line(-10, 10, 0, -10);
if(hasSaw) {
rect(0+2, 0-45, 20, 50);
}
popMatrix();
}
}