Quellcode durchsuchen

Bring it to life

Streetwalrus Einstein vor 10 Jahren
Ursprung
Commit
55dd043393
7 geänderte Dateien mit 36 neuen und 15 gelöschten Zeilen
  1. 1 1
      include/Camera.h
  2. 8 0
      include/graphics.h
  3. 8 0
      include/timers.h
  4. 9 2
      src/Camera.cpp
  5. 4 4
      src/Entity.cpp
  6. 3 3
      src/Map.cpp
  7. 3 5
      src/main.cpp

+ 1 - 1
include/Camera.h

@@ -20,7 +20,7 @@ namespace WalrusRPG
 			unsigned render_area_width; // What if you only want to display the map on a part of the screen?
 			unsigned render_area_height;
 
-			Camera();
+			Camera(unsigned x, unsigned y);
 			~Camera();
 			// This doesn't need any render as it's the utility which helps rendering. Unless you want to show debnug things.
 			// void render(float dt) const;

+ 8 - 0
include/graphics.h

@@ -1,6 +1,11 @@
 #ifndef INCLUDE_GRAPHICS_H
 #define INCLUDE_GRAPHICS_H
 
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
 typedef struct Rect Rect_t;
 struct Rect
 {
@@ -39,5 +44,8 @@ void draw_sprite_sheet(const unsigned short *sheet, int x, int y, const Rect_t *
 
 unsigned short sprite_pixel_get(const unsigned short *sprite, unsigned x, unsigned y);
 
+#ifdef __cplusplus
+}
+#endif
 #endif
 

+ 8 - 0
include/timers.h

@@ -1,11 +1,19 @@
 #ifndef INCLUDE_TIMERS_H
 #define INCLUDE_TIMERS_H
 
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
 void timer_init(unsigned timer);
 void timer_restore(unsigned timer);
 void timer_mode(unsigned timer, unsigned mode);
 void timer_load(unsigned timer, unsigned value);
 unsigned timer_read(unsigned timer);
 
+#ifdef __cplusplus
+}
+#endif
 #endif
 

+ 9 - 2
src/Camera.cpp

@@ -1,11 +1,13 @@
+#include <os.h>
 #include "Camera.h"
 #include "Entity.h"
 
 #define CAMERA WalrusRPG::Camera
 
-CAMERA::Camera()
+CAMERA::Camera(unsigned x, unsigned y)
 {
-	// TODO
+	this->x = x;
+	this->y = y;
 }
 
 CAMERA::~Camera()
@@ -21,5 +23,10 @@ void CAMERA::update(float dt)
 		position += velocity * dt;
 		velocity += acceleration * dt;
 	 */
+
+	if (isKeyPressed(KEY_NSPIRE_5)) this->y++;
+	if (isKeyPressed(KEY_NSPIRE_8)) this->y--;
+	if (isKeyPressed(KEY_NSPIRE_6)) this->x++;
+	if (isKeyPressed(KEY_NSPIRE_4)) this->x--;
 }
 

+ 4 - 4
src/Entity.cpp

@@ -1,18 +1,18 @@
 #include "Entity.h"
 
-#define Entity WalrusRPG::Entity
+#define ENTITY WalrusRPG::Entity
 
-Entity::Entity()
+ENTITY::Entity()
 {
 	// TODO
 }
 
-Entity::~Entity()
+ENTITY::~Entity()
 {
 	// TODO if you allocate dynamically members
 }
 
-void Entity::update(float dt)
+void ENTITY::update(float dt)
 {
 	// TODO update map's data according to elasped time
 	/*

+ 3 - 3
src/Map.cpp

@@ -23,7 +23,7 @@ void MAP::update(float dt)
 	// TODO update map's data according to elasped time
 }
 
-void MAP::render(WalrusRPG::Camera &camera, float dt)
+void MAP::render(WalrusRPG::Camera &camera, float dt) const
 {
 	unsigned offset_x = camera.x % 24 * -1;
 	unsigned offset_y = camera.y % 24 * -1;
@@ -37,13 +37,13 @@ void MAP::render(WalrusRPG::Camera &camera, float dt)
 	{
 		for (unsigned i = 0; i < 15; i++)
 		{
-			sprite.x = map->layer0[(camera.x / 24 + i) + (camera.y / 24 + j) * map->w] * 24;
+			sprite.x = this->layer0[(camera.x / 24 + i) + (camera.y / 24 + j) * this->width] * 24;
 			draw_sprite_sheet(tiles, offset_x + i * 24, offset_y + j * 24, &sprite);
 		}		
 	}
 }
 
-bool MAP::entity_collide(Entity &entity)
+bool MAP::entity_collide(Entity &entity) const
 {
 	return false;
 }

+ 3 - 5
src/main.cpp

@@ -14,15 +14,13 @@ void map_loop(unsigned x, unsigned y, Map &map)
 	unsigned loop_next = -loop_time;
 
 	unsigned keep_running = 1;
-	Camera camera;
+	Camera camera(x, y);
 
 	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--;
+
+		camera.update(0);
 
 		// Frameskip
 		if (timer_read(0) > loop_next)