Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/test_entity.cc @ 7644

Last change on this file since 7644 was 7488, checked in by patrick, 19 years ago

orxonox: mission manager less verbose and more secure now

File size: 2.6 KB
RevLine 
[4245]1
2
[4679]3/*
[4245]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
[4679]15   co-programmer:
[4245]16*/
[5357]17#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY
[4245]18
19
[6222]20#include "executor/executor.h"
[7193]21#include "util/loading/factory.h"
22#include "util/loading/load_param.h"
[6222]23
[7488]24#include "kill.h"
25#include "game_rules.h"
26
[4245]27#include "test_entity.h"
28#include "stdincl.h"
29#include "model.h"
30#include "md2Model.h"
[4682]31#include "obb_tree.h"
[5087]32#include "state.h"
[4245]33
34using namespace std;
35
36
[6222]37CREATE_FACTORY(TestEntity, CL_TEST_ENTITY);
[4245]38
[6222]39
[4762]40TestEntity::TestEntity ()
[4679]41{
[6222]42  this->init();
43}
[4245]44
[4714]45
[5994]46
[6222]47TestEntity::TestEntity(const TiXmlElement* root)
48{
49  this->init();
50  if (root != NULL)
51    this->loadParams(root);
[4245]52}
53
54
[4679]55TestEntity::~TestEntity ()
[6222]56{}
57
58
59
60void TestEntity::init()
[4462]61{
[6222]62  this->setClassID(CL_TEST_ENTITY, "TestEntity");
[7078]63  this->toList(OM_GROUP_00);
[7113]64
65  this->bDeath = false;
[4462]66}
[4245]67
[6222]68/**
69 * loads the Settings of a MD2Creature from an XML-element.
70 * @param root the XML-element to load the MD2Creature's properties from
71 */
72void TestEntity::loadParams(const TiXmlElement* root)
73{
[6512]74  WorldEntity::loadParams(root);
[4245]75
[6222]76  LoadParam(root, "md2animation", this, TestEntity, setAnim)
77      .describe("sets the animation of the md2 model")
[7198]78      .defaultValues(1);
[6222]79
80}
81
82
[7071]83void  TestEntity::setAnim(int animationIndex, int animPlaybackMode)
[4488]84{
[6222]85  if( likely(this->getModel(0) != NULL))
[7071]86    ((MD2Model*)this->getModel(0))->setAnim(animationIndex, animPlaybackMode);
[4488]87}
88
89
[4679]90void TestEntity::tick (float time)
[4245]91{
[6222]92  if( likely(this->getModel(0) != NULL))
93    ((MD2Model*)this->getModel(0))->tick(time);
94
[4245]95}
96
97
[5087]98void TestEntity::collidesWith(WorldEntity* entity, const Vector& location)
[7071]99{
100  if( this->lastCollided != entity)
101  {
102    this->dieHard();
103    this->lastCollided = entity;
[7488]104
105    if(State::getGameRules())
106      State::getGameRules()->registerKill(Kill(entity, this));
[7071]107  }
108}
[5087]109
[4245]110
[7071]111
112void TestEntity::dieHard()
113{
[7113]114  if( this->bDeath)
115    return;
[7488]116
[7113]117  this->bDeath = true;
118  float anim;
119  int randi = (int)(5.0f * (float)rand()/(float)RAND_MAX);
120
121  PRINTF(0)("randi = %i\n", randi);
122
123  if( randi == 1)
124    this->setAnim(DEATH_FALLBACK, MD2_ANIM_ONCE);
125  else if( randi == 2)
126    this->setAnim(DEATH_FALLFORWARD, MD2_ANIM_ONCE);
127  else if( randi == 3)
128    this->setAnim(DEATH_FALLBACKSLOW, MD2_ANIM_ONCE);
129  else if( randi == 4)
130    this->setAnim(CROUCH_DEATH, MD2_ANIM_ONCE);
131  else
132    this->setAnim(DEATH_FALLBACK, MD2_ANIM_ONCE);
[7071]133}
134
Note: See TracBrowser for help on using the repository browser.