Streetwalrus Einstein vor 10 Jahren
Ursprung
Commit
726a070e3f
8 geänderte Dateien mit 88 neuen und 69 gelöschten Zeilen
  1. 21 20
      include/Camera.h
  2. 17 13
      include/Entity.h
  3. 16 15
      include/Map.h
  4. 7 4
      src/Camera.cpp
  5. 7 4
      src/Entity.cpp
  6. 14 7
      src/Map.cpp
  7. 6 4
      src/graphics.c
  8. 0 2
      src/main.cpp

+ 21 - 20
include/Camera.h

@@ -1,31 +1,32 @@
 #ifndef INCLUDE_CAMERA_H
 #define INCLUDE_CAMERA_H
 
-namespace WalrusRPG {
+namespace WalrusRPG
+{
 	class Camera
 	{
-	protected:
-		
-		// Do you want to use classes for coordinates and allow them to have vector-based mathematics? With operator overriding that could be doable to have
-		// Vector2 a(3, 2); Vector2 b(1, 2); Vector3 c = a+b;
-		// Vector2 destination;
-		// Vector2 velocity;
-		// Vector2 acceleration;
+		protected:
+			// Do you want to use classes for coordinates and allow them to have vector-based mathematics? With operator overriding that could be doable to have
+			// Vector2 a(3, 2); Vector2 b(1, 2); Vector3 c = a+b;
+			// Vector2 destination;
+			// Vector2 velocity;
+			// Vector2 acceleration;
 
-	public:
-		// TODO!: TEMPOARY PUBLIC VARIABLES. Need to make getter/setters.
-		// So, how will track camera's position? Top left or center?
-		unsigned x; // You'll probably want to switch over signed coordonates.
-		unsigned y;
-		unsigned render_area_width; // What if you only want to display the map on a part of the screen?
-		unsigned render_area_height;
+		public:
+			// TODO!: TEMPOARY PUBLIC VARIABLES. Need to make getter/setters.
+			// So, how will track camera's position? Top left or center?
+			unsigned x; // You'll probably want to switch over signed coordonates.
+			unsigned y;
+			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();
-		// 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;
-		void update(float dt);
+			Camera();
+			~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;
+			void update(float dt);
 	};
 }
 
 #endif
+

+ 17 - 13
include/Entity.h

@@ -3,24 +3,28 @@
 
 #include "Camera.h"
 
-namespace WalrusRPG {
+namespace WalrusRPG
+{
 	/**
 	 * Well, for now, this class will be a non abstract for ALPHA PROGRAMMING REASONS.
 	 * Expect this sooner or later to be abstract.
 	 * I don't know at this moment how will we manage the different classes heriting or compositing from this, if we use components or heritance.
 	 */
-	class Entity {
-	protected:
-		unsigned x;
-		unsigned y;
-		unsigned width;
-		unsigned height;
-	public:
-		Entity();
-		~Entity();
-		void render(Camera &camera, float dt) const;
-		void update(float dt);
+	class Entity
+	{
+		protected:
+			unsigned x;
+			unsigned y;
+			unsigned width;
+			unsigned height;
 
+		public:
+			Entity();
+			~Entity();
+			void render(Camera &camera, float dt) const;
+			void update(float dt);
 	};
 }
-#endif
+
+#endif
+

+ 16 - 15
include/Map.h

@@ -4,25 +4,26 @@
 #include "Camera.h"
 #include "Entity.h"
 
-namespace WalrusRPG {
+namespace WalrusRPG
+{
 	class Map
 	{
-	protected:
-		// <Tiles> data;
-		// <Tileset> tileset;
-		unsigned int width;
-		unsigned int height;
-		unsigned *layer0;
-		unsigned *layer1;
+		protected:
+			// <Tiles> data;
+			// <Tileset> tileset;
+			unsigned int width;
+			unsigned int height;
+			unsigned *layer0;
+			unsigned *layer1;
 
-	public:
-
-		Map(int width, int height, unsigned *layer0, unsigned *layer1);
-		~Map();
-		void render(Camera &camera, float dt) const;
-		void update(float dt);
-		bool entity_collide(Entity &entity) const;
+		public:
+			Map(int width, int height, unsigned *layer0, unsigned *layer1);
+			~Map();
+			void render(Camera &camera, float dt) const;
+			void update(float dt);
+			bool entity_collide(Entity &entity) const;
 	};
 }
 
 #endif
+

+ 7 - 4
src/Camera.cpp

@@ -3,20 +3,23 @@
 
 #define CAMERA WalrusRPG::Camera
 
-CAMERA::Camera() {
+CAMERA::Camera()
+{
 	// TODO
 }
 
-CAMERA::~Camera() {
+CAMERA::~Camera()
+{
 	// TODO if you allocate dynamically members
 }
 
-void CAMERA::update(float dt) {
+void CAMERA::update(float dt)
+{
 	// TODO update map's data according to elasped time
 	/*
-	
 		// Need to think aagain on how to go to a target point and/or we need to align the corner OR the center to this point.
 		position += velocity * dt;
 		velocity += acceleration * dt;
 	 */
 }
+

+ 7 - 4
src/Entity.cpp

@@ -2,20 +2,23 @@
 
 #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
 	/*
-	
 		// Need to think aagain on how to go to a target point and/or we need to align the corner OR the center to this point.
 		position += velocity * dt;
 		velocity += acceleration * dt;
 	 */
 }
+

+ 14 - 7
src/Map.cpp

@@ -5,22 +5,26 @@
 
 #define MAP WalrusRPG::Map
 
-MAP::Map(int width, int height, unsigned *layer0, unsigned *layer1) {
+MAP::Map(int width, int height, unsigned *layer0, unsigned *layer1)
+{
 	this->width = width;
 	this->height = height;
 	this->layer0 = layer0;
 	this->layer1 = layer1;
 }
 
-MAP::~Map() {
+MAP::~Map()
+{
 	// TODO if you allocate dynamically members
 }
 
-void MAP::update(float dt) {
+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)
+{
 	unsigned offset_x = camera.x % 24 * -1;
 	unsigned offset_y = camera.y % 24 * -1;
 
@@ -29,7 +33,8 @@ void MAP::render(WalrusRPG::Camera &camera, float dt) {
 	sprite.w = 24;
 	sprite.h = 24;
 
-	for (unsigned j = 0; j < 11; j++) {
+	for (unsigned j = 0; j < 11; j++)
+	{
 		for (unsigned i = 0; i < 15; i++)
 		{
 			sprite.x = map->layer0[(camera.x / 24 + i) + (camera.y / 24 + j) * map->w] * 24;
@@ -38,6 +43,8 @@ void MAP::render(WalrusRPG::Camera &camera, float dt) {
 	}
 }
 
-bool MAP::entity_collide(Entity &entity) {
+bool MAP::entity_collide(Entity &entity)
+{
 	return false;
-}
+}
+

+ 6 - 4
src/graphics.c

@@ -92,11 +92,13 @@ void draw_sprite_sheet(const unsigned short *sheet, int x, int y, const Rect_t *
 	int h = min(window->h + y, 240);
 
 	for (int j = max(y, 0), l = window->y - min(y, 0); j < h; j++, l++)
-	for (int i = max(x, 0), k = window->x - min(x, 0); i < w; i++, k++)
 	{
-		color = sprite_pixel_get(sheet, k, l);
-		if (color != sheet[2])
-			draw_pixel(i, j, color);
+		for (int i = max(x, 0), k = window->x - min(x, 0); i < w; i++, k++)
+		{
+			color = sprite_pixel_get(sheet, k, l);
+			if (color != sheet[2])
+				draw_pixel(i, j, color);
+		}
 	}
 }
 

+ 0 - 2
src/main.cpp

@@ -37,8 +37,6 @@ void map_loop(unsigned x, unsigned y, Map &map)
 	}
 }
 
-
-
 int main(int argc, char *argv[])
 {
 	(void) argc;