two minutes to miiidnight

This commit is contained in:
attilavs2 2024-10-27 23:52:11 +01:00
parent 9e65d04d22
commit 0d363f0c8d
29 changed files with 506 additions and 101 deletions

View file

@ -11,7 +11,7 @@ find_package(Gint 2.9 REQUIRED)
find_package(LibProf 2.1 REQUIRED) find_package(LibProf 2.1 REQUIRED)
# le nom de votre jeu # le nom de votre jeu
set(NAMEOFGAME "Test3D") set(NAMEOFGAME "Illusion3D")
# Nom de l'auteur -> votre nom/pseudo # Nom de l'auteur -> votre nom/pseudo
set(AUTHOR "Fcalva") set(AUTHOR "Fcalva")
@ -30,8 +30,20 @@ set(SOURCES
) )
set(ASSETS set(ASSETS
assets-fx/title.png
assets-fx/blood.png
assets-fx/hands0.png
assets-fx/hands1.png
assets-fx/hands2.png
assets-fx/anvil0.png
assets-fx/anvil1.png
assets-fx/anvil2.png
assets-fx/anvil3.png
assets-fx/sprites/friendlyguy.png assets-fx/sprites/friendlyguy.png
assets-fx/sprites/friendlyguy1.png assets-fx/sprites/friendlyguy1.png
assets-fx/sprites/anvil_pickup.png
assets-fx/textures/briques0.png assets-fx/textures/briques0.png
assets-fx/textures/buisson1.png assets-fx/textures/buisson1.png
@ -53,8 +65,8 @@ target_link_options(Copy3DEngine PRIVATE -Wl,--print-memory-usage)
if("${FXSDK_PLATFORM_LONG}" STREQUAL fx9860G) if("${FXSDK_PLATFORM_LONG}" STREQUAL fx9860G)
generate_g1a(TARGET Copy3DEngine OUTPUT ${NAMEOFGAME}".g1a" generate_g1a(TARGET Copy3DEngine OUTPUT ${NAMEOFGAME}".g1a"
NAME ${NAMEOFGAME} ICON assets-fx/icon.png) NAME "Illu3D" ICON assets-fx/icon.png)
else() else()
generate_g3a(TARGET Copy3DEngine OUTPUT ${NAMEOFGAME}".g3a" generate_g3a(TARGET Copy3DEngine OUTPUT ${NAMEOFGAME}".g3a"
NAME ${NAMEOFGAME} ICONS assets-fx/icon.png assets-fx/icon.png) NAME "Illu3D" ICONS assets-fx/icon.png assets-fx/icon.png)
endif() endif()

View file

@ -1,8 +1,8 @@
# Copy3DEngine ### Illusion 3D, ma participation au CPC #31
Je ne recommande pas de prendre ce code comme base de quoi que ce soit :E
Un moteur de raycasting, fork de Maze3D, avec le but de faciliter la création de jeux de style <insérer nom ici> 3D Tout est sous license GPLv3, assets inclus
### Utiliser Dépendances :
- gint
Pour faire votre propre jeu, vous avez juste à changer le nom du jeu dans CMakeLists.txt, inclure vos propres assets dans assets-cg/ et les inclure dans main.c. - libprof
Vous pouvez aussi éditer la carte dans map.c, et sa taille dans map.h

BIN
assets-fx/anvil0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5 KiB

BIN
assets-fx/anvil1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

BIN
assets-fx/anvil2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

BIN
assets-fx/anvil3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

BIN
assets-fx/blood.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View file

@ -1 +1,37 @@
hands0.png:
type: bopti-image
profile: gray_alpha
name: hands0
hands1.png:
type: bopti-image
profile: gray_alpha
name: hands1
hands2.png:
type: bopti-image
profile: gray_alpha
name: hands2
anvil0.png:
type: bopti-image
profile: gray_alpha
name: anvil0
anvil1.png:
type: bopti-image
profile: gray_alpha
name: anvil1
anvil2.png:
type: bopti-image
profile: gray_alpha
name: anvil2
anvil3.png:
type: bopti-image
profile: gray_alpha
name: anvil3
blood.png:
type: bopti-image
profile: gray_alpha
name: blood
title.png:
type: bopti-image
name: title

BIN
assets-fx/hands0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 944 B

BIN
assets-fx/hands1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 998 B

BIN
assets-fx/hands2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1,015 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.3 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

View file

@ -6,3 +6,8 @@ friendlyguy1.png:
type: bopti-image type: bopti-image
name: sprite_tst1 name: sprite_tst1
profile: gray_alpha profile: gray_alpha
anvil_pickup.png:
type: bopti-image
name: anvil_pick
profile: gray_alpha

BIN
assets-fx/title.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1,016 B

View file

@ -380,7 +380,7 @@ void draw_walls(
texSampleY = 0; texSampleY = 0;
} }
int linePos = viewport_h/2 - lineHeight/2; int linePos = viewport_h/2 - lineHeight/2 + game->flags.v_offset;
bopti_image_t *tex = tex_index[map_test[mapX*map_w+mapY]]; bopti_image_t *tex = tex_index[map_test[mapX*map_w+mapY]];

View file

@ -31,9 +31,9 @@ void clear_sprites(){
spritec = 0; spritec = 0;
} }
void remove_sprite(Sprite *sprite){ int remove_sprite(Sprite *sprite){
if(!sprite) if(!sprite)
return; return 0;
int pos = -1; int pos = -1;
for(int i = 0; i < spritec; i++){ for(int i = 0; i < spritec; i++){
if(sprite == sprite_index[i]){ if(sprite == sprite_index[i]){
@ -42,7 +42,7 @@ void remove_sprite(Sprite *sprite){
} }
} }
if(pos < 0) if(pos < 0)
return; return 1;
memmove(&sprite_index[pos], &sprite_index[pos+1], sizeof(void*) * (spritec-pos)); memmove(&sprite_index[pos], &sprite_index[pos+1], sizeof(void*) * (spritec-pos));
} }
@ -219,7 +219,7 @@ fixed_t raycast(RcGame *game, RcActor *origin, Sprite **hit){
//perform DDA //perform DDA
while(true) { while(true) {
//Check if the ray is out of range/bounds //Check if the ray is out of range/bounds
if (sideDistX >= max_dist || sideDistY >= max_dist || mapX < 0 || mapY < 0 || mapY >= map_w || mapX >= map_h) { if (sideDistX >= max_dist || sideDistY >= max_dist || mapX <= 0 || mapY <= 0 || mapY >= map_w || mapX >= map_h) {
coll = 0; coll = 0;
break; break;
} }

View file

@ -11,7 +11,7 @@
#define viewport_h 64 #define viewport_h 64
#define max_dist fix(32) #define max_dist fix(32)
//Max sprites to attempt to render //Max sprites to attempt to render
#define max_sprites 16 #define max_sprites 32
#define TSIZE 32 #define TSIZE 32

View file

@ -16,6 +16,10 @@ typedef struct {
int32_t x,y; int32_t x,y;
} V2d; } V2d;
typedef struct {
int16_t x,y;
} V2d16;
static inline fixed_t fmul(fixed_t left, fixed_t right) static inline fixed_t fmul(fixed_t left, fixed_t right)
{ {
/* Generally optimized by the compiler to use dmuls.l and xtrct */ /* Generally optimized by the compiler to use dmuls.l and xtrct */
@ -25,6 +29,8 @@ static inline fixed_t fmul(fixed_t left, fixed_t right)
static inline fixed_t fdiv(fixed_t left, fixed_t right) static inline fixed_t fdiv(fixed_t left, fixed_t right)
{ {
if(!right)
return 0;
/* Pretty slow */ /* Pretty slow */
int64_t d = (int64_t)left << 16; int64_t d = (int64_t)left << 16;
return d / right; return d / right;

View file

@ -3,13 +3,15 @@
#pragma once #pragma once
#include <gint/display.h>
#include "utils.h" #include "utils.h"
typedef struct { typedef struct {
V2d pos; V2d pos;
Rect coll; Rect coll;
int tex; int16_t tex;
} Sprite; int16_t hp;
} GPACKED(4) Sprite;
typedef struct { typedef struct {
int w, h; int w, h;
@ -20,6 +22,8 @@ typedef struct {
Sprite sprites[SINDEX_S/2]; Sprite sprites[SINDEX_S/2];
V2d start_pos;
} RcMap; } RcMap;
@ -28,7 +32,9 @@ typedef struct {
V2d pos; V2d pos;
Rect coll; Rect coll;
int tex; int16_t tex;
int16_t hp;
V2d dir; V2d dir;
V2d plane; V2d plane;
@ -37,6 +43,8 @@ typedef struct {
typedef struct { typedef struct {
uint8_t exit; uint8_t exit;
uint8_t __pad;
int16_t v_offset;
} RcFlags; } RcFlags;

View file

@ -15,7 +15,7 @@ void add_sprite(Sprite *sprite);
void clear_sprites(); void clear_sprites();
void remove_sprite(Sprite *sprite); int remove_sprite(Sprite *sprite);
void draw_sprites(bopti_image_t *tex_index[], RcActor *player); void draw_sprites(bopti_image_t *tex_index[], RcActor *player);

View file

@ -11,10 +11,8 @@
#define min(x, xmin) (x > xmin ? xmin:x) #define min(x, xmin) (x > xmin ? xmin:x)
typedef struct { typedef struct {
int x0,x1; int16_t x0,x1;
int y0,y1; int16_t y0,y1;
} Rect; } Rect;
bool rect_rect_coll(Rect *a, Rect *b);
int cmpfunc (const void * a, const void * b); int cmpfunc (const void * a, const void * b);

View file

@ -4,7 +4,10 @@
#include "C3D/sprites.h" #include "C3D/sprites.h"
#include "C3D/fixed.h" #include "C3D/fixed.h"
#include "C3D/game.h" #include "C3D/game.h"
#include "game.h" #include "game.h"
#include "gfx.h"
#include "map.h"
int sreserve_c = 0; int sreserve_c = 0;
Sprite sprite_reserve[SINDEX_S]; Sprite sprite_reserve[SINDEX_S];
@ -14,7 +17,21 @@ Rect sprite_colls[] = {
{}, {},
{}, {},
{}, {},
{.x0 = fix(.25), .y0 = fix(.25), .x1 = fix(.5), .y1 = fix(.5)} {.x0 = fix(.25), .y0 = fix(.25), .x1 = fix(.5), .y1 = fix(.5)},
{},
{},
{}
};
int16_t sprite_hp[] = {
0x1000,
0x1000,
0x1000,
0x1000,
2,
0x1000,
0x1000,
0x1000
}; };
Sprite *cc_mksprite(V2d pos, int type){ Sprite *cc_mksprite(V2d pos, int type){
@ -24,50 +41,71 @@ Sprite *cc_mksprite(V2d pos, int type){
spr->tex = type; spr->tex = type;
spr->coll = sprite_colls[type]; spr->coll = sprite_colls[type];
spr->pos = pos; spr->pos = pos;
spr->hp = sprite_hp[type];
add_sprite(spr); add_sprite(spr);
return spr; return spr;
} }
void cc_rmsprite(int pos){ int cc_rmsprite(int pos){
if(pos < 0 || pos >= sreserve_c) if(pos < 0 || pos >= sreserve_c)
return; return 1;
remove_sprite(&sprite_reserve[pos]);
if(!remove_sprite(&sprite_reserve[pos]))
return 2;
if(pos+1 != sreserve_c){ if(pos+1 != sreserve_c){
memmove(&sprite_reserve[pos], &sprite_reserve[pos+1], sizeof(Sprite)*(sreserve_c-pos)); memmove(&sprite_reserve[pos], &sprite_reserve[pos+1], sizeof(Sprite)*(sreserve_c-pos));
} }
sreserve_c--; sreserve_c--;
return 0;
}
void cc_load_msprites(Sprite *mapsprites, int spritec){
sreserve_c = 0;
for(int i = 0; i < spritec; i++)
cc_mksprite(mapsprites[i].pos, mapsprites[i].tex);
} }
void cc_hit(CCGame *game, int hitstr){ void cc_hit(CCGame *game, int hitstr){
if(game->hit > 0) if(game->hit > 0)
return; return;
game->hit = 40; game->hit = 40;
game->hp -= hitstr; game->_bgame.player.hp -= hitstr;
} }
int cc_ai_mov(RcGame *game, Sprite *spr, fixed_t spd, int hitstr, int coll){ void cc_ai_mov(RcGame *game, Sprite *spr, fixed_t spd, int hitstr, int coll, fixed_t range){
fixed_t dx = spr->pos.x - game->player.pos.x; fixed_t dx = spr->pos.x - game->player.pos.x;
fixed_t dy = spr->pos.y - game->player.pos.y; fixed_t dy = spr->pos.y - game->player.pos.y;
fixed_t player_dist = fsq(dx) + fsq(dy); fixed_t player_dist = fsq(dx) + fsq(dy);
int dxs = (dx >= 0) * 2 - 1; int dxs = (dx >= 0) * 2 - 1;
int dys = (dy >= 0) * 2 - 1; int dys = (dy >= 0) * 2 - 1;
if(player_dist > fsq(max_dist)) if(player_dist > fsq(max_dist) || player_dist < fsq(fix(0.5)))
return 0; return;
if(fixabs(ffloor(dx)) <= 1 && fixabs(ffloor(dy)) <= 1) if(player_dist < fsq(range))
cc_hit((CCGame*)game, hitstr); cc_hit((CCGame*)game, hitstr);
int nx = spr->pos.x;
int ny = spr->pos.y;
if(fixabs(dx) >= fixabs(dy)) if(fixabs(dx) >= fixabs(dy))
spr->pos.x -= dxs * spd; nx -= dxs * spd;
else else
spr->pos.y -= dys * spd; ny -= dys * spd;
return 0; if(!game->current_map->dat[ffloor(nx)*game->current_map->w + ffloor(ny)] || !coll){
spr->pos.x = nx;
spr->pos.y = ny;
}
return;
} }
int cc_ai(RcGame *game){ int cc_ai(RcGame *game){
for(int i = 0; i < sreserve_c; i++){ for(int i = 0; i < sreserve_c; i++){
Sprite *spr = &sprite_reserve[i]; Sprite *spr = &sprite_reserve[i];
if(spr->hp <= 0){
if(cc_rmsprite(i) == 2)
game->flags.exit = 2;
continue;
}
switch(spr->tex){ switch(spr->tex){
default: default:
case 0: case 0:
@ -76,7 +114,7 @@ int cc_ai(RcGame *game){
case 3: case 3:
break; break;
case 4:{ case 4:{
cc_ai_mov(game, spr, fix(.025), 5, 0); cc_ai_mov(game, spr, fix(.025), 5, 1, fix(1));
break; break;
} }
} }
@ -84,12 +122,51 @@ int cc_ai(RcGame *game){
return 0; return 0;
} }
WeaponStat weapon_stats[] = {
{0},
{.range = fix(1), .dmg = 1},
{.range = fix(1.5), .dmg = 5}
};
void weapon_hurt_stuff(CCGame *game){
Sprite *hit;
int dist = raycast((RcGame*)game, &((RcGame*)game)->player, &hit);
if(dist > weapon_stats[game->curr_weapon].range || !hit)
return;
//:p
if(hit > 0x90000000)
return;
hit->hp -= weapon_stats[game->curr_weapon].dmg;
}
extern WeapAnim weap_anims[WEAP_ANIM_C];
int cc_logic(RcGame *_game){ int cc_logic(RcGame *_game){
CCGame *game = (void*)_game; CCGame *game = (void*)_game;
if(game->hit) game->hit --; if(game->hit)
game->hit--;
if(game->weapon_use){
game->weapon_use = (game->weapon_use+1) %
(weap_anims[game->curr_weapon].framec*4);
if(game->weapon_use == weap_anims[game->curr_weapon].frame_hit*4)
weapon_hurt_stuff(game);
}
if(_game->player.hp <= 0){
death_anim(_game);
switch_map(game, game->curr_map);
}
return 0; return 0;
} }
void use_weapon(CCGame *game){
if(game->weapon_use)
return;
game->weapon_use = 1;
}
void init_logic(){ void init_logic(){
add_logic_hook((RcLogicFunc*)&cc_ai); add_logic_hook((RcLogicFunc*)&cc_ai);
add_logic_hook((RcLogicFunc*)&cc_logic); add_logic_hook((RcLogicFunc*)&cc_logic);

View file

@ -5,18 +5,37 @@
#include "C3D/game.h" #include "C3D/game.h"
enum { enum {
stype_frenguy = 4 stype_frenguy = 4,
stype_anvilpick = 7
};
enum {
weap_none = 0,
weap_hands = 1,
weap_anvilstick = 2
}; };
typedef struct { typedef struct {
RcGame _bgame; RcGame _bgame;
int curr_map; int8_t curr_map;
int16_t hit; int8_t hit;
int16_t hp; int8_t curr_weapon;
int8_t weapon_use;
} CCGame; //CpC game Game struct } CCGame; //CpC game Game struct
typedef struct {
fixed_t range;
int dmg;
} WeaponStat;
void cc_load_msprites(Sprite *mapsprites, int spritec);
Sprite *cc_mksprite(V2d pos, int type); Sprite *cc_mksprite(V2d pos, int type);
void cc_rmsprite(int pos); int cc_rmsprite(int pos);
void use_weapon(CCGame *game);
int cc_logic_onframe(CCGame *game);
void init_logic(); void init_logic();

View file

@ -1,5 +1,7 @@
//Par Fcalva et est sous GPLv3 //Par Fcalva et est sous GPLv3
#include <gint/display.h> #include <gint/display.h>
#include <gint/keyboard.h>
#include <gint/clock.h>
#include "C3D/fixed.h" #include "C3D/fixed.h"
#include "C3D/game.h" #include "C3D/game.h"
@ -18,6 +20,7 @@ extern bopti_image_t bwain0;
extern bopti_image_t bwain1; extern bopti_image_t bwain1;
extern bopti_image_t meat0; extern bopti_image_t meat0;
extern bopti_image_t meat1; extern bopti_image_t meat1;
extern bopti_image_t anvil_pick;
bopti_image_t *tex_index[TINDEX_S] = { bopti_image_t *tex_index[TINDEX_S] = {
&briques0, //0 &briques0, //0
@ -26,7 +29,8 @@ bopti_image_t *tex_index[TINDEX_S] = {
&briques0, //3 &briques0, //3
&sprite_tst, //4 &sprite_tst, //4
&bwain0, //5 &bwain0, //5
&meat0 //6 &meat0, //6
&anvil_pick //7
}; };
int state = 0; int state = 0;
@ -43,7 +47,59 @@ void init_gfx(){
add_logic_hook((RcLogicFunc*)&anim_tex); add_logic_hook((RcLogicFunc*)&anim_tex);
} }
void draw_gui(CCGame *game){ extern bopti_image_t blood;
dprint_opt(127,20,3,C_NONE,DTEXT_RIGHT,DTEXT_TOP,"%d",game->hp);
dtext_opt(127,30,3,C_NONE,DTEXT_RIGHT,DTEXT_TOP,"HP",-1); void death_anim(RcGame *game){
for(int i = -23; i < DHEIGHT; i+=2){
dimage(0,i,&blood);
dupdate();
sleep_us(10000);
} }
dtext_opt(DWIDTH/2,DHEIGHT/2-20,0,C_NONE,DTEXT_CENTER,DTEXT_TOP,
"Votre inconscient",-1);
dtext_opt(DWIDTH/2,DHEIGHT/2-10,0,C_NONE,DTEXT_CENTER,DTEXT_TOP,
"l'a emporte...",-1);
dtext_opt(DWIDTH/2,DHEIGHT/2+10,0,C_NONE,DTEXT_CENTER,DTEXT_TOP,
"[shift] recommencer",-1);
dupdate();
while(getkey_opt(0,NULL).key != KEY_SHIFT){}
}
extern bopti_image_t hands0;
extern bopti_image_t hands1;
extern bopti_image_t hands2;
extern bopti_image_t anvil0;
extern bopti_image_t anvil1;
extern bopti_image_t anvil2;
extern bopti_image_t anvil3;
WeapAnim weap_anims[WEAP_ANIM_C] = {
{},
{.frames = {&hands0, &hands1, &hands2, &hands1},
.x = 15,
.y = 42,
.framec = 4,
.frame_hit = 2
},
{.frames = {&anvil0, &anvil1, &anvil2, &anvil3, &anvil2, &anvil1},
.x = 0,
.y = 0,
.framec = 6,
.frame_hit = 3
}
};
void draw_hands(CCGame *game){
WeapAnim *anim = &weap_anims[game->curr_weapon];
dimage(anim->x, anim->y, anim->frames[game->weapon_use/4]);
}
void draw_gui(CCGame *game){
draw_hands(game);
dline(100,0,100,63,3);
dprint_opt(127,10,3,C_NONE,DTEXT_RIGHT,DTEXT_TOP,"%d",game->_bgame.player.hp);
//TODO : replace w/ icon
dtext_opt(127,20,3,C_NONE,DTEXT_RIGHT,DTEXT_TOP,"HP",-1);
}

View file

@ -13,6 +13,19 @@
#include "game.h" #include "game.h"
#define WEAP_ANIM_C 8
#define WEAP_FRAMES_C 8
typedef struct {
bopti_image_t *frames[WEAP_FRAMES_C];
int8_t x;
int8_t y;
int8_t framec;
int8_t frame_hit;
} WeapAnim;
void death_anim(RcGame *game);
void init_gfx(); void init_gfx();
void draw_gui(CCGame *game); void draw_gui(CCGame *game);

View file

@ -5,6 +5,7 @@
#include <gint/display.h> #include <gint/display.h>
#include <gint/keyboard.h> #include <gint/keyboard.h>
#include <gint/clock.h>
#include <gint/image.h> #include <gint/image.h>
#include <gint/gray.h> #include <gint/gray.h>
#include <gint/dma.h> #include <gint/dma.h>
@ -43,10 +44,14 @@ CCGame game = {
.player = { .player = {
.pos = {fix(3.1), fix(3.1)}, .pos = {fix(3.1), fix(3.1)},
.dir = {fix(0), fix(1)}, .dir = {fix(0), fix(1)},
.plane = {fix(0.66), fix(0)} .plane = {fix(0.66), fix(0)},
.hp = 100
}, },
.flags = {0} .flags = {0, 0}
} },
.hit = 0,
.curr_weapon = 1,
.weapon_use = 0
}; };
int frame_time = 1; int frame_time = 1;
@ -56,6 +61,10 @@ void keys_get(RcGame *game){
move(game); move(game);
if(keydown(KEY_SHIFT)){
use_weapon((CCGame*)game);
}
if (keydown(KEY_F1) && frame_time_timer <= 0) { if (keydown(KEY_F1) && frame_time_timer <= 0) {
if (disp_frame_time == 0) { if (disp_frame_time == 0) {
disp_frame_time = 1; disp_frame_time = 1;
@ -74,7 +83,7 @@ void keys_get(RcGame *game){
} }
if(keydown(KEY_F3)){ if(keydown(KEY_F3)){
cc_mksprite(game->player.pos, stype_frenguy); cc_mksprite(game->player.pos, 7);
while(keydown(KEY_F3)){ while(keydown(KEY_F3)){
clearevents(); clearevents();
pollevent(); pollevent();
@ -90,22 +99,7 @@ void keys_get(RcGame *game){
#endif #endif
} }
Sprite tsprite = { extern bopti_image_t title;
.pos = {200000, 300000},
.tex = 4
};
int movdir = 1;
int test_logic(GUNUSED RcGame *game){
tsprite.pos.x += movdir*500;
if(tsprite.pos.x > fix(4) || tsprite.pos.x < fix(2))
movdir = -movdir;
return 0;
}
extern bopti_image_t sprite_tst;
int main(){ int main(){
RcGame *rcgame = (RcGame*)&game; RcGame *rcgame = (RcGame*)&game;
@ -122,17 +116,15 @@ int main(){
rcgame->flags.exit = 1; rcgame->flags.exit = 1;
dupdate(); dupdate();
dclear(0); dimage(0,0,&title);
dupdate();
sleep_us(2000000);
#if debug #if debug
EngineTimers timers; EngineTimers timers;
//gdb_start_on_exception(); //gdb_start_on_exception();
#endif #endif
add_sprite(&tsprite);
add_logic_hook((RcLogicFunc*)&test_logic);
init_gfx(); init_gfx();
init_map(&game); init_map(&game);
init_logic(); init_logic();
@ -158,6 +150,8 @@ int main(){
if (disp_frame_time == 1) dprint( 0, 0, C_BLACK, "%d ms", frame_time/1000); if (disp_frame_time == 1) dprint( 0, 0, C_BLACK, "%d ms", frame_time/1000);
draw_gui(&game);
#if debug #if debug
dprint( 1, 27, C_BLACK, "pX %d", ffloor(rcgame->player.pos.x)); dprint( 1, 27, C_BLACK, "pX %d", ffloor(rcgame->player.pos.x));
dprint( 1, 36, C_BLACK, "pY %d", ffloor(rcgame->player.pos.y)); dprint( 1, 36, C_BLACK, "pY %d", ffloor(rcgame->player.pos.y));
@ -166,7 +160,7 @@ int main(){
timers.raycast_time = prof_make(); timers.raycast_time = prof_make();
timers.draw_time = prof_make(); timers.draw_time = prof_make();
#endif #endif
if(game.hit > 20){ if(game.hit > 30){
drect(0,0,127,63,C_INVERT); drect(0,0,127,63,C_INVERT);
} }
dupdate(); dupdate();
@ -179,7 +173,11 @@ int main(){
prof_quit(); prof_quit();
//Libérez vos textures générées procéduralement if(rcgame->flags.exit > 1){
dclear(0);
dprint(0,0,3,"Error %x !", rcgame->flags.exit);
dupdate();
getkey();
}
return 1; return 1;
} }

199
src/map.c
View file

@ -5,40 +5,195 @@
#include "C3D/map.h" #include "C3D/map.h"
#include "C3D/moteur.h" #include "C3D/moteur.h"
#include "C3D/game.h" #include "C3D/game.h"
#include "C3D/fixed.h"
#include "map.h" #include "map.h"
#include "game.h" #include "game.h"
uint8_t __attribute__((section(".rodata"))) map_dat0[] = { #define SEC_ROM __attribute__((section(".rodata")))
1,1,1,1,1,1,1,1,1,1,
1,0,0,0,0,0,0,0,0,1, int trigger_weapon_anvilstick(RcGame *_game){
1,0,4,0,0,0,0,2,0,1, CCGame *game = (void*)_game;
1,0,0,0,0,0,0,0,0,1, game->curr_weapon = weap_anvilstick;
1,0,0,0,0,0,0,0,0,1, game->weapon_use = 0;
1,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,1, return 0;
1,0,5,5,6,6,0,1,0,1, }
1,0,0,0,0,0,0,0,0,1,
1,1,1,1,1,1,1,1,1,1, uint8_t SEC_ROM map_dat0[] = {
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
6,0,0,0,0,0,6,0,0,0,0,0,0,0,0,0,0,0,0,6,
6,0,0,0,0,0,6,0,0,0,0,0,0,0,0,0,0,0,0,6,
6,0,0,0,0,0,6,6,5,5,5,6,6,6,6,6,0,0,0,6,
6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0,0,6,
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,0,6,6,6,6,
6,0,0,0,0,0,6,0,0,0,0,0,0,0,0,0,0,0,0,6,
6,0,0,0,0,0,6,0,6,0,0,6,0,0,6,0,0,6,0,6,
6,0,0,0,0,0,6,0,0,0,0,0,0,0,0,0,0,0,0,6,
6,0,1,6,5,5,6,0,0,0,0,0,0,0,0,0,0,0,0,6,
6,1,0,0,0,0,0,0,6,0,0,6,0,0,6,0,0,6,0,6,
6,0,1,6,6,6,6,0,0,0,0,0,0,0,0,0,0,0,0,6,
6,0,0,0,0,0,6,0,0,0,0,0,0,0,0,0,0,0,0,6,
6,0,0,0,0,0,6,0,6,0,0,6,0,0,6,0,0,6,0,6,
6,0,0,0,0,0,6,0,0,0,0,0,0,0,0,0,0,0,0,6,
6,0,0,0,0,0,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,
6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,
6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6
}; };
RcMap map0 = { CCMap SEC_ROM map0 = {
.w = 10, ._bmap = {
.h = 10, .w = 20,
.dat = (void*)&map_dat0 .h = 20,
.dat = (void*)&map_dat0,
.start_pos = {fix(3.1),fix(1.1)},
.sprites = {
{.pos = {fix(4.2),fix(14.2)}, .tex = 4},
{.pos = {fix(8.2),fix(10.2)}, .tex = 4}
},
.spritec = 2
},
.triggers = {
{.pos = {10,2},
.dat = {.tolvl = 1},
.type = 0
},
{},
{}
}
}; };
#define MAPC 1 uint8_t SEC_ROM map_dat1[] = {
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
RcMap *maps[MAPC] = { 6,0,0,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,
&map0 6,0,0,6,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,6,
6,0,6,6,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,6,
6,0,0,0,6,0,0,0,0,0,0,0,2,0,0,0,0,0,0,6,
6,6,6,0,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,
6,0,0,0,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,
6,0,6,6,6,6,6,6,6,6,6,6,6,6,6,6,0,0,0,6,
6,0,0,0,0,0,0,0,0,6,0,0,0,0,0,6,0,0,0,6,
6,6,0,6,6,6,0,6,0,0,0,6,6,6,6,6,0,0,0,6,
6,0,0,0,0,0,0,6,6,6,6,0,0,0,6,6,0,0,0,6,
6,0,5,5,0,0,0,6,6,6,6,6,0,6,5,6,0,0,6,6,
6,0,5,0,0,5,0,6,0,0,0,0,0,0,0,0,0,6,0,6,
6,0,0,0,5,5,0,0,0,5,0,6,0,6,6,6,6,0,0,6,
6,0,5,0,0,0,0,6,6,0,0,6,0,6,0,0,0,0,0,6,
6,0,0,0,0,0,0,0,0,0,6,0,0,6,0,0,0,0,0,6,
6,0,6,6,6,6,6,6,6,6,6,0,5,6,6,6,6,6,6,6,
6,0,0,0,0,0,0,0,0,0,0,0,0,5,0,0,0,0,0,6,
6,0,0,0,0,0,0,0,5,0,0,0,0,0,0,0,0,0,0,6,
6,6,6,5,5,6,6,5,6,6,6,6,6,6,6,6,6,6,6,6
}; };
void init_map(CCGame *game){ CCMap SEC_ROM map1 = {
switch_map(game, 0); ._bmap = {
.w = 20,
.h = 20,
.dat = map_dat1,
.start_pos = {fix(1.5),fix(1.5)},
.spritec = 4,
.sprites = {
{.pos = {fix(17.25),fix(2.25)}, .tex = 7},
{.pos = {fix(12.25),fix(3.25)}, .tex = 4},
{.pos = {fix(15.25),fix(6.25)}, .tex = 4},
{.pos = {fix(8.25),fix(1.25)}, .tex = 4}
}
},
.triggers = {
{.pos = {3,12},
.type = 0,
.dat = {.tolvl = 2}
},
{.pos = {17,2},
.type = 1,
.dat = {&trigger_weapon_anvilstick}
},
{}
}
};
uint8_t SEC_ROM map_dat2[] = {
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0,0,0,0,0,0,0,0,0,6,
6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0,0,0,0,0,0,0,0,0,6,
6,0,0,0,0,0,0,0,0,0,5,5,5,5,5,5,5,5,5,5,5,5,5,0,0,0,0,0,0,6,
6,0,0,0,0,6,5,6,6,6,5,0,0,0,0,0,0,0,0,0,0,0,0,5,0,0,0,0,0,6,
6,0,0,0,6,0,0,0,0,0,0,0,5,5,0,0,5,5,0,0,5,5,0,5,0,0,0,0,0,6,
6,0,0,0,6,0,5,6,0,6,5,0,5,5,0,0,5,5,0,0,5,5,0,5,0,0,0,0,0,6,
6,0,0,0,5,0,5,0,0,6,5,0,0,0,0,0,0,0,0,0,0,0,0,5,0,0,0,0,0,6,
6,0,0,0,6,0,6,0,6,6,5,0,0,0,0,0,0,0,0,0,0,0,0,5,0,0,0,0,0,6,
6,0,0,0,6,0,6,0,0,6,5,0,5,5,0,0,0,0,0,0,5,5,0,5,0,0,0,0,0,6,
6,0,0,0,6,0,6,6,0,6,5,0,5,5,0,0,0,0,0,0,5,5,0,5,0,0,0,0,0,6,
6,0,0,0,5,0,6,0,0,6,5,0,0,0,0,0,0,0,0,0,0,0,0,5,0,0,0,0,0,6,
6,0,0,0,6,0,5,0,6,6,5,0,0,0,0,0,0,0,0,0,0,0,0,5,0,0,0,0,0,6,
6,0,0,0,6,0,6,0,0,6,5,0,5,5,0,0,5,5,0,0,5,5,0,5,0,0,0,0,0,6,
6,0,0,0,6,0,6,6,0,6,5,0,5,5,0,0,5,5,0,0,5,5,0,5,0,0,0,0,0,6,
6,6,5,6,6,0,5,0,0,6,5,0,0,0,0,0,0,0,0,0,0,0,0,5,0,0,0,0,0,6,
6,0,0,0,5,0,6,0,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,0,0,0,0,0,0,6,
6,0,0,0,5,0,0,0,6,6,0,0,0,0,0,0,0,0,0,6,0,0,0,0,0,0,0,0,0,6,
6,0,0,0,0,0,5,0,6,6,0,0,0,0,0,0,0,0,0,6,0,0,0,0,0,0,0,0,0,6,
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
};
CCMap SEC_ROM map2 = {
._bmap = {
.w = 30,
.h = 20,
.dat = map_dat2,
.start_pos = {fix(18.5),fix(1.5)},
.spritec = 0,
.sprites = {
}
},
.triggers = {
{},
{},
{}
}
};
#define MAPC 3
CCMap *maps[MAPC] = {
&map0,
&map1,
&map2
}; };
void switch_map(CCGame *game, int map){ void switch_map(CCGame *game, int map){
game->_bgame.current_map = maps[map]; clear_sprites();
RcMap *nmap = (RcMap*)maps[map];
game->_bgame.current_map = nmap;
game->curr_map = map; game->curr_map = map;
cc_load_msprites(nmap->sprites, nmap->spritec);
game->_bgame.player.pos = nmap->start_pos;
game->_bgame.player.hp = 100;
} }
int map_triggers_agent(RcGame *game){
CCMap *map = (CCMap*)game->current_map;
for(int i = 0; i < LTRIGGER_C; i++){
LevelTrigger *trig = &map->triggers[i];
if(trig->pos.x == ffloor(game->player.pos.x) &&
trig->pos.y == ffloor(game->player.pos.y)){
if(!trig->type)
switch_map((CCGame*)game, trig->dat.tolvl);
else
if(trig->dat.func(game))
game->flags.exit = 1;
}
}
return 0;
}
void init_map(CCGame *game){
switch_map(game, 0);
add_logic_hook((RcLogicFunc*)&map_triggers_agent);
};

View file

@ -8,6 +8,28 @@
#include "game.h" #include "game.h"
#define LTRIGGER_C 3
typedef union{
RcLogicFunc *func;
int tolvl;
} TriggerType;
typedef struct {
V2d pos;
TriggerType dat;
bool type;
} LevelTrigger;
typedef struct {
RcMap _bmap;
LevelTrigger triggers[3];
} CCMap;
void init_map(CCGame *game); void init_map(CCGame *game);
void switch_map(CCGame *game, int map); void switch_map(CCGame *game, int map);