two minutes to miiidnight
|
@ -11,7 +11,7 @@ find_package(Gint 2.9 REQUIRED)
|
|||
find_package(LibProf 2.1 REQUIRED)
|
||||
|
||||
# le nom de votre jeu
|
||||
set(NAMEOFGAME "Test3D")
|
||||
set(NAMEOFGAME "Illusion3D")
|
||||
# Nom de l'auteur -> votre nom/pseudo
|
||||
set(AUTHOR "Fcalva")
|
||||
|
||||
|
@ -30,8 +30,20 @@ set(SOURCES
|
|||
)
|
||||
|
||||
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/friendlyguy1.png
|
||||
assets-fx/sprites/anvil_pickup.png
|
||||
|
||||
assets-fx/textures/briques0.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)
|
||||
generate_g1a(TARGET Copy3DEngine OUTPUT ${NAMEOFGAME}".g1a"
|
||||
NAME ${NAMEOFGAME} ICON assets-fx/icon.png)
|
||||
NAME "Illu3D" ICON assets-fx/icon.png)
|
||||
else()
|
||||
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()
|
||||
|
|
12
README.md
|
@ -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
|
||||
|
||||
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.
|
||||
Vous pouvez aussi éditer la carte dans map.c, et sa taille dans map.h
|
||||
Dépendances :
|
||||
- gint
|
||||
- libprof
|
||||
|
|
BIN
assets-fx/anvil0.png
Normal file
After Width: | Height: | Size: 5 KiB |
BIN
assets-fx/anvil1.png
Normal file
After Width: | Height: | Size: 5.6 KiB |
BIN
assets-fx/anvil2.png
Normal file
After Width: | Height: | Size: 5.6 KiB |
BIN
assets-fx/anvil3.png
Normal file
After Width: | Height: | Size: 5.3 KiB |
BIN
assets-fx/blood.png
Normal file
After Width: | Height: | Size: 1.2 KiB |
|
@ -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
After Width: | Height: | Size: 944 B |
BIN
assets-fx/hands1.png
Normal file
After Width: | Height: | Size: 998 B |
BIN
assets-fx/hands2.png
Normal file
After Width: | Height: | Size: 1,015 B |
Before Width: | Height: | Size: 7.3 KiB After Width: | Height: | Size: 11 KiB |
BIN
assets-fx/sprites/anvil_pickup.png
Normal file
After Width: | Height: | Size: 4.5 KiB |
|
@ -6,3 +6,8 @@ friendlyguy1.png:
|
|||
type: bopti-image
|
||||
name: sprite_tst1
|
||||
profile: gray_alpha
|
||||
|
||||
anvil_pickup.png:
|
||||
type: bopti-image
|
||||
name: anvil_pick
|
||||
profile: gray_alpha
|
||||
|
|
BIN
assets-fx/title.png
Normal file
After Width: | Height: | Size: 1,016 B |
|
@ -380,7 +380,7 @@ void draw_walls(
|
|||
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]];
|
||||
|
||||
|
|
|
@ -31,9 +31,9 @@ void clear_sprites(){
|
|||
spritec = 0;
|
||||
}
|
||||
|
||||
void remove_sprite(Sprite *sprite){
|
||||
int remove_sprite(Sprite *sprite){
|
||||
if(!sprite)
|
||||
return;
|
||||
return 0;
|
||||
int pos = -1;
|
||||
for(int i = 0; i < spritec; i++){
|
||||
if(sprite == sprite_index[i]){
|
||||
|
@ -42,7 +42,7 @@ void remove_sprite(Sprite *sprite){
|
|||
}
|
||||
}
|
||||
if(pos < 0)
|
||||
return;
|
||||
return 1;
|
||||
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
|
||||
while(true) {
|
||||
//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;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
#define viewport_h 64
|
||||
#define max_dist fix(32)
|
||||
//Max sprites to attempt to render
|
||||
#define max_sprites 16
|
||||
#define max_sprites 32
|
||||
|
||||
#define TSIZE 32
|
||||
|
||||
|
|
|
@ -13,9 +13,13 @@ typedef int32_t fixed_t;
|
|||
/* Standard arithmetic. */
|
||||
|
||||
typedef struct {
|
||||
int32_t x ,y;
|
||||
int32_t x,y;
|
||||
} V2d;
|
||||
|
||||
typedef struct {
|
||||
int16_t x,y;
|
||||
} V2d16;
|
||||
|
||||
static inline fixed_t fmul(fixed_t left, fixed_t right)
|
||||
{
|
||||
/* 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)
|
||||
{
|
||||
if(!right)
|
||||
return 0;
|
||||
/* Pretty slow */
|
||||
int64_t d = (int64_t)left << 16;
|
||||
return d / right;
|
||||
|
|
|
@ -3,13 +3,15 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <gint/display.h>
|
||||
#include "utils.h"
|
||||
|
||||
typedef struct {
|
||||
V2d pos;
|
||||
Rect coll;
|
||||
int tex;
|
||||
} Sprite;
|
||||
int16_t tex;
|
||||
int16_t hp;
|
||||
} GPACKED(4) Sprite;
|
||||
|
||||
typedef struct {
|
||||
int w, h;
|
||||
|
@ -20,6 +22,8 @@ typedef struct {
|
|||
|
||||
Sprite sprites[SINDEX_S/2];
|
||||
|
||||
V2d start_pos;
|
||||
|
||||
} RcMap;
|
||||
|
||||
|
||||
|
@ -28,7 +32,9 @@ typedef struct {
|
|||
|
||||
V2d pos;
|
||||
Rect coll;
|
||||
int tex;
|
||||
int16_t tex;
|
||||
int16_t hp;
|
||||
|
||||
V2d dir;
|
||||
V2d plane;
|
||||
|
||||
|
@ -37,6 +43,8 @@ typedef struct {
|
|||
typedef struct {
|
||||
|
||||
uint8_t exit;
|
||||
uint8_t __pad;
|
||||
int16_t v_offset;
|
||||
|
||||
} RcFlags;
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ void add_sprite(Sprite *sprite);
|
|||
|
||||
void clear_sprites();
|
||||
|
||||
void remove_sprite(Sprite *sprite);
|
||||
int remove_sprite(Sprite *sprite);
|
||||
|
||||
void draw_sprites(bopti_image_t *tex_index[], RcActor *player);
|
||||
|
||||
|
|
|
@ -11,10 +11,8 @@
|
|||
#define min(x, xmin) (x > xmin ? xmin:x)
|
||||
|
||||
typedef struct {
|
||||
int x0,x1;
|
||||
int y0,y1;
|
||||
int16_t x0,x1;
|
||||
int16_t y0,y1;
|
||||
} Rect;
|
||||
|
||||
bool rect_rect_coll(Rect *a, Rect *b);
|
||||
|
||||
int cmpfunc (const void * a, const void * b);
|
||||
|
|
111
src/game.c
|
@ -4,7 +4,10 @@
|
|||
#include "C3D/sprites.h"
|
||||
#include "C3D/fixed.h"
|
||||
#include "C3D/game.h"
|
||||
|
||||
#include "game.h"
|
||||
#include "gfx.h"
|
||||
#include "map.h"
|
||||
|
||||
int sreserve_c = 0;
|
||||
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){
|
||||
|
@ -24,50 +41,71 @@ Sprite *cc_mksprite(V2d pos, int type){
|
|||
spr->tex = type;
|
||||
spr->coll = sprite_colls[type];
|
||||
spr->pos = pos;
|
||||
spr->hp = sprite_hp[type];
|
||||
add_sprite(spr);
|
||||
return spr;
|
||||
}
|
||||
|
||||
void cc_rmsprite(int pos){
|
||||
int cc_rmsprite(int pos){
|
||||
if(pos < 0 || pos >= sreserve_c)
|
||||
return;
|
||||
|
||||
remove_sprite(&sprite_reserve[pos]);
|
||||
return 1;
|
||||
|
||||
if(!remove_sprite(&sprite_reserve[pos]))
|
||||
return 2;
|
||||
if(pos+1 != sreserve_c){
|
||||
memmove(&sprite_reserve[pos], &sprite_reserve[pos+1], sizeof(Sprite)*(sreserve_c-pos));
|
||||
}
|
||||
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){
|
||||
if(game->hit > 0)
|
||||
return;
|
||||
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 dy = spr->pos.y - game->player.pos.y;
|
||||
fixed_t player_dist = fsq(dx) + fsq(dy);
|
||||
int dxs = (dx >= 0) * 2 - 1;
|
||||
int dys = (dy >= 0) * 2 - 1;
|
||||
|
||||
if(player_dist > fsq(max_dist))
|
||||
return 0;
|
||||
if(fixabs(ffloor(dx)) <= 1 && fixabs(ffloor(dy)) <= 1)
|
||||
int dys = (dy >= 0) * 2 - 1;
|
||||
|
||||
if(player_dist > fsq(max_dist) || player_dist < fsq(fix(0.5)))
|
||||
return;
|
||||
if(player_dist < fsq(range))
|
||||
cc_hit((CCGame*)game, hitstr);
|
||||
|
||||
int nx = spr->pos.x;
|
||||
int ny = spr->pos.y;
|
||||
if(fixabs(dx) >= fixabs(dy))
|
||||
spr->pos.x -= dxs * spd;
|
||||
nx -= dxs * spd;
|
||||
else
|
||||
spr->pos.y -= dys * spd;
|
||||
return 0;
|
||||
ny -= dys * spd;
|
||||
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){
|
||||
for(int i = 0; i < sreserve_c; i++){
|
||||
Sprite *spr = &sprite_reserve[i];
|
||||
if(spr->hp <= 0){
|
||||
if(cc_rmsprite(i) == 2)
|
||||
game->flags.exit = 2;
|
||||
continue;
|
||||
}
|
||||
switch(spr->tex){
|
||||
default:
|
||||
case 0:
|
||||
|
@ -76,7 +114,7 @@ int cc_ai(RcGame *game){
|
|||
case 3:
|
||||
break;
|
||||
case 4:{
|
||||
cc_ai_mov(game, spr, fix(.025), 5, 0);
|
||||
cc_ai_mov(game, spr, fix(.025), 5, 1, fix(1));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -84,12 +122,51 @@ int cc_ai(RcGame *game){
|
|||
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){
|
||||
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;
|
||||
}
|
||||
|
||||
void use_weapon(CCGame *game){
|
||||
if(game->weapon_use)
|
||||
return;
|
||||
game->weapon_use = 1;
|
||||
}
|
||||
|
||||
void init_logic(){
|
||||
add_logic_hook((RcLogicFunc*)&cc_ai);
|
||||
add_logic_hook((RcLogicFunc*)&cc_logic);
|
||||
|
|
29
src/game.h
|
@ -5,18 +5,37 @@
|
|||
#include "C3D/game.h"
|
||||
|
||||
enum {
|
||||
stype_frenguy = 4
|
||||
stype_frenguy = 4,
|
||||
stype_anvilpick = 7
|
||||
};
|
||||
|
||||
enum {
|
||||
weap_none = 0,
|
||||
weap_hands = 1,
|
||||
weap_anvilstick = 2
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
RcGame _bgame;
|
||||
int curr_map;
|
||||
int16_t hit;
|
||||
int16_t hp;
|
||||
int8_t curr_map;
|
||||
int8_t hit;
|
||||
int8_t curr_weapon;
|
||||
int8_t weapon_use;
|
||||
} 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);
|
||||
|
||||
void cc_rmsprite(int pos);
|
||||
int cc_rmsprite(int pos);
|
||||
|
||||
void use_weapon(CCGame *game);
|
||||
|
||||
int cc_logic_onframe(CCGame *game);
|
||||
|
||||
void init_logic();
|
||||
|
|
64
src/gfx.c
|
@ -1,5 +1,7 @@
|
|||
//Par Fcalva et est sous GPLv3
|
||||
#include <gint/display.h>
|
||||
#include <gint/keyboard.h>
|
||||
#include <gint/clock.h>
|
||||
|
||||
#include "C3D/fixed.h"
|
||||
#include "C3D/game.h"
|
||||
|
@ -18,6 +20,7 @@ extern bopti_image_t bwain0;
|
|||
extern bopti_image_t bwain1;
|
||||
extern bopti_image_t meat0;
|
||||
extern bopti_image_t meat1;
|
||||
extern bopti_image_t anvil_pick;
|
||||
|
||||
bopti_image_t *tex_index[TINDEX_S] = {
|
||||
&briques0, //0
|
||||
|
@ -26,7 +29,8 @@ bopti_image_t *tex_index[TINDEX_S] = {
|
|||
&briques0, //3
|
||||
&sprite_tst, //4
|
||||
&bwain0, //5
|
||||
&meat0 //6
|
||||
&meat0, //6
|
||||
&anvil_pick //7
|
||||
};
|
||||
|
||||
int state = 0;
|
||||
|
@ -43,7 +47,59 @@ void init_gfx(){
|
|||
add_logic_hook((RcLogicFunc*)&anim_tex);
|
||||
}
|
||||
|
||||
void draw_gui(CCGame *game){
|
||||
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);
|
||||
extern bopti_image_t blood;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
13
src/gfx.h
|
@ -13,6 +13,19 @@
|
|||
|
||||
#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 draw_gui(CCGame *game);
|
||||
|
|
54
src/main.c
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include <gint/display.h>
|
||||
#include <gint/keyboard.h>
|
||||
#include <gint/clock.h>
|
||||
#include <gint/image.h>
|
||||
#include <gint/gray.h>
|
||||
#include <gint/dma.h>
|
||||
|
@ -43,10 +44,14 @@ CCGame game = {
|
|||
.player = {
|
||||
.pos = {fix(3.1), fix(3.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;
|
||||
|
@ -56,6 +61,10 @@ void keys_get(RcGame *game){
|
|||
|
||||
move(game);
|
||||
|
||||
if(keydown(KEY_SHIFT)){
|
||||
use_weapon((CCGame*)game);
|
||||
}
|
||||
|
||||
if (keydown(KEY_F1) && frame_time_timer <= 0) {
|
||||
if (disp_frame_time == 0) {
|
||||
disp_frame_time = 1;
|
||||
|
@ -74,7 +83,7 @@ void keys_get(RcGame *game){
|
|||
}
|
||||
|
||||
if(keydown(KEY_F3)){
|
||||
cc_mksprite(game->player.pos, stype_frenguy);
|
||||
cc_mksprite(game->player.pos, 7);
|
||||
while(keydown(KEY_F3)){
|
||||
clearevents();
|
||||
pollevent();
|
||||
|
@ -90,22 +99,7 @@ void keys_get(RcGame *game){
|
|||
#endif
|
||||
}
|
||||
|
||||
Sprite tsprite = {
|
||||
.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;
|
||||
extern bopti_image_t title;
|
||||
|
||||
int main(){
|
||||
RcGame *rcgame = (RcGame*)&game;
|
||||
|
@ -122,17 +116,15 @@ int main(){
|
|||
rcgame->flags.exit = 1;
|
||||
dupdate();
|
||||
|
||||
dclear(0);
|
||||
dimage(0,0,&title);
|
||||
dupdate();
|
||||
sleep_us(2000000);
|
||||
|
||||
#if debug
|
||||
EngineTimers timers;
|
||||
//gdb_start_on_exception();
|
||||
#endif
|
||||
|
||||
add_sprite(&tsprite);
|
||||
|
||||
add_logic_hook((RcLogicFunc*)&test_logic);
|
||||
|
||||
init_gfx();
|
||||
init_map(&game);
|
||||
init_logic();
|
||||
|
@ -158,6 +150,8 @@ int main(){
|
|||
|
||||
if (disp_frame_time == 1) dprint( 0, 0, C_BLACK, "%d ms", frame_time/1000);
|
||||
|
||||
draw_gui(&game);
|
||||
|
||||
#if debug
|
||||
dprint( 1, 27, C_BLACK, "pX %d", ffloor(rcgame->player.pos.x));
|
||||
dprint( 1, 36, C_BLACK, "pY %d", ffloor(rcgame->player.pos.y));
|
||||
|
@ -166,7 +160,7 @@ int main(){
|
|||
timers.raycast_time = prof_make();
|
||||
timers.draw_time = prof_make();
|
||||
#endif
|
||||
if(game.hit > 20){
|
||||
if(game.hit > 30){
|
||||
drect(0,0,127,63,C_INVERT);
|
||||
}
|
||||
dupdate();
|
||||
|
@ -179,7 +173,11 @@ int main(){
|
|||
|
||||
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;
|
||||
}
|
||||
|
|
201
src/map.c
|
@ -5,40 +5,195 @@
|
|||
#include "C3D/map.h"
|
||||
#include "C3D/moteur.h"
|
||||
#include "C3D/game.h"
|
||||
#include "C3D/fixed.h"
|
||||
|
||||
#include "map.h"
|
||||
#include "game.h"
|
||||
|
||||
uint8_t __attribute__((section(".rodata"))) map_dat0[] = {
|
||||
1,1,1,1,1,1,1,1,1,1,
|
||||
1,0,0,0,0,0,0,0,0,1,
|
||||
1,0,4,0,0,0,0,2,0,1,
|
||||
1,0,0,0,0,0,0,0,0,1,
|
||||
1,0,0,0,0,0,0,0,0,1,
|
||||
1,0,0,0,0,0,0,0,0,1,
|
||||
1,0,0,0,0,0,0,0,0,1,
|
||||
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,
|
||||
#define SEC_ROM __attribute__((section(".rodata")))
|
||||
|
||||
int trigger_weapon_anvilstick(RcGame *_game){
|
||||
CCGame *game = (void*)_game;
|
||||
game->curr_weapon = weap_anvilstick;
|
||||
game->weapon_use = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
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 = {
|
||||
.w = 10,
|
||||
.h = 10,
|
||||
.dat = (void*)&map_dat0
|
||||
CCMap SEC_ROM map0 = {
|
||||
._bmap = {
|
||||
.w = 20,
|
||||
.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
|
||||
|
||||
RcMap *maps[MAPC] = {
|
||||
&map0
|
||||
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,
|
||||
6,0,0,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,
|
||||
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){
|
||||
switch_map(game, 0);
|
||||
CCMap SEC_ROM map1 = {
|
||||
._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){
|
||||
game->_bgame.current_map = maps[map];
|
||||
game->curr_map = map;
|
||||
clear_sprites();
|
||||
RcMap *nmap = (RcMap*)maps[map];
|
||||
game->_bgame.current_map = nmap;
|
||||
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);
|
||||
};
|
||||
|
||||
|
|
22
src/map.h
|
@ -8,6 +8,28 @@
|
|||
|
||||
#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 switch_map(CCGame *game, int map);
|
||||
|
|