Setup is better and small changes.

This commit is contained in:
Kapendev 2024-11-15 00:52:05 +02:00
parent 8f084526e1
commit ec4e7d2eb0
7 changed files with 141 additions and 122 deletions

View file

@ -14,13 +14,11 @@ bool update(float dt) {
// Move the camera.
cameraTarget += wasd * Vec2(cameraSpeed * dt);
camera.followPositionWithSlowdown(cameraTarget, 0.15);
// Draw the game world.
camera.attach();
drawDebugText("Move with arrow keys.", Vec2(8));
drawRect(camera.area.subAll(3), Color(50, 50, 40, 130));
camera.detach();
// Draw the game UI.
drawDebugText("I am UI!", Vec2(8));
drawDebugText("+", resolution * Vec2(0.5));

View file

@ -24,12 +24,10 @@ bool update(float dt) {
mapOptions.scale = Vec2(2);
auto tileOptions = mapOptions;
tileOptions.flip = tileLookDirection > 0 ? Flip.x : Flip.none;
// Move the tile and camera.
tile.position += wasd * Vec2(tileSpeed * dt);
camera.position = tile.position;
if (wasd.x != 0) tileLookDirection = cast(int) wasd.normalize.round.x;
// Check for collisions.
auto collisionArea = Rect();
foreach (gridPosition; map.gridPositions(camera.area, mapOptions)) {

View file

@ -13,8 +13,11 @@ bool update(float dt) {
// Resize the viewport when the window is resized.
if (isWindowResized) viewport.resize(resolutionWidth / 2, resolutionHeight / 2);
// Draw the mouse position inside the viewport.
auto viewportCenter = viewport.size * Vec2(0.5);
auto viewportMousePosition = mouseScreenPosition - Rect(resolution * Vec2(0.5), viewport.size).centerArea.position;
viewport.attach();
drawVec2(mouseScreenPosition - Rect(resolution * Vec2(0.5), viewport.size).centerArea.position, 24);
drawVec2(viewportCenter, 20);
drawVec2(viewportMousePosition, 20);
viewport.detach();
// Draw the viewport and other things inside the window.
drawViewport(viewport, resolution * Vec2(0.5), DrawOptions(Hook.center));