Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 7993 was 7713, checked in by patrick, 19 years ago

trunk: removed some valgrind errors, but no serious ones. Thunder sound now works, found a bug in my old class. its absolete anyway with the atmoshperic engine

File size: 3.0 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();
[7711]43  this->md2Model = new MD2Model("models/droidika.md2", "models/droideka.pcx");
[6222]44}
[4245]45
[4714]46
[7711]47//   this->md2Model = new MD2Model("models/tris.md2", "models/tris.pcx");
48// this->md2Model = new MD2Model("models/goblin.md2", "maps/goblin.bmp");
49//   this->obbTree = new OBBTree(4, (sVec3D*)this->md2Model->data->pVertices, this->md2Model->data->numVertices);
[5994]50
[7711]51
[6222]52TestEntity::TestEntity(const TiXmlElement* root)
53{
54  this->init();
55  if (root != NULL)
56    this->loadParams(root);
[4245]57}
58
59
[4679]60TestEntity::~TestEntity ()
[6222]61{}
62
63
64
65void TestEntity::init()
[4462]66{
[6222]67  this->setClassID(CL_TEST_ENTITY, "TestEntity");
[7078]68  this->toList(OM_GROUP_00);
[7113]69
[7713]70  this->lastCollided = NULL;
[7113]71  this->bDeath = false;
[4462]72}
[4245]73
[6222]74/**
75 * loads the Settings of a MD2Creature from an XML-element.
76 * @param root the XML-element to load the MD2Creature's properties from
77 */
78void TestEntity::loadParams(const TiXmlElement* root)
79{
[6512]80  WorldEntity::loadParams(root);
[4245]81
[6222]82  LoadParam(root, "md2animation", this, TestEntity, setAnim)
83      .describe("sets the animation of the md2 model")
[7198]84      .defaultValues(1);
[6222]85
86}
87
88
[7071]89void  TestEntity::setAnim(int animationIndex, int animPlaybackMode)
[4488]90{
[6222]91  if( likely(this->getModel(0) != NULL))
[7071]92    ((MD2Model*)this->getModel(0))->setAnim(animationIndex, animPlaybackMode);
[4488]93}
94
95
[4679]96void TestEntity::tick (float time)
[4245]97{
[6222]98  if( likely(this->getModel(0) != NULL))
99    ((MD2Model*)this->getModel(0))->tick(time);
100
[4245]101}
102
103
[5087]104void TestEntity::collidesWith(WorldEntity* entity, const Vector& location)
[7071]105{
106  if( this->lastCollided != entity)
107  {
108    this->dieHard();
109    this->lastCollided = entity;
[7488]110
111    if(State::getGameRules())
112      State::getGameRules()->registerKill(Kill(entity, this));
[7071]113  }
114}
[5087]115
[4245]116
[7071]117
118void TestEntity::dieHard()
119{
[7113]120  if( this->bDeath)
121    return;
[7488]122
[7113]123  this->bDeath = true;
124  float anim;
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.