summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Scheibenpflug <zorchenhimer@gmail.com>2015-03-18 00:47:24 (GMT)
committerNick Scheibenpflug <zorchenhimer@gmail.com>2015-03-18 00:47:24 (GMT)
commit0f0572b8df93aa68c9cb8ae8a88fcc1ef3925939 (patch)
tree4abf96ad367284cc1df80952d46edb5a9c7473e8
parent436f1706d3dab3f89f1ba95bc191a8d284165616 (diff)
downloadspace-zap-0f0572b8df93aa68c9cb8ae8a88fcc1ef3925939.zip
space-zap-0f0572b8df93aa68c9cb8ae8a88fcc1ef3925939.tar.gz
Add TileImage() function. Modified LoadImage() to use image's alpha channel.
-rw-r--r--Level.cpp2
-rw-r--r--Level.h1
-rw-r--r--Utils.cpp26
-rw-r--r--Utils.h1
4 files changed, 27 insertions, 3 deletions
diff --git a/Level.cpp b/Level.cpp
index 151e64c..cc05d67 100644
--- a/Level.cpp
+++ b/Level.cpp
@@ -3,6 +3,7 @@
3Level::Level() { 3Level::Level() {
4 this->Difficulty = 1; 4 this->Difficulty = 1;
5 this->PlayerObj = new Player(); 5 this->PlayerObj = new Player();
6 this->background = LoadImage("purple.png");
6} 7}
7 8
8Level::~Level() { 9Level::~Level() {
@@ -14,5 +15,6 @@ void Level::update() {
14} 15}
15 16
16void Level::draw(SDL_Surface* surf) { 17void Level::draw(SDL_Surface* surf) {
18 TileImage(this->background, surf);
17 this->PlayerObj->draw(surf); 19 this->PlayerObj->draw(surf);
18} \ No newline at end of file 20} \ No newline at end of file
diff --git a/Level.h b/Level.h
index 7087e3a..df700da 100644
--- a/Level.h
+++ b/Level.h
@@ -21,6 +21,7 @@ public:
21private: 21private:
22 // Max size of eight gives each quadrant room for two bullets at a time. 22 // Max size of eight gives each quadrant room for two bullets at a time.
23 Bullet* bulletList[8]; 23 Bullet* bulletList[8];
24 SDL_Surface* background;
24}; 25};
25 26
26bool CheckCollision(BulletInfo* A, BulletInfo* B); 27bool CheckCollision(BulletInfo* A, BulletInfo* B);
diff --git a/Utils.cpp b/Utils.cpp
index faf9120..0494dc5 100644
--- a/Utils.cpp
+++ b/Utils.cpp
@@ -7,12 +7,14 @@ SDL_Surface* LoadImage(char* file) {
7 char* fullpath = (char*) malloc(sizeof(char) * FILENAME_MAX); 7 char* fullpath = (char*) malloc(sizeof(char) * FILENAME_MAX);
8 // FIXME: this broke somehow. idk. 8 // FIXME: this broke somehow. idk.
9 //sprintf(fullpath, "%s\\%s", WorkingDir, file); 9 //sprintf(fullpath, "%s\\%s", WorkingDir, file);
10 sprintf(fullpath, "D:\\code\\cpp\\space-zap\\x64\\Debug\\%s", file); 10 sprintf(fullpath, "D:\\code\\cpp\\space-zap\\img\\%s", file);
11 11
12 if((tempsurf = IMG_Load(fullpath)) == NULL) 12 if((tempsurf = IMG_Load(fullpath)) == NULL)
13 return NULL; 13 return NULL;
14 14
15 retsurf = SDL_ConvertSurface(tempsurf, VideoSurface->format, SDL_SRCALPHA | SDL_HWSURFACE); 15 // Flags at the end aren't used, apparently.
16 //retsurf = SDL_ConvertSurface(tempsurf_alpha, VideoSurface->format, 0);
17 retsurf = SDL_DisplayFormatAlpha(tempsurf);
16 SDL_FreeSurface(tempsurf); 18 SDL_FreeSurface(tempsurf);
17 19
18 return retsurf; 20 return retsurf;
@@ -21,7 +23,7 @@ SDL_Surface* LoadImage(char* file) {
21void InitStuff() { 23void InitStuff() {
22 SDL_Init(SDL_INIT_EVERYTHING); 24 SDL_Init(SDL_INIT_EVERYTHING);
23 VideoSurface = SDL_SetVideoMode(WINDOW_WIDTH, WINDOW_HEIGHT, 32, SDL_HWSURFACE | SDL_DOUBLEBUF); 25 VideoSurface = SDL_SetVideoMode(WINDOW_WIDTH, WINDOW_HEIGHT, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
24 SDL_ShowCursor(0); 26 SDL_ShowCursor(1);
25} 27}
26 28
27void SetWorkingDir(char* argv_0) { 29void SetWorkingDir(char* argv_0) {
@@ -30,4 +32,22 @@ void SetWorkingDir(char* argv_0) {
30 std::string temp = (char*) strrchr(argv_0, '\\'); 32 std::string temp = (char*) strrchr(argv_0, '\\');
31 33
32 strncpy(WorkingDir, argv_0, full.length() - temp.length()); 34 strncpy(WorkingDir, argv_0, full.length() - temp.length());
35}
36
37void TileImage(SDL_Surface* source, SDL_Surface* destination) {
38 // This will probably break.
39 int num_x = destination->w / source->w;
40 int num_y = destination->h / source->h;
41
42 SDL_Rect* rect = new SDL_Rect();
43 rect->h = source->h;
44 rect->w = source->w;
45
46 for(int x = 0; x < num_x; x++) {
47 for(int y = 0; y < num_y; y++) {
48 rect->x = rect->w * x;
49 rect->y = rect->h * y;
50 SDL_BlitSurface(source, NULL, destination, rect);
51 }
52 }
33} \ No newline at end of file 53} \ No newline at end of file
diff --git a/Utils.h b/Utils.h
index 49f6c3c..e4da083 100644
--- a/Utils.h
+++ b/Utils.h
@@ -20,5 +20,6 @@ extern SDL_Surface* VideoSurface;
20SDL_Surface* LoadImage(char* file); 20SDL_Surface* LoadImage(char* file);
21void InitStuff(); 21void InitStuff();
22void SetWorkingDir(char* argv_0); 22void SetWorkingDir(char* argv_0);
23void TileImage(SDL_Surface* source, SDL_Surface* destination);
23 24
24#endif 25#endif