|
|
@@ -1,7 +1,43 @@
|
|
|
#include <os.h>
|
|
|
-#include <timers.h>
|
|
|
-#include <graphics.h>
|
|
|
-#include <map.h>
|
|
|
+#include "timers.h"
|
|
|
+#include "graphics.h"
|
|
|
+#include "Map.h"
|
|
|
+#include "Camera.h"
|
|
|
+
|
|
|
+using namespace WalrusRPG;
|
|
|
+
|
|
|
+void map_loop(unsigned x, unsigned y, Map &map)
|
|
|
+{
|
|
|
+ timer_mode(0, 0b0000010); // Free-running, no interrupts, divider = 1, 32 bit, wrapping
|
|
|
+ timer_load(0, 0);
|
|
|
+ unsigned loop_time = 546; // 32768Hz/60ups
|
|
|
+ unsigned loop_next = -loop_time;
|
|
|
+
|
|
|
+ unsigned keep_running = 1;
|
|
|
+ Camera camera;
|
|
|
+
|
|
|
+ while (keep_running)
|
|
|
+ {
|
|
|
+ if (isKeyPressed(KEY_NSPIRE_ESC)) keep_running = 0;
|
|
|
+ if (isKeyPressed(KEY_NSPIRE_5)) camera.y++;
|
|
|
+ if (isKeyPressed(KEY_NSPIRE_8)) camera.y--;
|
|
|
+ if (isKeyPressed(KEY_NSPIRE_6)) camera.x++;
|
|
|
+ if (isKeyPressed(KEY_NSPIRE_4)) camera.x--;
|
|
|
+
|
|
|
+ // Frameskip
|
|
|
+ if (timer_read(0) > loop_next)
|
|
|
+ {
|
|
|
+ map.render(camera, 1);
|
|
|
+ buffer_swap();
|
|
|
+ }
|
|
|
+
|
|
|
+ // Frame limiting
|
|
|
+ while (timer_read(0) > loop_next);
|
|
|
+ loop_next -= loop_time;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
{
|
|
|
@@ -11,9 +47,6 @@ int main(int argc, char *argv[])
|
|
|
buffer_allocate();
|
|
|
timer_init(0);
|
|
|
|
|
|
- Map_t map;
|
|
|
- map.w = 15;
|
|
|
- map.h = 21;
|
|
|
|
|
|
unsigned mapdata0[] =
|
|
|
{
|
|
|
@@ -65,11 +98,10 @@ int main(int argc, char *argv[])
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
|
|
};
|
|
|
|
|
|
+ Map map(15, 21, mapdata0, mapdata1);
|
|
|
|
|
|
- map.layer0 = mapdata0;
|
|
|
- map.layer1 = mapdata1;
|
|
|
|
|
|
- map_loop(0, 0, &map);
|
|
|
+ map_loop(0, 0, map);
|
|
|
|
|
|
timer_restore(0);
|
|
|
buffer_free();
|