Compare commits

...

5 Commits

Author SHA1 Message Date
jordan4ibanez ec2cb8079f run onTick() for client 2022-09-02 23:33:30 -04:00
jordan4ibanez ef1fce1b0f Create loop runner for client 2022-09-02 23:33:19 -04:00
jordan4ibanez f943636512 Implement basic player movement structure 2022-09-02 23:30:37 -04:00
jordan4ibanez 3d8d451965 inertia->velocity 2022-09-02 23:15:47 -04:00
jordan4ibanez fd1e2beefa Give player velocity 2022-09-02 23:14:11 -04:00
3 changed files with 45 additions and 14 deletions

View File

@ -37,6 +37,7 @@ import Window = engine.window.window;
import Camera = engine.camera.camera;
import SoundManager = engine.openal.sound_manager;
import ThreadLibrary = engine.thread.thread_library;
import PlayerClient = game.client.player_client;
void debugCreateBlockGraphics(){
@ -254,6 +255,8 @@ void main(string[] args) {
receiveChunksFromWorldGenerator();
receiveMeshesFromChunkMeshGenerator();
PlayerClient.onTick();
// Automatically plops the FPS and delta time onto the window title
Window.setTitle((
getVersionTitle() ~ " | FPS: " ~ to!string(Window.getFPS()) ~ " | Delta: " ~ to!string(getDelta()))

View File

@ -3,6 +3,7 @@ module game.client.player_client;
import vector_3d;
import vector_2d;
import vector_2i;
import delta_time;
import Math = math;
import Camera = engine.camera.camera;
@ -17,35 +18,62 @@ This is the player that is playing the game.
*/
private Vector3d position = *new Vector3d(0,0,0);
private Vector3d velocity = *new Vector3d(0,0,0);
private Vector3d rotation = *new Vector3d(0,0,0);
private Vector2d size = *new Vector2d(0.35, 1.8);
private double height = 1.5;
private bool inGame = true;
void testCameraHackRemoveThis() {
private static const double[string] speed;
shared static this() {
speed = [
"run" : 5.0,
"walk" : 2.5,
"sneak" : 1.0
];
}
double speed = 100;
private void playerClientIntakeKeyInputs() {
double deltaMultiplier = 100;
// This is an extreme hack for testing remove this garbage
Vector3d modifier = Vector3d(0,0,0);
if(Keyboard.getForward()){
modifier.z -= getDelta() * speed;
modifier.z -= getDelta() * deltaMultiplier;
} else if (Keyboard.getBack()) {
modifier.z += getDelta() * speed;
modifier.z += getDelta() * deltaMultiplier;
}
if(Keyboard.getLeft()){
modifier.x += getDelta() * speed;
modifier.x += getDelta() * deltaMultiplier;
} else if (Keyboard.getRight()) {
modifier.x -= getDelta() * speed;
modifier.x -= getDelta() * deltaMultiplier;
}
// Reserve this for jump and sneak
/*
if (Keyboard.getUp()){
modifier.y += getDelta() * speed;
modifier.y += getDelta() * deltaMultiplier;
} else if (Keyboard.getDown()) {
modifier.y -= getDelta() * speed;
modifier.y -= getDelta() * deltaMultiplier;
}
*/
movePosition(modifier);
//movePosition(modifier);
}
private void addVelocity(Vector3d moreVelocity) {
velocity.x += moreVelocity.x;
velocity.y += moreVelocity.y;
velocity.z += moreVelocity.z;
if (velocity.length() > speed["walk"]) {
velocity.normalize().mul(speed["walk"]);
}
}
void onTick() {
playerClientIntakeKeyInputs();
}

View File

@ -10,7 +10,7 @@ abstract class Entity {
// Entities must have spatial fields
private Vector3d position = *new Vector3d(0,0,0);
private Vector3d inertia = *new Vector3d(0,0,0);
private Vector3d velocity = *new Vector3d(0,0,0);
private Vector3d rotation = *new Vector3d(0,0,0);
// Entities have a width/depth (x) and a height (y)
@ -41,11 +41,11 @@ abstract class Entity {
void setPosition(Vector3d newPosition) {
this.position = newPosition;
}
Vector3d getIneritia() {
return this.inertia;
Vector3d getVelocity() {
return this.velocity;
}
void setInertia(Vector3d newInertia) {
this.inertia = newInertia;
void setVelocity(Vector3d newVelocity) {
this.velocity = newVelocity;
}
Vector3d getRotation() {
return this.rotation;