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 "npc_test.h" |
---|
21 | |
---|
22 | |
---|
23 | #include "state.h" |
---|
24 | #include "debug.h" |
---|
25 | |
---|
26 | #include "loading/factory.h" |
---|
27 | #include "loading/load_param.h" |
---|
28 | |
---|
29 | #include "md2/md2Model.h" |
---|
30 | #include "player.h" |
---|
31 | #include "playable.h" |
---|
32 | |
---|
33 | #include "class_id_DEPRECATED.h" |
---|
34 | ObjectListDefinitionID(NPC2, CL_NPC_TEST2); |
---|
35 | CREATE_FACTORY(NPC2); |
---|
36 | |
---|
37 | |
---|
38 | NPC2::NPC2(const TiXmlElement* root) |
---|
39 | : NPC(NULL) |
---|
40 | { |
---|
41 | this->registerObject(this, NPC2::_objectList); |
---|
42 | |
---|
43 | |
---|
44 | if (root != NULL) |
---|
45 | this->loadParams(root); |
---|
46 | } |
---|
47 | |
---|
48 | |
---|
49 | NPC2::~NPC2 () |
---|
50 | {} |
---|
51 | |
---|
52 | |
---|
53 | void NPC2::loadParams(const TiXmlElement* root) |
---|
54 | { |
---|
55 | NPC::loadParams(root); |
---|
56 | |
---|
57 | } |
---|
58 | |
---|
59 | |
---|
60 | |
---|
61 | |
---|
62 | |
---|
63 | void NPC2::tick(float dt) |
---|
64 | { |
---|
65 | // animating the md2 model (uninteressant) |
---|
66 | if( likely(this->getModel(0) != NULL)) |
---|
67 | ((MD2Model*)this->getModel(0))->tick(dt); |
---|
68 | |
---|
69 | |
---|
70 | |
---|
71 | PRINTF(0)("====================\n"); |
---|
72 | PRINTF(0)("NPC2::tick(%f)\n", dt); |
---|
73 | |
---|
74 | // information gathering |
---|
75 | |
---|
76 | Vector absPosition = this->getAbsCoor(); |
---|
77 | |
---|
78 | PRINTF(0)(" npc abs coor: %f, %f, %f\n", absPosition.x, absPosition.y, absPosition.z); |
---|
79 | |
---|
80 | Player* pl = State::getPlayer(); |
---|
81 | Vector playerAbsPos = pl->getPlayable()->getAbsCoor(); |
---|
82 | |
---|
83 | PRINTF(0)(" player abs coor: %f, %f, %f\n", playerAbsPos.x, playerAbsPos.y, playerAbsPos.z); |
---|
84 | |
---|
85 | |
---|
86 | // intelligent reaction |
---|
87 | |
---|
88 | Vector distanceVector = playerAbsPos - absPosition; |
---|
89 | distanceVector.normalize(); |
---|
90 | |
---|
91 | float speed = 10.0f; |
---|
92 | |
---|
93 | this->shiftCoor( distanceVector * speed * dt); |
---|
94 | |
---|
95 | |
---|
96 | |
---|
97 | } |
---|
98 | |
---|
99 | |
---|
100 | |
---|