package movement;
import processing.core.PApplet;
import processing.core.PImage;
public class LunasAdventures extends PApplet {
PImage moth;
PImage bg;
public static void main(String[] args) {
PApplet.main("movement.LunasAdventures");
}
public float rotationAmount = 0;
public float speed = 10;
public float x = 400;
public float y = 350;
public boolean moveForward = false;
public boolean moving = false;
public boolean rotatingLeft = false;
public boolean rotatingRight = false;
public void settings() {
size(747, 420);
}
public void setup() {
moth = loadImage("Images/mothc.png");
bg = loadImage("Images/cave.png");
}
public void draw() {
background (bg);
image(moth, 0, 0);
move();
changeRotation();
translate(x, y);
rotate(rotationAmount);
}
public void keyPressed() {
if (key == 'w') {
moveForward = true;
moving = true;
}
if (key == 'a') {
rotatingLeft = true;
}
if (key == 'd') {
rotatingRight = true;
}
}
public void keyReleased() {
if (key == 'w') {
moveForward = false;
moving = false;
}
if (key == 'a') {
rotatingLeft = false;
}
if (key == 'd') {
rotatingRight = false;
}
}
public void move() {
if (moveForward) {
x += speed * cos(rotationAmount);
y += speed * sin(rotationAmount);
}
}
public void changeRotation() {
if (rotatingLeft) {
rotationAmount -= .08;
if (rotationAmount < 0) {
rotationAmount = 2 * PI;
}
}
if (rotatingRight) {
rotationAmount += .08;
if (rotationAmount > 2 * PI) {
rotationAmount = 0;
}
}
}
}
Cris M.
Ah ok! Thank you! It works now!06/02/20