SegaRaycast/src/main.c

129 lines
2.8 KiB
C
Raw Normal View History

2024-08-29 17:51:49 -06:00
#include <genesis.h>
2024-08-29 18:49:38 -06:00
#define SPEED 2
2024-08-29 18:17:52 -06:00
Line l;
2024-08-29 19:39:58 -06:00
const u8 map[10][10] = {{1,1,1,1,1,1,1,1,1,1},
{1,0,0,0,0,0,0,0,0,1},
{1,1,1,1,0,0,1,1,1,1},
{1,0,0,1,0,0,1,0,0,1},
{1,0,0,0,0,0,1,0,0,1},
{1,0,0,1,0,0,1,1,0,1},
{1,1,1,1,0,0,1,0,0,1},
{1,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,1,0,0,1},
{1,1,1,1,1,1,1,1,1,1}};
2024-08-29 21:04:02 -06:00
void castRay(s16 angle){
u8 r,mx,my,mp,dof;
float rx,ry,ra,xo,yo;
s16 ind = (int)((float)angle/360.0f*1024.0f);
fix16 dx = sinFix16(ind);
fix16 dy = cosFix16(ind);
fix16 tan = fix16Div(dy, dx);
fix16 aTan = fix16Div(-1, tan);
s16 tanInt = fix16ToInt(fix16Mul(dx, 100));
char str[10];
sprintf(str, "%d", 10);
BMP_drawText(str, 20, 0);
}
2024-08-29 19:39:58 -06:00
void mapscan(){
2024-08-29 21:04:02 -06:00
u8 mapcolor = 12;
2024-08-29 19:39:58 -06:00
mapcolor |= mapcolor << 4;
int mapscale = 10;
for(u8 x = 0; x < 10; x++){
for(u8 y = 0; y < 10; y++){
if(map[y][x] == 1){
Vect2D_s16 mapverts[4] = {{x*mapscale,y*mapscale},{(x+1)*mapscale,y*mapscale},{(x+1)*mapscale,(y+1)*mapscale},{x*mapscale,(y+1)*mapscale}};
BMP_drawPolygon(mapverts, 4, mapcolor);
}
}
}
}
2024-08-29 18:49:38 -06:00
2024-08-29 18:17:52 -06:00
void render(){
//Clear the bitmap
BMP_clear();
//Draw the line defined above (in the background, hidden)
BMP_drawLine(&l);
2024-08-29 19:39:58 -06:00
mapscan();
2024-08-29 21:04:02 -06:00
castRay(10);
2024-08-29 19:39:58 -06:00
2024-08-29 18:17:52 -06:00
//Flip the data to the screen - i.e. actually draw the complete image on screen
BMP_flip(1);
//Increment the destination y coordinate
l.pt2.y = l.pt2.y + 2;
//Reset the destination y coordinate if it hits 160
if (l.pt2.y == 160)
{
l.pt2.y = 0;
}
2024-08-29 18:49:38 -06:00
SYS_doVBlankProcess();
2024-08-29 18:17:52 -06:00
}
void update(){
2024-08-29 18:49:38 -06:00
u16 joy = JOY_readJoypad(JOY_1);
if(joy & BUTTON_LEFT) {
l.pt1.x -= SPEED;
}
if(joy & BUTTON_RIGHT) {
l.pt1.x += SPEED;
}
if(joy & BUTTON_UP) {
l.pt1.y -= SPEED;
}
if(joy & BUTTON_DOWN) {
l.pt1.y += SPEED;
}
}
2024-08-29 18:17:52 -06:00
2024-08-29 18:49:38 -06:00
void initVDP(){
SYS_disableInts();
VDP_setPlaneSize(64,32,TRUE);
SYS_enableInts();
2024-08-29 18:17:52 -06:00
}
2024-08-29 17:51:49 -06:00
int main()
{
2024-08-29 18:49:38 -06:00
initVDP();
2024-08-29 17:51:49 -06:00
//Initialise the bitmap engine
2024-08-29 18:49:38 -06:00
BMP_init(FALSE, BG_A, PAL0, FALSE);
2024-08-29 17:51:49 -06:00
//Set the colour of the line. We are using pallete 0 for the bitmap, so we have 0->15. 15 is used for white text, so we set an unused pallet colour, 14 to blue - RGB 0000FF.
u16 colour_blue = RGB24_TO_VDPCOLOR(0x0000ff);
2024-08-29 19:39:58 -06:00
u16 colour_red = RGB24_TO_VDPCOLOR(0x756a4a);
2024-08-29 18:08:02 -06:00
PAL_setColor(14, colour_blue);
2024-08-29 18:13:30 -06:00
PAL_setColor(13, colour_red);
2024-08-29 21:04:02 -06:00
PAL_setColor(12, RGB24_TO_VDPCOLOR(0x00ff00));
PAL_setColor(15, RGB24_TO_VDPCOLOR(0xff0000));
2024-08-29 18:13:30 -06:00
VDP_setBackgroundColor(13);
2024-08-29 17:51:49 -06:00
//A line needs a source coordinate x,y and a destination coordinate x,y along with a pallete colour.
2024-08-29 21:04:02 -06:00
l.pt1.x = 15;
l.pt1.y = 15;
2024-08-29 17:51:49 -06:00
l.pt2.x = 255;
l.pt2.y = 0;
2024-08-29 18:08:02 -06:00
l.col = 14;
2024-08-29 17:51:49 -06:00
l.col |= l.col << 4; // if we do not left shift the colour, we get gaps in the line
while(TRUE)
{
2024-08-29 18:17:52 -06:00
render();
2024-08-29 18:49:38 -06:00
update();
2024-08-29 17:51:49 -06:00
}
return 0;
}