Merge remote-tracking branch 'origin/master'

master
John 2022-06-20 18:03:27 -07:00
commit c29272e758
10 changed files with 56 additions and 23 deletions

View File

@ -9,8 +9,8 @@
5700 150 kill slimes 5700 150 kill slimes
3320 200 They float! 3320 200 They float!
/ /
3480 500 Click left to throw a bomb You have a limited amount of bombs per level! 3450 500 Click left to throw a sticky bomb You have a limited amount of bombs per level!
2950 550 they can blow up boxes 2950 550 you can blow up boxes
500 200 Press WASD to move and R to restart 500 200 Press WASD to move and R to restart
500 250 S makes you fall down faster 500 250 S makes you fall down faster
500 300 P skips the level 500 300 P skips the level

View File

@ -14,5 +14,5 @@ sssssssssssssssssd
sssssssssssssssssd qe q e bb ad zc +ssssssssssssssd sssssssssssssssssd qe q e bb ad zc +ssssssssssssssd
sssssssssssssssssd ad qwwwrlllte bb ad +ssssssssssssssd sssssssssssssssssd ad qwwwrlllte bb ad +ssssssssssssssd
sssssssssssssssssd ad asssssssste bb ad +ssssssssssssssd sssssssssssssssssd ad asssssssste bb ad +ssssssssssssssd
sssssssssssssssssd+ ad ! qwrssssssssstwwwe bb ad h !!!!!!!!!!! +ssssssssssssssd sssssssssssssssssd ad ! qwrssssssssstwwwe bb ad h !!!!!!!!!!! +ssssssssssssssd
ssssssssssssssssstwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwrtwwwwwwwwwwwwwwwwwwwwwwwwwwrssssssssssssssstwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwd ssssssssssssssssstwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwrtwwwwwwwwwwwwwwwwwwwwwwwwwwrssssssssssssssstwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwd

View File

@ -1,5 +1,5 @@
1300 50 Jump to the top 1300 50 Jump to the top
1900 200 Trust me, the steel 1900 250 Trust me, the steel
1900 300 block is quite useful here 1900 300 block is quite useful here
3450 500 Steel block? 3450 500 Steel block?
4500 100 You need your bomb here... 4500 100 You need your bomb here...

View File

@ -12,7 +12,7 @@ sssssssssssssssssd zxc
sssssssssssssssssd agxxxxxxxxxxxxxxxxxxxxxxxxxfllllllllllgxxxxxxxxxxxxxxxc + sssssssssssssssssd agxxxxxxxxxxxxxxxxxxxxxxxxxfllllllllllgxxxxxxxxxxxxxxxc +
sssssssssssssssssd qwwwwwwwwwe o ad zxxxxxxxxxxc + sssssssssssssssssd qwwwwwwwwwe o ad zxxxxxxxxxxc +
sssssssssssssssssd zxxxxxxxxxc qwe ad + sssssssssssssssssd zxxxxxxxxxc qwe ad +
sssssssssssssssssd+ asd zc + sssssssssssssssssd asd zc +
ssssssssssssssssstwwwwwwwwwwwwwwwwwwwwwwwwwwe zxc qe ! ! ! ! qe ssssssssssssssssstwwwwwwwwwwwwwwwwwwwwwwwwwwe zxc qe ! ! ! ! qe
ssssssssssssssssssssssssssssssssssssssssssssdllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllatwwwwwwwwwwwwwwwwwwwwwwwwwrd ssssssssssssssssssssssssssssssssssssssssssssdllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllatwwwwwwwwwwwwwwwwwwwwwwwwwrd
ssssssssssssssssssssssssssssssssssssssssssssdllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllssssssssssssssssssssssssssssd ssssssssssssssssssssssssssssssssssssssssssssdllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllssssssssssssssssssssssssssssd

View File

