More Generalized
This commit is contained in:
@@ -5,7 +5,6 @@
|
|||||||
#include "Model.h"
|
#include "Model.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
Enemy::Enemy(const std::string &fileName,
|
Enemy::Enemy(const std::string &fileName,
|
||||||
const Vec3f &position,
|
const Vec3f &position,
|
||||||
Vec3f &rotation,
|
Vec3f &rotation,
|
||||||
@@ -21,6 +20,7 @@ Enemy::Enemy(const std::string &fileName,
|
|||||||
speed = 1;
|
speed = 1;
|
||||||
radius = 10;
|
radius = 10;
|
||||||
hasTarget = false;
|
hasTarget = false;
|
||||||
|
openal = new OpenAL();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -51,9 +51,12 @@ void Enemy::draw()
|
|||||||
|
|
||||||
void Enemy::update(float delta)
|
void Enemy::update(float delta)
|
||||||
{
|
{
|
||||||
|
if (!openal->isMusicPlaying()) {
|
||||||
|
openal->playMusic();
|
||||||
|
}
|
||||||
if (hasTarget)
|
if (hasTarget)
|
||||||
{
|
{
|
||||||
OpenAL();
|
|
||||||
//just 2d walking
|
//just 2d walking
|
||||||
float dx, dz, length;
|
float dx, dz, length;
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include "Entity.h"
|
#include "Entity.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "Vector.h"
|
#include "Vector.h"
|
||||||
|
#include "OpenAL.h"
|
||||||
|
|
||||||
class Enemy : public Entity
|
class Enemy : public Entity
|
||||||
{
|
{
|
||||||
@@ -16,5 +17,7 @@ public:
|
|||||||
|
|
||||||
void update(float);
|
void update(float);
|
||||||
void draw();
|
void draw();
|
||||||
|
private:
|
||||||
|
OpenAL *openal;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+13
-7
@@ -7,7 +7,6 @@
|
|||||||
|
|
||||||
OpenAL::OpenAL()
|
OpenAL::OpenAL()
|
||||||
{
|
{
|
||||||
Init();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -20,8 +19,10 @@ int OpenAL::EndWithError(char* msg)
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
int OpenAL::Init()
|
int OpenAL::playMusic(void) {
|
||||||
{
|
//start nieuwe thread
|
||||||
|
//speel sound;
|
||||||
|
isPlaying = true;
|
||||||
//Loading of the WAVE file
|
//Loading of the WAVE file
|
||||||
FILE *fp = NULL; //Create FILE pointer for the WAVE file
|
FILE *fp = NULL; //Create FILE pointer for the WAVE file
|
||||||
fp = fopen("WAVE/Sound.wav", "rb"); //Open the WAVE file
|
fp = fopen("WAVE/Sound.wav", "rb"); //Open the WAVE file
|
||||||
@@ -77,11 +78,11 @@ int OpenAL::Init()
|
|||||||
|
|
||||||
unsigned char* buf = new unsigned char[dataSize]; //Allocate memory for the sound data
|
unsigned char* buf = new unsigned char[dataSize]; //Allocate memory for the sound data
|
||||||
std::cout << fread(buf, sizeof(BYTE), dataSize, fp) << " bytes loaded\n"; //Read the sound data and display the
|
std::cout << fread(buf, sizeof(BYTE), dataSize, fp) << " bytes loaded\n"; //Read the sound data and display the
|
||||||
//number of bytes loaded.
|
//number of bytes loaded.
|
||||||
//Should be the same as the Data Size if OK
|
//Should be the same as the Data Size if OK
|
||||||
|
|
||||||
|
|
||||||
//Now OpenAL needs to be initialized
|
//Now OpenAL needs to be initialized
|
||||||
ALCdevice *device; //Create an OpenAL Device
|
ALCdevice *device; //Create an OpenAL Device
|
||||||
ALCcontext *context; //And an OpenAL Context
|
ALCcontext *context; //And an OpenAL Context
|
||||||
device = alcOpenDevice(NULL); //Open the device
|
device = alcOpenDevice(NULL); //Open the device
|
||||||
@@ -143,7 +144,7 @@ int OpenAL::Init()
|
|||||||
//PLAY
|
//PLAY
|
||||||
alSourcePlay(source); //Play the sound buffer linked to the source
|
alSourcePlay(source); //Play the sound buffer linked to the source
|
||||||
if (alGetError() != AL_NO_ERROR) return EndWithError("Error playing sound"); //Error when playing sound
|
if (alGetError() != AL_NO_ERROR) return EndWithError("Error playing sound"); //Error when playing sound
|
||||||
//system("PAUSE"); //Pause to let the sound play
|
system("PAUSE"); //Pause to let the sound play
|
||||||
|
|
||||||
//Clean-up
|
//Clean-up
|
||||||
fclose(fp); //Close the WAVE file
|
fclose(fp); //Close the WAVE file
|
||||||
@@ -154,9 +155,14 @@ int OpenAL::Init()
|
|||||||
alcDestroyContext(context); //Destroy the OpenAL Context
|
alcDestroyContext(context); //Destroy the OpenAL Context
|
||||||
alcCloseDevice(device); //Close the OpenAL Device
|
alcCloseDevice(device); //Close the OpenAL Device
|
||||||
|
|
||||||
|
isPlaying = false;
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool OpenAL::isMusicPlaying()
|
||||||
|
{
|
||||||
|
return isPlaying;
|
||||||
|
}
|
||||||
|
|
||||||
OpenAL::~OpenAL()
|
OpenAL::~OpenAL()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user