Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 8636 was 8490, checked in by patrick, 19 years ago

merged the bsp branche back to trunk

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