Added Particles

master
bob 2022-06-08 11:23:57 -04:00
parent d5bf288c26
commit 6af212ab1c
6 changed files with 70 additions and 5 deletions

View File

@ -14,5 +14,5 @@ sssssssssssssssssd bbb 1 zxc
sssssssssssssssssdbbbbbbbbbbbbbbbbbbbbbbb
sssssssssssssssssd qwwwwwwwwe
sssssssssssssssssd qrsssssssstwe
sssssssssssssssssd bbb qwwrssssssssssstwe qwe
sssssssssssssssssd bbb qwwrssssssssssstwe qwe +
ssssssssssssssssstwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwrsssssssssssssssstwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwrstwwwwww3

18
saves/Level3.txt Normal file
View File

@ -0,0 +1,18 @@
wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww

View File

@ -44,6 +44,7 @@ public class GamePanel extends JPanel implements Runnable, KeyListener{
public static Tile[][]map = new Tile[300][18];
public static ArrayList<NonPlayer>enemy = new ArrayList<NonPlayer>();
public static ArrayList<Particle>particles = new ArrayList<Particle>();
public static StickyBomb b;
public static Camera camera;
@ -140,6 +141,13 @@ public class GamePanel extends JPanel implements Runnable, KeyListener{
}
playerFrameCounter += player.draw(g, playerFrame);
b.draw(g);
for(int i=0; i<particles.size(); i++){
particles.get(i).draw(g);
particles.get(i).lifeSpan--;
if(particles.get(i).lifeSpan<=0){
particles.remove(i);
}
}
g.drawString(camera.x+" "+((camera.x+GAME_WIDTH)/Tile.length),100,100);
g.drawString(b.x+" "+((b.x+GamePanel.GAME_WIDTH)/Tile.length-4),100,200);
}
@ -152,6 +160,9 @@ public class GamePanel extends JPanel implements Runnable, KeyListener{
n.move();
}
b.move();
for (Particle p: particles) {
p.move();
}
}
//handles all collision detection and responds accordingly

View File

@ -18,6 +18,10 @@ public class LevelManager {
xSpawn = 200;
ySpawn = 0;
filePath = "saves/Level2.txt";
} else if(level == 3){
xSpawn = 200;
ySpawn = 0;
filePath = "saves/Level3.txt";
}
try {
MapReader.inputMap(filePath);

25
src/Particle.java Normal file
View File

@ -0,0 +1,25 @@
import java.awt.*;
public class Particle extends GenericSprite{
public static final int small = 3;
public static final int big = 10;
public int xVelocity;
public int yVelocity;
public int lifeSpan = 10;
public Particle(int x, int y, int xVelocity, int yVelocity){
super(x,y,(int)(Math.random()*(big-small+1))+3, (int)(Math.random()*(big-small+1))+3);
this.xVelocity = xVelocity;
this.yVelocity = yVelocity;
}
public void move(){
x+=xVelocity;
y+=yVelocity;
}
public void draw(Graphics g){
g.drawRect(x-GamePanel.camera.x,y,WIDTH,HEIGHT);
}
}

View File

@ -157,12 +157,19 @@ public class Player extends GenericSprite {
}
if(rightPressed && xVelocity<5){
xVelocity+=1;
if(rightPressed){
if(isGrounded){
GamePanel.particles.add(new Particle(x+GamePanel.camera.x+WIDTH/2,(int)(y+HEIGHT*0.8),3,3));
}
if(leftPressed && xVelocity>-5) {
if(xVelocity<5) {
xVelocity += 1;
}
}
if(leftPressed) {
if(xVelocity>-5) {
xVelocity -= 1;
}
}
if(upPressed&isGrounded){
y-=1;
isGrounded = false;