GameLayer
is the main container in our game and is coded as follows:
Select your
GameLayer.h
, then replace the code here with:#ifndef __GAMELAYER_H__ #define __GAMELAYER_H__ #define GOAL_WIDTH 400
We define the width of the goals in pixels.
Next add the declarations for our sprites and our score text labels:
#include "cocos2d.h" #include "GameSprite.h" using namespace cocos2d; class GameLayer : public cocos2d::CCLayer { GameSprite * _player1; GameSprite * _player2; GameSprite * _ball; CCArray * _players; CCLabelTTF * _player1ScoreLabel; CCLabelTTF * _player2ScoreLabel;
We have the
GameSprite
objects for two players (the weird looking things called mallets), and the ball (called puck). We'll store the two players inCCArray
. And we have two text labels to display score for each player.Declare a variable to store the screen size. We'll use this a lot for positioning:
CCSize _screenSize;
Add variables to store the score...