master
parent d433f8bc2d
commit 10478eb6c5
  1. 2
      CMakeLists.txt
  2. BIN
      assets-cg/bullet.png
  3. BIN
      assets-cg/missile1.ase
  4. BIN
      assets-cg/missile2.ase
  5. BIN
      assets-cg/scarlet.png
  6. 20
      include/bullet.h
  7. 2
      include/conf.h
  8. 1
      include/hook.h
  9. 1
      include/input.h
  10. 69
      levels/test.tmx
  11. 4
      levels/tileset.tsx
  12. 102
      src/bullet.c
  13. 13
      src/hook.c
  14. 1
      src/input.c
  15. 5
      src/main.c
  16. 59
      src/player.c

@ -18,6 +18,7 @@ set(SOURCES
src/tools.c
src/level.c
src/hook.c
src/bullet.c
)
set(ASSETS_cg
@ -25,6 +26,7 @@ set(ASSETS_cg
assets-cg/hooksel.png
assets-cg/scarletR.png
assets-cg/scarletL.png
assets-cg/bullet.png
)
fxconv_declare_assets(${ASSETS} ${ASSETS_fx} ${ASSETS_cg} WITH_METADATA)

Binary file not shown.

After

Width:  |  Height:  |  Size: 125 B

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

@ -0,0 +1,20 @@
#pragma once
#include "type.h"
struct Bullet {
struct Vec2 pos;
int v;
int active;
};
struct Bullet_table {
int n;
struct Bullet *bullets;
};
void bullet_table_init(void);
void bullet_table_update(void);
void bullet_table_draw(int timer);
void bullet_destroy(struct Bullet *bullet);
void bullet_fire(int x, int y, int v);
int bullet_nb(void);

@ -13,3 +13,5 @@
#define TILE_S 8
#define TILESET_W 16
#define TILESET_H 4
#define MAX_BULLETS 64

@ -15,4 +15,3 @@ struct Hook_table {
void hook_table_init(void);
int hook_nb(void);
struct Vec2 hook_closest(struct Vec2 *pos);
void hook_debug_draw(void);

@ -5,6 +5,7 @@
typedef enum Key {
K_A,
K_B,
K_X,
K_UP,
K_DOWN,
K_LEFT,

@ -1,39 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.5" tiledversion="1.7.2" orientation="orthogonal" renderorder="right-down" width="50" height="28" tilewidth="8" tileheight="8" infinite="0" backgroundcolor="#000000" nextlayerid="2" nextobjectid="1">
<editorsettings>
<export target="../assets-cg/test.lua" format="lua"/>
</editorsettings>
<map version="1.5" tiledversion="1.7.2" orientation="orthogonal" renderorder="right-down" width="60" height="34" tilewidth="16" tileheight="16" infinite="0" backgroundcolor="#9582ff" nextlayerid="2" nextobjectid="1">
<tileset firstgid="1" source="tileset.tsx"/>
<layer id="1" name="Calque de Tuiles 1" width="50" height="28">
<layer id="1" name="Tile Layer 1" width="60" height="34">
<data encoding="csv">
19,21,22,22,21,20,20,21,22,19,22,20,21,21,20,22,19,20,21,21,22,21,19,21,22,20,20,21,19,19,20,19,22,21,19,22,22,19,19,20,20,22,20,20,19,20,19,22,21,20,
22,19,20,20,22,22,19,19,21,21,22,22,22,20,20,22,22,21,22,21,22,22,19,20,22,21,22,22,20,21,19,19,20,22,21,19,20,22,20,19,19,20,19,20,21,22,20,21,22,21,
20,21,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,19,19,
19,22,17,25,0,0,0,0,58,57,58,57,58,0,0,0,0,0,0,58,0,0,0,0,0,58,58,57,58,57,58,57,58,57,58,57,58,58,0,42,42,42,42,41,42,42,26,18,19,20,
20,22,17,25,42,42,42,42,58,57,58,57,58,42,42,0,0,0,0,58,0,0,0,0,0,58,58,57,58,57,58,57,58,57,58,57,58,58,0,0,0,0,0,57,0,0,26,18,22,19,
20,21,17,25,0,0,0,0,58,57,58,57,58,0,0,0,0,0,0,41,0,0,0,0,0,0,58,57,58,57,58,57,58,57,58,57,58,0,0,0,0,42,42,41,42,42,26,18,20,20,
21,22,17,25,42,42,0,41,42,41,42,41,42,41,0,0,0,0,0,58,0,0,0,0,0,41,42,41,42,42,41,42,41,42,42,41,42,41,0,0,0,0,0,57,0,0,26,18,21,21,
19,22,17,25,0,0,0,0,57,58,57,58,57,0,0,0,0,0,0,58,0,0,0,0,0,0,58,0,57,58,57,58,57,58,57,0,58,0,0,0,0,0,0,57,0,0,26,18,21,20,
20,19,17,25,0,0,0,0,57,58,57,58,57,0,0,0,0,0,0,58,0,0,0,0,0,0,58,58,57,58,57,58,57,58,57,58,58,0,0,0,0,0,0,57,0,0,26,18,20,20,
19,22,17,25,0,0,0,0,57,58,57,58,57,0,0,0,0,0,0,9,0,0,0,0,0,0,0,0,57,58,57,58,57,58,57,0,0,0,0,0,0,0,0,0,0,0,26,18,22,19,
22,21,17,25,0,0,0,0,57,58,57,58,57,0,0,0,0,0,0,0,0,0,0,0,0,0,0,41,42,41,42,41,42,41,42,9,0,0,0,0,0,0,0,0,0,0,26,18,22,21,
19,21,17,25,0,0,0,0,57,58,57,58,57,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,57,58,57,58,57,0,0,0,0,0,0,0,0,0,0,0,0,26,18,21,22,
22,21,17,25,0,0,0,0,57,58,57,58,57,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,58,57,58,57,58,57,58,0,0,0,0,0,0,0,0,0,0,0,26,18,21,19,
19,19,17,25,0,0,0,0,57,58,57,58,57,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,57,58,57,58,57,0,0,0,0,0,0,0,0,0,0,0,0,26,18,21,21,
20,20,35,44,0,0,0,0,57,58,57,58,57,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,58,57,58,57,58,57,58,0,0,0,0,0,0,0,0,0,0,0,26,18,22,20,
20,22,51,60,0,0,0,0,57,58,57,58,57,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,57,58,57,58,57,0,0,0,0,0,0,0,0,0,0,0,0,26,18,22,21,
22,21,51,60,58,58,0,41,42,41,42,41,42,41,0,0,0,0,0,0,0,0,0,0,0,0,0,0,41,42,41,42,41,42,41,0,0,0,0,0,0,0,0,0,0,0,43,36,22,22,
21,21,3,3,3,3,0,0,58,57,58,57,58,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,58,57,58,57,58,0,0,0,0,0,0,0,0,0,0,0,0,59,52,22,20,
22,19,19,4,4,4,0,0,58,57,58,57,58,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,58,57,58,57,58,0,0,0,0,0,0,0,0,0,0,58,58,59,52,20,19,
22,21,17,25,0,0,0,0,58,57,58,57,58,0,0,33,34,34,34,34,33,34,34,33,0,1,1,2,0,58,57,58,57,58,0,2,1,1,0,33,34,34,33,34,34,34,34,34,19,20,
20,20,35,44,0,0,0,0,58,57,58,57,58,0,0,49,50,50,50,50,49,58,58,57,0,41,27,17,2,3,3,3,3,3,2,18,27,41,0,57,58,58,49,50,50,50,50,18,19,21,
20,21,51,60,0,0,0,0,58,57,58,57,58,0,0,49,50,50,50,50,49,58,58,57,0,41,2,2,19,19,3,2,3,19,19,2,2,41,0,57,58,58,49,50,50,50,50,18,20,20,
22,19,51,60,58,58,0,0,58,57,58,57,33,34,34,33,34,34,34,34,33,42,42,42,0,0,26,19,19,19,19,4,19,19,19,19,25,0,0,41,41,42,33,34,34,34,34,34,22,21,
20,20,3,3,3,3,3,3,58,57,58,57,49,50,50,49,50,50,50,50,49,58,58,57,0,0,0,18,4,4,4,4,4,4,4,17,0,0,0,57,58,58,49,50,50,50,50,18,20,19,
19,19,19,20,19,19,19,17,58,57,58,57,49,50,50,49,50,50,50,50,49,58,58,57,0,0,0,0,49,50,58,57,58,50,49,0,0,0,0,57,57,58,49,50,50,50,50,18,20,21,
19,21,21,22,20,20,19,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,20,20,
20,20,19,20,21,21,22,19,20,22,20,22,22,19,19,22,21,19,22,20,21,21,20,21,19,19,19,20,20,22,22,21,22,21,20,22,21,19,19,19,21,19,19,22,20,21,19,22,22,22,
21,20,19,22,20,22,19,22,20,20,19,21,21,22,19,19,22,21,19,22,20,22,20,22,20,22,20,19,20,21,20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18,18,18,18,35,19,17,21,21,21,21,17,19,35,18,18,0,0,0,0,0,0,0,0,0,0,0,0
</data>
</layer>
</map>

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<tileset version="1.5" tiledversion="1.7.2" name="tileset" tilewidth="8" tileheight="8" tilecount="64" columns="16">
<image source="../assets-cg/tileset.png" width="128" height="32"/>
<tileset version="1.5" tiledversion="1.7.2" name="tileset" tilewidth="16" tileheight="16" tilecount="16" columns="4">
<image source="../../pogchamp/assets/art/tileset.png" width="64" height="64"/>
</tileset>

@ -0,0 +1,102 @@
#include "bullet.h"
#include "conf.h"
#include "level.h"
#include <gint/display.h>
#include <stdlib.h>
#include <string.h>
static struct Bullet_table bullet_table;
static void bullet_table_free(void);
static void bullet_update(struct Bullet *bullet);
static void bullet_draw(struct Bullet *bullet, int timer);
extern bopti_image_t img_bullet;
void
bullet_table_init(void)
{
bullet_table_free();
bullet_table.bullets = malloc(MAX_BULLETS * sizeof(struct Bullet));
bullet_table.n = 0;
for (int i = 0; i < MAX_BULLETS; ++i) {
bullet_table.bullets[i].active = 0;
}
}
void
bullet_table_free(void)
{
if (bullet_table.bullets != NULL) {
bullet_table.bullets = NULL;
}
};
void
bullet_fire(int x, int y, int v)
{
for (int i = 0; i < MAX_BULLETS; ++i) {
if (!bullet_table.bullets[i].active) {
bullet_table.bullets[i] = (struct Bullet){
.pos = (struct Vec2){.x = x, .y = y},
.v = v,
.active = 1};
break;
}
}
++bullet_table.n;
}
void
bullet_table_update(void)
{
for (int i = 0; i < MAX_BULLETS; ++i) {
if (bullet_table.bullets[i].active) {
bullet_update(&bullet_table.bullets[i]);
}
}
}
void
bullet_update(struct Bullet *bullet)
{
bullet->pos.x += bullet->v;
/* boom */
const struct Vec2 level_dim = level_get_dim();
if (bullet->pos.x < -6 || bullet->pos.x > level_dim.x * TILE_S ||
bullet->pos.y < -6 || bullet->pos.y > level_dim.y * TILE_S) {
bullet_destroy(bullet);
}
}
void
bullet_table_draw(int timer)
{
for (int i = 0; i < MAX_BULLETS; ++i) {
if (bullet_table.bullets[i].active) {
bullet_draw(&bullet_table.bullets[i], timer);
}
}
}
void
bullet_draw(struct Bullet *bullet, int timer)
{
dsubimage(bullet->pos.x, bullet->pos.y, &img_bullet,
(timer / 2) % 2 * 6, 0, 6, 4, 0);
}
void
bullet_destroy(struct Bullet *bullet)
{
bullet->active = 0;
--bullet_table.n;
}
int
bullet_nb(void)
{
return bullet_table.n;
}

@ -62,16 +62,3 @@ hook_closest(struct Vec2 *pos)
shortest = (struct Vec2){shortest.x, shortest.y};
return shortest;
}
void
hook_debug_draw(void)
{
dprint(10, 20, C_WHITE, "%d", hook_table.n);
dprint(30, 20, C_WHITE, "%d", hook_table.hooks[0].pos.x);
dprint(50, 20, C_WHITE, "%d", hook_table.hooks[1].pos.x);
struct Vec2 player_pos = player_get_pos();
dprint(10, 40, C_WHITE, "%d",
(int)length(&hook_table.hooks[0].pos, &player_pos));
dprint(50, 40, C_WHITE, "%d",
(int)length(&hook_table.hooks[1].pos, &player_pos));
}

@ -14,6 +14,7 @@ input_init(void)
}
input.keys[K_A] = KEY_SHIFT;
input.keys[K_B] = KEY_ALPHA;
input.keys[K_X] = KEY_OPTN;
input.keys[K_LEFT] = KEY_LEFT;
input.keys[K_RIGHT] = KEY_RIGHT;
input.keys[K_UP] = KEY_UP;

@ -1,4 +1,5 @@
#include "main.h"
#include "bullet.h"
#include "draw.h"
#include "hook.h"
#include "input.h"
@ -32,6 +33,7 @@ init(void)
{
input_init();
level_init();
bullet_table_init();
}
static void
@ -39,6 +41,7 @@ update(void)
{
input_step();
player_update();
bullet_table_update();
++timer;
}
@ -49,6 +52,6 @@ draw(void)
dclear(C_BLACK);
level_draw();
player_draw(timer);
hook_debug_draw();
bullet_table_draw(timer);
dupdate();
}

