Hunde.
[hackover2013-badge-firmware.git] / badge / jumpnrun / level_load.c
index 3ae31d7..a945fc9 100644 (file)
@@ -3,6 +3,10 @@
 #include "items.h"
 #include "enemies.h"
 
+#ifndef __linux__
+#include <drivers/fatfs/ff.h>
+#endif
+
 #include <stdio.h>
 
 typedef struct {
@@ -36,20 +40,31 @@ static void jumpnrun_level_make_item(jumpnrun_item *dest, level_thing thing) {
 static void jumpnrun_level_make_enemy(jumpnrun_enemy *dest, level_thing thing) {
   dest->type = &jumpnrun_enemy_type_data[thing.type];
 
-  dest->spawn_pos.x   = FIXED_POINT(thing.x * JUMPNRUN_TILE_PIXEL_WIDTH , 0);
-  dest->spawn_pos.y   = FIXED_POINT(thing.y * JUMPNRUN_TILE_PIXEL_HEIGHT, 0);
-  dest->current_pos   = dest->spawn_pos;
-  dest->inertia       = dest->type->spawn_inertia;
-  dest->flags         = 0;
-  dest->tick_counter  = 0;
-  dest->current_frame = 0;
+  dest->spawn_pos.x          = FIXED_POINT(thing.x * JUMPNRUN_TILE_PIXEL_WIDTH , 0);
+  dest->spawn_pos.y          = FIXED_POINT(thing.y * JUMPNRUN_TILE_PIXEL_HEIGHT, 0);
+  dest->base.current_box     = rectangle_new(dest->spawn_pos, dest->type->extent);
+  dest->base.inertia         = dest->type->spawn_inertia;
+  dest->flags                = 0;
+  dest->base.tick_minor      = 0;
+  dest->base.anim_frame      = 0;
+  dest->base.anim_direction  = 0;
+  dest->base.touching_ground = 0;
+  dest->base.jumpable_frames = 0;
 }
 
+#ifdef __linux__
+int jumpnrun_load_level_header_from_file(jumpnrun_level *dest, FILE *fd) {
+#else
 int jumpnrun_load_level_header_from_file(jumpnrun_level *dest, FIL *fd) {
-  uint16_t head[3];
   UINT count;
+#endif
+  uint16_t head[3];
 
+#ifdef __linux__
+  if(1 != fread(&head, sizeof(head), 1, fd)) {
+#else
   if(FR_OK != f_read(fd, head, sizeof(head), &count) || count != sizeof(head)) {
+#endif
     return JUMPNRUN_LEVEL_LOAD_ERROR;
   }
 
@@ -60,13 +75,21 @@ int jumpnrun_load_level_header_from_file(jumpnrun_level *dest, FIL *fd) {
   return JUMPNRUN_LEVEL_LOAD_OK;
 }
 
+#ifdef __linux__
+int jumpnrun_load_level_from_file(jumpnrun_level *dest, FILE *fd) {
+#else
 int jumpnrun_load_level_from_file(jumpnrun_level *dest, FIL *fd) {
+  UINT count;
+#endif
   size_t i;
   unsigned char buf[3];
   uint16_t spos[2];
-  UINT count;
 
+#ifdef __linux__
+  if(1 != fread(spos, sizeof(spos), 1, fd)) {
+#else
   if(FR_OK != f_read(fd, spos, sizeof(spos), &count) || count != sizeof(spos)) {
+#endif
     return JUMPNRUN_LEVEL_LOAD_ERROR;
   } else {
     dest->start_pos.x = FIXED_POINT(spos[0] * JUMPNRUN_TILE_PIXEL_WIDTH , 0);
@@ -74,7 +97,11 @@ int jumpnrun_load_level_from_file(jumpnrun_level *dest, FIL *fd) {
   }
 
   for(i = 0; i < dest->header.tile_count; ++i) {
+#ifdef __linux__
+    if(1 != fread(buf, 3, 1, fd)) {
+#else
     if(FR_OK != f_read(fd, buf, sizeof(buf), &count) || count != sizeof(buf)) {
+#endif
       return JUMPNRUN_LEVEL_LOAD_ERROR;
     }
 
@@ -87,7 +114,11 @@ int jumpnrun_load_level_from_file(jumpnrun_level *dest, FIL *fd) {
   }
 
   for(i = 0; i < dest->header.item_count; ++i) {
+#ifdef __linux__
+    if(1 != fread(buf, 3, 1, fd)) {
+#else
     if(FR_OK != f_read(fd, buf, sizeof(buf), &count) || count != sizeof(buf)) {
+#endif
       return JUMPNRUN_LEVEL_LOAD_ERROR;
     }
 
@@ -100,7 +131,11 @@ int jumpnrun_load_level_from_file(jumpnrun_level *dest, FIL *fd) {
   }
 
   for(i = 0; i < dest->header.enemy_count; ++i) {
+#ifdef __linux__
+    if(1 != fread(buf, 3, 1, fd)) {
+#else
     if(FR_OK != f_read(fd, buf, sizeof(buf), &count) || count != sizeof(buf)) {
+#endif
       return JUMPNRUN_LEVEL_LOAD_ERROR;
     }
 
This page took 0.021281 seconds and 4 git commands to generate.