mirror of https://git.sr.ht/~kikoodx/crystal-tower
shine bright like
This commit is contained in:
parent
b8bf75a196
commit
342f2f3142
|
@ -21,6 +21,7 @@ set(SOURCES
|
|||
src/anim.c
|
||||
src/shatter.c
|
||||
src/particles.c
|
||||
src/stars.c
|
||||
)
|
||||
|
||||
set(LEVELS
|
||||
|
@ -32,6 +33,7 @@ set(LEVELS
|
|||
set(ASSETS
|
||||
res/tileset.png
|
||||
res/shatter.png
|
||||
res/player.png
|
||||
${LEVELS}
|
||||
)
|
||||
|
||||
|
|
42
inc/conf.h
42
inc/conf.h
|
@ -1,18 +1,28 @@
|
|||
#pragma once
|
||||
#include <gint/display.h>
|
||||
|
||||
#define TARGET_FPS 60
|
||||
#define TILE_SIZE 16
|
||||
#define PLAYER_WIDTH 14
|
||||
#define PLAYER_HEIGHT 14
|
||||
#define GRAVITY 0.2f
|
||||
#define AIR_RESISTANCE 0.03f
|
||||
#define MAX_WALK_SPEED 2.0f
|
||||
#define ACCELERATION_AIR 0.4f
|
||||
#define ACCELERATION_GROUND 0.4f
|
||||
#define FRICTION_AIR (ACCELERATION_AIR / MAX_WALK_SPEED)
|
||||
#define FRICTION_GROUND (ACCELERATION_GROUND / MAX_WALK_SPEED)
|
||||
#define FRICTION_BREAK (0.6f / MAX_WALK_SPEED)
|
||||
#define JUMP_GRACE 1
|
||||
#define JUMP_BUFFER 12
|
||||
#define JUMP_SPD -4.4
|
||||
#define WJUMP_LOCK 15
|
||||
#define TARGET_FPS 60
|
||||
#define TILE_SIZE 16
|
||||
#define PLAYER_WIDTH 12
|
||||
#define PLAYER_HEIGHT 12
|
||||
#define GRAVITY 0.2f
|
||||
#define AIR_RESISTANCE 0.03f
|
||||
#define MAX_WALK_SPEED 2.0f
|
||||
#define ACCELERATION_AIR 0.4f
|
||||
#define ACCELERATION_GROUND 0.4f
|
||||
#define FRICTION_AIR (ACCELERATION_AIR / MAX_WALK_SPEED)
|
||||
#define FRICTION_GROUND (ACCELERATION_GROUND / MAX_WALK_SPEED)
|
||||
#define FRICTION_BREAK (0.6f / MAX_WALK_SPEED)
|
||||
#define JUMP_GRACE 1
|
||||
#define JUMP_BUFFER 12
|
||||
#define JUMP_SPD -4.6
|
||||
#define WJUMP_LOCK 15
|
||||
#define STARS_COUNT 64
|
||||
#define STARS_SIZE 2
|
||||
#define STARS_MIN_X 0
|
||||
#define STARS_MAX_X (DWIDTH - STARS_SIZE)
|
||||
#define STARS_COLOR C_RGB(31, 31, 31)
|
||||
#define STARS_BASE_SPEED 1.0
|
||||
#define STARS_MAX_SPEED 3.0
|
||||
#define STARS_SPEED_VARIATION (STARS_MAX_SPEED - STARS_BASE_SPEED)
|
||||
#define STARS_STRETCH 2.0
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
void stars_init(void);
|
||||
void stars_update(void);
|
||||
void stars_draw(void);
|
|
@ -4,3 +4,6 @@ tileset.png:
|
|||
shatter.png:
|
||||
type: bopti-image
|
||||
name: bimg_shatter
|
||||
player.png:
|
||||
type: bopti-image
|
||||
name: bimg_player
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 8.5 KiB |
BIN
res/tileset.png
BIN
res/tileset.png
Binary file not shown.
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 12 KiB |
11
src/level.c
11
src/level.c
|
@ -62,15 +62,16 @@ level_draw(void)
|
|||
int y = 0;
|
||||
|
||||
for (i = 0; i < self.size; i++) {
|
||||
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;
|
||||
if (tile && tile != TILE_OOB) {
|
||||
const int sx = x * TILE_SIZE + off.x;
|
||||
const int sy = y * TILE_SIZE + off.y;
|
||||
const int rx = tile % tileset_width * TILE_SIZE;
|
||||
const int ry = tile / tileset_width * TILE_SIZE;
|
||||
|
||||
if (tile && tile != TILE_OOB)
|
||||
dsubimage(sx, sy, &bimg_tileset, rx, ry, TILE_SIZE,
|
||||
TILE_SIZE, DIMAGE_NONE);
|
||||
}
|
||||
|
||||
if (++x >= self.width) {
|
||||
x = 0;
|
||||
|
|
|
@ -4,10 +4,12 @@
|
|||
#include "level.h"
|
||||
#include "particles.h"
|
||||
#include "player.h"
|
||||
#include "stars.h"
|
||||
#include "vec.h"
|
||||
#include <gint/cpu.h>
|
||||
#include <gint/display.h>
|
||||
#include <gint/timer.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static void update(void);
|
||||
static void draw(void);
|
||||
|
@ -20,10 +22,12 @@ main(void)
|
|||
int frameskip = 1;
|
||||
volatile int has_ticked = 0;
|
||||
|
||||
srand(1337);
|
||||
timer = timer_configure(TIMER_ANY, 1000000 / TARGET_FPS,
|
||||
GINT_CALL(callback, &has_ticked));
|
||||
timer_start(timer);
|
||||
input_init();
|
||||
stars_init();
|
||||
level_load(0);
|
||||
camera_init(player_pos());
|
||||
|
||||
|
@ -54,12 +58,14 @@ update(void)
|
|||
input_update();
|
||||
player_update();
|
||||
camera_update();
|
||||
stars_update();
|
||||
}
|
||||
|
||||
static void
|
||||
draw(void)
|
||||
{
|
||||
dclear(C_BLACK);
|
||||
stars_draw();
|
||||
level_draw();
|
||||
player_draw();
|
||||
particles_draw();
|
||||
|
|
13
src/player.c
13
src/player.c
|
@ -4,6 +4,7 @@
|
|||
#include "input.h"
|
||||
#include "level.h"
|
||||
#include "shatter.h"
|
||||
#include "tile.h"
|
||||
#include "util.h"
|
||||
#include "vec.h"
|
||||
#include <gint/display.h>
|
||||
|
@ -21,12 +22,15 @@ void
|
|||
player_init(struct Vec pos)
|
||||
{
|
||||
self.pos = pos;
|
||||
self.pos.x += (TILE_SIZE - PLAYER_WIDTH) / 2;
|
||||
self.pos.y += TILE_SIZE - PLAYER_HEIGHT;
|
||||
self.spd = VECFZ;
|
||||
self.rem = VECFZ;
|
||||
self.jump_grace = 0;
|
||||
self.jump_buffer = 0;
|
||||
self.lock_direction = 0;
|
||||
self.last_direction = 1;
|
||||
level_set_px(pos.x, pos.y, TILE_VOID);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -140,12 +144,11 @@ death(void)
|
|||
void
|
||||
player_draw(void)
|
||||
{
|
||||
extern bopti_image_t bimg_player;
|
||||
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);
|
||||
const int x = self.pos.x + off.x;
|
||||
const int y = self.pos.y + off.y;
|
||||
dimage(x, y, &bimg_player);
|
||||
}
|
||||
|
||||
struct Vec
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
#include "stars.h"
|
||||
#include "conf.h"
|
||||
#include <gint/display.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
struct Star {
|
||||
int x;
|
||||
float y;
|
||||
float spd;
|
||||
int stretch;
|
||||
};
|
||||
|
||||
static struct Star stars[STARS_COUNT];
|
||||
|
||||
static void star_rand(struct Star *);
|
||||
static void star_update(struct Star *);
|
||||
static void star_draw(struct Star *);
|
||||
|
||||
void
|
||||
stars_init(void)
|
||||
{
|
||||
int i = STARS_COUNT;
|
||||
while (i-- > 0) {
|
||||
stars[i].y = (float)(rand() % DHEIGHT);
|
||||
star_rand(&stars[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
stars_update(void)
|
||||
{
|
||||
int i = STARS_COUNT;
|
||||
while (i-- > 0)
|
||||
star_update(&stars[i]);
|
||||
}
|
||||
|
||||
void
|
||||
stars_draw(void)
|
||||
{
|
||||
int i = STARS_COUNT;
|
||||
while (i-- > 0)
|
||||
star_draw(&stars[i]);
|
||||
}
|
||||
|
||||
static void
|
||||
star_rand(struct Star *s)
|
||||
{
|
||||
s->x = STARS_MIN_X + rand() % (STARS_MAX_X - STARS_MIN_X);
|
||||
s->spd = STARS_BASE_SPEED +
|
||||
(float)(rand() & 0xff) / 0xff * STARS_SPEED_VARIATION;
|
||||
s->stretch = s->spd * STARS_STRETCH * STARS_SIZE - 1.0f;
|
||||
}
|
||||
|
||||
static void
|
||||
star_update(struct Star *s)
|
||||
{
|
||||
s->y -= s->spd;
|
||||
if (s->y < -STARS_SIZE - STARS_MAX_SPEED * STARS_STRETCH) {
|
||||
s->y = DHEIGHT - STARS_SIZE;
|
||||
star_rand(s);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
star_draw(struct Star *s)
|
||||
{
|
||||
const int x = s->x;
|
||||
const int y = s->y;
|
||||
const int x2 = x + STARS_SIZE - 1;
|
||||
const int y2 = y + s->stretch;
|
||||
drect(x, y, x2, y2, STARS_COLOR);
|
||||
}
|
Loading…
Reference in New Issue