Cris M.

asked • 05/25/20

I can't make a my character move when I run my javascript (Intellij), what is wrong with my code?

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;
}
}

}

}


1 Expert Answer

By:

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.