Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cocobattleroyale.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#define FAMICON_VERSION (0)
#include "lib/micromages.h"
#include "lib/neslib.h"
#include "lib/globals.h"
#include "src/i18n.c"
#include "src/ia.c"
#include "src/draw.c"
#include "src/game.c"
4 changes: 4 additions & 0 deletions kokobatoru.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#define FAMICON_VERSION (1)
#include "lib/micromages.h"
#include "lib/neslib.h"
#include "lib/globals.h"
#include "src/i18n.c"
#include "src/ia.c"
#include "src/draw.c"
#include "src/game.c"
171 changes: 171 additions & 0 deletions lib/globals.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
/**
* @todo: refact this cheat.
*/
#define MAX_ENIMIES (4)
#define MAX_PLAYERS (4)
#define SPEED (1)
#define MIN_ARENA_X (6)
#define MAX_ARENA_X (242)
#define MID_ARENA_X ((MAX_ARENA_X/2)+MIN_ARENA_X)
#define MIN_ARENA_Y (22)
#define MAX_ARENA_Y (208)
#define MID_ARENA_Y ((MAX_ARENA_Y/2)+MIN_ARENA_Y)
#define RANGE_ARENA (40)
#define LOOK_RIGHT (0)
#define LOOK_LEFT (1)
#define PLAYER_1 (0)
#define PLAYER_2 (1)
#define FRAME_PREPARE (7)
#define FRAME_ATTACKING (6)
#define FRAME_RECOVERY (2)
#define DIGIT_WINNER (22)
#define DIGIT_NOOB (21)

/**
* FUNCTIONS
*/
#define SEED_PACK(v) ((unsigned char)(v-256))
#define SEED_UNPACK(v) ((unsigned int)(v+256))
#define ABS(v) (v<0?-v:v)
#define POW(v) (v*v)
#define PRESSING(g,b) ((g&b)==b)
#define CLAMP(v,min,max) (MIN(max,MAX(min,v)))
#define DISTANCE(a,b) (a>b?a-b:b-a)
#define DISTANCE2D(a1,a2,b1,b2) ((int)DISTANCE(a1,a2)+DISTANCE(b1,b2))

/**
* SPRITES
*/
#define SPR_EDGE 0xBF
#define SPR_EDGE_1 0xB9
#define SPR_EDGE_2 0xBC
#define SPR_POINTER 0x5C

/**
* TYPES
*/

enum fsm_game_e {
FSM_MUSIC_MENU,
FSM_MUSIC_ARENA,
FSM_DRAW_MENU,
FSM_DRAW_ARENA,
FSM_DRAW_CELEBRATION,
FSM_MENU,
FSM_GAMEPLAY,
FSM_CELEBRATION,
FSM_RESTART
};

enum fsm_ia_e {
FSM_DEFAULT,
FSM_RANDOM,
FSM_HUNTER_WAIT,
FSM_HUNTER,
FSM_SCAPE_WAIT,
FSM_SCAPE,
FSM_WINNER
};

struct coco_s {
unsigned char x;
unsigned char y;
unsigned char framedata;
union {
signed char sprite;
struct {
unsigned char walking: 1;
unsigned char flipped: 1;
unsigned char attacking: 1;
unsigned char recovering: 1;
unsigned char coloreven: 1;
unsigned char death: 1;
} status;
} info;
};

struct npc_ia_s {
unsigned char target;
unsigned char input;
enum fsm_ia_e state;
};

struct framecount_s {
unsigned char frames: 2;
unsigned char hunter_last: 2;
unsigned char hunter_step: 4;
};



/** GLOBAL CONSTANTS **/
static const unsigned char npc_groups[] = {
0, 0, 0, 1, 2,
3, 0, 1, 2, 3,
3, 0, 1, 2, 3,
3, 0, 1, 2, 3,
};

static const unsigned char good_seeds[] = {
SEED_PACK(283), SEED_PACK(285), SEED_PACK(499),
SEED_PACK(301), SEED_PACK(305), SEED_PACK(274),
SEED_PACK(332), SEED_PACK(336), SEED_PACK(353),
SEED_PACK(368), SEED_PACK(378), SEED_PACK(395),
SEED_PACK(451), SEED_PACK(507)
};


const char paletteBackgroundMenu[] = {
0x0f, 0x30, 0x30, 0x30,
0x0f, 0x30, 0x0f, 0x30,
0x0f, 0x30, 0x0f, 0x0f
};

