Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/network/src/world_entities/spawning_point.cc @ 6087

Last change on this file since 6087 was 6087, checked in by patrick, 18 years ago

network: loadparams extension

File size: 3.0 KB
Line 
1
2/*
3   orxonox - the future of 3D-vertical-scrollers
4
5   Copyright (C) 2004 orx
6
7   This program is free software; you can redistribute it and/or modify
8   it under the terms of the GNU General Public License as published by
9   the Free Software Foundation; either version 2, or (at your option)
10   any later version.
11
12### File Specific:
13   main-programmer: Patrick Boenzli
14   co-programmer:
15*/
16
17#include "spawning_point.h"
18#include "load_param.h"
19
20
21/**
22 *  standard constructor
23 */
24SpawningPoint::SpawningPoint (const Vector& absCoordinate, const World* world)
25    : WorldEntity(absCoodrinate)
26{
27  this->world = world;
28  this->frequency = 0.5f;
29  this->seed = 0.0f;
30  this->countDown = 0.0f;
31}
32
33
34/**
35 *  constructor
36 */
37SpawningPoint::SpawningPoint (const Vector& position, float frequency,
38                              float seed, int classID, const World* world)
39    : WorldEntity(position)
40{
41  this->frequency = frequency;
42  this->seed = seed;
43  this->classID = classID;
44  this->world = world;
45  this->countDown = 0.0f;
46}
47
48
49/**
50 *  deconstructor
51 */
52SpawningPoint::~SpawningPoint ()
53{}
54
55
56/**
57 * loads the WorldEntity Specific Parameters.
58 * @param root: the XML-Element to load the Data From
59 */
60void SpawningPoint::loadParams(const TiXmlElement* root)
61{
62  /* let the world entity its stuff first */
63  static_cast<WorldEntity*>(this)->loadParams(root);
64
65  /* now load the frequency */
66  LoadParam(root, "frequency", this, SpawningPoint, setSpawningFrequency)
67  .describe("sets the frequency of the spawning point")
68  .defaultValues(1, 1.0f);
69
70
71  /* now load the seed */
72  LoadParam(root, "randomseed", this, SpawningPoint, setPositionSeed)
73      .describe("sets the random position seed (variance in the spawning location around the position)")
74      .defaultValues(1, 0.0f);
75
76  /* now load the seed */
77  LoadParam(root, "classid", this, SpawningPoint, setSpawningEntity)
78      .describe("sets the random position seed (variance in the spawning location around the position)")
79      .defaultValues(1, CL_WORLD_ENTITY);
80}
81
82
83/**
84 *  spawn the entity
85 */
86void SpawningPoint::spawn()
87{
88  PRINTF(5)("Spangingpoint creates a new Entity (id: %i, frequency: %f, seed: %f)\n", this->classID,
89            this->frequency, this->seed);
90  BaseObject* spawningEntity = Factory::fabricate(this->classID);
91  if( LIKELY(this->world != NULL))
92    this->world->spawn(dynamic_cast<WorldEntity*>(spawningEntity));
93}
94
95
96/**
97 *  this method is called every frame
98 * @param time: the time in seconds that has passed since the last tick
99 *
100 * Handle all stuff that should update with time inside this method (movement, animation, etc.)
101 */
102void SpawningPoint::tick(float dt)
103{
104  this->countDown += dt;
105  if( this->countDown > this->frequency)
106  {
107    this->spawn();
108    this->countDown = 0.0f;
109  }
110}
111
112
113/**
114 *  the entity is drawn onto the screen with this function
115 *
116 * This is a central function of an entity: call it to let the entity painted to the screen.
117 * Just override this function with whatever you want to be drawn.
118 */
119void SpawningPoint::draw()
120{}
Note: See TracBrowser for help on using the repository browser.