@ -3,7 +3,7 @@ assssssgxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxfd
assssssd ad asssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssd assssssd ad asssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssd
assssssd ad ass ss s sssss ss ss sssssss ss ssssss ss ss s ss ssd assssssd ad ass ss s sssss ss ss sssssss ss ssssss ss ss s ss ssd
assssssd ad ass sss ss sssss ssssss ss ss ss ss ssssss sss ssss s sss s ss s s sssd assssssd ad ass sss ss sssss ssssss ss ss ss ss ssssss sss ssss s sss s ss s s sssd
assssssd+ ad ass sss ss ssss sssssss ss ss ss ss ss ss ssss s ss s s sss s ss s ssssd assssssd ad ass sss ss ssss sssssss ss ss ss ss ss ss ssss s ss s s sss s ss s ssssd
asssssstwwwwww wwwww ww w wwe ad ass ss sss ssssssss ss ss ss ss ssss sssss ss ss s s s ssssd asssssstwwwwww wwwww ww w wwe ad ass ss sss ssssssss ss ss ss ss ssss sssss ss ss s s s ssssd
assssssssssssslllsssssllllssllslllssd zc ass ssssss ss sssssssss ss ss ss ss sss ss sss ssssss s sss s s ss s sssd assssssssssssslllsssssllllssllslllssd zc ass ssssss ss sssssssss ss ss ss ss sss ss sss ssssss s sss s s ss s sssd
asssssgxxxxxxxxxxxxxxxxxxxxxxxxxxxxxc qe ass ssssss s sssss ss ss ss sssssss ssssss s sss s ss s ss ssd asssssgxxxxxxxxxxxxxxxxxxxxxxxxxxxxxc qe ass ssssss s sssss ss ss ss sssssss ssssss s sss s ss s ss ssd

View File

@ -13,6 +13,6 @@ d ad zc assssssss
swww3 hd asssssssssd swww3 hd asssssssssd
d ad asssssssssd d ad asssssssssd
d ad hsssssssssd d ad hsssssssssd
d+ ad ! ! qe asssssssssd d ad ! ! qe asssssssssd
twwww atwwwwwwwwwwwwwwwwwwwwwwrtwwwwwwuwwwwuwwwwuwwwwwwwwwrsssssssssd twwww atwwwwwwwwwwwwwwwwwwwwwwrtwwwwwwuwwwwuwwwwuwwwwwwwwwrsssssssssd
sssssllllllllllllllssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssd sssssllllllllllllllssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssd

View File

