Please help!!! Mini Frogger Project for Class
in
Programming Questions
•
2 years ago
Hello! I am very new to processing and I have a class project I am struggling with. I am supposed to make a very basic version of Frogger where I have 3 lanes of "cars" moving across the screen, three lanes represented by white lines, and a frog who has to go from one end to the other. So far, I was able to create the "cars" in class, which are just different colored rectangles and I have two .gifs that I am supposed to use for when the frog moves and one for when the frog gets hit by a car. I had a few more parts of code, but unfortunately I misplaced my flash drive. I can post the parts of the code that I have so far and if anyone could help me I would be very grateful.
I have two classes right now, and I think I'm supposed to make a third class for the frog. We were doing something with the if statement, where if frog.x > something there would be a collision with the car, but that's on my flashdrive. Like I said, I'm a complete newbie with this stuff, so I'm sorry if I'm a little vague or what I say is wrong.
EDIT: I figured out how to make the image of the frog appear, now I'm trying to work on movement of the frog, collision with a car, drawing the lanes, and ending the game.
CarAnimation
- final int WIDTH = 200;
- final int HEIGHT = WIDTH;
- final int MIDDLE = WIDTH / 2;
- final color BLACK = color(0);
- final color RED = color(255, 0, 0);
- final color GREEN = color(0, 255, 0);
- final color BLUE = color(0, 0, 255);
- final int CAR_WIDTH = 30;
- final int CAR_HEIGHT = 10;
- int frogx = MIDDLE;
- int frogy = 170;
- PImage frogimg;
- Car car1;
- Car car2;
- Car car3;
- Frog frog;
- void setup()
- {
- size(WIDTH, HEIGHT);
- rectMode(CENTER);
- car1 = new Car(RED, 0, 100, CAR_WIDTH, CAR_HEIGHT, 2);
- car2 = new Car(GREEN, 50, 50, CAR_WIDTH, CAR_HEIGHT, 1);
- car3 = new Car(BLUE, 150, 150, CAR_WIDTH, CAR_HEIGHT, 2);
- frogimg = loadImage("frog.gif");
- }
- void draw()
- {
- background(BLACK);
- car1.draw(); car1.move();
- car2.draw(); car2.move();
- car3.draw(); car3.move();
- image(frogimg, frogx, frogy, 32, 32);
- }
Car
- class Car
- {
- color col;
- int x, y, w, h;
- int speed;
- Car(color c, int x, int y, int w, int h, int s)
- {
- this.col = c;
- this.x = x;
- this.y = y;
- this.w = w;
- this.h = h;
- this.speed = s;
- }
- void draw()
- {
- noStroke();
- fill(this.col);
- rect(this.x, this.y, this.w, this.h);
- }
- void move()
- {
- this.x += this.speed;
- if (this.x > width) {
- this.x = 0;
- }
- }
- }
- class Frog
- {
- int x, y, w, h;
- Frog(int x, int y, int w, int h)
- {
- this.x = x;
- this.y = y;
- this.w = w;
- this.h = h;
- }
- }
2