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