const char paletteBackground[] = {
0x0f, 0x30, 0x30, 0x30,
0x0f, 0x30, 0x30, 0x30,
0x0f, 0x30, 0x30, 0x30,
0x0f, 0x27, 0x30, 0x0f
};

const char paletteSprite[] = {
0x0f,0x30,0x27,0x16,
0x0f,0x2C,0x25,0x30,
0x0f,0x13,0x15,0x25,
0x0f,0x26,0x2A,0x36,
};

const char digit_lockup[2][] = {
{' ', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 0xD1, '1', '2', '3'},
{' ', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '2', 0xD0, 0xFF, 0xEF, 0xDF}
};

/** GLOBAL VARIABLES **/
static struct npc_ia_s npcs[MAX_ENIMIES]; /** IA controll **/
static struct framecount_s framecount; /** IA manager groups **/
static struct coco_s players[MAX_ENIMIES]; /** all cocks entitys **/
static enum fsm_game_e gamestate; /** finite state machine **/
static unsigned char seed; /** randomness control **/
static unsigned char roosters_count; /** cocks counter **/
static unsigned char roosters_total; /** total of cocks arrive **/

/** micromages 4 players **/
static unsigned char joysticks = 1; /** local multiplayer mode **/
static unsigned char gamepad_old[MAX_PLAYERS]; /** last frame joysticks inputs **/
static const unsigned char* const gamepad = &joy1; /** joystick inputs **/

/** score rank 4 players **/
static unsigned char player_score[4] = {0, 1, 11, 21};
static unsigned char player_rank[4] = {186, 186, 202, 105};

/** GENERAL VARIABLES **/
static signed char s;
static unsigned int big1, big2;
static unsigned char i,j,l,r;
static unsigned char spr;

/** ANIMATION VARIABLE */
static unsigned char step_1;
static unsigned char step_2;
static unsigned char step_3;
static unsigned char step_4;
2 changes: 1 addition & 1 deletion lib/neslib.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ void __fastcall__ vram_read(unsigned char *dst,unsigned int size);

//write a block to current address of vram, works only when rendering is turned off

void __fastcall__ vram_write(unsigned char *src,unsigned int size);
void __fastcall__ vram_write(const char* src,unsigned int size);


//unpack RLE data to current address of vram, mostly used for nametables
Expand Down
Binary file modified res/tileset.chr
Binary file not shown.
190 changes: 190 additions & 0 deletions src/draw.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
void put_all(const char c)
{
vram_adr(NTADR_A(0,1));
vram_fill(c, 32*28);
}

void put_str(unsigned int adr,const char *str)
{
unsigned char fixed_x = (adr & 0x1f);
vram_adr(adr);
for (;*str != '\0'; ++str) {
/** line feed */
if (*str == '\n') {
/** y + 1*/
adr += 32;
vram_adr(adr);
continue;
}
/** carrier return */
if (*str == '\r') {
/** x = fixed_x */
adr = fixed_x | (adr & 0xffe0);
vram_adr(adr);
continue;
}
/** print */
vram_put(*str);
++adr;
}
}

void put_ret(unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2)
{
/** adjust size **/
x2 += 1;
y2 += 1;
j = x2 - x1;

/** draw horizontal lines **/
for (j = x1 + 1; j < x2; ++j)
{
vram_adr(NTADR_A(j,y1));
vram_put(SPR_EDGE_1 + (j % 3));
vram_adr(NTADR_A(j,y2));
vram_put(SPR_EDGE_1 + (j % 3));
}

/** draw vertical lines **/
for (j = y1 + 1; j < y2; ++j)
{
vram_adr(NTADR_A(x1, j));
vram_put(SPR_EDGE_2 + (j % 3));
vram_adr(NTADR_A(x2, j));
vram_put(SPR_EDGE_2 + (j % 3));
}
}

void put_borders()
{
put_ret(MIN_ARENA_X/8, MIN_ARENA_Y/8, MAX_ARENA_X/8, MAX_ARENA_Y/8);
vram_adr(ATADR_A(0, 1));
vram_fill(BR_BL_TR_TL(0,0,3,3), 8);
vram_adr(ATADR_A(0, 27));
vram_fill(BR_BL_TR_TL(0,0,2,1), 8);
for (i = 5; i < 25; i += 2) {
vram_adr(ATADR_A(0, i));
vram_put(BR_BL_TR_TL(3,1,3,1));
vram_adr(ATADR_A(30, i));
vram_put(BR_BL_TR_TL(2,3,2,3));
}
}

