raSystem  1.0 bata
raGameCharakter.cpp
Go to the documentation of this file.
1 #include "..\include\raMain.h"
2 
3 namespace System
4 {
6  UINT team,
7  raVector3 position, raVector3 destination,
8  raVector3 scale) : m_Position(position)
9  {
10  m_pGame = pGame;
11 
12  D3DXMatrixScaling((D3DXMATRIX*)&m_scale, scale.x, scale.y, scale.z);
13  m_speed = 1.0f;
14 
15  //m_pGroupNode = pGroupNode;
16  D3DXMATRIX m;
17  D3DXMatrixIdentity(&m);
18  //m_InstanceNo = m_pGroupNode->AddInstance(m);
19  SetDestination(destination);
20 
21  m_Team = team;
22  m_pFollow = NULL;
23  m_bIsFighting = false;
24  m_MaxHealth = 10;
25  m_AktHealth = 10;
26  }
27 
29  {
30  //m_pGroupNode->RemoveInstance(m_InstanceNo);
31  }
32 
33  void raGameCharakter::SetDestination(const raVector3& destination)
34  {
35  if(m_AktHealth <= 0) return;
36 
37  m_destination = destination;
38  raVector3 direction = m_destination - m_Position;
39  D3DXVec3Normalize((D3DXVECTOR3*)&direction, (D3DXVECTOR3*)&direction);
40  m_velocity = m_speed * direction;
41 
42  m_bIsFighting = false;
43 
44  SetAnimation(0);
45  }
46 
47  void raGameCharakter::Update(double fTime, float fElapsedTime)
48  {
49  if(m_AktHealth <= 0) return;
50 
51  if(m_pFollow)
52  {
54  }
55 
56  raVector3 direction = m_destination - m_Position;
57  if(D3DXVec3Length((D3DXVECTOR3*)&direction) <= m_speed)
58  {
60  if(m_pFollow && m_pFollow->m_Team != m_Team) //Gegner angreifen
61  {
62  m_bIsFighting = true;
63  SetAnimation(4);
64 
65  static float t = 0;
66  t += fElapsedTime;
67  if(t > 1)
68  {
69  m_pFollow->TakeHit(this);
70  t = 0;
71  }
72  }
73  else
74  {
75  m_pFollow = NULL;
76  SetAnimation(99);
77  }
78  return;
79  }
80  else if(m_bIsFighting) //wieder verfolgen
81  {
82  SetAnimation(0);
83  }
84 
85  D3DXVec3Normalize((D3DXVECTOR3*)&direction, (D3DXVECTOR3*)&direction);
86  m_velocity = m_speed * direction;
87 
88  //Character soll zum Ziel schauen
89  D3DXMATRIX invView;
90  raVector3 up(0, 1, 0);
91  D3DXMATRIX m;
92  D3DXMatrixLookAtRH((D3DXMATRIX *)&m, (D3DXVECTOR3*)&m_Position, (D3DXVECTOR3*)&m_destination, (D3DXVECTOR3*)&up); //aber warum RH??
93  D3DXMatrixInverse(&invView, NULL, &m);
94  //m_pGroupNode->SetWorldMatrix(m_scale * invView, m_InstanceNo);
95 
96  m_Position += m_velocity * fElapsedTime;
97  }
98 
100  {
101  m_AktHealth -= 1;
102  if(m_AktHealth > m_MaxHealth / 2) //zurückhauen
103  {
104  m_pFollow = pOther;
105  }
106  else //weglaufen
107  {
108  raVector3 direction = pOther->GetPosition() - m_Position;
109  if(D3DXVec3Length((D3DXVECTOR3*)&direction) == 0) direction.x = 1;
110  D3DXVec3Normalize((D3DXVECTOR3*)&direction, (D3DXVECTOR3*)&direction);
111  SetDestination(10 * direction);
112  }
113 
114  if(m_AktHealth <= 0)
115  {
116  //sterben
117  SetFollow(NULL);
118  m_speed = 0;
119 
120  SetAnimation(5);
121 
122  pOther->SetFollow(NULL);
123  //m_pGame->RemoveCharacter(this);
124  }
125  }
126 
127  void raGameCharakter::SetSelected(bool bSelected)
128  {
129  //m_pGroupNode->SetSelected(bSelected);
130  }
131 
133  {
134  if(m_AktHealth <= 0) return;
135 
136  m_bIsFighting = false;
137  m_pFollow = pOther;
138 
139  SetAnimation(0);
140  }
141 
143  {
144  //GetVisual()->SetAnimation(clip, m_InstanceNo);
145  }
146 }
void SetAnimation(UINT clip)
raFloat y
Definition: raVector3.h:13
void TakeHit(raGameCharakter *pOther)
raFloat x
Definition: raVector3.h:12
raVector3 m_velocity
raFloat z
Definition: raVector3.h:14
void SetSelected(bool bSelected)
raVector3 m_destination
void Update(double fTime, float fElapsedTime)
void SetFollow(raGameCharakter *pOther)
raGameCharakter(raGame *pGame, UINT team, raVector3 position, raVector3 destination, raVector3 scale=raVector3(1, 1, 1))
raVector3 m_Position
void SetDestination(const raVector3 &destination)
raVector3 GetPosition()
Definition: raGame.h:3
raGameCharakter * m_pFollow