Hi all,
I have designed this class to handle AI and animating for an alien hivebrain, the animations and model come with the DarkGDK with the DarkMatter models, and when i run my program, i get this error:
Run-Time Check Failure #2 - Stack around the variable 'test' was corrupted. and a blue screen
Here is my code:
hivebrain.h:
#include "DarkGDK.h"
class Hivebrain {
public:
Hivebrain(int id, int x, int y, int z);
void AI(void);
int r_id(){ return id; }
private:
int id;
int x;
int y;
int z;
char* animation_name;
char* default_animation;
char* attack_animation;
};
hivebrain.cpp:
#include "hivebrain.h"
#include "DarkGDK.h"
Hivebrain::Hivebrain(int id, int xx, int yy, int zz)
:x(x), y(y), z(z)
{
char* filename = "Alien HivebrainH-Alien Hivebrain-Static.x";
default_animation = "Alien HivebrainH-Alien Hivebrain-Idle.x";
attack_animation = "Alien HivebrainH-Alien Hivebrain-Attack.x";
dbLoadObject(filename, id);
dbPositionObject(id, x, y, z);
if(animation_name == default_animation)
dbSetObjectSpeed(id, 1);
else if(animation_name == attack_animation)
dbSetObjectSpeed(id, 10);
dbPlayObject(id);
dbLoopObject(id);
}
void Hivebrain::AI(int alertLevel)
{
float lvl;
switch(alertLevel)
{
case 1:
lvl = 1.0;
case 2:
lvl = 1.5;
case 3:
lvl = 2.0;
if(dbCameraPositionX() - dbObjectPositionX(id) == lvl)
{
dbRotateObject(id, -dbCameraAngleX(), -dbCameraAngleY(), -dbCameraAngleZ());
if(!dbObjectPositionX(id) == dbCameraPositionX() - 0.1 ||
!dbObjectPositionX(id) == dbCameraPositionX() + 0.1)
dbMoveObject(id, 0.2);
else
animation_name = attack_animation;
}
else
animation_name = default_animation;
if(dbCameraPositionY() - dbObjectPositionY(id) == lvl)
{
dbRotateObject(id, -dbCameraAngleX(), -dbCameraAngleY(), -dbCameraAngleZ());
if(!dbObjectPositionY(id) == dbCameraPositionY() - 0.1 ||
!dbObjectPositionY(id) == dbCameraPositionZ() + 0.1)
dbMoveObject(id, 0.2);
else
animation_name = attack_animation;
}
else
animation_name = default_animation;
dbAppendObject(animation_name, id, 1);
}
Main.cpp:
#include "DarkGDK.h"
#include "aliens.h"
void DarkGDK(void)
{
dbSyncOn();
dbSyncRate(60);
dbAutoCamOff();
Hivebrain test(1, 0, 0, 0);
float fCameraAngleX = 0.0f;
float fCameraAngleY = 0.0f;
while(LoopGDK())
{
dbMakeMatrix(4, 100, 100, 10, 10);
fCameraAngleX = dbWrapValue(fCameraAngleX + dbMouseMoveY());
fCameraAngleY = dbWrapValue(fCameraAngleY + dbMouseMoveX());
dbXRotateCamera(fCameraAngleX);
dbYRotateCamera(fCameraAngleY);
dbControlCameraUsingArrowKeys(0, 0.4, 2);
if(dbLeftKey())
dbMoveCameraLeft(0, 0.4);
if(dbRightKey())
dbMoveCameraRight(0, 0.4);
test.AI();
dbSync ();
}
return;
}
aliens.h:
All i want to know is what is stopping the loading of my objects, and how i could better design my class to make it work better/efficent.
Any help would be grately appreciated