0 Members and 1 Guest are viewing this topic.
#include "keyboard.hpp"#include "color.h"#include "display.h"#include "keyboard_syscalls.h"#include "math.h"#include "stdlib.h"void plot(int x0, int y0, int color) { char* VRAM = (char*)0xA8000000; VRAM += 2*(y0*LCD_WIDTH_PX + x0); *(VRAM++) = (color&0x0000FF00)>>8; *(VRAM++) = (color&0x000000FF); return;}void drawLine(int x1, int y1, int x2, int y2, int color) { signed char ix; signed char iy; // if x1 == x2 or y1 == y2, then it does not matter what we set here int delta_x = (x2 > x1?(ix = 1, x2 - x1):(ix = -1, x1 - x2)) << 1; int delta_y = (y2 > y1?(iy = 1, y2 - y1):(iy = -1, y1 - y2)) << 1; plot(x1, y1, color); if (delta_x >= delta_y) { int error = delta_y - (delta_x >> 1); // error may go below zero while (x1 != x2) { if (error >= 0) { if (error || (ix > 0)) { y1 += iy; error -= delta_x; } // else do nothing } // else do nothing x1 += ix; error += delta_y; plot(x1, y1, color); } } else { int error = delta_x - (delta_y >> 1); // error may go below zero while (y1 != y2) { if (error >= 0) { if (error || (iy > 0)) { x1 += ix; error -= delta_y; } // else do nothing } // else do nothing y1 += iy; error += delta_x; plot(x1, y1, color); } }}int PRGM_GetKey(){ unsigned char buffer[12]; PRGM_GetKey_OS( buffer ); return ( buffer[1] & 0x0F ) * 10 + ( ( buffer[2] & 0xF0 ) >> 4 );}int playerh = 32;int fov = 60;int viewingangle = 45;int playergridx = 2;int playergridy = 2;int playerunitx;int playerunity;int projectionh = 200;int projectionw = 320;int distance = 160/tan(30);int column = 60/320;int planemx = 160;int planemy = 100;int AngleInc = 1;int XDisplacement;int YDisplacement;int correctdistance;int sliceheight;int Ax;int Ay;int Cx;int Cy;int Dx;int Dy;int Bx;int By;int Xa;int Ya;int Xb;int Yb;int DxA;int DyA;int CyA;int CxA;int liney;int MapData[10][10] = { {1,1,1,1,1,1,1,1,1,1}, {1,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,1}, {1,1,1,1,1,1,1,1,1,1}};int absolute(int n){ if(n < 0){ n = -n; } return n;}int main(){ XDisplacement = cos(viewingangle) * 10; YDisplacement = sin(viewingangle) * 10; playerunitx = 32 + (playergridx * 64); playerunity = 32 + (playergridy * 64); while(1){ int key = PRGM_GetKey(); if(key == KEY_PRGM_MENU) { GetKey(&key); } if(viewingangle <= 180 && viewingangle >= 0){ Ya = 64; Ay = floor(playerunity / 64) * (64) - 1; } else if(viewingangle <= 360 && viewingangle >= 181){ Ya = -64; Ay = floor(playerunity / 64) * (64) + 64; } Ax = playerunitx + (playerunity - Ay) / tan(viewingangle); Xa = 64 / tan(viewingangle); Cx = Ax + Xa; Cy = Ay + Ya; CxA = floor(Cx / 64); CyA = floor(Cy / 64); playergridx = playerunitx/64; playergridy = playerunity/64; for(int w = 0; w < 10; w++){ if(MapData[CxA][CyA] == 1) break; CxA = floor(Cx / 64); CyA = floor(Cy / 64); Cx += Xa; Cy += Ya; } Cx = floor(Cx / 64); Cy = floor(Cy / 64); if(viewingangle <= 270 && viewingangle >= 90){ Xb = 64; Bx = floor(playerunity / 64) * (64) - 1; } else if((viewingangle <= 89 && viewingangle >= 0) && (viewingangle <=360 && viewingangle >= 271)){ Xb = -64; Bx = floor(playerunity / 64) * (64) + 64; } By = playerunity + (playerunitx - Bx) * tan(viewingangle); Dx = Bx + Xb; Dy = By + Yb; DxA = floor(Dx / 64); DyA = floor(Dy / 64); for(int e = 0; e < 10; e++){ if(MapData[DyA][DxA] == 1) break; DxA = floor(Dx / 64); DyA = floor(Dy / 64); Dx += Xa; Dy += Ya; } Dx = floor(Dx / 64); Dy = floor(Dy / 64); for(int i = 0; i < 320; i++){ if((absolute(playerunitx - Dx) / cos(viewingangle)) < (absolute(playerunitx - Cx) / cos(viewingangle))){ for(int j = -30; j < 30; j++){ correctdistance = (absolute(playerunitx - Dx) / cos(viewingangle)) * cos(j); sliceheight = 64 / correctdistance * 277; liney = 100 - (sliceheight / 2); drawLine(i, liney, i, liney + correctdistance, COLOR_RED); Bdisp_PutDisp_DD(); } } else { for(int j = -30; j < 30; j++){ correctdistance = (absolute(playerunitx - Cx) / cos(viewingangle)) * cos(j); sliceheight = 64 / correctdistance * 277; liney = 100 - (sliceheight / 2); drawLine(i, liney, i, liney + correctdistance, COLOR_RED); Bdisp_PutDisp_DD(); } } } if(key == KEY_PRGM_UP){ playerunitx += XDisplacement; playerunity += YDisplacement; } if(key == KEY_PRGM_DOWN){ playerunitx -= XDisplacement; playerunity -= YDisplacement; } if(key == KEY_PRGM_LEFT){ viewingangle -= AngleInc; } if(key == KEY_PRGM_RIGHT){ viewingangle += AngleInc; } if(viewingangle > 360){ viewingangle = 0; } if(viewingangle < 0){ viewingangle = 360; } } return 0;}
*BUMP*Can anyone help?
One last thing, in the future, you should put threads asking for programming help in the C language subforum.