@ -339,7 +339,7 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ
} }
// draw bomb counter (bomb image and amount of bombs remaining) // draw bomb counter (bomb image and amount of bombs remaining)
g.drawImage(bomb.image,20,20,35,35,null); g.drawImage(bomb.image,20,20,35,35,null);
g.drawString("X"+LevelManager.bombs,60,40); g.drawString("X"+LevelManager.bombs+" Sticky bombs",60,40);
if (isPaused) { if (isPaused) {
// cover background with translucent rectangle // cover background with translucent rectangle
g.setColor(new Color(255, 255, 255, 100)); g.setColor(new Color(255, 255, 255, 100));

View File

@ -1,5 +1,5 @@
// Eric Li, Charlie Zhao, ICS4U, Finished 6/18/22 // Eric Li, Charlie Zhao, ICS4U, Finished 6/18/22
// create particles when the character jumps or on top of lava // create particles when the character walks or on top of lava
import java.awt.*; import java.awt.*;
import java.io.IOException; import java.io.IOException;
@ -16,16 +16,21 @@ public class Particle extends GenericSprite implements Serializable {
public BufferedImageWrapper sprite; public BufferedImageWrapper sprite;
public Particle(int x, int y, int xVelocity, int yVelocity, int length, String filePath) throws IOException { public Particle(int x, int y, int xVelocity, int yVelocity, int length, String filePath) throws IOException {
//Creates generic sprite class
super(x,y,length, length); super(x,y,length, length);
this.xVelocity = xVelocity; this.xVelocity = xVelocity;
this.yVelocity = yVelocity; this.yVelocity = yVelocity;
sprite = new BufferedImageWrapper((filePath)); sprite = new BufferedImageWrapper((filePath));
} }
//Moves the sprite, and gives it gravity
public void move(){ public void move(){
x+=xVelocity; x+=xVelocity;
y+=yVelocity; y+=yVelocity;
yVelocity+=0.5; yVelocity+=0.5;
} }
//Draws the sprite on the screen
public void draw(Graphics g){ public void draw(Graphics g){
g.drawImage(sprite.image,x-GameFrame.game.camera.x,y,WIDTH,HEIGHT, null); g.drawImage(sprite.image,x-GameFrame.game.camera.x,y,WIDTH,HEIGHT, null);
} }

View File

@ -347,9 +347,9 @@ public class Player extends GenericSprite {
//Handles events when the player presses a mouse button. //Handles events when the player presses a mouse button.
//Left for throwing bombs, and right for picking and placing steel //Left for throwing bombs, and right for picking and placing steel
public void mousePressed(MouseEvent e) throws SpriteException, IOException { public void mousePressed(MouseEvent e) throws SpriteException, IOException {
//canReach(1,1);
mouseX = e.getX(); mouseX = e.getX();
mouseY = e.getY(); mouseY = e.getY();
//If the player left clicks and is holding steel and can place it, place the steel
if(e.getButton()==MouseEvent.BUTTON1) { if(e.getButton()==MouseEvent.BUTTON1) {
int x = (mouseX + GameFrame.game.camera.x + GamePanel.GAME_WIDTH / 2) / Tile.length; int x = (mouseX + GameFrame.game.camera.x + GamePanel.GAME_WIDTH / 2) / Tile.length;
int y = (mouseY / Tile.length); int y = (mouseY / Tile.length);
@ -364,6 +364,8 @@ public class Player extends GenericSprite {
leftMouseDown = true; leftMouseDown = true;
} }
} }
//If the player right clicks, either pick up steel, or places it down depending if the player
//is already holding steel
if(e.getButton()==MouseEvent.BUTTON3) { if(e.getButton()==MouseEvent.BUTTON3) {
int x = (mouseX + GameFrame.game.camera.x + GamePanel.GAME_WIDTH / 2) / Tile.length; int x = (mouseX + GameFrame.game.camera.x + GamePanel.GAME_WIDTH / 2) / Tile.length;
int y = (mouseY / Tile.length); int y = (mouseY / Tile.length);
@ -397,16 +399,15 @@ public class Player extends GenericSprite {
} }
//TODO
//Using BFS check if there is a physical path where the player can reach a block
public boolean canReach(int x, int y){ public boolean canReach(int x, int y){
try { try {
int pX = (int) (((double) GameFrame.game.camera.x + GamePanel.GAME_WIDTH) / Tile.length); int pX = (int) (((double) GameFrame.game.camera.x + GamePanel.GAME_WIDTH) / Tile.length);
int pY = (int) (((double) this.y + HEIGHT / 2) / Tile.length); int pY = (int) (((double) this.y + HEIGHT / 2) / Tile.length);
//System.out.println(pX+" "+pY);
if (pY < 0) { if (pY < 0) {
return false; return false;
} }
//BFS
int[][] check = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}}; int[][] check = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}};
int[][] dis = new int[1000][18]; int[][] dis = new int[1000][18];
for (int[] a : dis) { for (int[] a : dis) {
@ -447,20 +448,26 @@ public class Player extends GenericSprite {
return false; return false;
} }
} }
//When the player drags the mouse, update the the x and y position of the mouse
public void mouseDragged(MouseEvent e) throws IOException, SpriteException { public void mouseDragged(MouseEvent e) throws IOException, SpriteException {
mouseX = e.getX(); mouseX = e.getX();
mouseY = e.getY(); mouseY = e.getY();
} }
//When the player moves the mouse, update the x and y position of the mouse
public void mouseMoved(MouseEvent e) { public void mouseMoved(MouseEvent e) {
mouseX = e.getX(); mouseX = e.getX();
mouseY = e.getY(); mouseY = e.getY();
} }
//Handles actions when the player releases a mouse button
public void mouseReleased(MouseEvent e) throws IOException, SpriteException { public void mouseReleased(MouseEvent e) throws IOException, SpriteException {
mouseX = e.getX(); mouseX = e.getX();
mouseY = e.getY(); mouseY = e.getY();
//If it's the left button, throw a bomb, given they have bombs
if(e.getButton()==MouseEvent.BUTTON1) { if(e.getButton()==MouseEvent.BUTTON1) {
leftMouseDown = false; leftMouseDown = false;
if (leftClickPlacedSteel) { if (leftClickPlacedSteel) {
@ -473,26 +480,35 @@ public class Player extends GenericSprite {
} }
} }
} }
//If its right click, simply set rightMouseDown to false
if(e.getButton()==MouseEvent.BUTTON3){ if(e.getButton()==MouseEvent.BUTTON3){
rightMouseDown = false; rightMouseDown = false;
} }
} }
//Adds walking particles to the player
public void addParticle(int x) throws IOException { public void addParticle(int x) throws IOException {
if(UtilityFunction.randInt(1,3)==3) { if(UtilityFunction.randInt(1,3)==3) {
GameFrame.game.particles.add(new Particle(this.x + GameFrame.game.camera.x + WIDTH / 2 + UtilityFunction.randInt(-PLAYER_WIDTH / 2, PLAYER_WIDTH / 2) GameFrame.game.particles.add(new Particle(this.x + GameFrame.game.camera.x + WIDTH / 2 + UtilityFunction.randInt(-PLAYER_WIDTH / 2, PLAYER_WIDTH / 2)
, (int) (y + HEIGHT * 0.95), UtilityFunction.randInt(-2, 2) + x, UtilityFunction.randInt(-4, 1), UtilityFunction.randInt(1, 7), "img/particles/GrassParticle.png")); , (int) (y + HEIGHT * 0.95), UtilityFunction.randInt(-2, 2) + x, UtilityFunction.randInt(-4, 1), UtilityFunction.randInt(1, 7), "img/particles/GrassParticle.png"));
} }
} }
//Draws the player on the screen
public int draw(Graphics g, int frame) { public int draw(Graphics g, int frame) {
frame %= spriteArray[0][0].length; frame %= spriteArray[0][0].length;
//Draws the pickup range for steel if the player is holding down right click
if(rightMouseDown){ if(rightMouseDown){
g.drawOval((int)(x+WIDTH/2-(reach*steelReachRange)),(int)(y+HEIGHT/2-(reach*steelReachRange)), (int)(reach*steelReachRange*2),(int)(reach*steelReachRange*2)); g.drawOval((int)(x+WIDTH/2-(reach*steelReachRange)),(int)(y+HEIGHT/2-(reach*steelReachRange)), (int)(reach*steelReachRange*2),(int)(reach*steelReachRange*2));
} }
//If the player isn't pressing up/left/right, dont animate sprite
if (!upPressed && !leftPressed && !rightPressed) { if (!upPressed && !leftPressed && !rightPressed) {
g.drawImage(spriteArray[lastXDirection][lastYDirection][7].image, x-10, y, null); g.drawImage(spriteArray[lastXDirection][lastYDirection][7].image, x-10, y, null);
return 0; return 0;
} else { } else {
//If they do click one of those keys, animate the sprite
lastXDirection = (int)(Math.signum(xVelocity) + 1) / 2; lastXDirection = (int)(Math.signum(xVelocity) + 1) / 2;
lastYDirection = (int)(Math.signum(yVelocity) + 1) / 2; lastYDirection = (int)(Math.signum(yVelocity) + 1) / 2;
lastFrame = frame; lastFrame = frame;
@ -503,5 +519,4 @@ public class Player extends GenericSprite {
} }
//public int BfsDis()
} }

View File

@ -1,3 +1,6 @@
// Eric Li, Charlie Zhao, ICS4U, Completed 6/20/2022
// StickyBomb class creates a bomb with physics and exploding abilities
import javax.sound.sampled.LineUnavailableException; import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException; import javax.sound.sampled.UnsupportedAudioFileException;
import java.awt.*; import java.awt.*;
@ -27,11 +30,13 @@ public class StickyBomb extends GenericSprite implements Serializable {
public StickyBomb(int x, int y, int xVelocity, int yVelocity, BufferedImageWrapper sprite, BufferedImageWrapper[] explosionSpriteArray){ public StickyBomb(int x, int y, int xVelocity, int yVelocity, BufferedImageWrapper sprite, BufferedImageWrapper[] explosionSpriteArray){
//Creates generic sprite class
super(x,y,length,length); super(x,y,length,length);
this.xVelocity = xVelocity; this.xVelocity = xVelocity;
this.yVelocity = yVelocity; this.yVelocity = yVelocity;
this.sprite = sprite; this.sprite = sprite;
this.explosionSpriteArray = explosionSpriteArray; this.explosionSpriteArray = explosionSpriteArray;
//Sets default state of bomb
fuse = GlobalState.second*5; fuse = GlobalState.second*5;
isMove = true; isMove = true;
alive = true; alive = true;
@ -40,24 +45,18 @@ public class StickyBomb extends GenericSprite implements Serializable {
//Updates the realX position of the bomb, rather than where it is drawn on the screen.
public void update(){ public void update(){
realX = x - GameFrame.game.camera.x; realX = x - GameFrame.game.camera.x;
} }
//After the fuse runs out explode
public void explode() throws UnsupportedAudioFileException, LineUnavailableException, IOException { public void explode() throws UnsupportedAudioFileException, LineUnavailableException, IOException {
// Sound explode = new Sound("sound/explode.wav");
// if (explode == null) {
// try {
// explode = new Sound("sound/explode.wav");
// } catch (UnsupportedAudioFileException | LineUnavailableException e) {
// throw new RuntimeException(e);
// }
// }
// explode.start();
UtilityFunction.playSound("sound/explode.wav"); UtilityFunction.playSound("sound/explode.wav");
double yDis = GameFrame.game.player.y+Player.PLAYER_HEIGHT/2-(y+(double)length/2); double yDis = GameFrame.game.player.y+Player.PLAYER_HEIGHT/2-(y+(double)length/2);
double xDis = GameFrame.game.player.x+Player.PLAYER_WIDTH/2-(realX+(double)length/2); double xDis = GameFrame.game.player.x+Player.PLAYER_WIDTH/2-(realX+(double)length/2);
double hypo = Math.sqrt(yDis*yDis+xDis*xDis); double hypo = Math.sqrt(yDis*yDis+xDis*xDis);
//Propels player away from bomb
if(hypo<300) { if(hypo<300) {
if (yDis != 0) { if (yDis != 0) {
GameFrame.game.player.yVelocity += 10 * (yDis) / (hypo); GameFrame.game.player.yVelocity += 10 * (yDis) / (hypo);
@ -66,8 +65,10 @@ public class StickyBomb extends GenericSprite implements Serializable {
GameFrame.game.player.xVelocity += 10 * (xDis) / (hypo); GameFrame.game.player.xVelocity += 10 * (xDis) / (hypo);
} }
} }
//Caps player speed
GameFrame.game.player.capSpeed(); GameFrame.game.player.capSpeed();
alive = false; alive = false;
//Kills enemies
for(int i=0; i<GameFrame.game.enemy.size(); i++){ for(int i=0; i<GameFrame.game.enemy.size(); i++){
double disX = GameFrame.game.enemy.get(i).x+GameFrame.game.enemy.get(i).npcWidth/2 - (x+length/2); double disX = GameFrame.game.enemy.get(i).x+GameFrame.game.enemy.get(i).npcWidth/2 - (x+length/2);
double disY = GameFrame.game.enemy.get(i).y+GameFrame.game.enemy.get(i).npcHeight/2 - (y+length/2); double disY = GameFrame.game.enemy.get(i).y+GameFrame.game.enemy.get(i).npcHeight/2 - (y+length/2);
@ -77,6 +78,8 @@ public class StickyBomb extends GenericSprite implements Serializable {
} }
} }
//Blows up boxes in the region
int lowX = Math.max(0, ((this.x+GamePanel.GAME_WIDTH/2)/Tile.length)-4); int lowX = Math.max(0, ((this.x+GamePanel.GAME_WIDTH/2)/Tile.length)-4);
int highX = Math.min(lowX + 8, GameFrame.game.map.length); int highX = Math.min(lowX + 8, GameFrame.game.map.length);
int lowY = Math.max(0,(this.y/Tile.length)-6); int lowY = Math.max(0,(this.y/Tile.length)-6);
@ -96,6 +99,8 @@ public class StickyBomb extends GenericSprite implements Serializable {
} }
//Checks if the bomb collides with a tile
public boolean collide(Tile tile, double x, double y){ public boolean collide(Tile tile, double x, double y){
if(!tile.collision||tile.nonBombCollide){ if(!tile.collision||tile.nonBombCollide){
return false; return false;
@ -107,27 +112,35 @@ public class StickyBomb extends GenericSprite implements Serializable {
} }
return false; return false;
} }
//Updates the position of the bomb, and stops movement if the bomb can no longer move
public void move() throws UnsupportedAudioFileException, LineUnavailableException, IOException { public void move() throws UnsupportedAudioFileException, LineUnavailableException, IOException {
boolean checked = false; boolean checked = false;
//Caps speed
if(yVelocity>50){yVelocity=50;} if(yVelocity>50){yVelocity=50;}
update(); update();
//Updates fuse
if(fuse>0) { if(fuse>0) {
fuse-=1; fuse-=1;
if(fuse == 0) { if(fuse == 0) {
explode(); explode();
} }
} }
//If it can move, set movement to true
if(canUpdate(1,1)&&canUpdate(-1,1)&&canUpdate(0,-1)&&isMove == false&&fuse>0){ if(canUpdate(1,1)&&canUpdate(-1,1)&&canUpdate(0,-1)&&isMove == false&&fuse>0){
isMove = true; isMove = true;
xVelocity = 0; xVelocity = 0;
yVelocity = 0; yVelocity = 0;
} }
//If isMove is true, and the bomb can update, update the position
if(isMove) { if(isMove) {
if(canUpdate(xVelocity, 0)&&canUpdate(0, yVelocity)&&!canUpdate(xVelocity, yVelocity)){ if(canUpdate(xVelocity, 0)&&canUpdate(0, yVelocity)&&!canUpdate(xVelocity, yVelocity)){
checked = true; checked = true;
x += -Math.signum(xVelocity); x += -Math.signum(xVelocity);
isMove = false; isMove = false;
int updateAmount = 0; int updateAmount = 0;
//Depending on the xVelocity and yVelocity, check which direction to update in
if(xVelocity>0&&yVelocity>0){ if(xVelocity>0&&yVelocity>0){
while(canUpdate(updateAmount, updateAmount)){ while(canUpdate(updateAmount, updateAmount)){
updateAmount++; updateAmount++;