Camera finally working.
This commit is contained in:
@ -13,4 +13,5 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
typedef bool bool_t;
|
||||
typedef int int_t;
|
||||
typedef int int_t;
|
||||
typedef float float_t;
|
@ -22,8 +22,6 @@ void main(void) {
|
||||
while(!renderShouldExit()) {
|
||||
renderDraw();
|
||||
|
||||
OVERWORLD_CAMERA_SUB_X++;
|
||||
|
||||
overworldUpdate();
|
||||
}
|
||||
|
||||
|
@ -8,12 +8,12 @@
|
||||
#pragma once
|
||||
#include "tile.h"
|
||||
|
||||
#define CHUNK_MAP_WIDTH 5
|
||||
#define CHUNK_MAP_HEIGHT 5
|
||||
#define CHUNK_MAP_WIDTH 4
|
||||
#define CHUNK_MAP_HEIGHT 4
|
||||
#define CHUNK_MAP_COUNT (CHUNK_MAP_WIDTH * CHUNK_MAP_HEIGHT)
|
||||
|
||||
#define CHUNK_WIDTH 4
|
||||
#define CHUNK_HEIGHT 4
|
||||
#define CHUNK_WIDTH 8
|
||||
#define CHUNK_HEIGHT 8
|
||||
#define CHUNK_TILE_COUNT (CHUNK_WIDTH * CHUNK_HEIGHT)
|
||||
|
||||
typedef struct {
|
||||
|
@ -8,44 +8,41 @@
|
||||
#include "overworld.h"
|
||||
#include "chunk.h"
|
||||
#include "display/render.h"
|
||||
#include "assert/assert.h"
|
||||
|
||||
uint16_t OVERWORLD_CAMERA_X = 0;
|
||||
int8_t OVERWORLD_CAMERA_SUB_X = 0;
|
||||
uint16_t OVERWORLD_CAMERA_Y = 0;
|
||||
int8_t OVERWORLD_CAMERA_SUB_Y = 0;
|
||||
uint32_t OVERWORLD_CAMERA_X;
|
||||
uint32_t OVERWORLD_CAMERA_Y;
|
||||
overworldcameratype_t OVERWORLD_CAMERA_TYPE;
|
||||
|
||||
void overworldInit(void) {
|
||||
OVERWORLD_CAMERA_X = 0;
|
||||
OVERWORLD_CAMERA_SUB_X = 0;
|
||||
OVERWORLD_CAMERA_Y = 0;
|
||||
OVERWORLD_CAMERA_SUB_Y = 0;
|
||||
|
||||
chunkMapInit();
|
||||
OVERWORLD_CAMERA_X = 0;
|
||||
OVERWORLD_CAMERA_Y = 0;
|
||||
OVERWORLD_CAMERA_TYPE = OVERWORLD_CAMERA_TYPE_CENTERED_POSITION;
|
||||
}
|
||||
|
||||
void overworldUpdate() {
|
||||
while(OVERWORLD_CAMERA_SUB_X >= TILE_WIDTH) {
|
||||
OVERWORLD_CAMERA_SUB_X -= TILE_WIDTH;
|
||||
OVERWORLD_CAMERA_X++;
|
||||
}
|
||||
|
||||
while(OVERWORLD_CAMERA_SUB_X < 0) {
|
||||
OVERWORLD_CAMERA_SUB_X += TILE_WIDTH;
|
||||
OVERWORLD_CAMERA_X--;
|
||||
}
|
||||
|
||||
while(OVERWORLD_CAMERA_SUB_Y >= TILE_HEIGHT) {
|
||||
OVERWORLD_CAMERA_SUB_Y -= TILE_HEIGHT;
|
||||
OVERWORLD_CAMERA_Y++;
|
||||
}
|
||||
|
||||
while(OVERWORLD_CAMERA_SUB_Y < 0) {
|
||||
OVERWORLD_CAMERA_SUB_Y += TILE_HEIGHT;
|
||||
OVERWORLD_CAMERA_Y--;
|
||||
}
|
||||
|
||||
chunkMapSetPosition(
|
||||
(OVERWORLD_CAMERA_X - (RENDER_WIDTH / 2 / TILE_WIDTH)) / CHUNK_WIDTH,
|
||||
(OVERWORLD_CAMERA_Y - (RENDER_HEIGHT / 2 / TILE_HEIGHT)) / CHUNK_HEIGHT
|
||||
void overworldUpdate() {
|
||||
assertTrue(
|
||||
OVERWORLD_CAMERA_X < OVERWORLD_CAMERA_LIMIT_X,
|
||||
"Camera position limit (just because I haven't tested properly)"
|
||||
);
|
||||
assertTrue(
|
||||
OVERWORLD_CAMERA_Y < OVERWORLD_CAMERA_LIMIT_Y,
|
||||
"Camera position limit (just because I haven't tested properly)"
|
||||
);
|
||||
|
||||
uint16_t x, y;
|
||||
if(OVERWORLD_CAMERA_X < RENDER_WIDTH / 2) {
|
||||
x = 0;
|
||||
} else {
|
||||
x = (OVERWORLD_CAMERA_X - (RENDER_WIDTH / 2)) / (CHUNK_WIDTH * TILE_WIDTH);
|
||||
}
|
||||
|
||||
if(OVERWORLD_CAMERA_Y < RENDER_HEIGHT / 2) {
|
||||
y = 0;
|
||||
} else {
|
||||
y = (OVERWORLD_CAMERA_Y - (RENDER_HEIGHT / 2)) / (CHUNK_HEIGHT * TILE_HEIGHT);
|
||||
}
|
||||
|
||||
chunkMapSetPosition(x, y);
|
||||
}
|
@ -8,11 +8,16 @@
|
||||
#pragma once
|
||||
#include "dusk.h"
|
||||
|
||||
extern uint16_t OVERWORLD_CAMERA_X;
|
||||
extern int8_t OVERWORLD_CAMERA_SUB_X;
|
||||
extern uint16_t OVERWORLD_CAMERA_Y;
|
||||
extern int8_t OVERWORLD_CAMERA_SUB_Y;
|
||||
typedef enum {
|
||||
OVERWORLD_CAMERA_TYPE_CENTERED_POSITION,
|
||||
} overworldcameratype_t;
|
||||
|
||||
extern uint32_t OVERWORLD_CAMERA_X;
|
||||
extern uint32_t OVERWORLD_CAMERA_Y;
|
||||
extern overworldcameratype_t OVERWORLD_CAMERA_TYPE;
|
||||
|
||||
#define OVERWORLD_CAMERA_LIMIT_X (UINT32_MAX / 4)
|
||||
#define OVERWORLD_CAMERA_LIMIT_Y (UINT32_MAX / 4)
|
||||
|
||||
/**
|
||||
* Initializes the overworld.
|
||||
|
@ -22,18 +22,19 @@ void drawOverworldInit(void) {
|
||||
}
|
||||
|
||||
void drawOverworldDraw(void) {
|
||||
BeginMode2D(DRAW_OVERWORLD_CAMERA);
|
||||
if(OVERWORLD_CAMERA_X < RENDER_WIDTH / 2) {
|
||||
DRAW_OVERWORLD_CAMERA.target.x = 0;
|
||||
} else {
|
||||
DRAW_OVERWORLD_CAMERA.target.x = (OVERWORLD_CAMERA_X - RENDER_WIDTH) / 2;
|
||||
}
|
||||
|
||||
DRAW_OVERWORLD_CAMERA.target.x = (
|
||||
OVERWORLD_CAMERA_X * TILE_WIDTH + OVERWORLD_CAMERA_SUB_X
|
||||
) - (
|
||||
RENDER_WIDTH / 2
|
||||
);
|
||||
DRAW_OVERWORLD_CAMERA.target.y = (
|
||||
OVERWORLD_CAMERA_Y * TILE_HEIGHT + OVERWORLD_CAMERA_SUB_Y
|
||||
) - (
|
||||
RENDER_HEIGHT / 2
|
||||
);
|
||||
if(OVERWORLD_CAMERA_Y < RENDER_HEIGHT / 2) {
|
||||
DRAW_OVERWORLD_CAMERA.target.y = 0;
|
||||
} else {
|
||||
DRAW_OVERWORLD_CAMERA.target.y = (OVERWORLD_CAMERA_Y - RENDER_HEIGHT) / 2;
|
||||
}
|
||||
|
||||
BeginMode2D(DRAW_OVERWORLD_CAMERA);
|
||||
|
||||
chunk_t *chunk = CHUNK_MAP.chunks;
|
||||
do {
|
||||
|
@ -14,8 +14,8 @@ RenderTexture2D RENDER_SCREEN_TEXTURE;
|
||||
|
||||
void renderInit(void) {
|
||||
InitWindow(
|
||||
RENDER_WIDTH * 2,
|
||||
RENDER_HEIGHT * 2,
|
||||
RENDER_WIDTH * 3,
|
||||
RENDER_HEIGHT * 3,
|
||||
"Dusk Raylib Render"
|
||||
);
|
||||
SetTargetFPS(60);
|
||||
|
Reference in New Issue
Block a user