The *working* binary is now
1522 bytes!!!
I'm really trying to get this *finished* by this Thursday, but between changing jobs, the holidays, and finishing this current job demo, its pretty tight. I just need to get combat done and add in a status bar bit. Then, the original goal would've been hit! I then want to add xp, gold, and maybe a very very small level generator if possible!
There's a very interesting idea of making the map a multiple of 8 wide, then I could use bytes and bits to mark floors and walls! Items would be interesting, but I could make an item map to be overlaid on top of that I suppose (printMap and then printItems?)
Here's the code. But I have a
GLARING ERRORCode:
/* ------------------
Roguelike for Sym-1
Patrick Jackson
------------------
*/
#include "symRogue.h"
#define ROW_LEN 16
#define COL_HGHT 10
#define MAP_SIZE ROW_LEN * COL_HGHT
#define ROW_MASK ( ROW_LEN - 1 )
#define MONS_NUM 3
unsigned char map[ MAP_SIZE ];
#if SYM==1
#pragma bss-name (push,"ZEROPAGE")
unsigned char lpos, direction, glyph, pos, hp, m_i;
#pragma bss-name (pop)
#else
unsigned char lpos, direction, glyph;
unsigned char pos;
unsigned char hp;
unsigned char m_i;
#endif
unsigned char mons_xy[MONS_NUM];
unsigned char mons_ch[MONS_NUM];
unsigned char mons_hp[MONS_NUM];
unsigned char key_input = 0x00;
void printMap()
{
unsigned char i;
clrscr();
for ( i = 0; i < MAP_SIZE; ++i )
{
putchar( map[ i ] );
if ( ! ( ( i + 1 ) & ( ROW_MASK ) ) )
{
newline();
}
}
}
void chkMCmbt()
{
//
}
void chkPCmbt()
{
mons_hp[ m_i ] -= (unsigned char)10;
printf("Monster: %d\tHP: %d\n", m_i, mons_hp[ m_i ]);
}
unsigned char move()
{
unsigned char _lpos;
/* Move character around */
_lpos = lpos;
map[ _lpos ] = '.';
switch ( direction )
{
case 'w': case 0:
_lpos -= ROW_LEN;
break;
case 'a': case 1:
_lpos--;
break;
case 's': case 2:
_lpos += ROW_LEN;
break;
case 'd': case 3:
_lpos++;
default:
break;
}
/* Check for wall, player, or monster collision */
if (map[_lpos] == '#')
_lpos = lpos;
else if ( (glyph == '@') && (map[_lpos] == 'M'))
{
chkPCmbt();
_lpos = lpos;
}
else if (map[_lpos] == '@')
{
chkMCmbt();
_lpos = lpos;
}
map[_lpos] = glyph;
return _lpos;
}
int main()
{
/* Set up player pos */
pos = 25;
for ( m_i = 0; m_i < MONS_NUM; ++m_i )
{
mons_xy[ m_i ] = 50;
mons_hp[ m_i ] = 50;
}
clrdraw();
/* --------- Create map ---------
Fill entire grid with wall tiles '#' */
memset( map, '#', MAP_SIZE );
/* Fill interior with floor tiles '.' */
for ( m_i = ROW_LEN + 1; m_i < MAP_SIZE - ROW_LEN; m_i += ROW_LEN )
memset( map + m_i, '.', ROW_LEN - 2 );
/* --------- Main loop ----------- */
do
{
lpos = pos;
direction = key_input;
glyph = '@';
pos = move();
for ( m_i = 0; m_i < MONS_NUM; ++m_i )
{
lpos = mons_xy[ m_i ];
direction = rand() & 0x03;
glyph = 'M';
mons_xy[ m_i ] = move();
}
printMap();
key_input = input();
}
while ( key_input != 'q' );
return 0;
}
If I hit a monster, its HP will jump to say, something even like 90 or like 102 or something crazy. I have mons_hp being set to 50, and the combat to be -=10, as an unsigned char. What is possibly happening?