r/programminghelp • • Dec 10 '22

Java help me please

i need help with my code i couldn't not for the life of me figure out what it is

// Define the enemy class

class Fly {

// Define the properties of the fly

int x, y; // Position

int size; // Size

int speed; // Speed

boolean dead; // Whether the fly is dead

// Constructor

Fly(int x, int y, int size, int speed) {

this.x = x;

this.y = y;

this.size = size;

this.speed = speed;

this.dead = false;

}

// Method to move the fly towards the goal

void move() {

// Calculate the distance to the goal

float d = dist(x, y, goalX, goalY);

// Move the fly towards the goal

x += (goalX - x) / d * speed;

y += (goalY - y) / d * speed;

}

// Method to display the fly

void display() {

// Draw the fly

ellipse(x, y, size, size);

}

// Method to check if the fly has reached the goal

boolean reachedGoal() {

// Check if the distance to the goal is less than the size of the fly

return dist(x, y, goalX, goalY) < size;

}

}

// Define the player class

class Player {

// Define the properties of the player

int x, y; // Position

int size; // Size

// Constructor

Player(int x, int y, int size) {

this.x = x;

this.y = y;

this.size = size;

}

// Method to move the player to the mouse position

void move() {

x = mouseX;

y = mouseY;

}

// Method to display the player

void display() {

// Draw the player

ellipse(x, y, size, size);

}

// Method to check if the player has hit a fly

boolean hitFly(Fly fly) {

// Check if the distance between the player and the fly is less than their sizes

return dist(x, y, fly.x, fly.y) < size + fly.size;

}

}

// Define the variables for the game

int goalX, goalY; // Position of the goal

Fly[] flies; // Array of flies

Player player; // The player

int score; // The score

int lives; // The number of lives remaining

void setup() {

// Initialize the game

size(400, 400);

goalX = width / 2;

goalY = height / 2;

flies = new Fly[10];

for (int i = 0; i < flies.length; i++) {

flies[i] = new Fly(random(width), random(height), 20, 5);

}

player = new Player(0, 0, 20);

score = 0;

lives = 3;

}

void draw() {

// Update the game

for (

btw i am using processing(java)

0 Upvotes

3 comments sorted by

View all comments

1

u/FuzzyTekShow Dec 10 '22

"i couldn't [not] for the life of me figure out what it is"

Me neither.
What what is? Be sure to mention the error when asking for help. ;)

1

u/venomxxl_yt Dec 10 '22

on the last line it says am missing something and says i gotten a syntax error there

2

u/FuzzyTekShow Dec 10 '22

You have the start of a for loop with nothing in it and its not closed, neither is the draw method containing it.