summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Scheibenpflug <zorchenhimer@gmail.com>2015-03-17 23:57:38 (GMT)
committerNick Scheibenpflug <zorchenhimer@gmail.com>2015-03-17 23:57:38 (GMT)
commit436f1706d3dab3f89f1ba95bc191a8d284165616 (patch)
tree77b70638deede1df367e5f4e39772efb9ff808d5
parenta2bc432e64b0c6f4ff2ff67b1d00d100a621e576 (diff)
downloadspace-zap-436f1706d3dab3f89f1ba95bc191a8d284165616.zip
space-zap-436f1706d3dab3f89f1ba95bc191a8d284165616.tar.gz
Start actually drawing stuff.
-rw-r--r--Level.cpp12
-rw-r--r--Level.h4
-rw-r--r--Player.cpp12
-rw-r--r--Player.h2
-rw-r--r--Utils.cpp4
-rw-r--r--main.cpp18
-rw-r--r--main.h1
7 files changed, 44 insertions, 9 deletions
diff --git a/Level.cpp b/Level.cpp
index 87189f8..151e64c 100644
--- a/Level.cpp
+++ b/Level.cpp
@@ -1,10 +1,18 @@
1#include "Level.h" 1#include "Level.h"
2 2
3Level::Level(int difficulty) { 3Level::Level() {
4 this->Difficulty = difficulty; 4 this->Difficulty = 1;
5 this->PlayerObj = new Player(); 5 this->PlayerObj = new Player();
6} 6}
7 7
8Level::~Level() { 8Level::~Level() {
9 delete this->PlayerObj; 9 delete this->PlayerObj;
10} 10}
11
12void Level::update() {
13 this->PlayerObj->update();
14}
15
16void Level::draw(SDL_Surface* surf) {
17 this->PlayerObj->draw(surf);
18} \ No newline at end of file
diff --git a/Level.h b/Level.h
index 6ebf8f5..7087e3a 100644
--- a/Level.h
+++ b/Level.h
@@ -14,10 +14,10 @@ public:
14 int Difficulty; 14 int Difficulty;
15 Player* PlayerObj; 15 Player* PlayerObj;
16 16
17 Level(int difficulty); 17 Level();
18 ~Level(); 18 ~Level();
19 void update(); 19 void update();
20 void draw(); 20 void draw(SDL_Surface* surf);
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];
diff --git a/Player.cpp b/Player.cpp
index bdae47b..b49abbc 100644
--- a/Player.cpp
+++ b/Player.cpp
@@ -1,7 +1,11 @@
1#include "Player.h" 1#include "Player.h"
2 2
3Player::Player() { 3Player::Player() {
4 4 // FIXME: Catch NULL here
5 this->Sprite = LoadImage("player.png");
6 this->Rect = new SDL_Rect();
7 this->Rect->h = this->Sprite->h;
8 this->Rect->w = this->Sprite->w;
5} 9}
6 10
7Player::~Player() { 11Player::~Player() {
@@ -19,4 +23,10 @@ void Player::update() {
19Bullet* Player::Fire() { 23Bullet* Player::Fire() {
20 Bullet* newbullet = new Bullet(this->orientation); 24 Bullet* newbullet = new Bullet(this->orientation);
21 return newbullet; 25 return newbullet;
26}
27
28void Player::draw(SDL_Surface* surf) {
29 this->Rect->x = (surf->w / 2) - (this->Rect->w / 2);
30 this->Rect->y = (surf->h / 2) - (this->Rect->h / 2);
31 SDL_BlitSurface(this->Sprite, NULL, surf, this->Rect);
22} \ No newline at end of file 32} \ No newline at end of file
diff --git a/Player.h b/Player.h
index befc115..d55b26f 100644
--- a/Player.h
+++ b/Player.h
@@ -3,6 +3,7 @@
3 3
4#include "Enums.h" 4#include "Enums.h"
5#include "Bullet.h" 5#include "Bullet.h"
6#include "Utils.h"
6 7
7#include <SDL.h> 8#include <SDL.h>
8#include <SDL_image.h> 9#include <SDL_image.h>
@@ -18,6 +19,7 @@ public:
18 19
19private: 20private:
20 SDL_Surface* Sprite; 21 SDL_Surface* Sprite;
22 SDL_Rect* Rect;
21 Directions orientation; 23 Directions orientation;
22}; 24};
23 25
diff --git a/Utils.cpp b/Utils.cpp
index 3289467..faf9120 100644
--- a/Utils.cpp
+++ b/Utils.cpp
@@ -5,7 +5,9 @@ SDL_Surface* LoadImage(char* file) {
5 SDL_Surface* retsurf = NULL; 5 SDL_Surface* retsurf = NULL;
6 6
7 char* fullpath = (char*) malloc(sizeof(char) * FILENAME_MAX); 7 char* fullpath = (char*) malloc(sizeof(char) * FILENAME_MAX);
8 sprintf(fullpath, "%s\\%s", WorkingDir, file); 8 // FIXME: this broke somehow. idk.
9 //sprintf(fullpath, "%s\\%s", WorkingDir, file);
10 sprintf(fullpath, "D:\\code\\cpp\\space-zap\\x64\\Debug\\%s", file);
9 11
10 if((tempsurf = IMG_Load(fullpath)) == NULL) 12 if((tempsurf = IMG_Load(fullpath)) == NULL)
11 return NULL; 13 return NULL;
diff --git a/main.cpp b/main.cpp
index 9a5c1c0..ec76071 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1,19 +1,31 @@
1#include "main.h" 1#include "main.h"
2 2
3int main(int argc, char* argv[]) { 3int main(int argc, char* argv[]) {
4 SetWorkingDir(argv[0]); 4 SetWorkingDir("D:\\code\\cpp\\space-zap\\x64\\Debug");
5 InitStuff(); 5 InitStuff();
6 6
7 Level* currentLevel; 7 Level* currentLevel = new Level();
8 InputHandler* input; 8 InputHandler* input;
9 9
10 Running = true; 10 Running = true;
11 11
12 while(Running) { 12 while(Running) {
13 SDL_Event evnt;
14 while(SDL_PollEvent(&evnt)) {
15 // Exit if escape is hit.
16 if(evnt.type == SDL_KEYDOWN && evnt.key.keysym.sym == SDLK_ESCAPE) {
17 Running = false;
18 break;
19 }
20 }
13 21
22 currentLevel->update();
14 23
24 currentLevel->draw(VideoSurface);
25
26 SDL_Flip(VideoSurface);
15 } 27 }
16 delete currentLevel; 28// delete currentLevel;
17 29
18 return 0; 30 return 0;
19} 31}
diff --git a/main.h b/main.h
index 3c2dcf6..99de43f 100644
--- a/main.h
+++ b/main.h
@@ -4,6 +4,7 @@
4#include "Utils.h" 4#include "Utils.h"
5#include "Level.h" 5#include "Level.h"
6#include "InputHandler.h" 6#include "InputHandler.h"
7#include "Enemy.h"
7 8
8char* WorkingDir; 9char* WorkingDir;
9SDL_Surface* VideoSurface; 10SDL_Surface* VideoSurface;