1
This commit is contained in:
@@ -20,7 +20,7 @@ public class Bullet {
|
||||
private float speed;
|
||||
private int damage;
|
||||
private String ownerId;
|
||||
private String weapon;
|
||||
private int weaponIndex;
|
||||
private float range;
|
||||
private float distanceTraveled;
|
||||
private boolean explosive;
|
||||
@@ -31,7 +31,7 @@ public class Bullet {
|
||||
private boolean isGrenade;
|
||||
|
||||
public Bullet(int id, float x, float y, float angle, float speed, int damage,
|
||||
String ownerId, String weapon, float range) {
|
||||
String ownerId, int weaponIndex, float range) {
|
||||
this.id = id;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
@@ -42,21 +42,21 @@ public class Bullet {
|
||||
this.vz = 0;
|
||||
this.damage = damage;
|
||||
this.ownerId = ownerId;
|
||||
this.weapon = weapon;
|
||||
this.weaponIndex = weaponIndex;
|
||||
this.range = range;
|
||||
this.distanceTraveled = 0;
|
||||
this.explosive = weapon.equals(Constants.WEAPON_GRENADE);
|
||||
this.explosionRadius = explosive ? 3.0f : 0;
|
||||
this.explosive = false;
|
||||
this.explosionRadius = 0;
|
||||
this.flightTime = 0;
|
||||
this.maxFlightTime = 0;
|
||||
this.isGrenade = weapon.equals(Constants.WEAPON_GRENADE);
|
||||
this.isGrenade = false;
|
||||
this.targetX = x + (float) Math.sin(angle) * range;
|
||||
this.targetY = y + (float) Math.cos(angle) * range;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造函数 - 手榴弹
|
||||
*
|
||||
*
|
||||
* @param id 子弹ID
|
||||
* @param startX 起始X坐标
|
||||
* @param startY 起始Y坐标
|
||||
@@ -67,7 +67,7 @@ public class Bullet {
|
||||
* @param ownerId 发射者ID
|
||||
* @param explosionRadius 爆炸半径
|
||||
*/
|
||||
public Bullet(int id, float startX, float startY, float targetX, float targetY,
|
||||
public Bullet(int id, float startX, float startY, float targetX, float targetY,
|
||||
float flightDuration, int damage, String ownerId, float explosionRadius) {
|
||||
this.id = id;
|
||||
this.x = startX;
|
||||
@@ -77,7 +77,7 @@ public class Bullet {
|
||||
this.targetY = targetY;
|
||||
this.damage = damage;
|
||||
this.ownerId = ownerId;
|
||||
this.weapon = Constants.WEAPON_GRENADE;
|
||||
this.weaponIndex = -1;
|
||||
this.range = 0;
|
||||
this.distanceTraveled = 0;
|
||||
this.explosive = true;
|
||||
@@ -97,21 +97,21 @@ public class Bullet {
|
||||
public boolean update(float dt, GameMap map) {
|
||||
if (isGrenade) {
|
||||
flightTime += dt;
|
||||
|
||||
|
||||
x += vx * dt;
|
||||
y += vy * dt;
|
||||
|
||||
|
||||
float progress = flightTime / maxFlightTime;
|
||||
z = 0.5f + 4.0f * (float) Math.sin(progress * Math.PI);
|
||||
|
||||
|
||||
if (flightTime >= maxFlightTime || z <= 0.5f && progress > 0.5f) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (x < 0 || x >= Constants.GRID_SIZE || y < 0 || y >= Constants.GRID_SIZE) {
|
||||
|
||||
if (x < 0 || x >= GRID_SIZE || y < 0 || y >= GRID_SIZE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
} else {
|
||||
float moveX = vx * dt;
|
||||
@@ -121,7 +121,7 @@ public class Bullet {
|
||||
distanceTraveled += (float) Math.sqrt(moveX * moveX + moveY * moveY);
|
||||
|
||||
if (distanceTraveled >= range) return false;
|
||||
if (x < 0 || x >= Constants.GRID_SIZE || y < 0 || y >= Constants.GRID_SIZE) return false;
|
||||
if (x < 0 || x >= GRID_SIZE || y < 0 || y >= GRID_SIZE) return false;
|
||||
|
||||
int gx = (int) Math.floor(x);
|
||||
int gy = (int) Math.floor(y);
|
||||
@@ -135,7 +135,7 @@ public class Bullet {
|
||||
|
||||
/**
|
||||
* 检测子弹是否命中实体
|
||||
*
|
||||
*
|
||||
* @param ex 实体X坐标
|
||||
* @param ey 实体Y坐标
|
||||
* @param size 实体碰撞体大小
|
||||
@@ -150,7 +150,7 @@ public class Bullet {
|
||||
|
||||
/**
|
||||
* 将子弹状态转换为Map格式,用于网络传输
|
||||
*
|
||||
*
|
||||
* @return 包含子弹状态的Map
|
||||
*/
|
||||
public Map<String, Object> toStateMap() {
|
||||
@@ -166,7 +166,7 @@ public class Bullet {
|
||||
} else {
|
||||
map.put("angle", (float) Math.atan2(vx, vy));
|
||||
}
|
||||
map.put("weapon", weapon);
|
||||
map.put("weaponIndex", weaponIndex);
|
||||
map.put("ownerId", ownerId);
|
||||
return map;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user