Browse Source

Adicionado comentários sobre as coisas

JoaoHL 7 years ago
parent
commit
b4d177813a

+ 30 - 56
Classes/AppDelegate.cpp

@@ -1,20 +1,16 @@
+/********************************************************************
+ *  Nomes: Gabriel Capella                       Números USP: 8962078 
+ *         João Herique Luciano                               8535957
+ * 
+ *  Tarefa:    RedCore - EP2 MAC0463
+ *  Arquivo:   AppDelegate.cpp
+ *  Descrição: Classe para inicializar jogo. Padrão da biblioteca.
+ ********************************************************************/
+
 #include "AppDelegate.h"
 #include "BeginScene.h"
-
-// #define USE_AUDIO_ENGINE 1
-#define USE_SIMPLE_AUDIO_ENGINE 1
-
-#if USE_AUDIO_ENGINE && USE_SIMPLE_AUDIO_ENGINE
-#error "Don't use AudioEngine and SimpleAudioEngine at the same time. Please just select one in your game!"
-#endif
-
-#if USE_AUDIO_ENGINE
-#include "audio/include/AudioEngine.h"
-using namespace cocos2d::experimental;
-#elif USE_SIMPLE_AUDIO_ENGINE
 #include "audio/include/SimpleAudioEngine.h"
 using namespace CocosDenshion;
-#endif
 
 USING_NS_CC;
 
@@ -24,15 +20,9 @@ AppDelegate::AppDelegate() {
 }
 
 AppDelegate::~AppDelegate()  {
-#if USE_AUDIO_ENGINE
-    AudioEngine::end();
-#elif USE_SIMPLE_AUDIO_ENGINE
     SimpleAudioEngine::end();
-#endif
 }
 
-// if you want a different context, modify the value of glContextAttrs
-// it will affect all platforms
 void AppDelegate::initGLContextAttrs() {
     // set OpenGL context attributes: red,green,blue,alpha,depth,stencil
     GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8};
@@ -50,72 +40,56 @@ bool AppDelegate::applicationDidFinishLaunching() {
     auto director = Director::getInstance();
     auto glview = director->getOpenGLView();
     if(!glview) {
-#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
-    director->setContentScaleFactor(2);
-    glview = GLViewImpl::createWithRect("RedCore", cocos2d::Rect(0, 0, designResolutionSize.width, designResolutionSize.height));
-#else
+
+        // Personaliza para descktop
+        #if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
+        director->setContentScaleFactor(2);
+        glview = GLViewImpl::createWithRect(
+            "RedCore",
+            cocos2d::Rect(0, 0, designResolutionSize.width, designResolutionSize.height)
+        );
+        #else
         glview = GLViewImpl::create("RedCore");
-#endif
+        #endif
+
         director->setOpenGLView(glview);
     }
 
     // turn on display FPS
-#if DEBUG
+    #if DEBUG
     director->setDisplayStats(true);
-#endif
+    #endif
 
     // set FPS. the default value is 1.0/60 if you don't call this
     director->setAnimationInterval(1.0f / 60);
 
     // Set the design resolution
-    glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::NO_BORDER);
-    auto frameSize = glview->getFrameSize();
-    // if the frame's height is larger than the height of medium size.
-    // if (frameSize.height > mediumResolutionSize.height)
-    // {        
-    //     director->setContentScaleFactor(MIN(largeResolutionSize.height/designResolutionSize.height, largeResolutionSize.width/designResolutionSize.width));
-    // }
-    // // if the frame's height is larger than the height of small size.
-    // else if (frameSize.height > smallResolutionSize.height)
-    // {        
-    //     director->setContentScaleFactor(MIN(mediumResolutionSize.height/designResolutionSize.height, mediumResolutionSize.width/designResolutionSize.width));
-    // }
-    // // if the frame's height is smaller than the height of medium size.
-    // else
-    // {        
-    //     director->setContentScaleFactor(MIN(smallResolutionSize.height/designResolutionSize.height, smallResolutionSize.width/designResolutionSize.width));
-    // }
-    
+    glview->setDesignResolutionSize(
+        designResolutionSize.width,
+        designResolutionSize.height,
+        ResolutionPolicy::NO_BORDER
+    );
 
     register_all_packages();
 
-
     Scene* scene = BeginScene::createScene();
     director->runWithScene(scene);
 
     return true;
 }
 
