you don't get it
This commit is contained in:
parent
1c161f621f
commit
0658f191bd
|
@ -13,6 +13,7 @@ set(SOURCES
|
|||
src/input.c
|
||||
src/player.c
|
||||
src/level.c
|
||||
src/background.c
|
||||
)
|
||||
|
||||
set(ASSETS
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
void background_init(void);
|
||||
void background_update(void);
|
||||
void background_draw(void);
|
|
@ -2,5 +2,9 @@
|
|||
|
||||
void level_deinit(void);
|
||||
void level_load(int id);
|
||||
void level_next(void);
|
||||
void level_reload(void);
|
||||
void level_find(int tile, int *x, int *y);
|
||||
void level_draw(void);
|
||||
int level_at(int x, int y);
|
||||
int level_id(void);
|
||||
|
|
|
@ -6,3 +6,7 @@ void player_draw(void);
|
|||
|
||||
#define PLAYER_WIDTH 12
|
||||
#define PLAYER_HEIGHT 12
|
||||
#define PLAYER_SPEED 2
|
||||
#define GRAVITY 0.69
|
||||
#define MAX_Y_SPEED 5
|
||||
#define JUMP_SPEED -6
|
||||
|
|
BIN
res/0.kble
BIN
res/0.kble
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,7 +1,7 @@
|
|||
tset.png:
|
||||
type: bopti-image
|
||||
name: bimg_tset
|
||||
profile: p4
|
||||
profile: p8
|
||||
font.png:
|
||||
type: bopti-image
|
||||
name: bimg_font
|
||||
|
|
BIN
res/tset.png
BIN
res/tset.png
Binary file not shown.
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 43 KiB |
|
@ -0,0 +1,16 @@
|
|||
#include "conf.h"
|
||||
#include "level.h"
|
||||
#include "lzy.h"
|
||||
|
||||
void background_init(void) {}
|
||||
|
||||
void background_update(void) {}
|
||||
|
||||
void background_draw(void)
|
||||
{
|
||||
const int id = TSET_LINE + level_id() * TSET_LINE * 7;
|
||||
LZY_DrawTileEx(id, 0, 0, 13, 7);
|
||||
LZY_DrawTileEx(id, 0, DISPLAY_HEIGHT / 2, 13, 7);
|
||||
LZY_DrawTileEx(id, DISPLAY_WIDTH / 2, 0, 13, 7);
|
||||
LZY_DrawTileEx(id, DISPLAY_WIDTH / 2, DISPLAY_HEIGHT / 2, 13, 7);
|
||||
}
|
20
src/level.c
20
src/level.c
|
@ -34,6 +34,16 @@ void level_load(int nid)
|
|||
player_init(px, py);
|
||||
}
|
||||
|
||||
void level_next(void)
|
||||
{
|
||||
level_load(id + 1);
|
||||
}
|
||||
|
||||
void level_reload(void)
|
||||
{
|
||||
level_load(id);
|
||||
}
|
||||
|
||||
void level_find(int tile, int *x, int *y)
|
||||
{
|
||||
for (int i = 0; i < width * height; i++) {
|
||||
|
@ -57,3 +67,13 @@ void level_draw(void)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
int level_at(int x, int y)
|
||||
{
|
||||
return data[x / TILE_SIZE + y / TILE_SIZE * width];
|
||||
}
|
||||
|
||||
int level_id(void)
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#include "background.h"
|
||||
#include "conf.h"
|
||||
#include "input.h"
|
||||
#include "level.h"
|
||||
|
@ -16,18 +17,16 @@ int main(int argc, char **argv)
|
|||
}
|
||||
|
||||
level_load(0);
|
||||
background_init();
|
||||
|
||||
while (!LZY_ShouldQuit()) {
|
||||
LZY_CycleEvents();
|
||||
input_update();
|
||||
background_update();
|
||||
player_update();
|
||||
|
||||
LZY_DrawBegin();
|
||||
LZY_DrawTileEx(TSET_LINE, 0, 0, 13, 7);
|
||||
LZY_DrawTileEx(TSET_LINE, DISPLAY_WIDTH / 2, 0, 13, 7);
|
||||
LZY_DrawTileEx(TSET_LINE, 0, DISPLAY_HEIGHT / 2, 13, 7);
|
||||
LZY_DrawTileEx(TSET_LINE, DISPLAY_WIDTH / 2, DISPLAY_HEIGHT / 2,
|
||||
13, 7);
|
||||
background_draw();
|
||||
level_draw();
|
||||
player_draw();
|
||||
LZY_DrawEnd();
|
||||
|
|
57
src/player.c
57
src/player.c
|
@ -1,27 +1,51 @@
|
|||
#include "player.h"
|
||||
#include "conf.h"
|
||||
#include "input.h"
|
||||
#include "level.h"
|
||||
#include "lzy.h"
|
||||
|
||||
static float x, y, spd_x, spd_y;
|
||||
static int x, y;
|
||||
static float spd_y;
|
||||
|
||||
static int collide_wall(void);
|
||||
|
||||
void player_init(float nx, float ny)
|
||||
{
|
||||
x = nx;
|
||||
y = ny;
|
||||
spd_x = 0.0f;
|
||||
spd_y = 0.0f;
|
||||
y = ny + TILE_SIZE - PLAYER_HEIGHT;
|
||||
spd_y = 0.00000002022f;
|
||||
}
|
||||
|
||||
void player_update(void)
|
||||
{
|
||||
if (input_down(K_LEFT))
|
||||
x -= 2;
|
||||
if (input_down(K_RIGHT))
|
||||
x += 2;
|
||||
if (input_down(K_UP))
|
||||
y -= 2;
|
||||
if (input_down(K_DOWN))
|
||||
y += 2;
|
||||
x += input_down(K_RIGHT) * 2 - input_down(K_LEFT) * 3;
|
||||
if (collide_wall())
|
||||
x -= input_down(K_RIGHT) * 3 - input_down(K_LEFT) * 4;
|
||||
|
||||
y++;
|
||||
if (collide_wall()) {
|
||||
if (input_pressed(K_O))
|
||||
spd_y = JUMP_SPEED;
|
||||
} else {
|
||||
spd_y += GRAVITY;
|
||||
if (spd_y > MAX_Y_SPEED)
|
||||
spd_y = MAX_Y_SPEED;
|
||||
}
|
||||
y--;
|
||||
|
||||
y += spd_y;
|
||||
if (collide_wall()) {
|
||||
const int step = (MAX_Y_SPEED * (-1 + 2 * (spd_y > 0))) / 2;
|
||||
y -= step;
|
||||
if (collide_wall())
|
||||
y -= step;
|
||||
spd_y = 0.00000001337;
|
||||
}
|
||||
|
||||
if (level_at(x, y) == 3)
|
||||
level_next();
|
||||
if (level_at(x, y) == 4)
|
||||
level_reload();
|
||||
}
|
||||
|
||||
void player_draw(void)
|
||||
|
@ -29,3 +53,12 @@ void player_draw(void)
|
|||
LZY_DrawSetColor(255, 0, 255);
|
||||
LZY_DrawTile(2, x, y);
|
||||
}
|
||||
|
||||
static int collide_wall(void)
|
||||
{
|
||||
const int x2 = x + PLAYER_WIDTH - 1;
|
||||
const int y2 = y + PLAYER_HEIGHT - 1;
|
||||
|
||||
return level_at(x, y) == 1 || level_at(x2, y) == 1 ||
|
||||
/* level_at(x, y2) == 1 || */ level_at(x2, y2) == 1;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue