优化项目结构

This commit is contained in:
2025-09-27 15:02:52 +08:00
parent 4f486b367f
commit cee525b82e
61 changed files with 1015 additions and 208 deletions

View File

@@ -0,0 +1,54 @@
package uno.mloluyu.characters.effects;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.MathUtils;
/** 单个命中粒子:简单方块/短线喷射,带速度、重力与淡出。 */
public class HitParticle {
private float x, y;
private float vx, vy;
private float life; // 剩余寿命
private final float totalLife;
private final float size;
private final Color color = new Color();
private static final float GRAVITY = 900f; // 轻微下坠
public HitParticle(float x, float y, Color base, float speedMin, float speedMax, float lifeMin, float lifeMax,
float sizeMin, float sizeMax) {
this.x = x;
this.y = y;
float ang = MathUtils.random(15f, 165f) * MathUtils.degreesToRadians; // 向上扇形
float spd = MathUtils.random(speedMin, speedMax);
this.vx = MathUtils.cos(ang) * spd;
this.vy = MathUtils.sin(ang) * spd;
this.life = MathUtils.random(lifeMin, lifeMax);
this.totalLife = life;
this.size = MathUtils.random(sizeMin, sizeMax);
// 基础色随机稍许扰动
float tint = MathUtils.random(0.85f, 1.05f);
this.color.set(base.r * tint, base.g * tint, base.b * tint, 1f);
}
public boolean isAlive() {
return life > 0f;
}
public void update(float dt) {
if (!isAlive())
return;
life -= dt;
// 运动积分
x += vx * dt;
y += vy * dt;
vy -= GRAVITY * dt * 0.35f; // 轻微重力
}
public void render(ShapeRenderer sr) {
if (!isAlive())
return;
float a = (life / totalLife); // 线性淡出
sr.setColor(color.r, color.g, color.b, a);
sr.rect(x - size / 2f, y - size / 2f, size, size);
}
}