]> git.localhorst.tv Git - l2e.git/commitdiff
added simple sprite class
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Sun, 5 Aug 2012 15:09:26 +0000 (17:09 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Sun, 5 Aug 2012 15:09:26 +0000 (17:09 +0200)
Debug/makefile
Debug/sources.mk
Debug/src/graphics/subdir.mk [new file with mode: 0644]
Release/makefile
Release/sources.mk
Release/src/graphics/subdir.mk [new file with mode: 0644]
src/battle/Monster.h
src/graphics/Sprite.cpp [new file with mode: 0644]
src/graphics/Sprite.h [new file with mode: 0644]

index 3f180390f2dbc5771d3608ef73c631ce787d0751..507437a93cbfa29ba2e0136e4c244d637cf0e2b3 100644 (file)
@@ -9,6 +9,7 @@ RM := rm -rf
 # All of the sources participating in the build are defined here
 -include sources.mk
 -include src/sdl/subdir.mk
+-include src/graphics/subdir.mk
 -include src/battle/subdir.mk
 -include src/app/subdir.mk
 -include src/subdir.mk
index 92d6efe084fb4ab72e20274484a24d8569fde56d..0fdadd38f9a63f83ae891efcde4019c97aab7708 100644 (file)
@@ -25,6 +25,7 @@ C_UPPER_DEPS :=
 SUBDIRS := \
 src/sdl \
 src \
+src/graphics \
 src/battle \
 src/app \
 
diff --git a/Debug/src/graphics/subdir.mk b/Debug/src/graphics/subdir.mk
new file mode 100644 (file)
index 0000000..63083ec
--- /dev/null
@@ -0,0 +1,24 @@
+################################################################################
+# Automatically-generated file. Do not edit!
+################################################################################
+
+# Add inputs and outputs from these tool invocations to the build variables 
+CPP_SRCS += \
+../src/graphics/Sprite.cpp 
+
+OBJS += \
+./src/graphics/Sprite.o 
+
+CPP_DEPS += \
+./src/graphics/Sprite.d 
+
+
+# Each subdirectory must supply rules for building sources it contributes
+src/graphics/%.o: ../src/graphics/%.cpp
+       @echo 'Building file: $<'
+       @echo 'Invoking: GCC C++ Compiler'
+       g++ -I/usr/include/SDL -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<"
+       @echo 'Finished building: $<'
+       @echo ' '
+
+
index 3f180390f2dbc5771d3608ef73c631ce787d0751..507437a93cbfa29ba2e0136e4c244d637cf0e2b3 100644 (file)
@@ -9,6 +9,7 @@ RM := rm -rf
 # All of the sources participating in the build are defined here
 -include sources.mk
 -include src/sdl/subdir.mk
+-include src/graphics/subdir.mk
 -include src/battle/subdir.mk
 -include src/app/subdir.mk
 -include src/subdir.mk
index 92d6efe084fb4ab72e20274484a24d8569fde56d..0fdadd38f9a63f83ae891efcde4019c97aab7708 100644 (file)
@@ -25,6 +25,7 @@ C_UPPER_DEPS :=
 SUBDIRS := \
 src/sdl \
 src \
+src/graphics \
 src/battle \
 src/app \
 
diff --git a/Release/src/graphics/subdir.mk b/Release/src/graphics/subdir.mk
new file mode 100644 (file)
index 0000000..6325d12
--- /dev/null
@@ -0,0 +1,24 @@
+################################################################################
+# Automatically-generated file. Do not edit!
+################################################################################
+
+# Add inputs and outputs from these tool invocations to the build variables 
+CPP_SRCS += \
+../src/graphics/Sprite.cpp 
+
+OBJS += \
+./src/graphics/Sprite.o 
+
+CPP_DEPS += \
+./src/graphics/Sprite.d 
+
+
+# Each subdirectory must supply rules for building sources it contributes
+src/graphics/%.o: ../src/graphics/%.cpp
+       @echo 'Building file: $<'
+       @echo 'Invoking: GCC C++ Compiler'
+       g++ -I/usr/include/SDL -O3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<"
+       @echo 'Finished building: $<'
+       @echo ' '
+
+
index adebbb28703670c949a3490649d992efcbf6bbdf..0b35d31b742d43ca17bc8b906717806ccea2eecd 100644 (file)
@@ -10,6 +10,8 @@
 
 #include <SDL.h>
 
+namespace graphics { class Sprite; }
+
 namespace battle {
 
 class Monster {
@@ -21,7 +23,7 @@ public:
 public:
        const char *Name() const { return name; }
        Uint8 Level() const { return level; }
-       const /* Sprite */ void *Sprite() const { return sprite; }
+       const graphics::Sprite *Sprite() const { return sprite; }
 
        Uint16 MaxHealth() const { return maxHealth; }
        Uint16 Health() const { return health; }
@@ -49,7 +51,7 @@ public:
 
 private:
        const char *name;
-       /* Sprite */ void *sprite;
+       graphics::Sprite *sprite;
        /* Item */ void *dropItem;
        /* Script */ void *attackScript;
        /* Script */ void *defenseScript;
diff --git a/src/graphics/Sprite.cpp b/src/graphics/Sprite.cpp
new file mode 100644 (file)
index 0000000..67deeef
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Sprite.cpp
+ *
+ *  Created on: Aug 5, 2012
+ *      Author: holy
+ */
+
+#include "Sprite.h"
+
+namespace graphics {
+
+void Sprite::Draw(SDL_Surface *dest, int x, int y, int col, int row) const {
+       SDL_Rect srcRect, destRect;
+       srcRect.x = col * Width();
+       srcRect.y = row * Height();
+       srcRect.w = Width();
+       srcRect.h = Height();
+       destRect.x = x;
+       destRect.y = y;
+       destRect.w = Width();
+       destRect.h = Height();
+       SDL_BlitSurface(surface, &srcRect, dest, &destRect);
+}
+
+}
diff --git a/src/graphics/Sprite.h b/src/graphics/Sprite.h
new file mode 100644 (file)
index 0000000..5710ee5
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Sprite.h
+ *
+ *  Created on: Aug 5, 2012
+ *      Author: holy
+ */
+
+#ifndef GRAPHICS_SPRITE_H_
+#define GRAPHICS_SPRITE_H_
+
+#include <SDL.h>
+
+namespace graphics {
+
+class Sprite {
+
+public:
+       Sprite(SDL_Surface *s, int width, int height)
+       : surface(s), width(width), height(height) { }
+
+public:
+       int Width() const { return width; }
+       int Height() const { return height; }
+       void Draw(SDL_Surface *dest, int x, int y, int col = 0, int row = 0) const;
+
+private:
+       SDL_Surface *surface;
+       int width;
+       int height;
+
+};
+
+}
+
+#endif /* GRAPHICS_SPRITE_H_ */