Added shotgun!
This commit is contained in:
parent
0f31f32607
commit
2fb608de08
|
@ -31,6 +31,7 @@ public class InputHandler {
|
||||||
if (glfwGetKey(window, GLFW_KEY_1) == GLFW_PRESS) selectedInventoryIndex = 0;
|
if (glfwGetKey(window, GLFW_KEY_1) == GLFW_PRESS) selectedInventoryIndex = 0;
|
||||||
if (glfwGetKey(window, GLFW_KEY_2) == GLFW_PRESS) selectedInventoryIndex = 1;
|
if (glfwGetKey(window, GLFW_KEY_2) == GLFW_PRESS) selectedInventoryIndex = 1;
|
||||||
if (glfwGetKey(window, GLFW_KEY_3) == GLFW_PRESS) selectedInventoryIndex = 2;
|
if (glfwGetKey(window, GLFW_KEY_3) == GLFW_PRESS) selectedInventoryIndex = 2;
|
||||||
|
if (glfwGetKey(window, GLFW_KEY_4) == GLFW_PRESS) selectedInventoryIndex = 3;
|
||||||
|
|
||||||
ClientInputState currentInputState = new ClientInputState(
|
ClientInputState currentInputState = new ClientInputState(
|
||||||
comm.getClientId(),
|
comm.getClientId(),
|
||||||
|
|
|
@ -66,6 +66,7 @@ public class SoundManager {
|
||||||
load("footsteps_4", "sound/m_footsteps_4.wav");
|
load("footsteps_4", "sound/m_footsteps_4.wav");
|
||||||
load("shot_m1-garand_1", "sound/m_shot_m1-garand_1.wav");
|
load("shot_m1-garand_1", "sound/m_shot_m1-garand_1.wav");
|
||||||
load("shot_ak-47_1", "sound/m_shot_ak-47_1.wav");
|
load("shot_ak-47_1", "sound/m_shot_ak-47_1.wav");
|
||||||
|
load("shot_winchester_1", "sound/m_shot_winchester_1.wav");
|
||||||
load("bullet_impact_1", "sound/m_bullet_impact_1.wav");
|
load("bullet_impact_1", "sound/m_bullet_impact_1.wav");
|
||||||
load("bullet_impact_2", "sound/m_bullet_impact_2.wav");
|
load("bullet_impact_2", "sound/m_bullet_impact_2.wav");
|
||||||
load("bullet_impact_3", "sound/m_bullet_impact_3.wav");
|
load("bullet_impact_3", "sound/m_bullet_impact_3.wav");
|
||||||
|
|
|
@ -2,6 +2,7 @@ package nl.andrewl.aos_core.model.item;
|
||||||
|
|
||||||
import nl.andrewl.aos_core.model.item.gun.Ak47;
|
import nl.andrewl.aos_core.model.item.gun.Ak47;
|
||||||
import nl.andrewl.aos_core.model.item.gun.Rifle;
|
import nl.andrewl.aos_core.model.item.gun.Rifle;
|
||||||
|
import nl.andrewl.aos_core.model.item.gun.Winchester;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -16,11 +17,13 @@ public final class ItemTypes {
|
||||||
public static final BlockItem BLOCK = new BlockItem(1);
|
public static final BlockItem BLOCK = new BlockItem(1);
|
||||||
public static final Rifle RIFLE = new Rifle(2);
|
public static final Rifle RIFLE = new Rifle(2);
|
||||||
public static final Ak47 AK_47 = new Ak47(3);
|
public static final Ak47 AK_47 = new Ak47(3);
|
||||||
|
public static final Winchester WINCHESTER = new Winchester(4);
|
||||||
|
|
||||||
static {
|
static {
|
||||||
registerType(BLOCK);
|
registerType(BLOCK);
|
||||||
registerType(RIFLE);
|
registerType(RIFLE);
|
||||||
registerType(AK_47);
|
registerType(AK_47);
|
||||||
|
registerType(WINCHESTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void registerType(Item type) {
|
public static void registerType(Item type) {
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
package nl.andrewl.aos_core.model.item.gun;
|
||||||
|
|
||||||
|
import nl.andrewl.aos_core.model.item.Gun;
|
||||||
|
|
||||||
|
public class Winchester extends Gun {
|
||||||
|
public Winchester(int id) {
|
||||||
|
super(
|
||||||
|
id,
|
||||||
|
"Winchester",
|
||||||
|
10,
|
||||||
|
6,
|
||||||
|
4,
|
||||||
|
0.85f,
|
||||||
|
0.75f,
|
||||||
|
2.5f,
|
||||||
|
0.3f,
|
||||||
|
60f,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -34,19 +34,24 @@ public class ProjectileManager {
|
||||||
this.removalQueue = new LinkedList<>();
|
this.removalQueue = new LinkedList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void spawnBullet(ServerPlayer player, Gun gun) {
|
public void spawnBullets(ServerPlayer player, Gun gun) {
|
||||||
|
Random rand = ThreadLocalRandom.current();
|
||||||
|
Vector3f pos = new Vector3f();
|
||||||
|
Vector3f direction = new Vector3f();
|
||||||
|
Matrix4f bulletTransform = new Matrix4f();
|
||||||
|
|
||||||
|
for (int i = 0; i < gun.getBulletsPerRound(); i++) {
|
||||||
int id = nextProjectileId++;
|
int id = nextProjectileId++;
|
||||||
if (nextProjectileId == Integer.MAX_VALUE) nextProjectileId = 1;
|
if (nextProjectileId == Integer.MAX_VALUE) nextProjectileId = 1;
|
||||||
Random rand = ThreadLocalRandom.current();
|
|
||||||
|
|
||||||
Vector3f pos = new Vector3f();
|
pos.set(0);
|
||||||
Matrix4f bulletTransform = new Matrix4f()
|
bulletTransform.identity()
|
||||||
.translate(player.getEyePosition())
|
.translate(player.getEyePosition())
|
||||||
.rotate(player.getOrientation().x + (float) Math.PI, Directions.UPf)
|
.rotate(player.getOrientation().x + (float) Math.PI, Directions.UPf)
|
||||||
.translate(-0.35f, -0.4f, 0.35f);
|
.translate(-0.35f, -0.4f, 0.35f);
|
||||||
bulletTransform.transformPosition(pos);
|
bulletTransform.transformPosition(pos);
|
||||||
|
|
||||||
Vector3f direction = new Vector3f(player.getViewVector()).normalize();
|
direction.set(player.getViewVector()).normalize();
|
||||||
float accuracy = gun.getAccuracy();
|
float accuracy = gun.getAccuracy();
|
||||||
accuracy -= server.getConfig().actions.movementAccuracyDecreaseFactor * player.getVelocity().length();
|
accuracy -= server.getConfig().actions.movementAccuracyDecreaseFactor * player.getVelocity().length();
|
||||||
float perturbationFactor = (1 - accuracy) / 8;
|
float perturbationFactor = (1 - accuracy) / 8;
|
||||||
|
@ -58,10 +63,11 @@ public class ProjectileManager {
|
||||||
.mul(200 * MOVEMENT_FACTOR)
|
.mul(200 * MOVEMENT_FACTOR)
|
||||||
.add(player.getVelocity());
|
.add(player.getVelocity());
|
||||||
|
|
||||||
ServerProjectile bullet = new ServerProjectile(id, pos, vel, Projectile.Type.BULLET, player);
|
ServerProjectile bullet = new ServerProjectile(id, new Vector3f(pos), vel, Projectile.Type.BULLET, player);
|
||||||
projectiles.put(bullet.getId(), bullet);
|
projectiles.put(bullet.getId(), bullet);
|
||||||
server.getPlayerManager().broadcastUdpMessage(bullet.toMessage(false));
|
server.getPlayerManager().broadcastUdpMessage(bullet.toMessage(false));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void tick(float dt) {
|
public void tick(float dt) {
|
||||||
for (var projectile : projectiles.values()) {
|
for (var projectile : projectiles.values()) {
|
||||||
|
|
|
@ -9,6 +9,7 @@ import nl.andrewl.aos_core.model.item.GunItemStack;
|
||||||
import nl.andrewl.aos_core.model.item.ItemStack;
|
import nl.andrewl.aos_core.model.item.ItemStack;
|
||||||
import nl.andrewl.aos_core.model.item.gun.Ak47;
|
import nl.andrewl.aos_core.model.item.gun.Ak47;
|
||||||
import nl.andrewl.aos_core.model.item.gun.Rifle;
|
import nl.andrewl.aos_core.model.item.gun.Rifle;
|
||||||
|
import nl.andrewl.aos_core.model.item.gun.Winchester;
|
||||||
import nl.andrewl.aos_core.model.world.World;
|
import nl.andrewl.aos_core.model.world.World;
|
||||||
import nl.andrewl.aos_core.net.client.ClientInputState;
|
import nl.andrewl.aos_core.net.client.ClientInputState;
|
||||||
import nl.andrewl.aos_core.net.client.InventorySelectedStackMessage;
|
import nl.andrewl.aos_core.net.client.InventorySelectedStackMessage;
|
||||||
|
@ -111,7 +112,7 @@ public class PlayerActionManager {
|
||||||
now - gunLastShotAt > gun.getShotCooldownTime() * 1000 &&
|
now - gunLastShotAt > gun.getShotCooldownTime() * 1000 &&
|
||||||
(gun.isAutomatic() || !gunNeedsReCock)
|
(gun.isAutomatic() || !gunNeedsReCock)
|
||||||
) {
|
) {
|
||||||
server.getProjectileManager().spawnBullet(player, gun);
|
server.getProjectileManager().spawnBullets(player, gun);
|
||||||
g.setBulletCount(g.getBulletCount() - 1);
|
g.setBulletCount(g.getBulletCount() - 1);
|
||||||
gunLastShotAt = now;
|
gunLastShotAt = now;
|
||||||
if (!gun.isAutomatic()) {
|
if (!gun.isAutomatic()) {
|
||||||
|
@ -123,6 +124,8 @@ public class PlayerActionManager {
|
||||||
shotSound = "shot_m1-garand_1";
|
shotSound = "shot_m1-garand_1";
|
||||||
} else if (gun instanceof Ak47) {
|
} else if (gun instanceof Ak47) {
|
||||||
shotSound = "shot_ak-47_1";
|
shotSound = "shot_ak-47_1";
|
||||||
|
} else if (gun instanceof Winchester) {
|
||||||
|
shotSound = "shot_winchester_1";
|
||||||
}
|
}
|
||||||
server.getPlayerManager().broadcastUdpMessage(new SoundMessage(shotSound, 1, player.getPosition(), player.getVelocity()));
|
server.getPlayerManager().broadcastUdpMessage(new SoundMessage(shotSound, 1, player.getPosition(), player.getVelocity()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import nl.andrewl.aos_core.model.item.BlockItemStack;
|
||||||
import nl.andrewl.aos_core.model.item.GunItemStack;
|
import nl.andrewl.aos_core.model.item.GunItemStack;
|
||||||
import nl.andrewl.aos_core.model.item.Inventory;
|
import nl.andrewl.aos_core.model.item.Inventory;
|
||||||
import nl.andrewl.aos_core.model.item.ItemTypes;
|
import nl.andrewl.aos_core.model.item.ItemTypes;
|
||||||
|
import nl.andrewl.aos_core.model.item.gun.Winchester;
|
||||||
import nl.andrewl.aos_core.net.client.PlayerUpdateMessage;
|
import nl.andrewl.aos_core.net.client.PlayerUpdateMessage;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -34,8 +35,9 @@ public class ServerPlayer extends Player {
|
||||||
this.health = 1f;
|
this.health = 1f;
|
||||||
this.actionManager = new PlayerActionManager(this);
|
this.actionManager = new PlayerActionManager(this);
|
||||||
inventory.getItemStacks().add(new GunItemStack(ItemTypes.RIFLE));
|
inventory.getItemStacks().add(new GunItemStack(ItemTypes.RIFLE));
|
||||||
inventory.getItemStacks().add(new BlockItemStack(ItemTypes.BLOCK, 50, (byte) 1));
|
|
||||||
inventory.getItemStacks().add(new GunItemStack(ItemTypes.AK_47));
|
inventory.getItemStacks().add(new GunItemStack(ItemTypes.AK_47));
|
||||||
|
inventory.getItemStacks().add(new GunItemStack(ItemTypes.WINCHESTER));
|
||||||
|
inventory.getItemStacks().add(new BlockItemStack(ItemTypes.BLOCK, 50, (byte) 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayerActionManager getActionManager() {
|
public PlayerActionManager getActionManager() {
|
||||||
|
|
Loading…
Reference in New Issue