summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Scheibenpflug <zorchenhimer@gmail.com>2014-08-28 08:04:15 (GMT)
committerNick Scheibenpflug <zorchenhimer@gmail.com>2014-08-28 08:04:15 (GMT)
commit0303c9bc58059e630026f171945559283aeabeea (patch)
treea59d7f68998d73c76da07a0e2ea1c2d0cfa68072
parentcf1d7ecb21dd7850a5e0e6eb6f0651c28845a9aa (diff)
downloadspace-zap-0303c9bc58059e630026f171945559283aeabeea.zip
space-zap-0303c9bc58059e630026f171945559283aeabeea.tar.gz
Added an input handler class and started fleshing out the other stuff. Still need to do all the SDL stuff.
-rw-r--r--.gitignore1
-rw-r--r--Bullet.cpp0
-rw-r--r--Enemy.cpp0
-rw-r--r--InputHandler.cpp43
-rw-r--r--InputHandler.h34
-rw-r--r--Level.cpp10
-rw-r--r--Level.h7
-rw-r--r--Makefile5
-rw-r--r--Player.cpp9
-rw-r--r--Utils.h2
-rw-r--r--main.cpp14
-rw-r--r--main.h7
12 files changed, 126 insertions, 6 deletions
diff --git a/.gitignore b/.gitignore
index 9e5c7c3..4332120 100644
--- a/.gitignore
+++ b/.gitignore
@@ -28,3 +28,4 @@ _ReSharper*/
28[Tt]est[Rr]esult* 28[Tt]est[Rr]esult*
29 29
30*.swp 30*.swp
31*.o
diff --git a/Bullet.cpp b/Bullet.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Bullet.cpp
diff --git a/Enemy.cpp b/Enemy.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Enemy.cpp
diff --git a/InputHandler.cpp b/InputHandler.cpp
new file mode 100644
index 0000000..ca3c57a
--- /dev/null
+++ b/InputHandler.cpp
@@ -0,0 +1,43 @@
1#include "InputHandler.h"
2
3InputHandler::InputHandler() {
4 this->currentHandleID = 0;
5}
6
7InputHandler::~InputHandler() {
8 this->HandleVector.clear();
9}
10
11HandleNode::HandleNode(SDLKey key, CallbackKey callback, int id) {
12 this->Key = key;
13 this->Callback = callback;
14 this->ID = id;
15}
16
17HandleNode::~HandleNode() {
18 //delete this->Key; // lol, will this work?
19 //free(this->Callback);
20}
21
22int InputHandler::RegisterHandle(SDLKey key, CallbackKey callback) {
23 HandleNode* node = new HandleNode(key, callback, this->currentHandleID);
24 this->HandleVector.push_back(*node);
25
26 return this->currentHandleID++;
27}
28
29void InputHandler::DoCallback(SDLKey key) {
30 // There can be more than one callback per key and visa versa.
31 for(std::vector<HandleNode>::iterator i = this->HandleVector.begin(); i != this->HandleVector.end(); ++i) {
32 i->Callback();
33 }
34}
35
36// This shit might break. idk, I've never used vectors before.
37void InputHandler::UnRegisterHandle(int NodeID) {
38 for(std::vector<HandleNode>::iterator i = this->HandleVector.begin(); i != this->HandleVector.end(); ++i) {
39 if( i->ID == NodeID ) {
40 this->HandleVector.erase(i);
41 }
42 }
43}
diff --git a/InputHandler.h b/InputHandler.h
new file mode 100644
index 0000000..0c83ca3
--- /dev/null
+++ b/InputHandler.h
@@ -0,0 +1,34 @@
1#ifndef __INPUTHANDLER_H_
2#define __INPUTHANDLER_H_
3
4#include <SDL.h>
5#include <vector>
6
7typedef void (*CallbackKey)(void);
8
9class HandleNode {
10public:
11 SDLKey Key;
12 CallbackKey Callback;
13 int ID;
14
15 HandleNode(SDLKey Key, CallbackKey callback, int id);
16 ~HandleNode();
17};
18
19class InputHandler {
20public:
21 InputHandler();
22 ~InputHandler();
23 int RegisterHandle(SDLKey key, CallbackKey callback);
24 void UnRegisterHandle(SDLKey key);
25 void UnRegisterHandle(CallbackKey callback);
26 void UnRegisterHandle(int NodeID);
27
28 void DoCallback(SDLKey key);
29private:
30 int currentHandleID;
31 std::vector<HandleNode> HandleVector;
32};
33
34#endif
diff --git a/Level.cpp b/Level.cpp
new file mode 100644
index 0000000..87189f8
--- /dev/null
+++ b/Level.cpp
@@ -0,0 +1,10 @@
1#include "Level.h"
2
3Level::Level(int difficulty) {
4 this->Difficulty = difficulty;
5 this->PlayerObj = new Player();
6}
7
8Level::~Level() {
9 delete this->PlayerObj;
10}
diff --git a/Level.h b/Level.h
index a6fdeb1..6ebf8f5 100644
--- a/Level.h
+++ b/Level.h
@@ -4,6 +4,7 @@
4#include "Enums.h" 4#include "Enums.h"
5#include "Bullet.h" 5#include "Bullet.h"
6#include "Enemy.h" 6#include "Enemy.h"
7#include "Player.h"
7 8
8#include <SDL.h> 9#include <SDL.h>
9#include <SDL_image.h> 10#include <SDL_image.h>
@@ -11,14 +12,18 @@
11class Level { 12class Level {
12public: 13public:
13 int Difficulty; 14 int Difficulty;
15 Player* PlayerObj;
14 16
15 Level(int difficulty); 17 Level(int difficulty);
16 ~Level(); 18 ~Level();
17 void update(); 19 void update();
18 void draw(); 20 void draw();
21private:
22 // Max size of eight gives each quadrant room for two bullets at a time.
23 Bullet* bulletList[8];
19}; 24};
20 25
21bool CheckCollision(BulletInfo* A, BulletInfo* B); 26bool CheckCollision(BulletInfo* A, BulletInfo* B);
22bool CheckCollision(BulletInfo* A, Enemy* B); 27bool CheckCollision(BulletInfo* A, Enemy* B);
23 28
24#endif \ No newline at end of file 29#endif
diff --git a/Makefile b/Makefile
index 77a144e..2e92ed0 100644
--- a/Makefile
+++ b/Makefile
@@ -20,10 +20,13 @@ Utils.o: Utils.cpp Utils.h
20Bullet.o: Bullet.cpp Bullet.h 20Bullet.o: Bullet.cpp Bullet.h
21 $(CC) $(CFLAGS) -o Bullet.o Bullet.cpp 21 $(CC) $(CFLAGS) -o Bullet.o Bullet.cpp
22 22
23InputHandler.o: InputHandler.cpp InputHandler.h
24 $(CC) $(CFLAGS) -o InputHandler.o InputHandler.cpp
25
23main.o: main.cpp main.h 26main.o: main.cpp main.h
24 $(CC) $(CFLAGS) -o main.o main.cpp 27 $(CC) $(CFLAGS) -o main.o main.cpp
25 28
26main: main.o Bullet.o Utils.o Player.o Level.o Enemy.o 29main: main.o Bullet.o Utils.o Player.o Level.o Enemy.o InputHandler.o
27 $(CC) $(LDFLAGS) -o bin/main main.o Bullet.o Utils.o Player.o Level.o Enemy.o 30 $(CC) $(LDFLAGS) -o bin/main main.o Bullet.o Utils.o Player.o Level.o Enemy.o
28 31
29clean: 32clean:
diff --git a/Player.cpp b/Player.cpp
new file mode 100644
index 0000000..f2961cd
--- /dev/null
+++ b/Player.cpp
@@ -0,0 +1,9 @@
1#include "Player.h"
2
3Player::Player() {
4
5}
6
7Player::~Player() {
8
9}
diff --git a/Utils.h b/Utils.h
index 03c50ec..debcd07 100644
--- a/Utils.h
+++ b/Utils.h
@@ -19,4 +19,4 @@ SDL_Surface* LoadImage(char* file);
19void InitStuff(); 19void InitStuff();
20void SetWorkingDir(char* argv_0); 20void SetWorkingDir(char* argv_0);
21 21
22#endif \ No newline at end of file 22#endif
diff --git a/main.cpp b/main.cpp
index f391aeb..9a5c1c0 100644
--- a/main.cpp
+++ b/main.cpp
@@ -4,5 +4,17 @@ int main(int argc, char* argv[]) {
4 SetWorkingDir(argv[0]); 4 SetWorkingDir(argv[0]);
5 InitStuff(); 5 InitStuff();
6 6
7 Level* currentLevel;
8 InputHandler* input;
9
10 Running = true;
11
12 while(Running) {
13
14
15 }
16 delete currentLevel;
17
7 return 0; 18 return 0;
8} \ No newline at end of file 19}
20
diff --git a/main.h b/main.h
index f179316..3c2dcf6 100644
--- a/main.h
+++ b/main.h
@@ -2,12 +2,15 @@
2#define __MAIN_H_ 2#define __MAIN_H_
3 3
4#include "Utils.h" 4#include "Utils.h"
5//#include "Level.h" 5#include "Level.h"
6#include "InputHandler.h"
6 7
7char* WorkingDir; 8char* WorkingDir;
8SDL_Surface* VideoSurface; 9SDL_Surface* VideoSurface;
10bool Running;
11
9 12
10#include <SDL.h> 13#include <SDL.h>
11#include <SDL_image.h> 14#include <SDL_image.h>
12 15
13#endif \ No newline at end of file 16#endif