Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/terrain.older/src/world_entities/test_entity.cc @ 10581

Last change on this file since 10581 was 9003, checked in by bensch, 18 years ago

orxonox/trunk: merged the single_player_map branche back
merged with command:
svn merge -r8896:HEAD https://svn.orxonox.net/orxonox/branches/single_player_map .
no conflicts

File size: 3.5 KB
Line 
1
2
3/*
4   orxonox - the future of 3D-vertical-scrollers
5
6   Copyright (C) 2004 orx
7
8   This program is free software; you can redistribute it and/or modify
9   it under the terms of the GNU General Public License as published by
10   the Free Software Foundation; either version 2, or (at your option)
11   any later version.
12
13   ### File Specific
14   main-programmer: Patrick Boenzli
15   co-programmer:
16*/
17#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY
18
19
20#include "executor/executor.h"
21#include "util/loading/factory.h"
22#include "util/loading/load_param.h"
23
24#include "kill.h"
25#include "game_rules.h"
26
27#include "test_entity.h"
28
29
30#include "interactive_model.h"
31#include "md2/md2Model.h"
32
33#include "state.h"
34
35using namespace std;
36
37
38CREATE_FACTORY(TestEntity, CL_TEST_ENTITY);
39
40#include "script_class.h"
41CREATE_SCRIPTABLE_CLASS(TestEntity, CL_TEST_ENTITY,
42                            addMethod("setAbsCoor", ExecutorLua3<PNode,float,float,float>(&PNode::setAbsCoor))
43                            ->addMethod("getAbsCoorX", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorX))
44                            ->addMethod("getAbsCoorY", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorY))
45                            ->addMethod("getAbsCoorZ", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorZ))
46                           
47                       );
48
49
50TestEntity::TestEntity ()
51{
52  this->init();
53  this->md2Model = new MD2Model("models/droidika.md2", "models/droideka.pcx");
54}
55
56
57//   this->md2Model = new MD2Model("models/tris.md2", "models/tris.pcx");
58// this->md2Model = new MD2Model("models/goblin.md2", "maps/goblin.bmp");
59//   this->obbTree = new OBBTree(4, (sVec3D*)this->md2Model->data->pVertices, this->md2Model->data->numVertices);
60
61
62TestEntity::TestEntity(const TiXmlElement* root)
63{
64  this->init();
65  if (root != NULL)
66    this->loadParams(root);
67}
68
69
70TestEntity::~TestEntity ()
71{}
72
73
74
75void TestEntity::init()
76{
77  this->setClassID(CL_TEST_ENTITY, "TestEntity");
78  this->toList(OM_GROUP_00);
79
80  this->lastCollided = NULL;
81  this->bDeath = false;
82}
83
84/**
85 * loads the Settings of a MD2Creature from an XML-element.
86 * @param root the XML-element to load the MD2Creature's properties from
87 */
88void TestEntity::loadParams(const TiXmlElement* root)
89{
90  WorldEntity::loadParams(root);
91
92  LoadParam(root, "md2animation", this, TestEntity, setAnim)
93      .describe("sets the animation of the md2 model")
94      .defaultValues(1);
95
96}
97
98
99void  TestEntity::setAnim(int animationIndex, int animPlaybackMode)
100{
101  if( likely(this->getModel(0) != NULL))
102    ((InteractiveModel*)this->getModel(0))->setAnimation(animationIndex, animPlaybackMode);
103}
104
105
106void TestEntity::tick (float time)
107{
108  if( likely(this->getModel(0) != NULL))
109    ((InteractiveModel*)this->getModel(0))->tick(time);
110
111}
112
113
114void TestEntity::collidesWith(WorldEntity* entity, const Vector& location)
115{
116  if( this->lastCollided != entity)
117  {
118    this->destroy();
119    this->lastCollided = entity;
120
121    if(State::getGameRules())
122      State::getGameRules()->registerKill(Kill(entity, this));
123  }
124}
125
126
127
128void TestEntity::destroy()
129{
130  if( this->bDeath)
131    return;
132
133  this->bDeath = true;
134  int randi = (int)(5.0f * (float)rand()/(float)RAND_MAX);
135
136  PRINTF(0)("randi = %i\n", randi);
137
138  if( randi == 1)
139    this->setAnim(DEATH_FALLBACK, MD2_ANIM_ONCE);
140  else if( randi == 2)
141    this->setAnim(DEATH_FALLFORWARD, MD2_ANIM_ONCE);
142  else if( randi == 3)
143    this->setAnim(DEATH_FALLBACKSLOW, MD2_ANIM_ONCE);
144  else if( randi == 4)
145    this->setAnim(CROUCH_DEATH, MD2_ANIM_ONCE);
146  else
147    this->setAnim(DEATH_FALLBACK, MD2_ANIM_ONCE);
148}
149
Note: See TracBrowser for help on using the repository browser.