mirror of
https://git.planet-casio.com/Fcalva/Copy3DEngine.git
synced 2024-12-28 04:23:44 +01:00
CPC : premier ennemi
This commit is contained in:
parent
1084917cb6
commit
9e65d04d22
7 changed files with 77 additions and 5 deletions
|
@ -7,7 +7,7 @@
|
|||
|
||||
#define screen_w 128
|
||||
#define screen_h 64
|
||||
#define viewport_w 128
|
||||
#define viewport_w 100
|
||||
#define viewport_h 64
|
||||
#define max_dist fix(32)
|
||||
//Max sprites to attempt to render
|
||||
|
|
|
@ -72,7 +72,7 @@ static inline double f2double(fixed_t f)
|
|||
return (double)f / 65536;
|
||||
}
|
||||
|
||||
static inline fixed_t feasein(fixed_t x)
|
||||
static inline fixed_t fsq(fixed_t x)
|
||||
{
|
||||
return fmul(x, x);
|
||||
}
|
||||
|
|
57
src/game.c
57
src/game.c
|
@ -3,6 +3,8 @@
|
|||
|
||||
#include "C3D/sprites.h"
|
||||
#include "C3D/fixed.h"
|
||||
#include "C3D/game.h"
|
||||
#include "game.h"
|
||||
|
||||
int sreserve_c = 0;
|
||||
Sprite sprite_reserve[SINDEX_S];
|
||||
|
@ -37,3 +39,58 @@ void cc_rmsprite(int pos){
|
|||
}
|
||||
sreserve_c--;
|
||||
}
|
||||
|
||||
void cc_hit(CCGame *game, int hitstr){
|
||||
if(game->hit > 0)
|
||||
return;
|
||||
game->hit = 40;
|
||||
game->hp -= hitstr;
|
||||
}
|
||||
|
||||
int cc_ai_mov(RcGame *game, Sprite *spr, fixed_t spd, int hitstr, int coll){
|
||||
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)
|
||||
cc_hit((CCGame*)game, hitstr);
|
||||
if(fixabs(dx) >= fixabs(dy))
|
||||
spr->pos.x -= dxs * spd;
|
||||
else
|
||||
spr->pos.y -= dys * spd;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cc_ai(RcGame *game){
|
||||
for(int i = 0; i < sreserve_c; i++){
|
||||
Sprite *spr = &sprite_reserve[i];
|
||||
switch(spr->tex){
|
||||
default:
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
break;
|
||||
case 4:{
|
||||
cc_ai_mov(game, spr, fix(.025), 5, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cc_logic(RcGame *_game){
|
||||
CCGame *game = (void*)_game;
|
||||
if(game->hit) game->hit --;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void init_logic(){
|
||||
add_logic_hook((RcLogicFunc*)&cc_ai);
|
||||
add_logic_hook((RcLogicFunc*)&cc_logic);
|
||||
}
|
||||
|
|
|
@ -11,8 +11,12 @@ enum {
|
|||
typedef struct {
|
||||
RcGame _bgame;
|
||||
int curr_map;
|
||||
int16_t hit;
|
||||
int16_t hp;
|
||||
} CCGame; //CpC game Game struct
|
||||
|
||||
Sprite *cc_mksprite(V2d pos, int type);
|
||||
|
||||
void cc_rmsprite(int pos);
|
||||
|
||||
void init_logic();
|
||||
|
|
|
@ -42,3 +42,8 @@ int anim_tex(GUNUSED RcGame *game){
|
|||
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);
|
||||
}
|
||||
|
|
|
@ -11,4 +11,8 @@
|
|||
#include "C3D/map.h"
|
||||
#include "C3D/config.h"
|
||||
|
||||
#include "game.h"
|
||||
|
||||
void init_gfx();
|
||||
|
||||
void draw_gui(CCGame *game);
|
||||
|
|
|
@ -134,8 +134,8 @@ int main(){
|
|||
add_logic_hook((RcLogicFunc*)&test_logic);
|
||||
|
||||
init_gfx();
|
||||
|
||||
init_map(&game);
|
||||
init_logic();
|
||||
|
||||
while (!rcgame->flags.exit) {
|
||||
prof_t frame = prof_make();
|
||||
|
@ -166,7 +166,9 @@ int main(){
|
|||
timers.raycast_time = prof_make();
|
||||
timers.draw_time = prof_make();
|
||||
#endif
|
||||
|
||||
if(game.hit > 20){
|
||||
drect(0,0,127,63,C_INVERT);
|
||||
}
|
||||
dupdate();
|
||||
prof_leave(frame);
|
||||
frame_time = prof_time(frame);
|
||||
|
|
Loading…
Reference in a new issue