Enemy speelt cow!
This commit is contained in:
@@ -205,12 +205,9 @@
|
|||||||
<None Include="worlds\worlds.json" />
|
<None Include="worlds\worlds.json" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Media Include="WAVE\bond.wav" />
|
<Media Include="WAVE\enemy.wav" />
|
||||||
<Media Include="WAVE\jpark.wav" />
|
<Media Include="WAVE\test1.wav" />
|
||||||
<Media Include="WAVE\Sound.wav" />
|
|
||||||
<Media Include="WAVE\test.wav" />
|
|
||||||
<Media Include="WAVE\test2.wav" />
|
<Media Include="WAVE\test2.wav" />
|
||||||
<Media Include="WAVE\test3.wav" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
<ImportGroup Label="ExtensionTargets">
|
<ImportGroup Label="ExtensionTargets">
|
||||||
|
|||||||
@@ -168,22 +168,13 @@
|
|||||||
</None>
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Media Include="WAVE\Sound.wav">
|
<Media Include="WAVE\test1.wav">
|
||||||
<Filter>Resource Files</Filter>
|
|
||||||
</Media>
|
|
||||||
<Media Include="WAVE\bond.wav">
|
|
||||||
<Filter>Resource Files</Filter>
|
|
||||||
</Media>
|
|
||||||
<Media Include="WAVE\jpark.wav">
|
|
||||||
<Filter>Resource Files</Filter>
|
|
||||||
</Media>
|
|
||||||
<Media Include="WAVE\test.wav">
|
|
||||||
<Filter>Resource Files</Filter>
|
<Filter>Resource Files</Filter>
|
||||||
</Media>
|
</Media>
|
||||||
<Media Include="WAVE\test2.wav">
|
<Media Include="WAVE\test2.wav">
|
||||||
<Filter>Resource Files</Filter>
|
<Filter>Resource Files</Filter>
|
||||||
</Media>
|
</Media>
|
||||||
<Media Include="WAVE\test3.wav">
|
<Media Include="WAVE\enemy.wav">
|
||||||
<Filter>Resource Files</Filter>
|
<Filter>Resource Files</Filter>
|
||||||
</Media>
|
</Media>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include "Enemy.h"
|
#include "Enemy.h"
|
||||||
#include "Model.h"
|
#include "Model.h"
|
||||||
#include "CrystalPoint.h"
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
Enemy::Enemy(const std::string &fileName,
|
Enemy::Enemy(const std::string &fileName,
|
||||||
@@ -19,7 +18,8 @@ Enemy::Enemy(const std::string &fileName,
|
|||||||
speed = 1;
|
speed = 1;
|
||||||
radius = 10;
|
radius = 10;
|
||||||
hasTarget = false;
|
hasTarget = false;
|
||||||
hit_sound_id = CrystalPoint::GetSoundSystem().LoadSound("WAVE/Sound.wav", false);
|
hit_sound_id = CrystalPoint::GetSoundSystem().LoadSound("WAVE/enemy.wav", false);
|
||||||
|
music = CrystalPoint::GetSoundSystem().GetSound(hit_sound_id);
|
||||||
attack = false;
|
attack = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,9 +72,14 @@ void Enemy::collide(const Entity * entity)
|
|||||||
|
|
||||||
void Enemy::update(float delta)
|
void Enemy::update(float delta)
|
||||||
{
|
{
|
||||||
|
music->SetPos(position, Vec3f());
|
||||||
|
|
||||||
if (hasTarget)
|
if (hasTarget)
|
||||||
{
|
{
|
||||||
|
if (music->IsPlaying() == false)
|
||||||
|
{
|
||||||
|
music->Play();
|
||||||
|
}
|
||||||
//just 2d walking
|
//just 2d walking
|
||||||
float dx, dz, length;
|
float dx, dz, length;
|
||||||
|
|
||||||
@@ -98,15 +103,14 @@ void Enemy::update(float delta)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
attack = true;
|
attack = true;
|
||||||
|
if (music->IsPlaying() == true)
|
||||||
|
{
|
||||||
|
// music->Pause();
|
||||||
|
music->Stop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rotation.y = atan2f(dx, dz) * 180 / M_PI;
|
rotation.y = atan2f(dx, dz) * 180 / M_PI;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (false)
|
|
||||||
{
|
|
||||||
Sound* sound = CrystalPoint::GetSoundSystem().GetSound(hit_sound_id);
|
|
||||||
sound->SetPos(position, Vec3f());
|
|
||||||
sound->Play();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
#include "Entity.h"
|
#include "Entity.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "Vector.h"
|
#include "Vector.h"
|
||||||
|
#include "CrystalPoint.h"
|
||||||
|
|
||||||
class Enemy : public Entity
|
class Enemy : public Entity
|
||||||
{
|
{
|
||||||
@@ -10,6 +11,8 @@ public:
|
|||||||
Enemy(const std::string &fileName,const Vec3f &position,Vec3f &rotation,const float &scale);
|
Enemy(const std::string &fileName,const Vec3f &position,Vec3f &rotation,const float &scale);
|
||||||
~Enemy();
|
~Enemy();
|
||||||
|
|
||||||
|
Sound* music;
|
||||||
|
|
||||||
bool hasTarget;
|
bool hasTarget;
|
||||||
Vec3f target;
|
Vec3f target;
|
||||||
float speed,radius;
|
float speed,radius;
|
||||||
|
|||||||
@@ -9,8 +9,6 @@ Sound::Sound(const char* inWavPath, bool inLooping):
|
|||||||
source_id(0),
|
source_id(0),
|
||||||
is_looping(inLooping)
|
is_looping(inLooping)
|
||||||
{
|
{
|
||||||
isPlaying = false;
|
|
||||||
|
|
||||||
const char* path = inWavPath;
|
const char* path = inWavPath;
|
||||||
|
|
||||||
FILE *fp = fopen(path, "rb"); // Open the WAVE file
|
FILE *fp = fopen(path, "rb"); // Open the WAVE file
|
||||||
@@ -122,7 +120,6 @@ void Sound::SetPos(const Vec3f& inPos, const Vec3f& inVel)
|
|||||||
|
|
||||||
void Sound::Play()
|
void Sound::Play()
|
||||||
{
|
{
|
||||||
isPlaying = true;
|
|
||||||
alSourcePlay(source_id);
|
alSourcePlay(source_id);
|
||||||
int e = alGetError(); // != AL_NO_ERROR) return;
|
int e = alGetError(); // != AL_NO_ERROR) return;
|
||||||
}
|
}
|
||||||
@@ -136,12 +133,15 @@ void Sound::Pause()
|
|||||||
|
|
||||||
void Sound::Stop()
|
void Sound::Stop()
|
||||||
{
|
{
|
||||||
isPlaying = false;
|
|
||||||
alSourceStop(source_id);
|
alSourceStop(source_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Sound::IsPlaying()
|
bool Sound::IsPlaying()
|
||||||
{
|
{
|
||||||
return isPlaying;
|
ALenum state;
|
||||||
|
|
||||||
|
alGetSourcei(source_id, AL_SOURCE_STATE, &state);
|
||||||
|
|
||||||
|
return (state == AL_PLAYING);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ public:
|
|||||||
bool IsPlaying();
|
bool IsPlaying();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool isPlaying;
|
|
||||||
unsigned int buffer_id;
|
unsigned int buffer_id;
|
||||||
unsigned int source_id;
|
unsigned int source_id;
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
+1
-1
@@ -9,7 +9,7 @@
|
|||||||
"collision": true
|
"collision": true
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"music": "WAVE/test3.wav"
|
"music": "WAVE/test1.wav"
|
||||||
},
|
},
|
||||||
"player": {
|
"player": {
|
||||||
"startposition": [ 20, 5, 20 ]
|
"startposition": [ 20, 5, 20 ]
|
||||||
|
|||||||
Reference in New Issue
Block a user