소스 검색

Makefile for resources

Pabloader 5 년 전
부모
커밋
2c32353cb6

+ 2
- 0
.gitignore 파일 보기

@@ -2,3 +2,5 @@ awoorwa
2 2
 awoorwae
3 3
 *.exe
4 4
 *.o
5
+*.pack
6
+*.spr

+ 59
- 1
.vscode/settings.json 파일 보기

@@ -3,6 +3,64 @@
3 3
         "*.py": "python",
4 4
         "cstdint": "cpp",
5 5
         "algorithm": "cpp",
6
-        "fstream": "cpp"
6
+        "fstream": "cpp",
7
+        "cmath": "cpp",
8
+        "chrono": "cpp",
9
+        "cctype": "cpp",
10
+        "clocale": "cpp",
11
+        "cstdarg": "cpp",
12
+        "cstddef": "cpp",
13
+        "cstdio": "cpp",
14
+        "cstdlib": "cpp",
15
+        "cstring": "cpp",
16
+        "ctime": "cpp",
17
+        "cwchar": "cpp",
18
+        "cwctype": "cpp",
19
+        "array": "cpp",
20
+        "atomic": "cpp",
21
+        "hash_map": "cpp",
22
+        "strstream": "cpp",
23
+        "*.tcc": "cpp",
24
+        "bitset": "cpp",
25
+        "complex": "cpp",
26
+        "condition_variable": "cpp",
27
+        "deque": "cpp",
28
+        "list": "cpp",
29
+        "unordered_map": "cpp",
30
+        "vector": "cpp",
31
+        "exception": "cpp",
32
+        "functional": "cpp",
33
+        "initializer_list": "cpp",
34
+        "iomanip": "cpp",
35
+        "iosfwd": "cpp",
36
+        "iostream": "cpp",
37
+        "istream": "cpp",
38
+        "limits": "cpp",
39
+        "mutex": "cpp",
40
+        "new": "cpp",
41
+        "ostream": "cpp",
42
+        "numeric": "cpp",
43
+        "ratio": "cpp",
44
+        "sstream": "cpp",
45
+        "stdexcept": "cpp",
46
+        "streambuf": "cpp",
47
+        "system_error": "cpp",
48
+        "thread": "cpp",
49
+        "cfenv": "cpp",
50
+        "cinttypes": "cpp",
51
+        "tuple": "cpp",
52
+        "type_traits": "cpp",
53
+        "utility": "cpp",
54
+        "typeindex": "cpp",
55
+        "typeinfo": "cpp",
56
+        "optional": "cpp",
57
+        "string_view": "cpp",
58
+        "memory": "cpp",
59
+        "iterator": "cpp",
60
+        "map": "cpp",
61
+        "memory_resource": "cpp",
62
+        "random": "cpp",
63
+        "set": "cpp",
64
+        "string": "cpp"
7 65
     }
8 66
 }

+ 21
- 7
Makefile 파일 보기

@@ -1,12 +1,14 @@
1 1
 # To compile this you will need MinGW with MSYS installed in PATH
2 2
 
3
-CPPFLAGS=-Wall -Wno-misleading-indentation -Werror --std=c++1z -g -flto
3
+CPPFLAGS=-Wall -Wno-misleading-indentation -Werror --std=c++1z
4 4
 LDFLAGS=
5 5
 INCLUDES=-Ipge/include
6 6
 EXECUTABLE=awoorwae
7
+PACKER=packer/packer
7 8
 ifeq ($(OS),Windows_NT)
8 9
 	LIBRARIES=-luser32 -lgdi32 -lopengl32 -lgdiplus -lwinmm
9 10
 	EXECUTABLE+=.exe
11
+	PACKER+=.exe
10 12
 	LDFLAGS+=--machine=windows
11 13
 	CPP=i686-w64-mingw32-g++
12 14
 	CC=i686-w64-mingw32-gcc
@@ -15,21 +17,33 @@ else
15 17
 	CC=gcc
16 18
 	CPP=g++
17 19
 endif
