Fixed some casting weirdness
This commit is contained in:
parent
8574f9d0f0
commit
20e8375f18
29
src/main.c
29
src/main.c
@ -28,7 +28,7 @@ void castRay(s16 angle){
|
|||||||
|
|
||||||
fix16 dy = sinFix16(ind);
|
fix16 dy = sinFix16(ind);
|
||||||
fix16 dx = cosFix16(ind);
|
fix16 dx = cosFix16(ind);
|
||||||
fix16 tan = FIX16(1);
|
fix16 tan = FIX16(0);
|
||||||
if(dx != 0) tan = fix16Div(dy, dx);
|
if(dx != 0) tan = fix16Div(dy, dx);
|
||||||
fix16 aTan = FIX16(0);
|
fix16 aTan = FIX16(0);
|
||||||
if(tan != 0) aTan = fix16Div(FIX16(-1), tan);
|
if(tan != 0) aTan = fix16Div(FIX16(-1), tan);
|
||||||
@ -37,7 +37,7 @@ void castRay(s16 angle){
|
|||||||
fix16 distH = FIX16(500);
|
fix16 distH = FIX16(500);
|
||||||
fix16 hx = FIX16(l.pt1.x);
|
fix16 hx = FIX16(l.pt1.x);
|
||||||
fix16 hy = FIX16(l.pt1.y);
|
fix16 hy = FIX16(l.pt1.y);
|
||||||
if(angle == 0 || angle == 180){
|
if(dy == 0){
|
||||||
rx = FIX16(l.pt1.x);
|
rx = FIX16(l.pt1.x);
|
||||||
ry = FIX16(l.pt1.y);
|
ry = FIX16(l.pt1.y);
|
||||||
dof = 8;
|
dof = 8;
|
||||||
@ -58,7 +58,11 @@ void castRay(s16 angle){
|
|||||||
while(dof<8){
|
while(dof<8){
|
||||||
mx = fix16ToInt(rx) / 10;
|
mx = fix16ToInt(rx) / 10;
|
||||||
my = fix16ToInt(ry) / 10;
|
my = fix16ToInt(ry) / 10;
|
||||||
if(mx >=0 && my >= 0 && mx < 10 && my < 10 && map[my][mx] == 1){
|
if(rx < 0 || ry < 0){
|
||||||
|
dof = 8;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(mx < 10 && my < 10 && map[my][mx] == 1){
|
||||||
dof = 8;
|
dof = 8;
|
||||||
hx = rx;
|
hx = rx;
|
||||||
hy = ry;
|
hy = ry;
|
||||||
@ -87,9 +91,11 @@ void castRay(s16 angle){
|
|||||||
xo = FIX16(10);
|
xo = FIX16(10);
|
||||||
yo = fix16Mul(0-xo,nTan);
|
yo = fix16Mul(0-xo,nTan);
|
||||||
}
|
}
|
||||||
if(angle == 90 || angle == 270){
|
if(dx == 0){
|
||||||
rx = FIX16(l.pt1.x);
|
rx = FIX16(l.pt1.x);
|
||||||
ry = FIX16(l.pt1.y);
|
ry = FIX16(l.pt1.y);
|
||||||
|
xo = FIX16(0);
|
||||||
|
yo = FIX16(0);
|
||||||
dof = 8;
|
dof = 8;
|
||||||
}
|
}
|
||||||
while(dof<8){
|
while(dof<8){
|
||||||
@ -113,12 +119,6 @@ void castRay(s16 angle){
|
|||||||
l.pt2.x = fix16ToInt(hx);
|
l.pt2.x = fix16ToInt(hx);
|
||||||
l.pt2.y = fix16ToInt(hy);
|
l.pt2.y = fix16ToInt(hy);
|
||||||
}
|
}
|
||||||
char* str[5];
|
|
||||||
sprintf(str, "%d", distV);
|
|
||||||
BMP_drawText(str, 20, 0);
|
|
||||||
char* str2[5];
|
|
||||||
sprintf(str2, "%d", distH);
|
|
||||||
BMP_drawText(str2, 20, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void mapscan(){
|
void mapscan(){
|
||||||
@ -147,10 +147,11 @@ void render(){
|
|||||||
//Draw the line defined above (in the background, hidden)
|
//Draw the line defined above (in the background, hidden)
|
||||||
|
|
||||||
mapscan();
|
mapscan();
|
||||||
if(angle > 360) angle = 0;
|
if(angle >= 360) angle = angle - 360;
|
||||||
if(angle < 0) angle = 359;
|
if(angle < 0) angle = 360 + angle;
|
||||||
castRay(angle);
|
castRay(angle);
|
||||||
BMP_drawLine(&l);
|
BMP_drawLine(&l);
|
||||||
|
BMP_showFPS(0);
|
||||||
|
|
||||||
//Flip the data to the screen - i.e. actually draw the complete image on screen
|
//Flip the data to the screen - i.e. actually draw the complete image on screen
|
||||||
BMP_flip(1);
|
BMP_flip(1);
|
||||||
@ -172,11 +173,11 @@ void update(){
|
|||||||
u16 joy = JOY_readJoypad(JOY_1);
|
u16 joy = JOY_readJoypad(JOY_1);
|
||||||
if(joy & BUTTON_LEFT) {
|
if(joy & BUTTON_LEFT) {
|
||||||
//l.pt1.x -= SPEED;
|
//l.pt1.x -= SPEED;
|
||||||
angle--;
|
angle -= 1;
|
||||||
}
|
}
|
||||||
if(joy & BUTTON_RIGHT) {
|
if(joy & BUTTON_RIGHT) {
|
||||||
//l.pt1.x += SPEED;
|
//l.pt1.x += SPEED;
|
||||||
angle++;
|
angle += 1;
|
||||||
}
|
}
|
||||||
if(joy & BUTTON_UP) {
|
if(joy & BUTTON_UP) {
|
||||||
l.pt1.y -= SPEED;
|
l.pt1.y -= SPEED;
|
||||||
|
Loading…
Reference in New Issue
Block a user