dummy camera

This commit is contained in:
KikooDX 2021-11-10 12:10:04 +01:00
parent 69fb783dc6
commit b5b5c24dac
7 changed files with 54 additions and 5 deletions

View File

@ -17,6 +17,7 @@ set(SOURCES
src/level.c
src/player.c
src/util.c
src/camera.c
)
set(LEVELS

11
inc/camera.h Normal file
View File

@ -0,0 +1,11 @@
#pragma once
#include "vec.h"
struct Camera {
struct Vec *follow;
struct VecF pos;
};
void camera_init(struct Vec *follow);
void camera_update(void);
struct Vec camera_offset(void);

View File

@ -13,3 +13,4 @@ void player_draw(void);
/* return truncated speed */
struct Vec player_update_rem(void);
void player_move(struct Vec spd);
struct Vec *player_pos(void);

22
src/camera.c Normal file
View File

@ -0,0 +1,22 @@
#include "camera.h"
#include "vec.h"
static struct Camera self;
void
camera_init(struct Vec *follow)
{
self.follow = follow;
self.pos = VECF(follow->x, follow->y);
}
void
camera_update(void)
{
}
struct Vec
camera_offset(void)
{
return VEC(0, 0);
}

View File

@ -1,4 +1,5 @@
#include "level.h"
#include "camera.h"
#include "conf.h"
#include "tile.h"
#include "vec.h"
@ -31,13 +32,14 @@ level_draw(void)
{
extern bopti_image_t bimg_tileset;
const int tileset_width = bimg_tileset.width / TILE_SIZE;
const struct Vec off = camera_offset();
int i;
int x = 0;
int y = 0;
for (i = 0; i < self.size; i++) {
const int sx = x * TILE_SIZE;
const int sy = y * TILE_SIZE;
const int sx = x * TILE_SIZE + off.x;
const int sy = y * TILE_SIZE + off.y;
const int tile = self.data[i];
const int rx = tile % tileset_width * TILE_SIZE;
const int ry = tile / tileset_width * TILE_SIZE;

View File

@ -1,3 +1,4 @@
#include "camera.h"
#include "conf.h"
#include "input.h"
#include "level.h"
@ -8,7 +9,6 @@
#include <gint/timer.h>
extern struct LevelBin lvl_test;
struct Player player;
static void update(void);
static void draw(void);
@ -27,6 +27,7 @@ main(void)
input_init();
level_load(&lvl_test);
player_init(level_find(TILE_VOID));
camera_init(player_pos());
while (!input_pressed(K_EXIT)) {
int i;
@ -53,6 +54,7 @@ update(void)
{
input_update();
player_update();
camera_update();
}
static void

View File

@ -1,4 +1,5 @@
#include "player.h"
#include "camera.h"
#include "conf.h"
#include "input.h"
#include "level.h"
@ -46,8 +47,11 @@ player_update(void)
void
player_draw(void)
{
const int x2 = self.pos.x + PLAYER_WIDTH - 1;
const int y2 = self.pos.y + PLAYER_HEIGHT - 1;
const struct Vec off = camera_offset();
const int x1 = self.pos.x + off.x;
const int y1 = self.pos.y + off.y;
const int x2 = x1 + PLAYER_WIDTH - 1;
const int y2 = y1 + PLAYER_HEIGHT - 1;
drect(self.pos.x, self.pos.y, x2, y2, C_BLUE);
}
@ -99,3 +103,9 @@ collide_solid(int x, int y)
level_get_px(x2, y) == TILE_SOLID ||
level_get_px(x2, y2) == TILE_SOLID;
}
struct Vec *
player_pos(void)
{
return &self.pos;
}