Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,039 changes: 861 additions & 178 deletions Where's Perry3/src/Frame.java

Large diffs are not rendered by default.

150 changes: 84 additions & 66 deletions Where's Perry3/src/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,192 +12,218 @@

import javax.imageio.ImageIO;

import imgs.Door;
import imgs.Gems;
import imgs.Lava;
import imgs.Levers;

public class Player{
private Image img;
private AffineTransform tx;
private int x,y;
private double vx, vy;
private int floor= 700;
private int Lwall= 0;
private int Rwall= 700;
private double vx ,vy;
private int floor= 790;
private int Lwall= 15;
private int Rwall= 790;
private int ceil= 10;
private double gravity = 0.1;
private int gemAmt = 0;


public Player(String fileName) {
img = getImage("/imgs/"+fileName); //load the image for Phineas
tx = AffineTransform.getTranslateInstance(x, y);

x = 0;
y = 0;
tx = AffineTransform.getTranslateInstance(x, y);
tx = AffineTransform.getTranslateInstance(x, y);

}

public void changePicture(String fileName) {
//img = getImage("/imgs/Phinflip.png");
img = getImage("/imgs/"+fileName);
}

public void paint(Graphics g) {
//these are the 2 lines of code needed draw an image on the screen
Graphics2D g2 = (Graphics2D) g;
g2.drawImage(img, tx, null);
update();

g.drawRect((int) x, (int)y, 10, 10);
//g.drawRect((int) x, (int)y, 10, 10);

g.drawRect((int) x+15, (int) y, 20, 80);
//g.drawRect((int) x+25, (int) y, 25, 67);

update();
}

private void init(double a, double b) {
tx.setToTranslation(a,b);
tx.scale(.05, .05);
}

public void stop(){
vx = 0;
}

public void restart(String filename) {
dissapear(getImage("/imgs/"+filename));
x = 0;
y = 0;
gemAmt = 0;
}

public void stop(){
vx = 0;

}

public int getX() {
return x;
}

public int getY() {
return y;
}

public void stop(){
vx = 0;
}
public void moveRight(){
vx = -3;


}

public void moveLeft(){
vx = 3;


vx=3;
}

public void jump() {
if(y == floor) {
vy = -6;
vy = -7;
}


}

public void setFlor(int val) {
floor = val;
}

public void setLwall(int val) {
Lwall = val;
}

public void setRwall(int val) {
Rwall = val;
}

public void setCeil(int val) {
ceil = val;
}

public void update() {
tx = AffineTransform.getTranslateInstance(x, y);
tx.scale(0.75,0.75);
tx.scale(0.65,0.65);
x += vx;
y += vy;
vy += gravity;



if (y >= floor) {
y = floor;
vy =0;
} else {
vy+= gravity;
}

if(y <= ceil) {
vy = 6;

}

if(x <= Lwall) {
x = Lwall;
}
if(x >= Rwall) {
x = Rwall;
}

if (y >= 795) {
y = 690;
}
if (x <= 0) {
x = 15;
}
if(x >= 795) {
x = 770;

touchLev();

}

public boolean touchLev() {
//represent mouse as rectangle
Rectangle p = new Rectangle(x,y,70,70);

// duck hit
//lever
Rectangle l = new Rectangle (670,75,90,90);

if(p.intersects(l)) {
// lever touched
Rectangle l = new Rectangle (670,75,70,70);
Rectangle l2 = new Rectangle (530,370,70,70);
//check hit
if(p.intersects(l) || p.intersects(l2)) { //if lever is touched, move it, each time it should change image
System.out.println("hit");
return true;

}

return false;
//System.out.println("X location " + getX() + ", Y location " + getY());

}
public void restart(String filename, int initx, int inity) {
dissapear(getImage("/imgs/"+filename));
x = initx;
y = inity;
Lwall = 15;
Rwall = 790;
update();

}
//when steps in wrong lava
public void dissapear(Image image) {
img = image;
vx = 0;
}

public double getHeight() {
return y;
}

}
//helper method to detect if player walked through wrong lava
public boolean crossedLava(Lava l) {
boolean crossed = false;

//represent the mouse as a rectangle object
//represent the lava as a rectangle object
Rectangle lava = new Rectangle(l.getX()+60, l.getY()+105, 80, 20);

//level press box
Rectangle player = new Rectangle(x+15, y, 20, 80);
//player rectangle box
Rectangle player = new Rectangle(x+15, y, 20, 63);

if(player.intersects(lava)) {
crossed = true;
}


return crossed;
}

public int getGem() {
return gemAmt;
}
//helper method to detect if player picked up correct gem
public boolean grabbedGem(Gems gem) {
boolean didGrab = false;
//represent the mouse as a rectangle object

//represent the gem as a rectangle object
Rectangle gems = new Rectangle(gem.getX(), gem.getY(), 35, 35);

//level press box
Rectangle player = new Rectangle(x+15, y, 20, 80);
//player rectangle box
Rectangle player = new Rectangle(x+15, y, 20, 63);

if(player.intersects(gems)) {
didGrab = true;
gemAmt ++;
}

return didGrab;
}

//helper method for detecting when both players are at the door
public boolean touchDoor(Door door) {
//represent the door as a rectangle object
Rectangle m = new Rectangle(door.getX()+50, door.getY()+50, 60, 60);

//player rectangle
Rectangle p = new Rectangle(x+15,y, 20, 63);

//check if the two boxes overlap
if(m.intersects(p)) {
return true;
}

return false;
}

private Image getImage(String path) {
Image tempImage = null;
try {
Expand All @@ -208,12 +234,4 @@ private Image getImage(String path) {
}
return tempImage;
}








}
4 changes: 2 additions & 2 deletions Where's Perry3/src/imgs/Buttons.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ private Image getImage(String path) {
//helper method for pressing button on home page
public boolean hit(MouseEvent mouse) {
//represent the mouse as a rectangle object
Rectangle m = new Rectangle(mouse.getX(), mouse.getY(), 50, 50);
Rectangle m = new Rectangle(mouse.getX(), mouse.getY(), 30, 30);

//level press box
Rectangle d = new Rectangle(x,y, 75, 75);
Rectangle d = new Rectangle(x+20,y+20, 70, 70);

//check if the two boxes overlap
if(m.intersects(d)) {
Expand Down
70 changes: 70 additions & 0 deletions Where's Perry3/src/imgs/Candace.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package imgs;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.geom.AffineTransform;
import java.net.URL;

public class Candace {
private int x,y; //location attributes
private Image img2;
private AffineTransform tx;

//default constructor
public Candace() {
img2 = getImage("/imgs/Candace.png"); //load the image
tx = AffineTransform.getTranslateInstance(x,y);
//initialize the location of the image, use your variables
x = 300;
y = 100;
}

//constructor that allows specifying the file name of the image
//sets fileName of the image to use
public Candace(String fileName) {
img2 = getImage("/imgs/" + fileName);
tx = AffineTransform.getTranslateInstance(x,y);
init(x,y);
}


public void changePicture(String newFileName) {
img2 = getImage(newFileName);
init(0, 0);
}

public void paint(Graphics g) {
//these are the 2 lines of code needed draw an image on the screen
Graphics2D g2 = (Graphics2D) g;
update();
g2.drawImage(img2, tx, null);

}

//update the picture variable location
private void update() {
tx.setToTranslation(x, y);
tx.scale(3, 3);
}

private void init(double a, double b) {
tx.setToTranslation(a, b);
tx.scale(3, 3);
}

private Image getImage(String path) {
Image tempImage = null;
try {
URL imageURL = RestartMenu.class.getResource(path);
tempImage = Toolkit.getDefaultToolkit().getImage(imageURL);
} catch (Exception e) {
e.printStackTrace();
}
return tempImage;
}
}
Loading