Just for fun, I want to make a "roguelike" for the Synertek Sym-1 in under 4Kb... in C! I'm using the CC65 compiler. However, this number is more like 3.5Kb, because the first 512 bytes are used for the zero page and stack...
**EDIT**
You can also compile this on windows or linux to test out!
Originally, I wanted to compile it for purely the 6502, but the 65c02 option seems to generate slightly better code, so I'll use the 65c02 for now and switch back if I can.
Right now, after rewriting the dungeon generator (literally just make a box) and changing some variables and structures around, I have reduced the size from ~3200 bytes to 2688 bytes. However, I want to add in:
1. Multiple monsters!
2. Display your HP!
3. Simple combat!
4. Simple random floor generation (possibly just simple pillars?)
The code is such:
Code:
// ------------------
// Roguelike for Sym-1
// Patrick Jackson
// ------------------
#define SYM 1
//#include "symrogue.h"
#if (SYM == 1)
#include <symio.h>
#define input() getchar()
#define _putchar(c) putchar(c)
#define puts(s) _puts(s)
#define input() getchar()
#if (ALTAIR == 1)
#define newline() putchar('\r')
#else
#define newline() putchar('\n');putchar('\r')
#endif
#else
#include <stdio.h>
#define input() getch()
#define newline() putchar('\n');
#endif
#include <stdlib.h>
#include <string.h>
#define clrscr() puts("\033[H");
#define ROW_LEN 10
#define COL_HGHT 10
#define MAP_SIZE ROW_LEN * COL_HGHT
#define MONS_NUM 1
typedef struct
{
int xy;
int _xy;
char ch;
} Entity;
Entity *monster;
int pos = 15;
char hp = 50;
unsigned char key_input = 0x00;
unsigned char map[MAP_SIZE + 1];
#if (SYM == 1)
void _puts(s)
char *s;
{
char c;
while ( c = *s++ )
_putchar(c);
newline();
}
#endif
// Function to create an X by Y box
void printMap()
{
unsigned char i;
for (i = 0; i < MAP_SIZE; i++)
{
putchar(map[ i ]);
if ( ( (i + 1) % ROW_LEN) == 0)
newline();
}
}
void printStat()
{
//
}
void combat()
{
//
}
void gameLoop()
{
static int _pos;
static int m_dir;
map[pos] = '.';
map[monster->xy] = '.';
_pos = pos;
monster->_xy = monster->xy;
switch (key_input)
{
case 'w':
pos -= ROW_LEN;
break;
case 'a':
pos--;
break;
case 's':
pos += ROW_LEN;
break;
case 'd':
pos++;
break;
default:
break;
}
// check for wall tile
if ( map[pos] == '#' )
pos = _pos;
// check for player combat
if ( pos == monster->xy )
{
combat();
pos = _pos;
}
// move monster
m_dir = ( rand() % 4 ); // really large, perhaps there's a smaller way?
switch ( m_dir )
{
case 0:
monster->xy++;
break;
case 1:
monster->xy--;
break;
case 2:
monster->xy += ROW_LEN;
break;
case 3:
monster->xy -= ROW_LEN;
break;
}
if ( map[monster->xy] == '#' )
{
monster->xy = monster->_xy;
}
// print player
map[pos] = '@';
// print monster
map[monster->xy] = monster->ch;
clrscr();
printMap();
printStat();
}
int main(void)
{
unsigned char i;
Entity loc_monster = {75, 0, 'M'};
monster = &loc_monster;
// truly clears screen
puts("\033[2J");
// --------- Create map --------------
// Fill entire grid with wall tiles '#'
memset(map, '#', MAP_SIZE);
// Fill interior with floor tiles '.'
for (i = 0; i < COL_HGHT - 2; i++)
{
memset(map + (i * ROW_LEN + ROW_LEN + 1), '.', ROW_LEN - 2);
}
do
{
gameLoop();
key_input = input();
}
while ( key_input != 'q' );
return 0;
}
I'm looking to see if I can optimize anything for size even more, given this code. I'm honestly kind of stuck at this point.
I'm using the -Cl -Osir cc65 command line options for the Synertek Sym-1.
Does anyone have some pointers/ideas?