change ship x to pos.x and introduce speed
This commit is contained in:
parent
a26432dbdd
commit
4b2e32591f
18
kek2.pde
18
kek2.pde
@ -5,21 +5,21 @@
|
|||||||
// Robi muss noch beschleunigen können
|
// Robi muss noch beschleunigen können
|
||||||
|
|
||||||
float checkDistance(Log log, Ship ship) {
|
float checkDistance(Log log, Ship ship) {
|
||||||
float testX = ship.x;
|
float testX = ship.pos.x;
|
||||||
float testY = ship.y;
|
float testY = ship.pos.y;
|
||||||
|
|
||||||
// which edge is closest?
|
// which edge is closest?
|
||||||
if (ship.x < log.x) testX = log.x;
|
if (ship.pos.x < log.x) testX = log.x;
|
||||||
else if (ship.x > log.x+log.logwidth) testX = log.x+log.logwidth;
|
else if (ship.pos.x > log.x+log.logwidth) testX = log.x+log.logwidth;
|
||||||
if (ship.y < log.y) testY = log.y;
|
if (ship.pos.y < log.y) testY = log.y;
|
||||||
else if (ship.y > log.y+log.logheight) testY = log.y+log.logheight;
|
else if (ship.pos.y > log.y+log.logheight) testY = log.y+log.logheight;
|
||||||
|
|
||||||
// get distant
|
// get distant
|
||||||
float distX = ship.x-testX;
|
float distX = ship.pos.x-testX;
|
||||||
float distY = ship.y-testY;
|
float distY = ship.pos.y-testY;
|
||||||
float distance = sqrt( (distX*distX) + (distY*distY) );
|
float distance = sqrt( (distX*distX) + (distY*distY) );
|
||||||
|
|
||||||
line(testX, testY, ship.x, ship.y);
|
line(testX, testY, ship.pos.x, ship.pos.y);
|
||||||
|
|
||||||
// if the distance is less than the radius, collision!
|
// if the distance is less than the radius, collision!
|
||||||
return distance;
|
return distance;
|
||||||
|
|||||||
43
ship.pde
43
ship.pde
@ -2,20 +2,25 @@
|
|||||||
// TODO Abprallen nicht machen, wenn newx nicht erreicht sein kann, sondern wenn Robi tatsächlich die Wand berührt
|
// TODO Abprallen nicht machen, wenn newx nicht erreicht sein kann, sondern wenn Robi tatsächlich die Wand berührt
|
||||||
|
|
||||||
class Ship {
|
class Ship {
|
||||||
float x, y, a;
|
PVector pos = new PVector();
|
||||||
|
|
||||||
|
float a;
|
||||||
float newX, newY;
|
float newX, newY;
|
||||||
boolean colliding = false;
|
boolean colliding = false;
|
||||||
boolean colliding2 = false;
|
boolean colliding2 = false;
|
||||||
boolean hasSaw = false;
|
boolean hasSaw = false;
|
||||||
float rotationSpeed = 4; // The speed of rotation
|
float rotationSpeed = 4; // The speed of rotation
|
||||||
float movementSpeed = 2; // The speed of movement
|
float speed; // The speed of movement
|
||||||
|
float maxSpeed = 4;
|
||||||
|
float minSpeed = 2;
|
||||||
int nextLog;
|
int nextLog;
|
||||||
|
|
||||||
int health = 3;
|
int health = 3;
|
||||||
|
|
||||||
Ship() {
|
Ship() {
|
||||||
x = width / 2;
|
pos.x = width/2;
|
||||||
y = height / 2;
|
pos.y = height/2;
|
||||||
|
|
||||||
a = -90;
|
a = -90;
|
||||||
newX = width/2;
|
newX = width/2;
|
||||||
newY = height/2;
|
newY = height/2;
|
||||||
@ -43,11 +48,11 @@ class Ship {
|
|||||||
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(x, y -20, 20);
|
circle(pos.x, pos.y -20, 20);
|
||||||
fill(0);
|
fill(0);
|
||||||
textSize(32);
|
textSize(32);
|
||||||
textAlign(CENTER, CENTER);
|
textAlign(CENTER, CENTER);
|
||||||
text("s", x, y - 27);
|
text("s", pos.x, pos.y - 27);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -79,28 +84,28 @@ class Ship {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (NORTH) {
|
if (NORTH) {
|
||||||
newX = x + cos(radians(a)) * movementSpeed;
|
newX = pos.x + cos(radians(a)) * speed;
|
||||||
newY = y + sin(radians(a)) * movementSpeed;
|
newY = pos.y + sin(radians(a)) * speed;
|
||||||
|
|
||||||
// Check if the new position is within the bounds of the screen
|
// Check if the new position is within the bounds of the screen
|
||||||
if(colliding == false && colliding2 == false) {
|
if(colliding == false && colliding2 == false) {
|
||||||
x = newX;
|
pos.x = newX;
|
||||||
y = newY;
|
pos.y = newY;
|
||||||
} else {
|
} else {
|
||||||
float richtungX = x-newX;
|
float richtungX = pos.x-newX;
|
||||||
float richtungY = y-newY;
|
float richtungY = pos.y-newY;
|
||||||
x = (7*richtungX) + x;
|
pos.x = (7*richtungX) + pos.x;
|
||||||
y = (7*richtungY) + y;
|
pos.y = (7*richtungY) + pos.y;
|
||||||
health = health - 1;
|
health = health - 1;
|
||||||
}
|
}
|
||||||
} else if (SOUTH) {
|
} else if (SOUTH) {
|
||||||
newX = x - cos(radians(a)) * movementSpeed;
|
newX = pos.x - cos(radians(a)) * speed;
|
||||||
newY = y - sin(radians(a)) * movementSpeed;
|
newY = pos.y - sin(radians(a)) * speed;
|
||||||
|
|
||||||
// Check if the new position is within the bounds of the screen
|
// Check if the new position is within the bounds of the screen
|
||||||
if(colliding == false && colliding2 == false) {
|
if(colliding == false && colliding2 == false) {
|
||||||
x = newX;
|
pos.x = newX;
|
||||||
y = newY;
|
pos.y = newY;
|
||||||
} //else {
|
} //else {
|
||||||
// x = newX - x;
|
// x = newX - x;
|
||||||
// y = newY - y;
|
// y = newY - y;
|
||||||
@ -127,7 +132,7 @@ class Ship {
|
|||||||
|
|
||||||
void render() {
|
void render() {
|
||||||
pushMatrix();
|
pushMatrix();
|
||||||
translate(x, y);
|
translate(pos.x, pos.y);
|
||||||
rotate(radians(a + 90));
|
rotate(radians(a + 90));
|
||||||
stroke(255);
|
stroke(255);
|
||||||
noFill();
|
noFill();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user