player & main skeletons

This commit is contained in:
KikooDX 2021-12-15 23:43:04 +01:00
parent 6de3ccda3b
commit 2a5e9e2412
9 changed files with 130 additions and 1 deletions

View File

@ -11,6 +11,8 @@ include_directories(inc)
set(SOURCES
src/main.c
src/draw.c
src/player.c
)
set(ASSETS
@ -27,5 +29,5 @@ target_link_options(proj PRIVATE -Wl,-Map=map)
generate_g3a(TARGET proj
OUTPUT "jtmm2.g3a"
NAME "JTMM2"
NAME ""
ICONS res/icon/uns.png res/icon/sel.png)

11
Makefile Normal file
View File

@ -0,0 +1,11 @@
all: format
fxsdk build-cg
format:
clang-format -style=file -i src/**.c inc/**.h
clean:
rm -Rf build-cg/
rm -f *.g3a
.PHONY: format clean

3
inc/conf.h Normal file
View File

@ -0,0 +1,3 @@
#pragma once
#define TILE_SIZE 16

4
inc/draw.h Normal file
View File

@ -0,0 +1,4 @@
#pragma once
#include <gint/display.h>
void draw_rectangle(int c, int x, int y, int w, int h);

11
inc/player.h Normal file
View File

@ -0,0 +1,11 @@
#pragma once
#include "vec.h"
typedef struct Player {
Vec pos;
VecF spd, rem;
} Player;
void player_init(Player *);
void player_update(Player *);
void player_draw(Player *);

9
inc/vec.h Normal file
View File

@ -0,0 +1,9 @@
#pragma once
typedef struct Vec {
int x, y;
} Vec;
typedef struct VecF {
float x, y;
} VecF;

10
src/draw.c Normal file
View File

@ -0,0 +1,10 @@
#include "draw.h"
#include <gint/display.h>
void
draw_rectangle(int c, int x, int y, int w, int h)
{
const int x2 = x + w - 1;
const int y2 = y + h - 1;
drect(x, y, x2, y2, c);
}

View File

@ -1,5 +1,51 @@
#include "player.h"
#include <gint/display.h>
#include <gint/keyboard.h>
static Player player;
static void init(void);
static void deinit(void);
static void draw(void);
static void update(void);
int
main(void)
{
init();
draw();
do {
update();
draw();
} while (!keydown(KEY_EXIT));
deinit();
return 0;
}
static void
init(void)
{
player_init(&player);
}
static void
deinit(void)
{
}
static void
update(void)
{
clearevents();
player_update(&player);
}
static void
draw(void)
{
dclear(C_BLACK);
player_draw(&player);
dupdate();
}

33
src/player.c Normal file
View File

@ -0,0 +1,33 @@
#include "player.h"
#include "draw.h"
static void player_reset_speed(Player *);
void
player_init(Player *p)
{
p->pos.x = 0;
p->pos.y = 0;
player_reset_speed(p);
}
void
player_update(Player *p)
{
p->pos.x++;
}
void
player_draw(Player *p)
{
draw_rectangle(C_WHITE, p->pos.x, p->pos.y, 16, 16);
}
static void
player_reset_speed(Player *p)
{
p->spd.x = 0.0f;
p->spd.y = 0.0f;
p->rem.x = 0.0f;
p->rem.y = 0.0f;
}