@ -1,22 +1,27 @@
#include "player.h"
#include "bullet.h"
#include "conf.h"
#include "draw.h"
#include "hook.h"
#include "input.h"
#include "level.h"
#include "tools.h"
#include <math.h>
#include <stdlib.h>
static int k_up, k_down, k_left, k_right, k_jump, k_jumpdown, k_hook;
static int k_up, k_down, k_left, k_right, k_jump, k_jumpdown, k_hook, k_fire;
static struct Player player;
static void player_get_input(void);
static void player_move(struct Vec2 spd);
static void player_hook(void);
static void player_hook_draw(void);
static int player_update_frame(int timer);
static struct Vec2 player_update_rem();
static int player_collide_pixel(int x, int y, tile_t id);
static int player_collide(struct Vec2 pos, tile_t id, int h);
extern bopti_image_t img_scarletR;
extern bopti_image_t img_scarletL;
extern bopti_image_t img_hooksel;
struct Vec2
@ -35,6 +40,7 @@ player_init(void)
player.airbreak = 1;
player.hooking = 0;
player.locked = 0;
player.dir = 1;
player.hook_pos = (struct Vec2){0, 0};
player.hook_near = hook_closest(&player.pos);
}
@ -42,6 +48,7 @@ player_init(void)
void
player_update(void)
{
/* input and air movement */
player_get_input();
const int dir = k_right - k_left;
@ -55,6 +62,7 @@ player_update(void)
player.airbreak = 0;
}
/* hooking */
player_hook();
if (!player.hooking) {
@ -64,12 +72,19 @@ player_update(void)
player.spd.y +=
GRAVITY + GRAVITY * (player.airbreak && !player.hooking);
/* applying movement */
player_move(player_update_rem());
if (player_collide((struct Vec2){player.pos.x, player.pos.y + 1}, 1,
0)) {
player.jumping = 0;
}
/* shooting */
if (k_fire) {
bullet_fire(player.pos.x, player.pos.y,
(dir ? dir : player.dir) * 6);
}
}
void
@ -123,12 +138,42 @@ player_hook(void)
}
void
player_draw(void)
player_draw(int timer)
{
const int frame = player_update_frame(timer);
if (player.dir == 1) {
dsubimage(player.pos.x - 5, player.pos.y - 5, &img_scarletR,
frame * PLAYER_W, 0, PLAYER_W, PLAYER_H, 0);
} else {
dsubimage(player.pos.x - 5, player.pos.y - 5, &img_scarletL,
frame * PLAYER_W, 0, PLAYER_W, PLAYER_H, 0);
}
/* draw_rectangle(player.pos.x, player.pos.y, PLAYER_S, PLAYER_S,
* C_WHITE); */
player_hook_draw();
draw_rectangle(player.pos.x, player.pos.y, PLAYER_S, PLAYER_S, C_WHITE);
dprint(10, 20, C_WHITE, "%f", player.spd.y);
dprint(70, 30, C_WHITE, "%d", hook_closest(&player.pos).x);
}
int
player_update_frame(int timer)
{
if (player.hooking) {
return 5;
}
if (player.jumping && player.spd.y <= 0) {
return 2;
}
if (player.jumping && player.spd.y > 0) {
return 3;
}
if (abs(player.spd.x) > 0) {
return (6 + (timer / 2) % 8);
}
return ((timer / 60) % 2);
}
void
@ -143,7 +188,7 @@ player_hook_draw(void)
};
if (player.hooking) {
dline(player.pos.x + PLAYER_S / 2, player.pos.y + PLAYER_S / 2,
dline(player.pos.x + PLAYER_S / 2, player.pos.y + 7,
player.hook_pos.x, player.hook_pos.y, C_RED);
}
}
@ -158,6 +203,7 @@ player_get_input(void)
k_jump = input_pressed(K_A);
k_jumpdown = input_down(K_A);
k_hook = input_down(K_B);
k_fire = input_pressed(K_X);
}
static struct Vec2
@ -184,6 +230,7 @@ player_move(struct Vec2 spd)
if (spd.x) {
const int sign_x = sign(spd.x);
player.dir = sign_x;
player.pos.x += spd.x;
if (player.pos.x < 0) {
player.pos.x = 1;

Loading…
Cancel
Save