Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/new_class_id/src/world_entities/test_entity.cc @ 9716

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

more renamings

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
35
36
37#include "class_id_DEPRECATED.h"
38ObjectListDefinition(TestEntity);
39CREATE_FACTORY(TestEntity);
40
41#include "script_class.h"
42CREATE_SCRIPTABLE_CLASS(TestEntity, TestEntity::classID(),
43                            addMethod("setAbsCoor", ExecutorLua3<PNode,float,float,float>(&PNode::setAbsCoor))
44                            ->addMethod("getAbsCoorX", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorX))
45                            ->addMethod("getAbsCoorY", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorY))
46                            ->addMethod("getAbsCoorZ", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorZ))
47
48                       );
49
50
51TestEntity::TestEntity ()
52{
53  this->init();
54  this->md2Model = new MD2Model("models/droidika.md2", "models/droideka.pcx");
55}
56
57
58//   this->md2Model = new MD2Model("models/tris.md2", "models/tris.pcx");
59// this->md2Model = new MD2Model("models/goblin.md2", "maps/goblin.bmp");
60//   this->obbTree = new OBBTree(4, (sVec3D*)this->md2Model->data->pVertices, this->md2Model->data->numVertices);
61
62
63TestEntity::TestEntity(const TiXmlElement* root)
64{
65  this->init();
66  if (root != NULL)
67    this->loadParams(root);
68}
69
70
71TestEntity::~TestEntity ()
72{}
73
74
75
76void TestEntity::init()
77{
78  this->registerObject(this, TestEntity::_objectList);
79  this->toList(OM_GROUP_00);
80
81  this->lastCollided = NULL;
82  this->bDeath = false;
83}
84
85/**
86 * loads the Settings of a MD2Creature from an XML-element.
87 * @param root the XML-element to load the MD2Creature's properties from
88 */
89void TestEntity::loadParams(const TiXmlElement* root)
90{
91  WorldEntity::loadParams(root);
92
93  LoadParam(root, "md2animation", this, TestEntity, setAnim)
94      .describe("sets the animation of the md2 model")
95      .defaultValues(1);
96
97}
98
99
100void  TestEntity::setAnim(int animationIndex, int animPlaybackMode)
101{
102  if( likely(this->getModel(0) != NULL))
103    ((InteractiveModel*)this->getModel(0))->setAnimation(animationIndex, animPlaybackMode);
104}
105
106
107void TestEntity::tick (float time)
108{
109  if( likely(this->getModel(0) != NULL))
110    ((InteractiveModel*)this->getModel(0))->tick(time);
111
112}
113
114
115void TestEntity::collidesWith(WorldEntity* entity, const Vector& location)
116{
117  if( this->lastCollided != entity)
118  {
119    this->destroy( entity );
120    this->lastCollided = entity;
121
122    if(State::getGameRules())
123      State::getGameRules()->registerKill(Kill(entity, this));
124  }
125}
126
127
128
129void TestEntity::destroy(WorldEntity* killer)
130{
131  if( this->bDeath)
132    return;
133
134  this->bDeath = true;
135  int randi = (int)(5.0f * (float)rand()/(float)RAND_MAX);
136
137  PRINTF(0)("randi = %i\n", randi);
138
139  if( randi == 1)
140    this->setAnim(DEATH_FALLBACK, MD2_ANIM_ONCE);
141  else if( randi == 2)
142    this->setAnim(DEATH_FALLFORWARD, MD2_ANIM_ONCE);
143  else if( randi == 3)
144    this->setAnim(DEATH_FALLBACKSLOW, MD2_ANIM_ONCE);
145  else if( randi == 4)
146    this->setAnim(CROUCH_DEATH, MD2_ANIM_ONCE);
147  else
148    this->setAnim(DEATH_FALLBACK, MD2_ANIM_ONCE);
149}
150
Note: See TracBrowser for help on using the repository browser.