added shitty healthbar to the GUI.
This commit is contained in:
		
							parent
							
								
									e1456707dd
								
							
						
					
					
						commit
						4e0e1a32fa
					
				| 
						 | 
				
			
			@ -169,6 +169,8 @@ public class Client implements Runnable {
 | 
			
		|||
					projectiles.remove(p.getId());
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		} else if (msg instanceof ClientHealthMessage healthMessage) {
 | 
			
		||||
			myPlayer.setHealth(healthMessage.health());
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -9,12 +9,14 @@ import java.util.ArrayList;
 | 
			
		|||
 | 
			
		||||
public class ClientPlayer extends Player {
 | 
			
		||||
	private final Inventory inventory;
 | 
			
		||||
	private float health;
 | 
			
		||||
 | 
			
		||||
	private final Matrix4f heldItemTransform = new Matrix4f();
 | 
			
		||||
	private final float[] heldItemTransformData = new float[16];
 | 
			
		||||
 | 
			
		||||
	public ClientPlayer(int id, String username) {
 | 
			
		||||
		super(id, username);
 | 
			
		||||
		this.health = 1;
 | 
			
		||||
		this.inventory = new Inventory(new ArrayList<>(), 0);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -28,6 +30,14 @@ public class ClientPlayer extends Player {
 | 
			
		|||
		this.inventory.setSelectedIndex(inv.getSelectedIndex());
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public float getHealth() {
 | 
			
		||||
		return health;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void setHealth(float health) {
 | 
			
		||||
		this.health = health;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void updateHeldItemTransform(Camera cam) {
 | 
			
		||||
		heldItemTransform.identity()
 | 
			
		||||
				.translate(cam.getPosition())
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -51,6 +51,8 @@ public class GameRenderer {
 | 
			
		|||
	private GUITexture crosshairTexture;
 | 
			
		||||
	private GUITexture clipTexture;
 | 
			
		||||
	private GUITexture bulletTexture;
 | 
			
		||||
	private GUITexture healthBarRedTexture;
 | 
			
		||||
	private GUITexture healthBarGreenTexture;
 | 
			
		||||
 | 
			
		||||
	private long windowHandle;
 | 
			
		||||
	private int screenWidth = 800;
 | 
			
		||||
| 
						 | 
				
			
			@ -123,9 +125,13 @@ public class GameRenderer {
 | 
			
		|||
		crosshairTexture = new GUITexture("gui/crosshair.png");
 | 
			
		||||
		clipTexture = new GUITexture("gui/clip.png");
 | 
			
		||||
		bulletTexture = new GUITexture("gui/bullet.png");
 | 
			
		||||
		healthBarRedTexture = new GUITexture("gui/health-red.png");
 | 
			
		||||
		healthBarGreenTexture = new GUITexture("gui/health-green.png");
 | 
			
		||||
		guiRenderer.addTexture("crosshair", crosshairTexture);
 | 
			
		||||
		guiRenderer.addTexture("clip", clipTexture);
 | 
			
		||||
		guiRenderer.addTexture("bullet", bulletTexture);
 | 
			
		||||
		guiRenderer.addTexture("health-red", healthBarRedTexture);
 | 
			
		||||
		guiRenderer.addTexture("health-green", healthBarGreenTexture);
 | 
			
		||||
		log.debug("Initialized GUI renderer.");
 | 
			
		||||
 | 
			
		||||
		this.modelRenderer = new ModelRenderer();
 | 
			
		||||
| 
						 | 
				
			
			@ -255,6 +261,21 @@ public class GameRenderer {
 | 
			
		|||
				);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		// Render the player's health.
 | 
			
		||||
		guiRenderer.draw(
 | 
			
		||||
				healthBarRedTexture,
 | 
			
		||||
				healthBarRedTexture.getIdealScaleX(64, screenWidth),
 | 
			
		||||
				healthBarRedTexture.getIdealScaleY(16, screenHeight),
 | 
			
		||||
				-0.90f,
 | 
			
		||||
				-0.90f
 | 
			
		||||
		);
 | 
			
		||||
		guiRenderer.draw(
 | 
			
		||||
				healthBarGreenTexture,
 | 
			
		||||
				healthBarGreenTexture.getIdealScaleX(64 * client.getMyPlayer().getHealth(), screenWidth),
 | 
			
		||||
				healthBarGreenTexture.getIdealScaleY(16, screenHeight),
 | 
			
		||||
				-0.90f,
 | 
			
		||||
				-0.90f
 | 
			
		||||
		);
 | 
			
		||||
		guiRenderer.end();
 | 
			
		||||
 | 
			
		||||
		glfwSwapBuffers(windowHandle);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 90 B  | 
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 90 B  | 
| 
						 | 
				
			
			@ -76,6 +76,10 @@ public class PlayerManager {
 | 
			
		|||
		return clientHandlers.get(id);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public ClientCommunicationHandler getHandler(ServerPlayer player) {
 | 
			
		||||
		return clientHandlers.get(player.getId());
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public Collection<ClientCommunicationHandler> getHandlers() {
 | 
			
		||||
		return Collections.unmodifiableCollection(clientHandlers.values());
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,6 +6,7 @@ import nl.andrewl.aos_core.Directions;
 | 
			
		|||
import nl.andrewl.aos_core.model.Player;
 | 
			
		||||
import nl.andrewl.aos_core.model.Projectile;
 | 
			
		||||
import nl.andrewl.aos_core.model.world.Hit;
 | 
			
		||||
import nl.andrewl.aos_core.net.client.ClientHealthMessage;
 | 
			
		||||
import nl.andrewl.aos_core.net.world.ChunkUpdateMessage;
 | 
			
		||||
import org.joml.Matrix4f;
 | 
			
		||||
import org.joml.Vector3f;
 | 
			
		||||
| 
						 | 
				
			
			@ -122,6 +123,8 @@ public class ProjectileManager {
 | 
			
		|||
			if (hitPlayer.getHealth() == 0) {
 | 
			
		||||
				System.out.println("Player killed!!!");
 | 
			
		||||
				server.getPlayerManager().playerKilled(hitPlayer);
 | 
			
		||||
			} else {
 | 
			
		||||
				server.getPlayerManager().getHandler(hitPlayer).sendDatagramPacket(new ClientHealthMessage(hitPlayer.getHealth()));
 | 
			
		||||
			}
 | 
			
		||||
			deleteProjectile(projectile);
 | 
			
		||||
		} else {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue