summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Level.cpp11
-rw-r--r--Level.h3
-rw-r--r--Player.cpp17
-rw-r--r--Player.h6
-rw-r--r--main.cpp35
-rw-r--r--main.h9
-rw-r--r--space-zap.vcxproj2
7 files changed, 72 insertions, 11 deletions
diff --git a/Level.cpp b/Level.cpp
index cc05d67..f163a9d 100644
--- a/Level.cpp
+++ b/Level.cpp
@@ -2,19 +2,22 @@
2 2
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 this->background = LoadImage("purple.png");
7 globalPlayer = new Player();
7} 8}
8 9
9Level::~Level() { 10Level::~Level() {
10 delete this->PlayerObj; 11 //delete this->PlayerObj;
11} 12}
12 13
13void Level::update() { 14void Level::update() {
14 this->PlayerObj->update(); 15 //this->PlayerObj->update();
16 globalPlayer->update();
15} 17}
16 18
17void Level::draw(SDL_Surface* surf) { 19void Level::draw(SDL_Surface* surf) {
18 TileImage(this->background, surf); 20 TileImage(this->background, surf);
19 this->PlayerObj->draw(surf); 21 //this->PlayerObj->draw(surf);
22 globalPlayer->draw(surf);
20} \ No newline at end of file 23} \ No newline at end of file
diff --git a/Level.h b/Level.h
index df700da..880030a 100644
--- a/Level.h
+++ b/Level.h
@@ -24,6 +24,9 @@ private:
24 SDL_Surface* background; 24 SDL_Surface* background;
25}; 25};
26 26
27
28extern Player* globalPlayer;
29
27bool CheckCollision(BulletInfo* A, BulletInfo* B); 30bool CheckCollision(BulletInfo* A, BulletInfo* B);
28bool CheckCollision(BulletInfo* A, Enemy* B); 31bool CheckCollision(BulletInfo* A, Enemy* B);
29 32
diff --git a/Player.cpp b/Player.cpp
index b49abbc..245cd4f 100644
--- a/Player.cpp
+++ b/Player.cpp
@@ -26,7 +26,18 @@ Bullet* Player::Fire() {
26} 26}
27 27
28void Player::draw(SDL_Surface* surf) { 28void Player::draw(SDL_Surface* surf) {
29 this->Rect->x = (surf->w / 2) - (this->Rect->w / 2); 29 SDL_Surface* rotated_surf;
30 this->Rect->y = (surf->h / 2) - (this->Rect->h / 2); 30 if(this->orientation == EAST)
31 SDL_BlitSurface(this->Sprite, NULL, surf, this->Rect); 31 rotated_surf = rotozoomSurface(this->Sprite, 270, 1, 1);
32 else if(this->orientation == SOUTH)
33 rotated_surf = rotozoomSurface(this->Sprite, 180, 1, 1);
34 else if(this->orientation == WEST)
35 rotated_surf = rotozoomSurface(this->Sprite, 90, 1, 1);
36 else // should prolly just copy this...
37 rotated_surf = rotozoomSurface(this->Sprite, 0, 1, 1);
38
39 this->Rect->x = floor((surf->w / (float)2) - (this->Rect->w / (float)2) - 0.5);
40 this->Rect->y = floor((surf->h / (float)2) - (this->Rect->h / (float)2) - 0.5);
41 SDL_BlitSurface(rotated_surf, NULL, surf, this->Rect);
42 SDL_FreeSurface(rotated_surf);
32} \ No newline at end of file 43} \ No newline at end of file
diff --git a/Player.h b/Player.h
index d55b26f..bb3cfcf 100644
--- a/Player.h
+++ b/Player.h
@@ -7,9 +7,14 @@
7 7
8#include <SDL.h> 8#include <SDL.h>
9#include <SDL_image.h> 9#include <SDL_image.h>
10#include "SDL_rotozoom.h"
11
12#include <math.h>
13
10 14
11class Player { 15class Player {
12public: 16public:
17 SDL_Rect* Rect;
13 Player(); 18 Player();
14 ~Player(); 19 ~Player();
15 void Orient(Directions direction); 20 void Orient(Directions direction);
@@ -19,7 +24,6 @@ public:
19 24
20private: 25private:
21 SDL_Surface* Sprite; 26 SDL_Surface* Sprite;
22 SDL_Rect* Rect;
23 Directions orientation; 27 Directions orientation;
24}; 28};
25 29
diff --git a/main.cpp b/main.cpp
index 124618d..4c8c331 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1,4 +1,5 @@
1#include "main.h" 1#include "main.h"
2#include <iostream>
2 3
3int main(int argc, char* argv[]) { 4int main(int argc, char* argv[]) {
4 // FIXME: this shit doesn't work for whatever reason. Keeps putting a '' 5 // FIXME: this shit doesn't work for whatever reason. Keeps putting a ''
@@ -13,13 +14,18 @@ int main(int argc, char* argv[]) {
13 Running = true; 14 Running = true;
14 15
15 input->RegisterHandle(SDLK_ESCAPE, &exit_spacezap); 16 input->RegisterHandle(SDLK_ESCAPE, &exit_spacezap);
17 input->RegisterHandle(SDLK_UP, &k_up);
18 input->RegisterHandle(SDLK_RIGHT, &k_right);
19 input->RegisterHandle(SDLK_DOWN, &k_down);
20 input->RegisterHandle(SDLK_LEFT, &k_left);
16 21
17 while(Running) { 22 while(Running) {
18 SDL_Event evnt; 23 SDL_Event evnt;
19 while(SDL_PollEvent(&evnt)) { 24 while(SDL_PollEvent(&evnt)) {
20 if(evnt.type == SDL_KEYDOWN) 25 if(evnt.type == SDL_KEYDOWN) {
21 input->DoCallback(evnt.key.keysym.sym); 26 input->DoCallback(evnt.key.keysym.sym);
22 else if(evnt.type == SDL_QUIT) 27 std::cout << "Key: " << evnt.key.keysym.sym << std::endl;
28 } else if(evnt.type == SDL_QUIT)
23 exit_spacezap(); 29 exit_spacezap();
24 } 30 }
25 31
@@ -36,4 +42,29 @@ int main(int argc, char* argv[]) {
36 42
37void exit_spacezap() { 43void exit_spacezap() {
38 Running = false; 44 Running = false;
45}
46
47void k_up() {
48 globalPlayer->Orient(NORTH);
49 print_coords();
50}
51
52void k_right() {
53 globalPlayer->Orient(EAST);
54 print_coords();
55}
56
57void k_down() {
58 globalPlayer->Orient(SOUTH);
59 print_coords();
60}
61
62void k_left() {
63 globalPlayer->Orient(WEST);
64 print_coords();
65}
66
67void print_coords() {
68 std::cout << "> " << globalPlayer->Rect->x << ", " << globalPlayer->Rect->y << std::endl
69 << ">> " << globalPlayer->Rect->x << "x" << globalPlayer->Rect->y << std::endl;
39} \ No newline at end of file 70} \ No newline at end of file
diff --git a/main.h b/main.h
index ed6d1a9..7ab4c98 100644
--- a/main.h
+++ b/main.h
@@ -5,13 +5,22 @@
5#include "Level.h" 5#include "Level.h"
6#include "InputHandler.h" 6#include "InputHandler.h"
7#include "Enemy.h" 7#include "Enemy.h"
8#include "Player.h"
8 9
9char* WorkingDir; 10char* WorkingDir;
10SDL_Surface* VideoSurface; 11SDL_Surface* VideoSurface;
11bool Running; 12bool Running;
13Player* globalPlayer;
12 14
13void exit_spacezap(); 15void exit_spacezap();
14 16
17void k_up();
18void k_right();
19void k_down();
20void k_left();
21
22void print_coords();
23
15#include <SDL.h> 24#include <SDL.h>
16#include <SDL_image.h> 25#include <SDL_image.h>
17 26
diff --git a/space-zap.vcxproj b/space-zap.vcxproj
index 78034cb..4642e59 100644
--- a/space-zap.vcxproj
+++ b/space-zap.vcxproj
@@ -108,7 +108,7 @@ copy D:\code\cpp\SDL_image-1.2.12\lib\x86\*.dll $(OutDir)</Command>
108 <Link> 108 <Link>
109 <GenerateDebugInformation>true</GenerateDebugInformation> 109 <GenerateDebugInformation>true</GenerateDebugInformation>
110 <AdditionalDependencies>SDL.lib;SDLmain.lib;SDL_image.lib;%(AdditionalDependencies)</AdditionalDependencies> 110 <AdditionalDependencies>SDL.lib;SDLmain.lib;SDL_image.lib;%(AdditionalDependencies)</AdditionalDependencies>
111 <SubSystem>Windows</SubSystem> 111 <SubSystem>Console</SubSystem>
112 </Link> 112 </Link>
113 <PostBuildEvent> 113 <PostBuildEvent>
114 <Command>copy D:\code\cpp\SDL-1.2.15\lib\x64\SDL.dll $(OutDir) 114 <Command>copy D:\code\cpp\SDL-1.2.15\lib\x64\SDL.dll $(OutDir)