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_2) == GLFW_PRESS) selectedInventoryIndex = 1;
|
||||
if (glfwGetKey(window, GLFW_KEY_3) == GLFW_PRESS) selectedInventoryIndex = 2;
|
||||
if (glfwGetKey(window, GLFW_KEY_4) == GLFW_PRESS) selectedInventoryIndex = 3;
|
||||
|
||||
ClientInputState currentInputState = new ClientInputState(
|
||||
comm.getClientId(),
|
||||
|
|
|
@ -66,6 +66,7 @@ public class SoundManager {
|
|||
load("footsteps_4", "sound/m_footsteps_4.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_winchester_1", "sound/m_shot_winchester_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_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.Rifle;
|
||||
import nl.andrewl.aos_core.model.item.gun.Winchester;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
@ -16,11 +17,13 @@ public final class ItemTypes {
|
|||
public static final BlockItem BLOCK = new BlockItem(1);
|
||||
public static final Rifle RIFLE = new Rifle(2);
|
||||
public static final Ak47 AK_47 = new Ak47(3);
|
||||
public static final Winchester WINCHESTER = new Winchester(4);
|
||||
|
||||
static {
|
||||
registerType(BLOCK);
|
||||
registerType(RIFLE);
|
||||
registerType(AK_47);
|
||||
registerType(WINCHESTER);
|
||||
}
|
||||
|
||||
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,33 +34,39 @@ public class ProjectileManager {
|
|||
this.removalQueue = new LinkedList<>();
|
||||
}
|
||||
|
||||
public void spawnBullet(ServerPlayer player, Gun gun) {
|
||||
int id = nextProjectileId++;
|
||||
if (nextProjectileId == Integer.MAX_VALUE) nextProjectileId = 1;
|
||||
public void spawnBullets(ServerPlayer player, Gun gun) {
|
||||
Random rand = ThreadLocalRandom.current();
|
||||
|
||||
Vector3f pos = new Vector3f();
|
||||
Matrix4f bulletTransform = new Matrix4f()
|
||||
.translate(player.getEyePosition())
|
||||
.rotate(player.getOrientation().x + (float) Math.PI, Directions.UPf)
|
||||
.translate(-0.35f, -0.4f, 0.35f);
|
||||
bulletTransform.transformPosition(pos);
|
||||
Vector3f direction = new Vector3f();
|
||||
Matrix4f bulletTransform = new Matrix4f();
|
||||
|
||||
Vector3f direction = new Vector3f(player.getViewVector()).normalize();
|
||||
float accuracy = gun.getAccuracy();
|
||||
accuracy -= server.getConfig().actions.movementAccuracyDecreaseFactor * player.getVelocity().length();
|
||||
float perturbationFactor = (1 - accuracy) / 8;
|
||||
direction.x += rand.nextGaussian(0, perturbationFactor);
|
||||
direction.y += rand.nextGaussian(0, perturbationFactor);
|
||||
direction.z += rand.nextGaussian(0, perturbationFactor);
|
||||
for (int i = 0; i < gun.getBulletsPerRound(); i++) {
|
||||
int id = nextProjectileId++;
|
||||
if (nextProjectileId == Integer.MAX_VALUE) nextProjectileId = 1;
|
||||
|
||||
Vector3f vel = new Vector3f(direction).normalize()
|
||||
.mul(200 * MOVEMENT_FACTOR)
|
||||
.add(player.getVelocity());
|
||||
pos.set(0);
|
||||
bulletTransform.identity()
|
||||
.translate(player.getEyePosition())
|
||||
.rotate(player.getOrientation().x + (float) Math.PI, Directions.UPf)
|
||||
.translate(-0.35f, -0.4f, 0.35f);
|
||||
bulletTransform.transformPosition(pos);
|
||||
|
||||
ServerProjectile bullet = new ServerProjectile(id, pos, vel, Projectile.Type.BULLET, player);
|
||||
projectiles.put(bullet.getId(), bullet);
|
||||
server.getPlayerManager().broadcastUdpMessage(bullet.toMessage(false));
|
||||
direction.set(player.getViewVector()).normalize();
|
||||
float accuracy = gun.getAccuracy();
|
||||
accuracy -= server.getConfig().actions.movementAccuracyDecreaseFactor * player.getVelocity().length();
|
||||
float perturbationFactor = (1 - accuracy) / 8;
|
||||
direction.x += rand.nextGaussian(0, perturbationFactor);
|
||||
direction.y += rand.nextGaussian(0, perturbationFactor);
|
||||
direction.z += rand.nextGaussian(0, perturbationFactor);
|
||||
|
||||
Vector3f vel = new Vector3f(direction).normalize()
|
||||
.mul(200 * MOVEMENT_FACTOR)
|
||||
.add(player.getVelocity());
|
||||
|
||||
ServerProjectile bullet = new ServerProjectile(id, new Vector3f(pos), vel, Projectile.Type.BULLET, player);
|
||||
projectiles.put(bullet.getId(), bullet);
|
||||
server.getPlayerManager().broadcastUdpMessage(bullet.toMessage(false));
|
||||
}
|
||||
}
|
||||
|
||||
public void tick(float dt) {
|
||||
|
|
|
@ -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.gun.Ak47;
|
||||
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.net.client.ClientInputState;
|
||||
import nl.andrewl.aos_core.net.client.InventorySelectedStackMessage;
|
||||
|
@ -111,7 +112,7 @@ public class PlayerActionManager {
|
|||
now - gunLastShotAt > gun.getShotCooldownTime() * 1000 &&
|
||||
(gun.isAutomatic() || !gunNeedsReCock)
|
||||
) {
|
||||
server.getProjectileManager().spawnBullet(player, gun);
|
||||
server.getProjectileManager().spawnBullets(player, gun);
|
||||
g.setBulletCount(g.getBulletCount() - 1);
|
||||
gunLastShotAt = now;
|
||||
if (!gun.isAutomatic()) {
|
||||
|
@ -123,6 +124,8 @@ public class PlayerActionManager {
|
|||
shotSound = "shot_m1-garand_1";
|
||||
} else if (gun instanceof Ak47) {
|
||||
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()));
|
||||
}
|
||||
|
|
|
@ -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.Inventory;
|
||||
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 org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -34,8 +35,9 @@ public class ServerPlayer extends Player {
|
|||
this.health = 1f;
|
||||
this.actionManager = new PlayerActionManager(this);
|
||||
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.WINCHESTER));
|
||||
inventory.getItemStacks().add(new BlockItemStack(ItemTypes.BLOCK, 50, (byte) 1));
|
||||
}
|
||||
|
||||
public PlayerActionManager getActionManager() {
|
||||
|
|
Loading…
Reference in New Issue