-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathPongGame.cpp
82 lines (60 loc) · 2.18 KB
/
PongGame.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "Player.hpp"
#include "RealPlayer.hpp"
#include "Ball.hpp"
#include "PongGame.hpp"
#include "PongScore.hpp"
#include <iostream>
using namespace std;
osg::ref_ptr<osg::Node> PongGame::createGameGroup()
{
osg::ref_ptr<osg::Group> gameGroup = new osg::Group;
gameGroup->setName( "gameGroup" );
// TODO: remove duplicated code
osg::ref_ptr<RealPlayer> player1 = new RealPlayer(1.0f, 5.0f);
player1->setMatrix( osg::Matrix::translate(2.0f, 45.0f, 0.0f) );
player1->setPlayerNumber( 1 );
player1->setName( "player1" );
osg::ref_ptr<PongScore> scorep1 = new PongScore();
scorep1->setScoreSide(PongScore::LEFT);
osg::ref_ptr<RealPlayer> player2 = new RealPlayer(1.0f, 5.0f);
player2->setMatrix( osg::Matrix::translate(158.0f, 45.0f, 0.0f) );
player2->setPlayerNumber( 2 );
player2->setName( "player2" );
osg::ref_ptr<PongScore> scorep2 = new PongScore();
scorep2->setScoreSide(PongScore::RIGHT);
osg::ref_ptr<Ball> ball = new Ball(1.0f, 1.0f);
ball->setMatrix( osg::Matrix::translate(80.0f, 45.0f, 0.0f) );
ball->setName( "ball" );
gameGroup->addChild( player1.get() );
gameGroup->addChild( player2.get() );
gameGroup->addChild( scorep1.get() );
gameGroup->addChild( scorep2.get() );
gameGroup->addChild( ball.get() );
return gameGroup.get();
}
osg::ref_ptr<osg::Node> PongGame::createTitleGroup()
{
osg::ref_ptr<osg::Group> titleGroup = new osg::Group;
return titleGroup.get();
}
osg::ref_ptr<osg::Node> PongGame::createScoreGroup()
{
osg::ref_ptr<osg::Group> scoreGroup = new osg::Group;
osg::ref_ptr<osgText::Text> score = new osgText::Text;
score->setFont("fonts/times.ttf");
score->setAxisAlignment(osgText::Text::XY_PLANE);
score->setText("0 0");
score->setName("globalScore");
score->setPosition(osg::Vec3(25.0f,50.0f,0.0f)); // TODO: un-hardcode placement
scoreGroup->addChild( score.get() );
return scoreGroup.get();
}
osg::ref_ptr<osg::Node> PongGame::createGameScene()
{
osg::ref_ptr<osg::Switch> gameSwitch = new osg::Switch;
gameSwitch->setName("gameSwitch");
gameSwitch->addChild( createGameGroup(), true );
gameSwitch->addChild( createScoreGroup(), false );
gameSwitch->addChild( createTitleGroup(), false );
return gameSwitch.get();
}