This commit is contained in:
wfz
2026-04-25 22:09:27 +08:00
parent 9be6b17593
commit 7bffe41d41
33 changed files with 3461 additions and 581 deletions

View File

@@ -1,7 +1,15 @@
package com.zombie.game.model;
import lombok.Getter;
import java.util.*;
/**
* 子弹/投掷物类
*
* 管理玩家和僵尸发射的子弹、手榴弹等投掷物。
* 支持普通子弹的直线飞行和手榴弹的抛物线轨迹。
*/
@Getter
public class Bullet {
private int id;
private float x, y;
@@ -44,6 +52,19 @@ public class Bullet {
this.targetY = y + (float) Math.cos(angle) * range;
}
/**
* 构造函数 - 手榴弹
*
* @param id 子弹ID
* @param startX 起始X坐标
* @param startY 起始Y坐标
* @param targetX 目标X坐标
* @param targetY 目标Y坐标
* @param flightDuration 飞行时长
* @param damage 伤害值
* @param ownerId 发射者ID
* @param explosionRadius 爆炸半径
*/
public Bullet(int id, float startX, float startY, float targetX, float targetY,
float flightDuration, int damage, String ownerId, float explosionRadius) {
this.id = id;
@@ -71,21 +92,6 @@ public class Bullet {
this.vz = 3.0f;
}
public int getId() { return id; }
public float getX() { return x; }
public float getY() { return y; }
public float getZ() { return z; }
public float getVx() { return vx; }
public float getVy() { return vy; }
public int getDamage() { return damage; }
public String getOwnerId() { return ownerId; }
public String getWeapon() { return weapon; }
public boolean isExplosive() { return explosive; }
public float getExplosionRadius() { return explosionRadius; }
public float getTargetX() { return targetX; }
public float getTargetY() { return targetY; }
public boolean isGrenade() { return isGrenade; }
public boolean update(float dt, GameMap map) {
if (isGrenade) {
flightTime += dt;
@@ -123,6 +129,14 @@ public class Bullet {
}
}
/**
* 检测子弹是否命中实体
*
* @param ex 实体X坐标
* @param ey 实体Y坐标
* @param size 实体碰撞体大小
* @return true 表示命中
*/
public boolean hitsEntity(float ex, float ey, float size) {
float dx = x - ex;
float dy = y - ey;
@@ -130,6 +144,11 @@ public class Bullet {
return dist < size / 2 + 0.1f;
}
/**
* 将子弹状态转换为Map格式用于网络传输
*
* @return 包含子弹状态的Map
*/
public Map<String, Object> toStateMap() {
Map<String, Object> map = new LinkedHashMap<>();
map.put("id", id);