Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/cd/src/world_entities/test_entity.cc @ 7365

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

orxonox/branches/cd: merged the new collision-detection back.
merged and collissions resolved.

File size: 2.8 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 "test_entity.h"
25#include "stdincl.h"
26#include "model.h"
27#include "md2Model.h"
28#include "obb_tree.h"
29#include "state.h"
30
31using namespace std;
32
33
34CREATE_FACTORY(TestEntity, CL_TEST_ENTITY);
35
36
37TestEntity::TestEntity ()
38{
39  this->init();
40  this->md2Model = new MD2Model("models/droidika.md2", "models/droideka.pcx");
41}
42
43
44//   this->md2Model = new MD2Model("models/tris.md2", "models/tris.pcx");
45// this->md2Model = new MD2Model("models/goblin.md2", "maps/goblin.bmp");
46//   this->obbTree = new OBBTree(4, (sVec3D*)this->md2Model->data->pVertices, this->md2Model->data->numVertices);
47
48
49TestEntity::TestEntity(const TiXmlElement* root)
50{
51  this->init();
52  if (root != NULL)
53    this->loadParams(root);
54}
55
56
57TestEntity::~TestEntity ()
58{}
59
60
61
62void TestEntity::init()
63{
64  this->setClassID(CL_TEST_ENTITY, "TestEntity");
65  this->toList(OM_GROUP_00);
66
67  this->bDeath = false;
68}
69
70/**
71 * loads the Settings of a MD2Creature from an XML-element.
72 * @param root the XML-element to load the MD2Creature's properties from
73 */
74void TestEntity::loadParams(const TiXmlElement* root)
75{
76  WorldEntity::loadParams(root);
77
78  LoadParam(root, "md2animation", this, TestEntity, setAnim)
79      .describe("sets the animation of the md2 model")
80      .defaultValues(1);
81
82}
83
84
85void  TestEntity::setAnim(int animationIndex, int animPlaybackMode)
86{
87  if( likely(this->getModel(0) != NULL))
88    ((MD2Model*)this->getModel(0))->setAnim(animationIndex, animPlaybackMode);
89}
90
91
92void TestEntity::tick (float time)
93{
94  if( likely(this->getModel(0) != NULL))
95    ((MD2Model*)this->getModel(0))->tick(time);
96
97}
98
99
100void TestEntity::collidesWith(WorldEntity* entity, const Vector& location)
101{
102  if( this->lastCollided != entity)
103  {
104    this->dieHard();
105    this->lastCollided = entity;
106  }
107}
108
109
110
111void TestEntity::dieHard()
112{
113  if( this->bDeath)
114    return;
115  this->bDeath = true;
116  float anim;
117  int randi = (int)(5.0f * (float)rand()/(float)RAND_MAX);
118
119  PRINTF(0)("randi = %i\n", randi);
120
121  if( randi == 1)
122    this->setAnim(DEATH_FALLBACK, MD2_ANIM_ONCE);
123  else if( randi == 2)
124    this->setAnim(DEATH_FALLFORWARD, MD2_ANIM_ONCE);
125  else if( randi == 3)
126    this->setAnim(DEATH_FALLBACKSLOW, MD2_ANIM_ONCE);
127  else if( randi == 4)
128    this->setAnim(CROUCH_DEATH, MD2_ANIM_ONCE);
129  else
130    this->setAnim(DEATH_FALLBACK, MD2_ANIM_ONCE);
131}
132
Note: See TracBrowser for help on using the repository browser.