Rotation of a vehicle game problem ?
in
Programming Questions
•
1 year ago
Hi
I´m trying to make a simple boat game but bumped in to a problem with the image to rotate.
the vehicle rotates around the x and y on the screen and not around it self.
How can I update the x and y so it follows the boat ?
this is what the code looks like.
- float x;
- float y;
- float speed;
- float acc=0.81;
- float counter;
- boolean keyDOWNdown=false;
- boolean keyUPdown=false;
- PImage bg, boat;
- String fileadress="where files are located";
- void setup() {
- size(800, 600);
- frameRate(30);
- smooth();
- // imageMode(CENTER);
- counter=0.0;
- bg = loadImage(fileadress+"bg.jpg");
- boat = loadImage(fileadress+"boat.gif");
- }
- void draw() {
- background(bg);
- rotate(counter*TWO_PI/360);
- translate(-boat.width/2+50, -boat.height/2+50);
- image(boat, x, y);
- if (keyDOWNdown==true) {
- y+=acc;
- speed=+20;
- }
- if (keyDOWNdown==false) {
- }
- if (keyUPdown==true) {
- y-=acc;
- speed=-20;
- }
- if (keyUPdown==false) {
- }
- if (speed>0) {
- y=y+speed*acc;
- speed--;
- }
- if (speed<0) {
- y=y+speed*acc;
- speed++;
- }
- println(y);
- }
- void keyPressed() {
- println(y);
- println(keyCode);
- if (keyCode==40) { //key 40=down
- keyDOWNdown=true;
- println(keyDOWNdown);
- }
- if (keyCode==38) { //key 38=up
- keyUPdown=true;
- println(keyDOWNdown);
- }
- if (keyCode==37) { //key 37=left
- counter++;
- }
- if (keyCode==39) { //key 39=right
- counter--;
- }
- }
- void keyReleased() {
- println(keyCode);
- if (keyCode==40) { //key 40=down
- keyDOWNdown=false;
- println(keyDOWNdown);
- }
- if (keyCode==38) { //key 38=up
- keyUPdown=false;
- println(keyUPdown);
- }
- }
1