JacksonHoggard / voodoo2d

👹 2D Java Game Engine built in OpenGL
MIT License
131 stars 50 forks source link

Added and implemented delta time #32

Closed GarrettBassen closed 9 months ago

GarrettBassen commented 9 months ago

Description

Major engine changes and reworks to allow for similar play on different devices. Movement and animations are now time-dependent using delta time as opposed to frame-dependent. This allows the game to run the same without need for locking frame rate with former sync() function or vsync. Fixed update was added which is updated 60 times per second regardless of frame rate.

Fixes and Changes

Timer.java: Removed unused and redundant functions and variables. Added delta time to make calculations time dependent instead of frame dependent. Made functions static

Player.Java: Removed redundant import Changed variable speeds Changed delta position directions Added delta time in movement to make player movement time-dependent instead of frame-dependent

Animation.java: Formatted file Removed redundant and unused variables Renamed variables and functions for readability Fixed run() to use new delta time

GameEngine.java: Removed redundant and unused variables Frame unlocked update() Added fixedUpdate() Implemented delta time in fixed update Removed sync() as it was redundant and overridden by glfwSwapInterval(1) Implemented delta time in FPS counter

GameObject.java: Formatted variables

GameLogic.java: Frame-unlocked update function

Game.java: Changed update() to work with new changes. Made camera follow player

Main.java: Formatted GameEngine() arguments for readability

MapTree.java: Small formatting

Type of change

Checklist:

Possible Bugs and Errors

Animations, while called in fixedUpdate(), are slightly slower when vsync is enabled compared to when frame rate is unlocked. Movement does not appear to be effected by this bug and there does not appear to be any impact on game play.

Tests were conducted to ensure movement speed was the same among multiple frame rates. Further testing on separate devices is encouraged.

GarrettBassen commented 9 months ago

Changes were made. Happy thanksgiving!