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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
/*
intro/intro.cc
This file is part of the Osirion project and is distributed under
the terms of the GNU General Public License version 2
*/
#include "core/gameserver.h"
#include "example/example.h"
#include "example/spectator.h"
namespace example
{
core::Module *factory()
{
return new Example();
}
Example::Example() : core::Module("The Osirion Project Example", true)
{
/*
Initialize engine game variables
*/
Spectator::g_spectatorspeed = core::Cvar::get("g_spectatorspeed", "4", core::Cvar::Game | core::Cvar::Archive);
Spectator::g_spectatorspeed->set_info("[float] speed of the spectator");
Spectator::g_spectatorrotation = core::Cvar::get("g_spectatorrotation", "45", core::Cvar::Game | core::Cvar::Archive);
Spectator::g_spectatorrotation->set_info("[float] rotation speed of the spectator in degrees per second");
/*
The Osirion world consists of Zones. Zones are different
areas in the game. The example has only one zone.
*/
zone = new core::Zone("example"); // create a Zone object
zone->set_name("Example Zone"); // set the zone name
zone->set_ambient_color(0.5f, 0.5f, 0.5f); // set the zone ambient light color
core::Zone::add(zone); // add the zone to the world
/*
Every object in the Osirion world is derived from core::Entity.
We create a few basic entities
*/
core::Entity *cube = new core::Entity(); // a new entity
cube->set_label("cube");
cube->set_name("The Red Cube");
cube->set_shape(core::Entity::Cube); // set the shape to cube
cube->get_location().assign(16, -8, 0); // set location
cube->get_color().assign(1, 0, 0); // set RGB color red
cube->set_radius(0.25f); // set radius, in game units
cube->set_zone(zone); // add the entity to the zone
cube->set_flag(core::Entity::ShowOnMap); // entity appears on the map
core::Entity *sphere = new core::Entity(); // a new entity
sphere->set_label("sphere");
sphere->set_name("The Green Sphere");
sphere->set_shape(core::Entity::Sphere); // set the shape to sphere
sphere->get_location().assign(16, 0, 0); // set location
sphere->get_color().assign(0, 1, 0); // set RGB color green
sphere->set_radius(0.5f); // set radius, in game units
sphere->set_zone(zone); // add the entity to the zone
sphere->set_flag(core::Entity::ShowOnMap); // entity appears on the map
core::Entity *diamond = new core::Entity(); // a new entity
diamond->set_label("diamond");
diamond->set_name("The Blue Diamond");
diamond->set_shape(core::Entity::Diamond); // set the shape to cube
diamond->get_location().assign(16, 8, 0); // set location
diamond->get_color().assign(0, 0, 1); // set RGB color blue
diamond->set_radius(0.25f); // set radius, in game units
diamond->set_zone(zone); // add the entity to the zone
diamond->set_flag(core::Entity::ShowOnMap); // entity appears on the map
core::Entity *axis = new core::Entity(); // a new entity
axis->set_label("origin");
axis->set_name("The Origin");
axis->set_shape(core::Entity::Axis); // set the shape to axis
axis->get_location().assign(0, 0, 0); // set location
axis->get_color().assign(1); // set greyscale color white
axis->get_color_second().assign(0.5f, 0.0f, 0.5f); // set RGB secondary color
axis->set_radius(0.25f); // set radius, in game units
axis->set_zone(zone); // add the entity to the zone
axis->set_flag(core::Entity::ShowOnMap); // entity appears on the map
}
Example::~Example()
{
/*
The world is automaticly deleted on shutdown,
but local variables have to be cleaned up
*/
zone = 0;
}
void Example::player_connect(core::Player *player)
{
// add a spectator object for the new player
Spectator *spectator;
spectator = new Spectator(player);
spectator->set_zone(zone);
spectator->set_dirty();
// set the player's control to the spectator object
player->set_zone(zone);
player->set_control(spectator);
player->set_dirty();
// send a message to the player
player->send("Welcome to " + name());
// broadcast a message to all players
core::server()->broadcast("^B" + player->name() + " ^Bentered.");
}
void Example::player_disconnect(core::Player *player)
{
// broadcast a message to all players
core::server()->broadcast("^B" + player->name() + " ^Bhas left.");
}
void Example::frame(float elapsed)
{
}
}
|