-// This function will be called when the app is inactive. Note, when receiving a phone call it is invoked.
+/** This function will be called when the app is inactive. Note, when
+ * receiving a phone call it is invoked.
+ * */
 void AppDelegate::applicationDidEnterBackground() {
     Director::getInstance()->stopAnimation();
-
-#if USE_AUDIO_ENGINE
-    AudioEngine::pauseAll();
-#elif USE_SIMPLE_AUDIO_ENGINE
     SimpleAudioEngine::getInstance()->pauseBackgroundMusic();
     SimpleAudioEngine::getInstance()->pauseAllEffects();
-#endif
 }
 
 // this function will be called when the app is active again
 void AppDelegate::applicationWillEnterForeground() {
     Director::getInstance()->startAnimation();
-
-#if USE_AUDIO_ENGINE
-    AudioEngine::resumeAll();
-#elif USE_SIMPLE_AUDIO_ENGINE
     SimpleAudioEngine::getInstance()->resumeBackgroundMusic();
     SimpleAudioEngine::getInstance()->resumeAllEffects();
-#endif
 }

+ 34 - 32
Classes/AppDelegate.h

@@ -1,40 +1,42 @@
+/********************************************************************
+ *  Nomes: Gabriel Capella                       Números USP: 8962078 
+ *         João Herique Luciano                               8535957
+ * 
+ *  Tarefa:    RedCore - EP2 MAC0463
+ *  Arquivo:   AppDelegate.h
+ *  Descrição: Classe para inicializar jogo. Padrão da biblioteca.
+ ********************************************************************/
+
 #ifndef  _APP_DELEGATE_H_
 #define  _APP_DELEGATE_H_
 
 #include "cocos2d.h"
 
