added particles
This commit is contained in:
@@ -5,6 +5,7 @@ import de.miaurizius.jgame2d.core.enums.Direction;
|
||||
import de.miaurizius.jgame2d.core.GamePanel;
|
||||
import de.miaurizius.jgame2d.core.Utility;
|
||||
import de.miaurizius.jgame2d.core.enums.EntityType;
|
||||
import de.miaurizius.jgame2d.entity.particle.Particle;
|
||||
import de.miaurizius.jgame2d.entity.projectile.Projectile;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
@@ -214,6 +215,35 @@ public class Entity {
|
||||
}
|
||||
}
|
||||
|
||||
// PARTICLE SETUP
|
||||
public Color getParticleColor() {
|
||||
return null;
|
||||
}
|
||||
public int getParticleSize() {
|
||||
return -1;
|
||||
}
|
||||
public int getParticleSpeed() {
|
||||
return -1;
|
||||
}
|
||||
public int getParticleMaxLife() {
|
||||
return -1;
|
||||
}
|
||||
public void generateParticle(Entity generator, Entity target) {
|
||||
Color color = generator.getParticleColor();
|
||||
int size = generator.getParticleSize();
|
||||
int speed = generator.getParticleSpeed();
|
||||
int maxLife = generator.getParticleMaxLife();
|
||||
|
||||
Particle p1 = new Particle(panel, generator, color, size, speed, maxLife, -2, -1);
|
||||
Particle p2 = new Particle(panel, generator, color, size, speed, maxLife, 2, -1);
|
||||
Particle p3 = new Particle(panel, generator, color, size, speed, maxLife, -2, 1);
|
||||
Particle p4 = new Particle(panel, generator, color, size, speed, maxLife, 2, 1);
|
||||
panel.particleList.add(p1);
|
||||
panel.particleList.add(p2);
|
||||
panel.particleList.add(p3);
|
||||
panel.particleList.add(p4);
|
||||
}
|
||||
|
||||
// SETTING THINGS UP
|
||||
BufferedImage parseSprite() {
|
||||
return switch (direction) {
|
||||
|
||||
@@ -225,6 +225,7 @@ public class Player extends Entity {
|
||||
panel.iTile[index].playSE();
|
||||
panel.iTile[index].life--;
|
||||
panel.iTile[index].invincible = true;
|
||||
generateParticle(panel.iTile[index], panel.iTile[index]);
|
||||
if(panel.iTile[index].life == 0) panel.iTile[index] = panel.iTile[index].getDestroyedForm();
|
||||
}
|
||||
|
||||
|
||||
50
src/de/miaurizius/jgame2d/entity/particle/Particle.java
Normal file
50
src/de/miaurizius/jgame2d/entity/particle/Particle.java
Normal file
@@ -0,0 +1,50 @@
|
||||
package de.miaurizius.jgame2d.entity.particle;
|
||||
|
||||
import de.miaurizius.jgame2d.core.GamePanel;
|
||||
import de.miaurizius.jgame2d.entity.Entity;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class Particle extends Entity {
|
||||
|
||||
GamePanel panel;
|
||||
Entity generator;
|
||||
Color color;
|
||||
int size;
|
||||
int xd, yd;
|
||||
|
||||
public Particle(GamePanel panel, Entity generator, Color color, int size, int speed, int maxLife, int xd, int yd) {
|
||||
super(panel);
|
||||
this.panel = panel;
|
||||
this.generator = generator;
|
||||
this.color = color;
|
||||
this.size = size;
|
||||
this.speed = speed;
|
||||
this.maxLife = maxLife;
|
||||
this.xd = xd;
|
||||
this.yd = yd;
|
||||
|
||||
life = maxLife;
|
||||
int offset = (panel.tileSize/2) - (size/2);
|
||||
worldX = generator.worldX + offset;
|
||||
worldY = generator.worldY + offset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
life--;
|
||||
if(life < maxLife/3) yd++;
|
||||
worldX += xd*speed;
|
||||
worldY += yd*speed;
|
||||
alive = (life != 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Graphics2D graphics2d) {
|
||||
int screenX = worldX - panel.player.worldX + panel.player.screenX;
|
||||
int screenY = worldY - panel.player.worldY + panel.player.screenY;
|
||||
|
||||
graphics2d.setColor(color);
|
||||
graphics2d.fillRect(screenX, screenY, size, size);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user