[6080] | 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" |
---|
[6086] | 18 | #include "load_param.h" |
---|
[6093] | 19 | #include "factory.h" |
---|
| 20 | #include "compiler.h" |
---|
| 21 | #include "world.h" /* only temp. until the object manager is implemented*/ |
---|
[6080] | 22 | |
---|
| 23 | /** |
---|
[6081] | 24 | * standard constructor |
---|
[6080] | 25 | */ |
---|
[6093] | 26 | SpawningPoint::SpawningPoint (World* world, const Vector& absCoordinate) |
---|
[6084] | 27 | { |
---|
| 28 | this->world = world; |
---|
| 29 | this->frequency = 0.5f; |
---|
| 30 | this->seed = 0.0f; |
---|
[6088] | 31 | |
---|
| 32 | this->init(); |
---|
[6084] | 33 | } |
---|
[6080] | 34 | |
---|
| 35 | |
---|
| 36 | /** |
---|
[6081] | 37 | * constructor |
---|
| 38 | */ |
---|
[6083] | 39 | SpawningPoint::SpawningPoint (const Vector& position, float frequency, |
---|
[6093] | 40 | float seed, ClassID classID, World* world) |
---|
[6081] | 41 | { |
---|
[6083] | 42 | this->frequency = frequency; |
---|
| 43 | this->seed = seed; |
---|
| 44 | this->classID = classID; |
---|
| 45 | this->world = world; |
---|
[6088] | 46 | |
---|
| 47 | this->init(); |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | |
---|
| 51 | void SpawningPoint::init() |
---|
| 52 | { |
---|
[6084] | 53 | this->countDown = 0.0f; |
---|
[6081] | 54 | } |
---|
| 55 | |
---|
| 56 | |
---|
| 57 | /** |
---|
[6080] | 58 | * deconstructor |
---|
| 59 | */ |
---|
| 60 | SpawningPoint::~SpawningPoint () |
---|
| 61 | {} |
---|
| 62 | |
---|
| 63 | |
---|
[6081] | 64 | /** |
---|
[6086] | 65 | * loads the WorldEntity Specific Parameters. |
---|
| 66 | * @param root: the XML-Element to load the Data From |
---|
| 67 | */ |
---|
| 68 | void SpawningPoint::loadParams(const TiXmlElement* root) |
---|
| 69 | { |
---|
[6087] | 70 | /* let the world entity its stuff first */ |
---|
| 71 | static_cast<WorldEntity*>(this)->loadParams(root); |
---|
[6086] | 72 | |
---|
[6087] | 73 | /* now load the frequency */ |
---|
| 74 | LoadParam(root, "frequency", this, SpawningPoint, setSpawningFrequency) |
---|
| 75 | .describe("sets the frequency of the spawning point") |
---|
| 76 | .defaultValues(1, 1.0f); |
---|
[6086] | 77 | |
---|
[6087] | 78 | |
---|
| 79 | /* now load the seed */ |
---|
| 80 | LoadParam(root, "randomseed", this, SpawningPoint, setPositionSeed) |
---|
| 81 | .describe("sets the random position seed (variance in the spawning location around the position)") |
---|
| 82 | .defaultValues(1, 0.0f); |
---|
| 83 | |
---|
| 84 | /* now load the seed */ |
---|
[6093] | 85 | /* LoadParam(root, "classid", this, SpawningPoint, setSpawningEntity) |
---|
[6088] | 86 | .describe("sets the class id of the entity to spawn") |
---|
[6093] | 87 | .defaultValues(1, CL_WORLD_ENTITY);*/ |
---|
[6086] | 88 | } |
---|
| 89 | |
---|
| 90 | |
---|
| 91 | /** |
---|
[6081] | 92 | * spawn the entity |
---|
| 93 | */ |
---|
| 94 | void SpawningPoint::spawn() |
---|
[6083] | 95 | { |
---|
| 96 | PRINTF(5)("Spangingpoint creates a new Entity (id: %i, frequency: %f, seed: %f)\n", this->classID, |
---|
[6087] | 97 | this->frequency, this->seed); |
---|
[6083] | 98 | BaseObject* spawningEntity = Factory::fabricate(this->classID); |
---|
[6093] | 99 | if( likely(this->world != NULL)) |
---|
[6083] | 100 | this->world->spawn(dynamic_cast<WorldEntity*>(spawningEntity)); |
---|
| 101 | } |
---|
[6080] | 102 | |
---|
| 103 | |
---|
| 104 | /** |
---|
| 105 | * this method is called every frame |
---|
| 106 | * @param time: the time in seconds that has passed since the last tick |
---|
| 107 | * |
---|
| 108 | * Handle all stuff that should update with time inside this method (movement, animation, etc.) |
---|
| 109 | */ |
---|
| 110 | void SpawningPoint::tick(float dt) |
---|
[6084] | 111 | { |
---|
| 112 | this->countDown += dt; |
---|
| 113 | if( this->countDown > this->frequency) |
---|
| 114 | { |
---|
| 115 | this->spawn(); |
---|
| 116 | this->countDown = 0.0f; |
---|
| 117 | } |
---|
| 118 | } |
---|
[6080] | 119 | |
---|
| 120 | |
---|
| 121 | /** |
---|
| 122 | * the entity is drawn onto the screen with this function |
---|
| 123 | * |
---|
| 124 | * This is a central function of an entity: call it to let the entity painted to the screen. |
---|
| 125 | * Just override this function with whatever you want to be drawn. |
---|
| 126 | */ |
---|
| 127 | void SpawningPoint::draw() |
---|
[6087] | 128 | {} |
---|