-/**
-@brief    The cocos2d Application..
-
-Private inheritance here hides part of interface from Director.
-*/
-class  AppDelegate : private cocos2d::Application
-{
-public:
-    AppDelegate();
-    virtual ~AppDelegate();
-
-    virtual void initGLContextAttrs();
-
-    /**
-    @brief    Implement Director and Scene init code here.
-    @return true    Initialize success, app continue.
-    @return false   Initialize failed, app terminate.
-    */
-    virtual bool applicationDidFinishLaunching();
-
-    /**
-    @brief  Called when the application moves to the background
-    @param  the pointer of the application
-    */
-    virtual void applicationDidEnterBackground();
-
-    /**
-    @brief  Called when the application reenters the foreground
-    @param  the pointer of the application
-    */
-    
-    virtual void applicationWillEnterForeground();
+class  AppDelegate : private cocos2d::Application {
+    public:
+        AppDelegate();
+        virtual ~AppDelegate();
+
+        virtual void initGLContextAttrs();
+
+        /**
+        @brief    Implement Director and Scene init code here.
+        @return true    Initialize success, app continue.
+        @return false   Initialize failed, app terminate.
+        */
+        virtual bool applicationDidFinishLaunching();
+
+        /**
+        @brief  Called when the application moves to the background
+        @param  the pointer of the application
+        */
+        virtual void applicationDidEnterBackground();
+
+        /**
+        @brief  Called when the application reenters the foreground
+        @param  the pointer of the application
+        */
+        virtual void applicationWillEnterForeground();
 };
 
 #endif // _APP_DELEGATE_H_

+ 14 - 6
Classes/BeginScene.cpp

@@ -1,3 +1,12 @@
+/********************************************************************
+ *  Nomes: Gabriel Capella                       Números USP: 8962078 
+ *         João Herique Luciano                               8535957
+ * 
+ *  Tarefa:    RedCore - EP2 MAC0463
+ *  Arquivo:   BeginScene.cpp
+ *  Descrição: Classe para tela inicial do jogo.
+ ********************************************************************/
+
 #include "BeginScene.h"
 #include "GameScene.h"
 #include "SimpleAudioEngine.h"
@@ -34,8 +43,7 @@ Scene* BeginScene::createScene() {
 }
 
 bool BeginScene::init() {
-    //////////////////////////////
-    // 1. super init first
+
     if (!Layer::init()) {
         return false;
     }
@@ -47,7 +55,7 @@ bool BeginScene::init() {
     auto bg = cocos2d::LayerColor::create(COLOR_back);
     this->addChild(bg);
     
-    auto menu_item_start = MenuItemFont::create(MSG_START, CC_CALLBACK_1(BeginScene::Play, this));
+    auto menu_item_start = MenuItemFont::create(MSG_START, CC_CALLBACK_0(BeginScene::Play, this));
     menu_item_start->setFontNameObj(FONT);
     
     menu_item_start->setPosition(Point(visibleSize.width / 2, (visibleSize.height*0.25)));
@@ -95,7 +103,7 @@ bool BeginScene::init() {
     userdata->setDoubleForKey("time", last);
     userdata->setIntegerForKey("level", level);
     
-    this->levels = level;
+    this->level_game = level;
     
     char level_text[256];
     if (level != 0) {
@@ -109,8 +117,8 @@ bool BeginScene::init() {
     return true;
 }
 
-void BeginScene::Play(cocos2d::Ref *pSender) {
-    auto scene = GameScene::createScene(this->levels);
+void BeginScene::Play() {
+    auto scene = GameScene::createScene(this->level_game);
     Director::getInstance()->replaceScene(scene);
 }
 

+ 36 - 2
Classes/BeginScene.h

@@ -1,3 +1,12 @@
+/********************************************************************
+ *  Nomes: Gabriel Capella                       Números USP: 8962078 
+ *         João Herique Luciano                               8535957
+ * 
+ *  Tarefa:    RedCore - EP2 MAC0463
+ *  Arquivo:   BeginScene.h
+ *  Descrição: Classe para tela inicial do jogo.
+ ********************************************************************/
+
 #ifndef __BEGIN_SCENE_H__
 #define __BEGIN_SCENE_H__
 
@@ -5,12 +14,37 @@
 
 class BeginScene: public cocos2d::Layer {
     public:
+    	/**
+    	 * Inicia tela do jogo.
+    	 * @return um Scene. Veja mais na documentação do cocos2d-x.
+    	 */
         static cocos2d::Scene* createScene();
+
+        /**
+         * Sobreesvreve o método padrão da classe. Serve para
+         * inicializar a cena.
+         * @return se conseguiu ou não iniciar
+         */
         virtual bool init();
-        void Play(Ref *pSender);
+
+        /**
+         * Inicia o jogo jogável. Vai para GameScene.
+         */
+        void Play();
+
+        /**
+         * É um macro do cocos2d-x que define a função create do
+         * do classe.
+         * 
+         * @param Classe para qual vai criar.
+         */
         CREATE_FUNC(BeginScene);
     private:
-        int levels;
+    	/**
+    	 * Armazena qual o nível atual do jogador. Variável usada
+    	 * para fazer regressão de nível.
+    	 */
+        int level_game;
 };
 
 #endif // __BEGIN_SCENE_H__

+ 3 - 3
Classes/GameScene.cpp

@@ -199,7 +199,7 @@ void GameScene::caseBallCollision (Node *ball) {
         auto text = Label::createWithTTF(MSG_OVER, FONT, 40);
         text->setPosition(width/2, height/2);
         addChild(text);
-        auto menu_item_start = MenuItemFont::create(MSG_RESTART, CC_CALLBACK_1(GameScene::NextLevel, this));
+        auto menu_item_start = MenuItemFont::create(MSG_RESTART, CC_CALLBACK_0(GameScene::nextLevel, this));
         menu_item_start->setFontNameObj(FONT);
         menu_item_start->setPosition(text->getPosition());
         menu_item_start->setPositionY(menu_item_start->getPositionY()-50);
@@ -218,7 +218,7 @@ void GameScene::caseBallCore (Node *core, Node *ball) {
     
     auto callbackRotate = CallFunc::create([=](){
         level = level + 1;
-        auto menu_item_start = MenuItemFont::create(MSG_NEXT_LEVEL, CC_CALLBACK_1(GameScene::NextLevel, this));
+        auto menu_item_start = MenuItemFont::create(MSG_NEXT_LEVEL, CC_CALLBACK_0(GameScene::nextLevel, this));
         menu_item_start->setFontNameObj(FONT);
         menu_item_start->setPosition(Point(width / 2, (height / 2)));
         auto *menu = Menu::create(menu_item_start, NULL);
@@ -241,7 +241,7 @@ void GameScene::caseSaveLevel(Node *powerup_ball) {
     powerup_ball->removeFromParentAndCleanup(true);
 }
 
-void GameScene::NextLevel(Ref *pSender) {
+void GameScene::nextLevel() {
     auto scene = GameScene::createScene(level);
     Director::getInstance()->replaceScene(scene);
 }

+ 1 - 2
Classes/GameScene.h

@@ -84,9 +84,8 @@ class GameScene : public cocos2d::Layer {
         /**
          * @brief Substitui a cena atual pela cena do próximo nível
          * 
-         * @param pSender 
          */
-        void NextLevel(cocos2d::Ref *pSender);
+        void nextLevel();
 
         /**
          * @brief Salva o nível atual

+ 9 - 5
Classes/GameScene/Ball.cpp

@@ -1,7 +1,11 @@
-//
-//  Ball.cpp
-//  RedCore
-//
+/********************************************************************
+ *  Nomes: Gabriel Capella                       Números USP: 8962078 
+ *         João Herique Luciano                               8535957
+ * 
+ *  Tarefa:    RedCore - EP2 MAC0463
+ *  Arquivo:   Ball.cpp
+ *  Descrição: Classe para auxiliar na criação da bola no jogo.
+ ********************************************************************/ 
 
 #include "Ball.h"
 #include "params.h"
@@ -21,7 +25,7 @@ bool Ball::init() {
     auto material = PHYSICSBODY_MATERIAL_DEFAULT;
     material.density = 0.0f;
     material.restitution = 1.005f;
-    material.friction = 0.0f; //set friction here
+    material.friction = 0.0f;
     
     auto physicsBody = PhysicsBody::createCircle(BALL_SIZE, material);
     physicsBody->setGravityEnable(false);

+ 50 - 4
Classes/GameScene/Ball.h

@@ -1,7 +1,11 @@
-//
-//  Ball.h
-//  RedCore
-//
+/********************************************************************
+ *  Nomes: Gabriel Capella                       Números USP: 8962078 
+ *         João Herique Luciano                               8535957
+ * 
+ *  Tarefa:    RedCore - EP2 MAC0463
+ *  Arquivo:   Ball.h
+ *  Descrição: Classe para auxiliar na criação da bola no jogo.
+ ********************************************************************/
 
 #ifndef Ball_h
 #define Ball_h
@@ -10,15 +14,57 @@
 
 class Ball : public cocos2d::Node {
     public:
+        /**
+         * Inicia elementos quando a bola é criada.
+         * @return se foi possível criar a bola ou não.
+         */
         virtual bool init();
+
+        /**
+         * Reescreve a função de posicionar o node.
+         * A bola somente colide após esse método ser chamado.
+         * 
+         * @param x posição da bola no eixo x
+         * @param y posição da bola no eixo y
+         */
         virtual void setPosition(float x, float y);
+
+        /**
+         * Lança a bola.
+         */
         void throwBall();
+
+        /**
+         * É um macro do cocos2d-x que define a função create do
+         * do classe.
+         * 
+         * @param Classe para qual vai criar.
+         */
         CREATE_FUNC(Ball);
+
+        /**
+         * Marca se é uma superbola ou não.
+         */
         bool superball;
+
+        /**
+         * Transforma em uma super bola.
+         */
         void setSuperball();
+
+        /**
+         * Transforma a bola em uma bola normar, sem poderes.
+         */
         void resetNormalball();
     private:
+        /**
+         * Desenho (imagem) da bola normal.
+         */
         cocos2d::DrawNode* ball_draw;
+
+        /**
+         * Desenho (imagem) da superbola.
+         */
         cocos2d::DrawNode* superball_draw;
 };
 

+ 8 - 4
Classes/GameScene/Paddle.cpp

@@ -1,7 +1,11 @@
-//
-//  BlocksLayer.cpp
-//  RedCore
-//
+/********************************************************************
+ *  Nomes: Gabriel Capella                       Números USP: 8962078 
+ *         João Herique Luciano                               8535957
+ * 
+ *  Tarefa:    RedCore - EP2 MAC0463
+ *  Arquivo:   Paddle.cpp
+ *  Descrição: Classe para auxiliar na criação da raquete.
+ ********************************************************************/
 
 #include "Paddle.h"
 #include "../params.h"

+ 69 - 8
Classes/GameScene/Paddle.h

@@ -1,7 +1,11 @@
-//
-//  BlocksLayer.h
-//  RedCore
-//
+/********************************************************************
+ *  Nomes: Gabriel Capella                       Números USP: 8962078 
+ *         João Herique Luciano                               8535957
+ * 
+ *  Tarefa:    RedCore - EP2 MAC0463
+ *  Arquivo:   Paddle.h
+ *  Descrição: Classe para auxiliar na criação da raquete.
+ ********************************************************************/
 
 #ifndef Paddle_h
 #define Paddle_h
@@ -14,19 +18,76 @@
 
 class Paddle : public cocos2d::Node {
     public:
+        /**
+         * Inicia elementos quando a raquete é criada.
+         * @return se foi possível criar a raquete ou não.
+         */
         virtual bool init();
+
+        /**
+         * Duplica o tamanho da raquete.
+         */
         void doubleSize();
+
+        /**
+         * Divide por dois o tamanho da raquete.
+         */
         void halfSize();
-        void listen(double width); // começa escutar eventos do touch
+
+        /**
+         * Possibilita que esse nó escute eventos provenientes do
+         * touch. 
+         * 
+         * @param width largura da tela
+         */
+        void listen(double width);
+
+        /**
+         * É um macro do cocos2d-x que define a função create do
+         * do classe.
+         * 
+         * @param Classe para qual vai criar.
+         */
         CREATE_FUNC(Paddle);
     private:
+        /**
+         * Desenho da raquete grande.
+         */
         cocos2d::DrawNode* double_paddle;
+
+        /**
+         * Desenho da raquete normal.
+         */
         cocos2d::DrawNode* normal_paddle;
+
+        /**
+         * Desenho da raquete pequena.
+         */
         cocos2d::DrawNode* half_paddle;
-        int stade; // armaze em que tamanho esta
-        void setPX (double px, double width); // arruma a posicao de todas as raquetes
+
+        /**
+         * Marca qual o tamanho atual da raquete.
+         */
+        int stade;
+
+        /**
+         * Move a raquete
+         * 
+         * @param px posicao para quall ela vai.
+         * @param width largura em pixels da tela
+         */
+        void setPX (double px, double width);
+
+        /**
+         * Transforma uma raquete para seu tamanho norma.
+         */
         void normalSize();
-        void startNormalTimer(); // Inicia o timer para voltar ao normal
+
+        /**
+         * Inicia um timer para voltar a raquete para seu tamnho
+         * norma.
+         */
+        void startNormalTimer();
 
 };
 

+ 17 - 1
README.md

@@ -1,3 +1,5 @@
+Não roda no emuladador!
+
 Antes de montar o arquivo você deve configurar o arquivo `proj.android-studio/local.properties`.
 
 Para montar o APK do jogo:
@@ -6,4 +8,18 @@ Para montar o APK do jogo:
 ./build
 ```
 
-Esse script vai fazer o download do cocos2d-x (por volta de 350mb).
+# Manual
+
+## Power UPs
+### SuperBola
+ë o power up laranja o responsável por esse efeito. Qunado o usuário possui uma superbola, a bola fica laranja e tem capacidade de destruir os blocos indestritíveis (somente um toque).
+
+
+Esse script vai fazer o download do cocos2d-x (por volta de 350mb).
+
+Quando uma raquete muda de tamanho, ela volta ao seu tamho original depois de certo tempo.
+
+Politica de redimencionamento.
+
+No border policy will scale proportionally the container so that it fills up the entire frame. In this case, if the width/height ratio of the frame doesn't equal to your designed ratio, some area of your game will be cut off. In the meantime, under no border policy, cc.visibleRect represent the viewport of canvas in the game world, and it can be smaller than cc.winSize.
+

BIN
proj.android-studio/app/res/drawable-hdpi/ic_launcher.png


BIN
proj.android-studio/app/res/drawable-ldpi/ic_launcher.png


BIN
proj.android-studio/app/res/drawable-mdpi/ic_launcher.png


BIN
proj.android-studio/app/res/drawable-xhdpi/ic_launcher.png


BIN
proj.android-studio/app/res/drawable-xxhdpi/ic_launcher.png


BIN
proj.android-studio/app/res/drawable-xxxhdpi/ic_launcher.png


BIN
proj.ios_mac/RedCore.xcodeproj/project.xcworkspace/xcuserdata/capella.xcuserdatad/UserInterfaceState.xcuserstate