20
+ifeq ($(DEBUG),1)
21
+	CPPFLAGS+=-g -Og
22
+else
23
+	CPPFLAGS+=-flto -O3
24
+endif
18 25
 SOURCES=$(wildcard src/*.cpp) $(wildcard src/**/*.cpp) $(wildcard pge/src/*.cpp)
26
+IMAGES=$(wildcard res/*.png)
27
+
19 28
 OBJECTS=$(SOURCES:.cpp=.o)
29
+SPRITES=$(IMAGES:.png=.spr)
20 30
 
21
-all: $(SOURCES) $(EXECUTABLE)
22
-	$(MAKE) -C packer all
31
+all: $(SOURCES) $(SPRITES) $(EXECUTABLE)
23 32
 
24 33
 clean: 
25
-	$(RM) $(OBJECTS) $(EXECUTABLE)
26
-	$(MAKE) -C packer clean
34
+	$(RM) $(OBJECTS) $(SPRITES) $(EXECUTABLE)
27 35
 	
28
-$(EXECUTABLE): $(OBJECTS) 
36
+$(EXECUTABLE): $(OBJECTS)
29 37
 	$(CPP) $(LDFLAGS) $(OBJECTS) -o $@ $(LIBRARIES)
30 38
 
31 39
 .cpp.o:
32 40
 	$(CPP) $(INCLUDES) -c $(CPPFLAGS) $< -o $@
33 41
 
34
-run: $(EXECUTABLE)
42
+%.spr: %.png $(PACKER)
43
+	$(PACKER) --convert $< $@
44
+
45
+run: $(SPRITES) $(EXECUTABLE)
35 46
 	./$(EXECUTABLE)
47
+
48
+$(PACKER):
49
+	$(MAKE) -C packer

+ 1
- 0
packer/.gitignore 파일 보기

@@ -1,3 +1,4 @@
1 1
 *.pack
2
+*.spr
2 3
 *.o
3 4
 packer

+ 3
- 2
packer/Makefile 파일 보기

@@ -2,16 +2,17 @@ CPPFLAGS=-Wall -Wno-misleading-indentation -Werror --std=c++1z -O3 -flto
2 2
 LDFLAGS=
3 3
 INCLUDES=-I../pge/include
4 4
 EXECUTABLE=packer
5
-LIBRARIES=
6 5
 ifeq ($(OS),Windows_NT)
6
+	LIBRARIES=-luser32 -lgdi32 -lgdiplus
7 7
 	EXECUTABLE+=.exe
8 8
 	CPP=i686-w64-mingw32-g++
9 9
 	CC=i686-w64-mingw32-gcc
10 10
 else
11
+	LIBRARIES=-lpng
11 12
 	CC=gcc
12 13
 	CPP=g++
13 14
 endif
14
-SOURCES=packer.cpp ../pge/src/olcPGE_ResourcePack.cpp
15
+SOURCES=packer.cpp ../pge/src/olcPGE_ResourcePack.cpp ../pge/src/olcPGE_Sprite.cpp ../pge/src/olcPGE_Pixel.cpp
15 16
 OBJECTS=$(SOURCES:.cpp=.o)
16 17
 
17 18
 all: $(SOURCES) $(EXECUTABLE)

+ 24
- 3
packer/packer.cpp 파일 보기

@@ -1,3 +1,4 @@
1
+#include "olcPGE_Sprite.h"
1 2
 #include "olcPGE_ResourcePack.h"
2 3
 #include <iostream>
3 4
 #include <string>
@@ -6,7 +7,7 @@ void PrintUsage() {
6 7
     std::cout << "Usage: packer --list PACK_FILE"            << std::endl;
7 8
     std::cout << "       packer --add PACK_FILE FILE"        << std::endl;
8 9
     std::cout << "       packer --remove PACK_FILE FILE"     << std::endl;
9
-    // std::cout << "       packer --convert PNG_FILE SPR_FILE" << std::endl;
10
+    std::cout << "       packer --convert PNG_FILE SPR_FILE" << std::endl;
10 11
 }
11 12
 
12 13
 void ListEntries(olc::ResourcePack& pack) {
@@ -31,7 +32,9 @@ int main(int argc, char *argv[])
31 32
     packFile = argv[2];
32 33
 
33 34
     olc::ResourcePack pack;
34
-    pack.LoadPack(packFile);
35
+    if (action != "--convert") {
36
+        pack.LoadPack(packFile);
37
+    }
35 38
 
36 39
     if (action == "--list") {
37 40
         ListEntries(pack);
@@ -58,12 +61,30 @@ int main(int argc, char *argv[])
58 61
         }
59 62
         std::cout << std::endl;
60 63
         ListEntries(pack);
64
+    } else if (action == "--convert") {
65
+        if (argc < 4) {
66
+            PrintUsage();
67
+            return -1;
68
+        }
69
+        olc::Sprite sprite;
70
+        if (sprite.LoadFromFile(packFile) != olc::OK) {
71
+            std::cerr << "Not valid PNG file " << packFile << std::endl;
72
+            return -4;
73
+        }
74
+        std::string sprFile = argv[3];
75
+        if (!sprite.SaveToPGESprFile(sprFile)) {
76
+            std::cerr << "Could not save file " << sprFile << std::endl;
77
+            return -3;
78
+        }
79
+        return 0;
61 80
     } else {
62 81
         PrintUsage();
63 82
         return -1;
64 83
     }
65 84
 
66
-    pack.SavePack(packFile);
85
+    if (!pack.SavePack(packFile)) {
86
+        std::cerr << "Could not save file " << packFile << std::endl;
87
+    }
67 88
 
68 89
     return 0;
69 90
 }

+ 23
- 0
pge/include/olcPGE_Common.h 파일 보기

@@ -1,12 +1,35 @@
1 1
 #ifndef OLC_PGE_COMMON
2 2
 #define OLC_PGE_COMMON
3 3
 
4
+#ifdef _WIN32
5
+	// Link to libraries
6
+#ifndef __MINGW32__
7
+	#pragma comment(lib, "user32.lib")
8
+#else
9
+	// In Code::Blocks, Select C++14 in your build options, and add the
10
+	// following libs to your linker: user32 gdi32 opengl32 gdiplus
11
+	#if !defined _WIN32_WINNT
12
+        #ifdef HAVE_MSMF
13
+            #define _WIN32_WINNT 0x0600 // Windows Vista
14
+        #else
15
+            #define _WIN32_WINNT 0x0500 // Windows 2000
16
+        #endif
17
+    #endif
18
+#endif
19
+	// Include WinAPI
20
+	#include <windows.h>
21
+#else
22
+#endif
23
+
24
+#include <string>
25
+
4 26
 namespace olc {
5 27
     enum rcode {
6 28
         FAIL = 0,
7 29
         OK = 1,
8 30
         NO_FILE = -1,
9 31
     };
32
+    std::wstring ConvertS2W(std::string s);
10 33
 }
11 34
 
12 35
 #endif

+ 43
- 0
pge/include/olcPGE_Pixel.h 파일 보기

@@ -0,0 +1,43 @@
1
+#ifndef OLC_PGE_PIXEL
2
+#define OLC_PGE_PIXEL
3
+
4
+#include <cstdint>
5
+#include "olcPGE_Common.h"
6
+
7
+namespace olc {
8
+    struct Pixel
9
+	{
10
+		union
11
+		{
12
+			uint32_t n = 0xFF000000;
13
+			struct
14
+			{
15
+				uint8_t r;	uint8_t g;	uint8_t b;	uint8_t a;
16
+			};
17
+		};
18
+
19
+		Pixel();
20
+		Pixel(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha = 255);
21
+		Pixel(uint32_t p);
22
+
23
+		static Pixel CreateFromHSV(uint8_t h, uint8_t s, uint8_t v, uint8_t alpha = 255);
24
+		enum Mode { NORMAL, MASK, ALPHA, CUSTOM };
25
+	};
26
+
27
+	// Some constants for symbolic naming of Pixels
28
+	static const Pixel
29
+		WHITE(255, 255, 255),
30
+		GREY(192, 192, 192), DARK_GREY(128, 128, 128), VERY_DARK_GREY(64, 64, 64),
31
+		RED(255, 0, 0), DARK_RED(128, 0, 0), VERY_DARK_RED(64, 0, 0),
32
+		YELLOW(255, 255, 0), DARK_YELLOW(128, 128, 0), VERY_DARK_YELLOW(64, 64, 0),
33
+		GREEN(0, 255, 0), DARK_GREEN(0, 128, 0), VERY_DARK_GREEN(0, 64, 0),
34
+		CYAN(0, 255, 255), DARK_CYAN(0, 128, 128), VERY_DARK_CYAN(0, 64, 64),
35
+		BLUE(0, 0, 255), DARK_BLUE(0, 0, 128), VERY_DARK_BLUE(0, 0, 64),
36
+		MAGENTA(255, 0, 255), DARK_MAGENTA(128, 0, 128), VERY_DARK_MAGENTA(64, 0, 64),
37
+		BLACK(0, 0, 0),
38
+		BLANK(0, 0, 0, 0);
39
+
40
+	//==================================================================================
41
+}
42
+
43
+#endif

+ 80
- 0
pge/include/olcPGE_Sprite.h 파일 보기

@@ -0,0 +1,80 @@
1
+#ifndef OLC_PGE_SPRITE
2
+#define OLC_PGE_SPRITE
3
+
4
+#ifdef _WIN32
5
+	// Link to libraries
6
+#ifndef __MINGW32__
7
+	#pragma comment(lib, "user32.lib")		// Visual Studio Only
8
+	#pragma comment(lib, "gdi32.lib")		// For other Windows Compilers please add
9
+	#pragma comment(lib, "gdiplus.lib")		// these libs to your linker input
10
+#else
11
+	// In Code::Blocks, Select C++14 in your build options, and add the
12
+	// following libs to your linker: user32 gdi32 opengl32 gdiplus
13
+	#if !defined _WIN32_WINNT
14
+        #ifdef HAVE_MSMF
15
+            #define _WIN32_WINNT 0x0600 // Windows Vista
16
+        #else
17
+            #define _WIN32_WINNT 0x0500 // Windows 2000
18
+        #endif
19
+    #endif
20
+#endif
21
+	// Include WinAPI
22
+	#include <windows.h>
23
+	#include <gdiplus.h>
24
+#else
25
+	#include <png.h>
26
+#endif
27
+
28
+#include <cstdint>
29
+#include <cmath>
30
+#include <string>
31
+#include <map>
32
+#include <vector>
33
+#include <streambuf>
34
+#include <iostream>
35
+#include <fstream>
36
+#include "olcPGE_Common.h"
37
+#include "olcPGE_Pixel.h"
38
+#include "olcPGE_ResourcePack.h"
39
+
40
+namespace olc {
41
+	// A bitmap-like structure that stores a 2D array of Pixels
42
+	class Sprite
43
+	{
44
+	public:
45
+		Sprite();
46
+		Sprite(std::string sImageFile);
47
+		Sprite(std::string sImageFile, olc::ResourcePack *pack);
48
+		Sprite(int32_t w, int32_t h);
49
+		~Sprite();
50
+
51
+	public:
52
+		olc::rcode LoadFromFile(std::string sImageFile, olc::ResourcePack *pack = nullptr);
53
+		olc::rcode LoadFromPGESprFile(std::string sImageFile, olc::ResourcePack *pack = nullptr);
54
+		olc::rcode SaveToPGESprFile(std::string sImageFile);
55
+
56
+	public:
57
+		int32_t width = 0;
58
+		int32_t height = 0;
59
+		enum Mode { NORMAL, PERIODIC };
60
+
61
+	public:
62
+		void SetSampleMode(olc::Sprite::Mode mode = olc::Sprite::Mode::NORMAL);
63
+		Pixel GetPixel(int32_t x, int32_t y);
64
+		bool  SetPixel(int32_t x, int32_t y, Pixel p);
65
+
66
+		Pixel Sample(float x, float y);
67
+		Pixel SampleBL(float u, float v);
68
+		Pixel* GetData();
69
+
70
+	private:
71
+		Pixel *pColData = nullptr;
72
+		Mode modeSample = Mode::NORMAL;
73
+
74
+#ifdef OLC_DBG_OVERDRAW
75
+	public:
76
+		static int nOverdrawCount;
77
+#endif
78
+	};
79
+}
80
+#endif

+ 1
- 77
pge/include/olcPixelGameEngine.h 파일 보기

@@ -206,7 +206,6 @@
206 206
 	#include <GL/glx.h>
207 207
 	#include <X11/X.h>
208 208
 	#include <X11/Xlib.h>
209
-	#include <png.h>
210 209
 	typedef int(glSwapInterval_t) (Display *dpy, GLXDrawable drawable, int interval);
211 210
 #endif
212 211
 
@@ -228,6 +227,7 @@
228 227
 #include <functional>
229 228
 #include <algorithm>
230 229
 #include "olcPGE_Common.h"
230
+#include "olcPGE_Sprite.h"
231 231
 #include "olcPGE_ResourcePack.h"
232 232
 
233 233
 #undef min
@@ -235,40 +235,6 @@
235 235
 
236 236
 namespace olc // All OneLoneCoder stuff will now exist in the "olc" namespace
237 237
 {
238
-	struct Pixel
239
-	{
240
-		union
241
-		{
242
-			uint32_t n = 0xFF000000;
243
-			struct
244
-			{
245
-				uint8_t r;	uint8_t g;	uint8_t b;	uint8_t a;
246
-			};
247
-		};
248
-
249
-		Pixel();
250
-		Pixel(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha = 255);
251
-		Pixel(uint32_t p);
252
-
253
-		static Pixel CreateFromHSV(uint8_t h, uint8_t s, uint8_t v, uint8_t alpha = 255);
254
-		enum Mode { NORMAL, MASK, ALPHA, CUSTOM };
255
-	};
256
-
257
-	// Some constants for symbolic naming of Pixels
258
-	static const Pixel
259
-		WHITE(255, 255, 255),
260
-		GREY(192, 192, 192), DARK_GREY(128, 128, 128), VERY_DARK_GREY(64, 64, 64),
261
-		RED(255, 0, 0), DARK_RED(128, 0, 0), VERY_DARK_RED(64, 0, 0),
262
-		YELLOW(255, 255, 0), DARK_YELLOW(128, 128, 0), VERY_DARK_YELLOW(64, 64, 0),
263
-		GREEN(0, 255, 0), DARK_GREEN(0, 128, 0), VERY_DARK_GREEN(0, 64, 0),
264
-		CYAN(0, 255, 255), DARK_CYAN(0, 128, 128), VERY_DARK_CYAN(0, 64, 64),
265
-		BLUE(0, 0, 255), DARK_BLUE(0, 0, 128), VERY_DARK_BLUE(0, 0, 64),
266
-		MAGENTA(255, 0, 255), DARK_MAGENTA(128, 0, 128), VERY_DARK_MAGENTA(64, 0, 64),
267
-		BLACK(0, 0, 0),
268
-		BLANK(0, 0, 0, 0);
269
-
270
-	//==================================================================================
271
-
272 238
 	template <class T>
273 239
 	struct v2d_generic
274 240
 	{
@@ -316,48 +282,6 @@ namespace olc // All OneLoneCoder stuff will now exist in the "olc" namespace
316 282
 
317 283
 	//=============================================================
318 284
 
319
-	// A bitmap-like structure that stores a 2D array of Pixels
320
-	class Sprite
321
-	{
322
-	public:
323
-		Sprite();
324
-		Sprite(std::string sImageFile);
325
-		Sprite(std::string sImageFile, olc::ResourcePack *pack);
326
-		Sprite(int32_t w, int32_t h);
327
-		~Sprite();
328
-
329
-	public:
330
-		olc::rcode LoadFromFile(std::string sImageFile, olc::ResourcePack *pack = nullptr);
331
-		olc::rcode LoadFromPGESprFile(std::string sImageFile, olc::ResourcePack *pack = nullptr);
332
-		olc::rcode SaveToPGESprFile(std::string sImageFile);
333
-
334
-	public:
335
-		int32_t width = 0;
336
-		int32_t height = 0;
337
-		enum Mode { NORMAL, PERIODIC };
338
-
339
-	public:
340
-		void SetSampleMode(olc::Sprite::Mode mode = olc::Sprite::Mode::NORMAL);
341
-		Pixel GetPixel(int32_t x, int32_t y);
342
-		bool  SetPixel(int32_t x, int32_t y, Pixel p);
343
-
344
-		Pixel Sample(float x, float y);
345
-		Pixel SampleBL(float u, float v);
346
-		Pixel* GetData();
347
-
348
-	private:
349
-		Pixel *pColData = nullptr;
350
-		Mode modeSample = Mode::NORMAL;
351
-
352
-#ifdef OLC_DBG_OVERDRAW
353
-	public:
354
-		static int nOverdrawCount;
355
-#endif
356
-
357
-	};
358
-
359
-	//=============================================================
360
-
361 285
 	enum Key
362 286
 	{
363 287
 		NONE,

+ 17
- 0
pge/src/olcPGE_Common.cpp 파일 보기

@@ -0,0 +1,17 @@
1
+#include "olcPGE_Common.h"
2
+
3
+namespace olc {
4
+	std::wstring ConvertS2W(std::string s)
5
+	{
6
+#ifdef _WIN32
7
+		int count = MultiByteToWideChar(CP_UTF8, 0, s.c_str(), -1, NULL, 0);
8
+		wchar_t* buffer = new wchar_t[count];
9
+		MultiByteToWideChar(CP_UTF8, 0, s.c_str(), -1, buffer, count);
10
+		std::wstring w(buffer);
11
+		delete[] buffer;
12
+		return w;
13
+#else
14
+		return L"SVN FTW!";
15
+#endif
16
+	}
17
+}

+ 63
- 0
pge/src/olcPGE_Pixel.cpp 파일 보기

@@ -0,0 +1,63 @@
1
+#include "olcPGE_Pixel.h"
2
+
3
+namespace olc {
4
+    Pixel::Pixel()
5
+	{
6
+		r = 0; g = 0; b = 0; a = 255;
7
+	}
8
+
9
+	Pixel::Pixel(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha)
10
+	{
11
+		r = red; g = green; b = blue; a = alpha;
12
+	}
13
+
14
+	Pixel::Pixel(uint32_t p)
15
+	{
16
+		n = p;
17
+	}
18
+
19
+	Pixel Pixel::CreateFromHSV(uint8_t h, uint8_t s, uint8_t v, uint8_t alpha) {
20
+		Pixel rgb;
21
+		rgb.a = alpha;
22
+		uint8_t region, remainder, p, q, t;
23
+
24
+		if (s == 0)
25
+		{
26
+			rgb.r = v;
27
+			rgb.g = v;
28
+			rgb.b = v;
29
+			return rgb;
30
+		}
31
+
32
+		region = h / 43;
33
+		remainder = (h - (region * 43)) * 6; 
34
+
35
+		p = (v * (255 - s)) >> 8;
36
+		q = (v * (255 - ((s * remainder) >> 8))) >> 8;
37
+		t = (v * (255 - ((s * (255 - remainder)) >> 8))) >> 8;
38
+
39
+		switch (region)
40
+		{
41
+			case 0:
42
+				rgb.r = v; rgb.g = t; rgb.b = p;
43
+				break;
44
+			case 1:
45
+				rgb.r = q; rgb.g = v; rgb.b = p;
46
+				break;
47
+			case 2:
48
+				rgb.r = p; rgb.g = v; rgb.b = t;
49
+				break;
50
+			case 3:
51
+				rgb.r = p; rgb.g = q; rgb.b = v;
52
+				break;
53
+			case 4:
54
+				rgb.r = t; rgb.g = p; rgb.b = v;
55
+				break;
56
+			default:
57
+				rgb.r = v; rgb.g = p; rgb.b = q;
58
+				break;
59
+		}
60
+
61
+		return rgb;
62
+	}
63
+}

+ 268
- 0
pge/src/olcPGE_Sprite.cpp 파일 보기

@@ -0,0 +1,268 @@
1
+#include "olcPGE_Sprite.h"
2
+
3
+namespace olc {
4
+	Sprite::Sprite()
5
+	{
6
+		pColData = nullptr;
7
+		width = 0;
8
+		height = 0;
9
+	}
10
+
11
+	Sprite::Sprite(std::string sImageFile)
12
+	{
13
+		LoadFromFile(sImageFile);
14
+	}
15
+
16
+	Sprite::Sprite(std::string sImageFile, olc::ResourcePack *pack)
17
+	{
18
+		LoadFromPGESprFile(sImageFile, pack);
19
+	}
20
+
21
+	Sprite::Sprite(int32_t w, int32_t h)
22
+	{
23
+		if(pColData) delete[] pColData;
24
+		width = w;		height = h;
25
+		pColData = new Pixel[width * height];
26
+		for (int32_t i = 0; i < width*height; i++)
27
+			pColData[i] = Pixel();
28
+	}
29
+
30
+	Sprite::~Sprite()
31
+	{
32
+		if (pColData) delete pColData;
33
+	}
34
+
35
+	olc::rcode Sprite::LoadFromPGESprFile(std::string sImageFile, olc::ResourcePack *pack)
36
+	{
37
+		if (pColData) delete[] pColData;
38
+
39
+		auto ReadData = [&](std::istream &is)
40
+		{
41
+			is.read((char*)&width, sizeof(int32_t));
42
+			is.read((char*)&height, sizeof(int32_t));
43
+			pColData = new Pixel[width * height];
44
+			is.read((char*)pColData, width * height * sizeof(uint32_t));
45
+		};
46
+
47
+		// These are essentially Memory Surfaces represented by olc::Sprite
48
+		// which load very fast, but are completely uncompressed
49
+		if (pack == nullptr)
50
+		{
51
+			std::ifstream ifs;
52
+			ifs.open(sImageFile, std::ifstream::binary);
53
+			if (ifs.is_open())
54
+			{
55
+				ReadData(ifs);
56
+				return olc::OK;
57
+			}
58
+			else
59
+				return olc::FAIL;
60
+		}
61
+		else
62
+		{
63
+			auto streamBuffer = pack->GetStreamBuffer(sImageFile);
64
+			std::istream is(&streamBuffer);
65
+			ReadData(is);
66
+		}
67
+
68
+
69
+		return olc::FAIL;
70
+		}
71
+
72
+	olc::rcode Sprite::SaveToPGESprFile(std::string sImageFile)
73
+	{
74
+		if (pColData == nullptr) return olc::FAIL;
75
+
76
+		std::ofstream ofs;
77
+		ofs.open(sImageFile, std::ifstream::binary);
78
+		if (ofs.is_open())
79
+		{
80
+			ofs.write((char*)&width, sizeof(int32_t));
81
+			ofs.write((char*)&height, sizeof(int32_t));
82
+			ofs.write((char*)pColData, width*height*sizeof(uint32_t));
83
+			ofs.close();
84
+			return olc::OK;
85
+		}
86
+
87
+		return olc::FAIL;
88
+	}
89
+
90
+	olc::rcode Sprite::LoadFromFile(std::string sImageFile, olc::ResourcePack *pack)
91
+	{
92
+#ifdef _WIN32
93
+		// Use GDI+
94
+		std::wstring wsImageFile;
95
+#ifdef __MINGW32__
96
+        wchar_t *buffer = new wchar_t[sImageFile.length() + 1];
97
+        mbstowcs(buffer, sImageFile.c_str(), sImageFile.length());
98
+        buffer[sImageFile.length()] = L'\0';
99
+        wsImageFile = buffer;
100
+        delete [] buffer;
101
+#else
102
+		wsImageFile = ConvertS2W(sImageFile);
103
+#endif
104
+        Gdiplus::Bitmap *bmp = Gdiplus::Bitmap::FromFile(wsImageFile.c_str());
105
+		if (bmp == nullptr)
106
+			return olc::NO_FILE;
107
+
108
+		width = bmp->GetWidth();
109
+		height = bmp->GetHeight();
110
+		pColData = new Pixel[width * height];
111
+
112
+		for(int x=0; x<width; x++)
113
+			for (int y = 0; y < height; y++)
114
+			{
115
+				Gdiplus::Color c;
116
+				bmp->GetPixel(x, y, &c);
117
+				SetPixel(x, y, Pixel(c.GetRed(), c.GetGreen(), c.GetBlue(), c.GetAlpha()));
118
+			}
119
+		delete bmp;
120
+		return olc::OK;
121
+#else
122
+		////////////////////////////////////////////////////////////////////////////
123
+		// Use libpng, Thanks to Guillaume Cottenceau
124
+		// https://gist.github.com/niw/5963798
125
+		png_structp png;
126
+		png_infop info;
127
+
128
+		FILE *f = fopen(sImageFile.c_str(), "rb");
129
+		if (!f) return olc::NO_FILE;
130
+
131
+		png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
132
+		if (!png) goto fail_load;
133
+
134
+		info = png_create_info_struct(png);
135
+		if (!info) goto fail_load;
136
+
137
+		if (setjmp(png_jmpbuf(png))) goto fail_load;
138
+
139
+		png_init_io(png, f);
140
+		png_read_info(png, info);
141
+
142
+		png_byte color_type;
143
+		png_byte bit_depth;
144
+		png_bytep *row_pointers;
145
+		width = png_get_image_width(png, info);
146
+		height = png_get_image_height(png, info);
147
+		color_type = png_get_color_type(png, info);
148
+		bit_depth = png_get_bit_depth(png, info);
149
+
150
+#ifdef _DEBUG
151
+		std::cout << "Loading PNG: " << sImageFile << "\n";
152
+		std::cout << "W:" << width << " H:" << height << " D:" << (int)bit_depth << "\n";
153
+#endif
154
+
155
+		if (bit_depth == 16) png_set_strip_16(png);
156
+		if (color_type == PNG_COLOR_TYPE_PALETTE) png_set_palette_to_rgb(png);
157
+		if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)	png_set_expand_gray_1_2_4_to_8(png);
158
+		if (png_get_valid(png, info, PNG_INFO_tRNS)) png_set_tRNS_to_alpha(png);
159
+		if (color_type == PNG_COLOR_TYPE_RGB ||
160
+			color_type == PNG_COLOR_TYPE_GRAY ||
161
+			color_type == PNG_COLOR_TYPE_PALETTE)
162
+			png_set_filler(png, 0xFF, PNG_FILLER_AFTER);
163
+		if (color_type == PNG_COLOR_TYPE_GRAY ||
164
+			color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
165
+			png_set_gray_to_rgb(png);
166
+
167
+		png_read_update_info(png, info);
168
+		row_pointers = (png_bytep*)malloc(sizeof(png_bytep) * height);
169
+		for (int y = 0; y < height; y++) {
170
+			row_pointers[y] = (png_byte*)malloc(png_get_rowbytes(png, info));
171
+		}
172
+		png_read_image(png, row_pointers);
173
+		////////////////////////////////////////////////////////////////////////////
174
+
175
+		// Create sprite array
176
+		pColData = new Pixel[width * height];
177
+
178
+		// Iterate through image rows, converting into sprite format
179
+		for (int y = 0; y < height; y++)
180
+		{
181
+			png_bytep row = row_pointers[y];
182
+			for (int x = 0; x < width; x++)
183
+			{
184
+				png_bytep px = &(row[x * 4]);
185
+				SetPixel(x, y, Pixel(px[0], px[1], px[2], px[3]));
186
+			}
187
+		}
188
+
189
+		fclose(f);
190
+		return olc::OK;
191
+
192
+	fail_load:
193
+		width = 0;
194
+		height = 0;
195
+		fclose(f);
196
+		pColData = nullptr;
197
+		return olc::FAIL;
198
+#endif
199
+	}
200
+
201
+	void Sprite::SetSampleMode(olc::Sprite::Mode mode)
202
+	{
203
+		modeSample = mode;
204
+	}
205
+
206
+
207
+	Pixel Sprite::GetPixel(int32_t x, int32_t y)
208
+	{
209
+		if (modeSample == olc::Sprite::Mode::NORMAL)
210
+		{
211
+			if (x >= 0 && x < width && y >= 0 && y < height)
212
+				return pColData[y*width + x];
213
+			else
214
+				return Pixel(0, 0, 0, 0);
215
+		}
216
+		else
217
+		{
218
+			return pColData[abs(y%height)*width + abs(x%width)];
219
+		}
220
+	}
221
+
222
+	bool Sprite::SetPixel(int32_t x, int32_t y, Pixel p)
223
+	{
224
+
225
+#ifdef OLC_DBG_OVERDRAW
226
+		nOverdrawCount++;
227
+#endif
228
+
229
+		if (x >= 0 && x < width && y >= 0 && y < height)
230
+		{
231
+			pColData[y*width + x] = p;
232
+			return true;
233
+		}
234
+		else
235
+			return false;
236
+	}
237
+
238
+	Pixel Sprite::Sample(float x, float y)
239
+	{
240
+		int32_t sx = std::min((int32_t)((x * (float)width)), width - 1);
241
+		int32_t sy = std::min((int32_t)((y * (float)height)), height - 1);
242
+		return GetPixel(sx, sy);
243
+	}
244
+
245
+	Pixel Sprite::SampleBL(float u, float v)
246
+	{
247
+		u = u * width - 0.5f;
248
+		v = v * height - 0.5f;
249
+		int x = (int)floor(u); // cast to int rounds toward zero, not downward
250
+		int y = (int)floor(v); // Thanks @joshinils
251
+		float u_ratio = u - x;
252
+		float v_ratio = v - y;
253
+		float u_opposite = 1 - u_ratio;
254
+		float v_opposite = 1 - v_ratio;
255
+
256
+		olc::Pixel p1 = GetPixel(std::max(x, 0), std::max(y, 0));
257
+		olc::Pixel p2 = GetPixel(std::min(x + 1, (int)width - 1), std::max(y, 0));
258
+		olc::Pixel p3 = GetPixel(std::max(x, 0), std::min(y + 1, (int)height - 1));
259
+		olc::Pixel p4 = GetPixel(std::min(x + 1, (int)width - 1), std::min(y + 1, (int)height - 1));
260
+
261
+		return olc::Pixel(
262
+			(uint8_t)((p1.r * u_opposite + p2.r * u_ratio) * v_opposite + (p3.r * u_opposite + p4.r * u_ratio) * v_ratio),
263
+			(uint8_t)((p1.g * u_opposite + p2.g * u_ratio) * v_opposite + (p3.g * u_opposite + p4.g * u_ratio) * v_ratio),
264
+			(uint8_t)((p1.b * u_opposite + p2.b * u_ratio) * v_opposite + (p3.b * u_opposite + p4.b * u_ratio) * v_ratio));
265
+	}
266
+
267
+	Pixel* Sprite::GetData() { return pColData; }
268
+}

+ 0
- 343
pge/src/olcPixelGameEngine.cpp 파일 보기

@@ -8,349 +8,6 @@
8 8
 
9 9
 namespace olc
10 10
 {
11
-	Pixel::Pixel()
12
-	{
13
-		r = 0; g = 0; b = 0; a = 255;
14
-	}
15
-
16
-	Pixel::Pixel(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha)
17
-	{
18
-		r = red; g = green; b = blue; a = alpha;
19
-	}
20
-
21
-	Pixel::Pixel(uint32_t p)
22
-	{
23
-		n = p;
24
-	}
25
-
26
-	Pixel Pixel::CreateFromHSV(uint8_t h, uint8_t s, uint8_t v, uint8_t alpha) {
27
-		Pixel rgb;
28
-		rgb.a = alpha;
29
-		uint8_t region, remainder, p, q, t;
30
-
31
-		if (s == 0)
32
-		{
33
-			rgb.r = v;
34
-			rgb.g = v;
35
-			rgb.b = v;
36
-			return rgb;
37
-		}
38
-
39
-		region = h / 43;
40
-		remainder = (h - (region * 43)) * 6; 
41
-
42
-		p = (v * (255 - s)) >> 8;
43
-		q = (v * (255 - ((s * remainder) >> 8))) >> 8;
44
-		t = (v * (255 - ((s * (255 - remainder)) >> 8))) >> 8;
45
-
46
-		switch (region)
47
-		{
48
-			case 0:
49
-				rgb.r = v; rgb.g = t; rgb.b = p;
50
-				break;
51
-			case 1:
52
-				rgb.r = q; rgb.g = v; rgb.b = p;
53
-				break;
54
-			case 2:
55
-				rgb.r = p; rgb.g = v; rgb.b = t;
56
-				break;
57
-			case 3:
58
-				rgb.r = p; rgb.g = q; rgb.b = v;
59
-				break;
60
-			case 4:
61
-				rgb.r = t; rgb.g = p; rgb.b = v;
62
-				break;
63
-			default:
64
-				rgb.r = v; rgb.g = p; rgb.b = q;
65
-				break;
66
-		}
67
-
68
-		return rgb;
69
-	}
70
-
71
-	//==========================================================
72
-
73
-	std::wstring ConvertS2W(std::string s)
74
-	{
75
-#ifdef _WIN32
76
-		int count = MultiByteToWideChar(CP_UTF8, 0, s.c_str(), -1, NULL, 0);
77
-		wchar_t* buffer = new wchar_t[count];
78
-		MultiByteToWideChar(CP_UTF8, 0, s.c_str(), -1, buffer, count);
79
-		std::wstring w(buffer);
80
-		delete[] buffer;
81
-		return w;
82
-#else
83
-		return L"SVN FTW!";
84
-#endif
85
-	}
86
-
87
-	Sprite::Sprite()
88
-	{
89
-		pColData = nullptr;
90
-		width = 0;
91
-		height = 0;
92
-	}
93
-
94
-	Sprite::Sprite(std::string sImageFile)
95
-	{
96
-		LoadFromFile(sImageFile);
97
-	}
98
-
99
-	Sprite::Sprite(std::string sImageFile, olc::ResourcePack *pack)
100
-	{
101
-		LoadFromPGESprFile(sImageFile, pack);
102
-	}
103
-
104
-	Sprite::Sprite(int32_t w, int32_t h)
105
-	{
106
-		if(pColData) delete[] pColData;
107
-		width = w;		height = h;
108
-		pColData = new Pixel[width * height];
109
-		for (int32_t i = 0; i < width*height; i++)
110
-			pColData[i] = Pixel();
111
-	}
112
-
113
-	Sprite::~Sprite()
114
-	{
115
-		if (pColData) delete pColData;
116
-	}
117
-
118
-	olc::rcode Sprite::LoadFromPGESprFile(std::string sImageFile, olc::ResourcePack *pack)
119
-	{
120
-		if (pColData) delete[] pColData;
121
-
122
-		auto ReadData = [&](std::istream &is)
123
-		{
124
-			is.read((char*)&width, sizeof(int32_t));
125
-			is.read((char*)&height, sizeof(int32_t));
126
-			pColData = new Pixel[width * height];
127
-			is.read((char*)pColData, width * height * sizeof(uint32_t));
128
-		};
129
-
130
-		// These are essentially Memory Surfaces represented by olc::Sprite
131
-		// which load very fast, but are completely uncompressed
132
-		if (pack == nullptr)
133
-		{
134
-			std::ifstream ifs;
135
-			ifs.open(sImageFile, std::ifstream::binary);
136
-			if (ifs.is_open())
137
-			{
138
-				ReadData(ifs);
139
-				return olc::OK;
140
-			}
141
-			else
142
-				return olc::FAIL;
143
-		}
144
-		else
145
-		{
146
-			auto streamBuffer = pack->GetStreamBuffer(sImageFile);
147
-			std::istream is(&streamBuffer);
148
-			ReadData(is);
149
-		}
150
-
151
-
152
-		return olc::FAIL;
153
-		}
154
-
155
-	olc::rcode Sprite::SaveToPGESprFile(std::string sImageFile)
156
-	{
157
-		if (pColData == nullptr) return olc::FAIL;
158
-
159
-		std::ofstream ofs;
160
-		ofs.open(sImageFile, std::ifstream::binary);
161
-		if (ofs.is_open())
162
-		{
163
-			ofs.write((char*)&width, sizeof(int32_t));
164
-			ofs.write((char*)&height, sizeof(int32_t));
165
-			ofs.write((char*)pColData, width*height*sizeof(uint32_t));
166
-			ofs.close();
167
-			return olc::OK;
168
-		}
169
-
170
-		return olc::FAIL;
171
-	}
172
-
173
-	olc::rcode Sprite::LoadFromFile(std::string sImageFile, olc::ResourcePack *pack)
174
-	{
175
-#ifdef _WIN32
176
-		// Use GDI+
177
-		std::wstring wsImageFile;
178
-#ifdef __MINGW32__
179
-        wchar_t *buffer = new wchar_t[sImageFile.length() + 1];
180
-        mbstowcs(buffer, sImageFile.c_str(), sImageFile.length());
181
-        buffer[sImageFile.length()] = L'\0';
182
-        wsImageFile = buffer;
183
-        delete [] buffer;
184
-#else
185
-		wsImageFile = ConvertS2W(sImageFile);
186
-#endif
187
-        Gdiplus::Bitmap *bmp = Gdiplus::Bitmap::FromFile(wsImageFile.c_str());
188
-		if (bmp == nullptr)
189
-			return olc::NO_FILE;
190
-
191
-		width = bmp->GetWidth();
192
-		height = bmp->GetHeight();
193
-		pColData = new Pixel[width * height];
194
-
195
-		for(int x=0; x<width; x++)
196
-			for (int y = 0; y < height; y++)
197
-			{
198
-				Gdiplus::Color c;
199
-				bmp->GetPixel(x, y, &c);
200
-				SetPixel(x, y, Pixel(c.GetRed(), c.GetGreen(), c.GetBlue(), c.GetAlpha()));
201
-			}
202
-		delete bmp;
203
-		return olc::OK;
204
-#else
205
-		////////////////////////////////////////////////////////////////////////////
206
-		// Use libpng, Thanks to Guillaume Cottenceau
207
-		// https://gist.github.com/niw/5963798
208
-		png_structp png;
209
-		png_infop info;
210
-
211
-		FILE *f = fopen(sImageFile.c_str(), "rb");
212
-		if (!f) return olc::NO_FILE;
213
-
214
-		png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
215
-		if (!png) goto fail_load;
216
-
217
-		info = png_create_info_struct(png);
218
-		if (!info) goto fail_load;
219
-
220
-		if (setjmp(png_jmpbuf(png))) goto fail_load;
221
-
222
-		png_init_io(png, f);
223
-		png_read_info(png, info);
224
-
225
-		png_byte color_type;
226
-		png_byte bit_depth;
227
-		png_bytep *row_pointers;
228
-		width = png_get_image_width(png, info);
229
-		height = png_get_image_height(png, info);
230
-		color_type = png_get_color_type(png, info);
231
-		bit_depth = png_get_bit_depth(png, info);
232
-
233
-#ifdef _DEBUG
234
-		std::cout << "Loading PNG: " << sImageFile << "\n";
235
-		std::cout << "W:" << width << " H:" << height << " D:" << (int)bit_depth << "\n";
236
-#endif
237
-
238
-		if (bit_depth == 16) png_set_strip_16(png);
239
-		if (color_type == PNG_COLOR_TYPE_PALETTE) png_set_palette_to_rgb(png);
240
-		if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)	png_set_expand_gray_1_2_4_to_8(png);
241
-		if (png_get_valid(png, info, PNG_INFO_tRNS)) png_set_tRNS_to_alpha(png);
242
-		if (color_type == PNG_COLOR_TYPE_RGB ||
243
-			color_type == PNG_COLOR_TYPE_GRAY ||
244
-			color_type == PNG_COLOR_TYPE_PALETTE)
245
-			png_set_filler(png, 0xFF, PNG_FILLER_AFTER);
246
-		if (color_type == PNG_COLOR_TYPE_GRAY ||
247
-			color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
248
-			png_set_gray_to_rgb(png);
249
-
250
-		png_read_update_info(png, info);
251
-		row_pointers = (png_bytep*)malloc(sizeof(png_bytep) * height);
252
-		for (int y = 0; y < height; y++) {
253
-			row_pointers[y] = (png_byte*)malloc(png_get_rowbytes(png, info));
254
-		}
255
-		png_read_image(png, row_pointers);
256
-		////////////////////////////////////////////////////////////////////////////
257
-
258
-		// Create sprite array
259
-		pColData = new Pixel[width * height];
260
-
261
-		// Iterate through image rows, converting into sprite format
262
-		for (int y = 0; y < height; y++)
263
-		{
264
-			png_bytep row = row_pointers[y];
265
-			for (int x = 0; x < width; x++)
266
-			{
267
-				png_bytep px = &(row[x * 4]);
268
-				SetPixel(x, y, Pixel(px[0], px[1], px[2], px[3]));
269
-			}
270
-		}
271
-
272
-		fclose(f);
273
-		return olc::OK;
274
-
275
-	fail_load:
276
-		width = 0;
277
-		height = 0;
278
-		fclose(f);
279
-		pColData = nullptr;
280
-		return olc::FAIL;
281
-#endif
282
-	}
283
-
284
-	void Sprite::SetSampleMode(olc::Sprite::Mode mode)
285
-	{
286
-		modeSample = mode;
287
-	}
288
-
289
-
290
-	Pixel Sprite::GetPixel(int32_t x, int32_t y)
291
-	{
292
-		if (modeSample == olc::Sprite::Mode::NORMAL)
293
-		{
294
-			if (x >= 0 && x < width && y >= 0 && y < height)
295
-				return pColData[y*width + x];
296
-			else
297
-				return Pixel(0, 0, 0, 0);
298
-		}
299
-		else
300
-		{
301
-			return pColData[abs(y%height)*width + abs(x%width)];
302
-		}
303
-	}
304
-
305
-	bool Sprite::SetPixel(int32_t x, int32_t y, Pixel p)
306
-	{
307
-
308
-#ifdef OLC_DBG_OVERDRAW
309
-		nOverdrawCount++;
310
-#endif
311
-
312
-		if (x >= 0 && x < width && y >= 0 && y < height)
313
-		{
314
-			pColData[y*width + x] = p;
315
-			return true;
316
-		}
317
-		else
318
-			return false;
319
-	}
320
-
321
-	Pixel Sprite::Sample(float x, float y)
322
-	{
323
-		int32_t sx = std::min((int32_t)((x * (float)width)), width - 1);
324
-		int32_t sy = std::min((int32_t)((y * (float)height)), height - 1);
325
-		return GetPixel(sx, sy);
326
-	}
327
-
328
-	Pixel Sprite::SampleBL(float u, float v)
329
-	{
330
-		u = u * width - 0.5f;
331
-		v = v * height - 0.5f;
332
-		int x = (int)floor(u); // cast to int rounds toward zero, not downward
333
-		int y = (int)floor(v); // Thanks @joshinils
334
-		float u_ratio = u - x;
335
-		float v_ratio = v - y;
336
-		float u_opposite = 1 - u_ratio;
337
-		float v_opposite = 1 - v_ratio;
338
-
339
-		olc::Pixel p1 = GetPixel(std::max(x, 0), std::max(y, 0));
340
-		olc::Pixel p2 = GetPixel(std::min(x + 1, (int)width - 1), std::max(y, 0));
341
-		olc::Pixel p3 = GetPixel(std::max(x, 0), std::min(y + 1, (int)height - 1));
342
-		olc::Pixel p4 = GetPixel(std::min(x + 1, (int)width - 1), std::min(y + 1, (int)height - 1));
343
-
344
-		return olc::Pixel(
345
-			(uint8_t)((p1.r * u_opposite + p2.r * u_ratio) * v_opposite + (p3.r * u_opposite + p4.r * u_ratio) * v_ratio),
346
-			(uint8_t)((p1.g * u_opposite + p2.g * u_ratio) * v_opposite + (p3.g * u_opposite + p4.g * u_ratio) * v_ratio),
347
-			(uint8_t)((p1.b * u_opposite + p2.b * u_ratio) * v_opposite + (p3.b * u_opposite + p4.b * u_ratio) * v_ratio));
348
-	}
349
-
350
-	Pixel* Sprite::GetData() { return pColData; }
351
-
352
-	//==========================================================
353
-
354 11
 	PixelGameEngine::PixelGameEngine()
355 12
 	{
356 13
 		sAppName = "Undefined";

BIN
res/awoorwa.png 파일 보기


+ 27
- 11
src/pabloader/awoorwae.cpp 파일 보기

@@ -4,6 +4,17 @@
4 4
 
5 5
 namespace pabloader {
6 6
 
7
+bool Awoorwae::OnUserCreate() {
8
+    if (!player->Load()) {
9
+        std::cerr << "Could not load awoorwa.spr" << std::endl;
10
+        return false;
11
+    }
12
+
13
+    SetPixelMode(olc::Pixel::MASK);
14
+
15
+    return true;
16
+}
17
+
7 18
 bool Awoorwae::OnUserUpdate(float fElapsedTime)
8 19
 {
9 20
     Clear(olc::BLACK);
@@ -25,35 +36,40 @@ Entity::Entity(Awoorwae* game_, float x_, float y_)
25 36
     yv = 10;
26 37
 }
27 38
 
39
+olc::rcode Entity::Load() 
40
+{
41
+    return img.LoadFromPGESprFile("res/awoorwa.spr");
42
+}
43
+
28 44
 void Entity::Update(float dt)
29 45
 {
30 46
     x += dt * xv;
31 47
     y += dt * yv;
32 48
 
33
-    if (x > game->ScreenWidth() - 20) {
34
-        xv *= -1;
35
-        x = game->ScreenWidth() - 20;
49
+    if (x > game->ScreenWidth() - img.width) {
50
+        xv *= -1.1;
51
+        x = game->ScreenWidth() - img.width;
36 52
     }
37 53
 
38
-    if (x < 20) {
54
+    if (x < 0) {
39 55
         xv *= -1.1;
40
-        x = 20;
56
+        x = 0;
41 57
     }
42 58
 
43
-    if (y > game->ScreenHeight() - 20) {
44
-        yv *= -1;
45
-        y = game->ScreenHeight() - 20;
59
+    if (y > game->ScreenHeight() - img.height) {
60
+        yv *= -1.1;
61
+        y = game->ScreenHeight() - img.height;
46 62
     }
47 63
 
48
-    if (y < 20) {
64
+    if (y < 0) {
49 65
         yv *= -1.1;
50
-        y = 20;
66
+        y = 0;
51 67
     }
52 68
     color = fmodf(color + 256 * dt, 256);
53 69
 }
54 70
 
55 71
 void Entity::Draw()
56 72
 {
57
-    game->DrawCircle((int)x, (int)y, 20, olc::Pixel::CreateFromHSV((int)color, 255, 255));
73
+    game->DrawSprite((int)x, (int)y, &img);
58 74
 }
59 75
 }

+ 3
- 5
src/pabloader/awoorwae.h 파일 보기

@@ -10,6 +10,7 @@ class Awoorwae;
10 10
 class Entity {
11 11
 private:
12 12
     Awoorwae* game;
13
+    olc::Sprite img;
13 14
     float x;
14 15
     float y;
15 16
     float xv;
@@ -21,6 +22,7 @@ public:
21 22
 
22 23
     void Update(float dt);
23 24
     void Draw();
25
+    olc::rcode Load(); 
24 26
 };
25 27
 
26 28
 class Awoorwae : public olc::PixelGameEngine {
@@ -40,11 +42,7 @@ public:
40 42
     }
41 43
 
42 44
 public:
43
-    bool OnUserCreate() override
44
-    {
45
-        return true;
46
-    }
47
-
45
+    bool OnUserCreate() override;
48 46
     bool OnUserUpdate(float fElapsedTime) override;
49 47
 };
50 48
 }

Loading…
취소
저장