Commits

Ivan Vučica committed 9a02ddb

Gamemode switching support.

Comments (0)

Files changed (7)

Pucaljka.xcodeproj/project.pbxproj

 		7F225DF01710484000D00DBE /* gameobject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7F225DEA1710483F00D00DBE /* gameobject.cpp */; };
 		7F225DF11710484000D00DBE /* gm_level.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7F225DEC1710484000D00DBE /* gm_level.cpp */; };
 		7F225DF21710484000D00DBE /* layer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7F225DEE1710484000D00DBE /* layer.cpp */; };
+		7F9B660C1719986C004DC616 /* enemyship.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7F9B66081719986B004DC616 /* enemyship.cpp */; };
+		7F9B660D1719986C004DC616 /* playership.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7F9B660A1719986C004DC616 /* playership.cpp */; };
+		7F9B66101719987B004DC616 /* enemyship01.png in Resources */ = {isa = PBXBuildFile; fileRef = 7F9B660E1719987B004DC616 /* enemyship01.png */; };
+		7F9B66111719987B004DC616 /* playership.png in Resources */ = {isa = PBXBuildFile; fileRef = 7F9B660F1719987B004DC616 /* playership.png */; };
 		AF1D1E8F1477E6D400C95550 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AF1D1E8E1477E6D400C95550 /* Cocoa.framework */; };
 		AF1D1E991477E6D400C95550 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = AF1D1E971477E6D400C95550 /* InfoPlist.strings */; };
 		AF1D1E9F1477E6D400C95550 /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = AF1D1E9D1477E6D400C95550 /* Credits.rtf */; };
 		7F225DED1710484000D00DBE /* gm_level.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = gm_level.h; sourceTree = SOURCE_ROOT; };
 		7F225DEE1710484000D00DBE /* layer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = layer.cpp; sourceTree = SOURCE_ROOT; };
 		7F225DEF1710484000D00DBE /* layer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = layer.h; sourceTree = SOURCE_ROOT; };
+		7F9B66081719986B004DC616 /* enemyship.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = enemyship.cpp; sourceTree = SOURCE_ROOT; };
+		7F9B66091719986B004DC616 /* enemyship.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = enemyship.h; sourceTree = SOURCE_ROOT; };
+		7F9B660A1719986C004DC616 /* playership.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = playership.cpp; sourceTree = SOURCE_ROOT; };
+		7F9B660B1719986C004DC616 /* playership.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = playership.h; sourceTree = SOURCE_ROOT; };
+		7F9B660E1719987B004DC616 /* enemyship01.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = enemyship01.png; sourceTree = "<group>"; };
+		7F9B660F1719987B004DC616 /* playership.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = playership.png; sourceTree = "<group>"; };
 		AF1D1E8A1477E6D400C95550 /* Pucaljka.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Pucaljka.app; sourceTree = BUILT_PRODUCTS_DIR; };
 		AF1D1E8E1477E6D400C95550 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
 		AF1D1E911477E6D400C95550 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; };
 		AF1D1E941477E6D400C95550 /* Pucaljka */ = {
 			isa = PBXGroup;
 			children = (
+				7F225DE01710464100D00DBE /* button.cpp */,
+				7F9B66081719986B004DC616 /* enemyship.cpp */,
+				AF1D1EAB1477E73E00C95550 /* gamemode.cpp */,
 				7F225DEA1710483F00D00DBE /* gameobject.cpp */,
+				7F225DEC1710484000D00DBE /* gm_level.cpp */,
+				7F225DD51710459C00D00DBE /* gm_mainmenu.cpp */,
+				7F225DEE1710484000D00DBE /* layer.cpp */,
+				7F9B660A1719986C004DC616 /* playership.cpp */,
+				7F225DD91710459C00D00DBE /* pucaljka.cpp */,
+				AF1D1EB31477E73E00C95550 /* texture.cpp */,
+				7F225DE11710464100D00DBE /* button.h */,
+				7F9B66091719986B004DC616 /* enemyship.h */,
+				AF1D1EAC1477E73E00C95550 /* gamemode.h */,
 				7F225DEB1710484000D00DBE /* gameobject.h */,
-				7F225DEC1710484000D00DBE /* gm_level.cpp */,
 				7F225DED1710484000D00DBE /* gm_level.h */,
-				7F225DEE1710484000D00DBE /* layer.cpp */,
+				7F225DD61710459C00D00DBE /* gm_mainmenu.h */,
 				7F225DEF1710484000D00DBE /* layer.h */,
-				7F225DE01710464100D00DBE /* button.cpp */,
-				7F225DE11710464100D00DBE /* button.h */,
-				7F225DD51710459C00D00DBE /* gm_mainmenu.cpp */,
-				7F225DD61710459C00D00DBE /* gm_mainmenu.h */,
+				7F9B660B1719986C004DC616 /* playership.h */,
+				AF1D1EB11477E73E00C95550 /* SDLMain.h */,
+				AF1D1EB41477E73E00C95550 /* texture.h */,
+				AF1D1EB21477E73E00C95550 /* SDLMain.m */,
 				7F225DD71710459C00D00DBE /* newgame.png */,
 				7F225DD81710459C00D00DBE /* options.png */,
-				7F225DD91710459C00D00DBE /* pucaljka.cpp */,
-				AF1D1EAB1477E73E00C95550 /* gamemode.cpp */,
-				AF1D1EAC1477E73E00C95550 /* gamemode.h */,
-				AF1D1EB11477E73E00C95550 /* SDLMain.h */,
-				AF1D1EB21477E73E00C95550 /* SDLMain.m */,
-				AF1D1EB31477E73E00C95550 /* texture.cpp */,
-				AF1D1EB41477E73E00C95550 /* texture.h */,
 				AF1D1E951477E6D400C95550 /* Supporting Files */,
 			);
 			path = Pucaljka;
 		AF1D1EC61477E74D00C95550 /* Resources */ = {
 			isa = PBXGroup;
 			children = (
+				7F9B660E1719987B004DC616 /* enemyship01.png */,
+				7F9B660F1719987B004DC616 /* playership.png */,
 				7F225DE41710465E00D00DBE /* background.png */,
 				7F225DE51710465E00D00DBE /* credits.png */,
 				7F225DE61710465E00D00DBE /* exit.png */,
 				7F225DE71710465E00D00DBE /* background.png in Resources */,
 				7F225DE81710465E00D00DBE /* credits.png in Resources */,
 				7F225DE91710465E00D00DBE /* exit.png in Resources */,
+				7F9B66101719987B004DC616 /* enemyship01.png in Resources */,
+				7F9B66111719987B004DC616 /* playership.png in Resources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
 				7F225DF01710484000D00DBE /* gameobject.cpp in Sources */,
 				7F225DF11710484000D00DBE /* gm_level.cpp in Sources */,
 				7F225DF21710484000D00DBE /* layer.cpp in Sources */,
+				7F9B660C1719986C004DC616 /* enemyship.cpp in Sources */,
+				7F9B660D1719986C004DC616 /* playership.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
 #include "button.h"
 #include "texture.h"
+#include "gm_level.h"
 
+extern GameMode * gGame;
 extern bool gRunning;
 
 Button::Button(const std::string& textureFile,
 }
 
 
-void Button::mouseUp(const SDL_Event &event)
+bool Button::mouseUp(const SDL_Event &event)
 {
 
     if(state == STATE_DOWN)
     {
         if(mouseInside(event.button.x, event.button.y))
         {
-            this->handleClick();
+            if(this->handleClick())
+            {
+                return true;
+            }
             state = STATE_OVER;
         }
         else
     {
         state = STATE_UP;
     }
+    return false;
 }
 void Button::mouseDown(const SDL_Event &event)
 {
     }
 }
 
-void Button::handleClick()
+bool Button::handleClick()
 {
     printf("Click\n");
+    return false;
 }
 
 ///////////////////////////////
 
-void ExitButton::handleClick()
+bool ExitButton::handleClick()
 {
     gRunning = 0;
+    return true;
 }
 ///////////////////////////////
-void NewGameButton::handleClick()
+bool NewGameButton::handleClick()
 {
-    printf("New Game clicked\n");
+    gGame->switchGameMode(new GM_Level());
+    return true;
 }
 /////////////////////////////////
-void OptionsButton::handleClick()
+bool OptionsButton::handleClick()
 {
     printf("Options clicked\n");
+    return false;
 }
 ////////////////////////////////
-void CreditsButton::handleClick()
+bool CreditsButton::handleClick()
 {
     printf("Credits clicked\n");
+    return false;
 }
 
     void paintSelf();
     void updateSelf(const float timeDelta);
 
-    void mouseUp(const SDL_Event &event);
+    bool mouseUp(const SDL_Event &event);
     void mouseDown(const SDL_Event &event);
     void mouseMove(const SDL_Event &event);
 
-    virtual void handleClick();
+    virtual bool handleClick();
 
     private:
     Texture * texture;
                Button(textureFile, x, y)
     {
     }
-    void handleClick();
+    bool handleClick();
 };
 class NewGameButton : public Button
 {
     {
     }
 
-    void handleClick();
+    bool handleClick();
 
 };
 class OptionsButton : public Button
                 Button(textureFile, x, y)
     {
     }
-    void handleClick();
+    bool handleClick();
 
 };
 class CreditsButton : public Button
                 Button(textureFile, x, y)
     {
     }
-    void handleClick();
+    bool handleClick();
 };
 
 #endif
 #include "gamemode.h"
+
+GameMode * gGame = NULL;
+
+void GameMode::switchGameMode(GameMode *gameMode)
+{
+    GameMode * oldGameMode = gGame;
+    gGame = gameMode;
+    delete oldGameMode;
+}
     {
     }
 
+    void switchGameMode(GameMode * gamemode);
+    
+    ////////////////////////////////////////
+    
     virtual void keyDown(const SDL_Event& event)
     {
     }
         it != this->buttons.end();
         it++)
     {
-        (*it)->mouseUp(event);
+        if((*it)->mouseUp(event))
+        {
+            return;
+        }
     }
 }
 
 
 SDL_Surface * gScreen = NULL;
 bool gRunning = true;
-GameMode * gGame = NULL;
+extern GameMode * gGame;
 
 /*****************************/