#include #include "utils.h" #include "raymath.h" #include "sort.h" #include "render.h" #include "testlevel.c" asm(".string \"PRG\"\n"); int main(void) { //set CPU to 150 Mhz *(volatile unsigned*) 0x900B0000 = 0x00000002; *(volatile unsigned*) 0x900B000C = 4; //set up some buffers char* scrbuf = (char*) malloc(SCREEN_BYTES_SIZE); float* zbuf = (float*) malloc (320 * 240 * sizeof(float)); int colbuf[240]; //initial camera variables float posX = 12, posY = 12; float dirX = -1, dirY = 0; float planeX = 0, planeY = 0.66; float heye = 0.5; float hplay = 0; //other variables int w = 320, h = 240; int res = 1; float stpsize = 0.3; int redraw; char *texture[6]; texture[0] = &bluestone[0][0]; texture[1] = &icon[0][0]; texture[2] = &uac[0][0]; texture[3] = &imp[0][0]; texture[4] = &cacodemon[0][0]; texture[5] = &skull[0][0]; int texW[6] = {64, 64, 64, 64, 64, 64}; int texH[6] = {64, 64, 64, 64, 64, 64}; while (!isKeyPressed(KEY_NSPIRE_ESC)) { redraw = 0; if (isKeyPressed(KEY_NSPIRE_LEFT)) { float oldDirX = dirX; dirX = dirX * cos1 - dirY * sin1; dirY = oldDirX * sin1 + dirY * cos1; float oldPlaneX = planeX; planeX = planeX * cos1 - planeY * sin1; planeY = oldPlaneX * sin1 + planeY * cos1; redraw = 1; } if (isKeyPressed(KEY_NSPIRE_RIGHT)) { float oldDirX = dirX; dirX = dirX * cos1 + dirY * sin1; dirY = -oldDirX * sin1 + dirY * cos1; float oldPlaneX = planeX; planeX = planeX * cos1 + planeY * sin1; planeY = -oldPlaneX * sin1 + planeY * cos1; redraw = 1; } if (isKeyPressed(KEY_NSPIRE_UP)) { int moved = false; float hNext = height[(int) (posX + stpsize * dirX)][(int) (posY + stpsize * dirY)]; float aNext = alt[(int) (posX + stpsize * dirX)][(int) (posY + stpsize * dirY)]; if (hplay + 0.3 >= hNext + aNext) { posX += stpsize * dirX; posY += stpsize * dirY; heye += hNext + aNext - hplay; hplay = hNext + aNext; moved = true; } if (!moved && heye < aNext) { posX += stpsize * dirX; posY += stpsize * dirY; } if (posX < 0) posX = 0; if (posX > 24) posX = 24; if (posY < 0) posY = 0; if (posY > 24) posY = 24; redraw = true; } if (isKeyPressed(KEY_NSPIRE_DOWN)) { int moved = false; float hNext = height[(int) (posX - stpsize * dirX)][(int) (posY - stpsize * dirY)]; float aNext = alt[(int) (posX - stpsize * dirX)][(int) (posY - stpsize * dirY)]; if (hplay + 0.3 >= hNext + aNext) { posX -= stpsize * dirX; posY -= stpsize * dirY; heye += hNext + aNext - hplay; hplay = hNext + aNext; moved = true; } if (!moved && hplay < aNext) { posX -= stpsize * dirX; posY -= stpsize * dirY; } if (posX < 0) posX = 0; if (posX > 24) posX = 24; if (posY < 0) posY = 0; if (posY > 24) posY = 24; redraw = true; } if (isKeyPressed(KEY_NSPIRE_DIVIDE)) { w = (int) (w * 1.1); if (w > 320) w = 320; h = (int) (h * 1.1); if (h > 240) h = 240; redraw = true; } if (isKeyPressed(KEY_NSPIRE_MULTIPLY)) { w = (int) (w * 0.9); h = (int) (h * 0.9); redraw = true; } if (isKeyPressed(KEY_NSPIRE_H)) { res = 1; redraw = true; } if (isKeyPressed(KEY_NSPIRE_L)) { res = 2; redraw = true; } if (redraw) { render(&map[0][0], 26, 26, &height[0][0], &alt[0][0], texture, &texW[0], &texH[0], &sprite[0], 8, w, h, heye, posX, posY, dirX, dirY, planeX, planeY, scrbuf, zbuf, colbuf, res); refresh(scrbuf); } } //set CPU to 90 Mhz *(volatile unsigned*) 0x900B0000 = 0x00141002; *(volatile unsigned*) 0x900B000C = 4; return 0; }