One last Frogger question
in
Programming Questions
•
10 months ago
I accidentally deleted my last post. My last question is how can I make it so my frog doesn't move after you've won?
final int WIDTH=800, HEIGHT=300;
final color GRASS = color(0, 255, 0);
final color ROADWAY = color(32);
final color ROAD_LINES = color(245, 228, 200);
final color RED = color(255, 0, 0);
final color GREEN= color(0, 255, 0);
final color YELLOW= color(255, 255, 0);
final float BORDER= 30.0;
final float LINE_BORDER = 5.0;
final float LINE_THICKNESS = 15.0;
Car car1, car2, car3;
Frog frog;
boolean FrogIsDead;
boolean FrogWins;
PImage frog_img, frogsplat_img;
void setup()
{
size(WIDTH, HEIGHT);
noStroke();
car1 = new Car(RED, 0, HEIGHT/2, 3, 0);
car2 = new Car(GREEN, 0, HEIGHT/2 - 70, 4, 0);
car3 = new Car(YELLOW, 0, HEIGHT/2 + 70, 2, 0);
frog = new Frog(WIDTH/2, HEIGHT/2 + 133);
frog_img = loadImage("frog.gif");
frogsplat_img= loadImage("frogsplat.gif");
}
void draw()
{
if (FrogIsDead == false) {
if(FrogWins == false) {
background(GRASS);
drawRoadway();
car1.draw(); car1.move();
car2.draw(); car2.move();
car3.draw(); car3.move();
frog.draw();
frog.FrogIsHit(car1);
frog.FrogIsHit(car2);
frog.FrogIsHit(car3);
}
else
{
frog.draw();
fill(0, 0, 255);
text("YOU WIN", 200, 20);
}
}
else
{
background(GRASS);
drawRoadway();
car1.draw();
car2.draw();
car3.draw();
frog.draw();
fill(255, 0 , 0);
text("YOU LOSE", 200, 20);
}
}
void drawRoadway()
{
fill(ROADWAY);
rect(0, BORDER, WIDTH, HEIGHT - 2 * BORDER);
fill(ROAD_LINES);
rect(0, BORDER + LINE_BORDER, WIDTH, LINE_THICKNESS);
rect(0, HEIGHT - BORDER - LINE_BORDER - LINE_THICKNESS,
WIDTH, LINE_THICKNESS);
rect(0, BORDER + 75, WIDTH, LINE_THICKNESS);
rect(0, BORDER + 150, WIDTH, LINE_THICKNESS);
}
void keyPressed()
{
if (FrogIsDead == false) {
if (key == CODED) {
if (keyCode == DOWN)
{
frog.Down();
}
else if (keyCode == UP)
{
frog.Up();
}
}
}
}
class Car
{
static final float WIDTH= 50;
static final float HEIGHT= 25;
color col;
PVector loc, speed;
Car(color col, float x, float y, float dx, float dy)
{
this.col= col;
this.loc= new PVector(x, y);
this.speed= new PVector(dx, dy);
}
void draw()
{
rectMode(CENTER);
fill(this.col);
rect(this.loc.x, this.loc.y, Car.WIDTH, Car.HEIGHT);
rectMode(CORNER);
}
void move()
{
this.loc.add(this.speed);
if(this.loc.x > width) this.loc.x = 0;
}
}
class Frog {
static final float WIDTH = 35;
static final float HEIGHT= 35;
float FrogX;
float FrogY;
Frog(float tempXpos, float tempYpos)
{
FrogX= tempXpos;
FrogY= tempYpos;
}
void draw()
{
if(FrogIsDead == false) {
imageMode(CENTER);
image(frog_img, FrogX, FrogY, WIDTH, HEIGHT);
}
else
{
imageMode(CENTER);
image(frogsplat_img, FrogX, FrogY, WIDTH, HEIGHT);
}
if(FrogY <= 20) {
FrogWins=true;
}
}
void FrogIsHit (Car Car) {
if (FrogX + frog_img.width/2 >= Car.loc.x -Car.WIDTH/2 && FrogX - frog_img.width/2 <= Car.loc.x + Car.WIDTH/2 &&
FrogY + frog_img.height/2 >= Car.loc.y - Car.HEIGHT/2 && FrogY - frog_img.height/2 <= Car.loc.y + Car.HEIGHT/2) {
FrogIsDead=true;
}
}
void Down()
{ if(FrogY <= 270) {
FrogY = FrogY + 15;
}
}
void Up()
{ if(FrogY >= 15) {
FrogY= FrogY - 15;
}
}
}
1