Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/bsp_model/src/world_entities/test_entity.cc @ 7895

Last change on this file since 7895 was 7198, checked in by bensch, 19 years ago

orxonox/trunk: new Default Values… they now too are in MultiType instead of (count, …) or (count, va_arg) style

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