void put_logo()
{
for (i = 0; i < 6; i++){
vram_adr(NTADR_A(7, 4 + i));
vram_write((jp? I18N_JP_LOGO: I18N_EN_LOGO) + (i*17), 17);
}
}

void put_score()
{
/** show scores */
for (l = 0; l < MAX_PLAYERS; ++l) {
s = player_rank[l];
vram_adr(NTADR_A(l << 2, 1));
if (l < joysticks) {
vram_put(0x5c + l);
vram_put('P');
} else {
vram_put(' ');
vram_put(' ');
}
vram_put(digit_lockup[1][s]);
vram_put(digit_lockup[0][s]);
}
}

void draw_menu()
{
ppu_off();
pal_bg(paletteBackgroundMenu);
oam_clear();
/** reset nametable */
put_all(' ');
/** reset attribute table*/
vram_adr(ATADR_A(0, 1));
vram_fill(BR_BL_TR_TL(0,0,0,0), 3*8);
vram_fill(BR_BL_TR_TL(2,2,2,2), 5*8);
/** colorize logo */
vram_adr(ATADR_A(7,7));
vram_put(BR_BL_TR_TL(2,0,2,0));
vram_adr(ATADR_A(7,9));
vram_put(BR_BL_TR_TL(0,0,2,0));
vram_adr(ATADR_A(8,7));
vram_fill(BR_BL_TR_TL(2,2,2,2), 4);
vram_adr(ATADR_A(8,8));
vram_fill(BR_BL_TR_TL(0,0,2,2), 4);
vram_adr(ATADR_A(18,6));
vram_put(BR_BL_TR_TL(1,1,2,2));
/** colorize link */
vram_adr(ATADR_A(1,26));
vram_fill(BR_BL_TR_TL(1,1,2,2), 30);
/** game title */
put_ret(5, 3, 25, 9);
put_logo();
/** put menu options */
vram_adr(NTADR_A(11,16));
vram_write(jp? I18N_JP_1_PLAYERS: I18N_EN_1_PLAYERS, 9);
vram_adr(NTADR_A(11,17));
vram_write(jp? I18N_JP_2_PLAYERS: I18N_EN_2_PLAYERS, 9);
vram_adr(NTADR_A(11,18));
vram_write(jp? I18N_JP_3_PLAYERS: I18N_EN_3_PLAYERS, 9);
vram_adr(NTADR_A(11,19));
vram_write(jp? I18N_JP_4_PLAYERS: I18N_EN_4_PLAYERS, 9);
/** put copyright */
put_str(NTADR_A(3,25), I18N_EN_CREDITS_1);
put_str(NTADR_A(1,26), I18N_EN_CREDITS_2);
/** put menu option 'continue' */
if (roosters_count) {
vram_adr(NTADR_A(11,15));
vram_write(jp? I18N_JP_CONTINUE: I18N_EN_CONTINUE, 9);
}
ppu_on_all();
gamestate = FSM_MENU;
}

void draw_arena()
{
ppu_off();
oam_clear();
pal_bg(paletteBackground);
pal_spr(paletteSprite);
/** reset nametable */
put_all(' ');
/** reset attribute table*/
vram_adr(ATADR_A(0, 1));
vram_fill(BR_BL_TR_TL(3,3,3,3), 8*8);
/** put borders */
put_borders();
/* put footer */
put_str(NTADR_A(0,28), I18N_EN_GAMEPLAY_NAME);
/* put header */
put_str(NTADR_A(26,1), "\x10 /20");
put_score();
gamestate = FSM_GAMEPLAY;
ppu_on_all();
}

void draw_celebration()
{
ppu_off();
oam_clear();
put_all(' ');
put_borders();
put_score();
for (i = 0; i < MAX_PLAYERS; ++i) {
s = player_score[i];
if (!s) {
continue;
}
vram_adr(NTADR_A(7, 19 + i));
vram_write(I18N_EN_1_PLAYERS + (i * 10), 8);
vram_write(I18N_EN_SCORE, sizeof(I18N_EN_SCORE) - 1);
vram_put(digit_lockup[1][s]);
vram_put(digit_lockup[0][s]);
}
gamestate = FSM_CELEBRATION;
ppu_on_all();
}
Loading