I had this code working perfectly:
#include "DarkGDK.h"
#include "SC_Collision.h"
//-------------------------------------------------------------------------
// Global variables
//-------------------------------------------------------------------------
int ObjID = 1;
int TexID = 1;
int SndID = 1;
int Game_Mode; // 0 = main menu, 1 = loading, 2 = gameplay, 3 = cutscene, 4 = pause menu
//-------------------------------------------------------------------------
// Structures
//-------------------------------------------------------------------------
// Structure for characters
struct Char_Struct
{
int Mesh; // .X mesh file for the character
int AI; // 0 = Player, 1 = Ally, 2 = Neutral, 3 = Enemy
float Position[3]; // XYZ coordinate of the character's initial position in the level
float Rotation; // The character's initial rotation in the level
float Health_Max; // If max <= 0 the character is dead right from the start and therefore
float Health_Current; // only exists as a corpse, otherwise he/she will die when current <= 0
int Alert_Mode; // 0 = undetected, 1 = alert, 2 = searching, 3 = detected
};
// Structure for cover objects
struct Cover_Struct
{
int Mesh; // .X mesh file for the cover object
float Position[3]; // XYZ coordinate for the cover object's position
float Rotation; // Rotation of the cover object
float Health_Max; // If max < 0 the cover object is indestructible,
float Health_Current; // otherwise it will be destroyed when current <= 0
};
// Structure for hazards
struct Hazard_Struct
{
int Mesh; // .X mesh file for the hazard
float Position[3]; // XYZ coordinate for the hazard's position
float Rotation; // Rotation of the hazard
float Damage; // Damage that the hazard deals to a character who is inside it
};
// Structure for each item in a terminal's list
struct Terminal_Item_Struct
{
char Text[50]; // The text for the item that appears in the terminal screen
int Type; // The type of effect that is triggered when the item is selected in the terminal screen, 0 for non selectable (a.k.a. just a label)
int Target; // The target of the effect triggered by selecting the item, 0 for none if the effect type doesn't need one
};
// Structure for terminals
struct Terminal_Struct
{
int Mesh; // .X mesh file for the terminal
float Position[3]; // XYZ coordinate for the terminal's position
float Rotation; // Rotation of the terminal
struct Terminal_Item_Struct List[1000]; // The list of items that appear in the terminal screen
};
// Structure for levels
struct Level
{
int Mesh; // .X mesh file for the level
float End_Position[3]; // A cube that ends the level when
float End_Scale[3]; // entered by the player
struct Char_Struct Character[1000]; // Array of all the human characters in the level
struct Cover_Struct Cover[1000]; // Array of all the cover objects in the level
struct Hazard_Struct Hazard[1000]; // Array of all the hazards in the level
struct Terminal_Struct Terminal[1000]; // Array of all the terminals in the level
};
//-------------------------------------------------------------------------
// Loading functions
//-------------------------------------------------------------------------
// Function to load 3D objects
int Load_3D (char Local_Filepath[], int Local_Collision_Group)
{
int Local_ID;
// Generate an ID number for the mesh
Local_ID = ObjID;
++ObjID;
// Load the mesh
dbLoadObject (Local_Filepath, Local_ID);
// Setup collision
if (Local_Collision_Group > 0)
{
SC_SetupObject (Local_ID, Local_Collision_Group, 0);
}
return Local_ID;
}
//-------------------------------------------------------------------------
// Structure Functions
//-------------------------------------------------------------------------
// Function to create a character
struct Char_Struct Create_Character (char Local_Mesh[], int Local_AI, float Local_X, float Local_Y, float Local_Z, float Local_Rot, float Local_Health)
{
struct Char_Struct Local_Character;
// Load character mesh
Local_Character.Mesh = Load_3D (Local_Mesh, 1);
// Set AI type
Local_Character.AI = Local_AI;
// Set starting position and rotation
Local_Character.Position[0] = Local_X;
Local_Character.Position[1] = Local_Y;
Local_Character.Position[2] = Local_Z;
Local_Character.Rotation = Local_Rot;
// Set health
Local_Character.Health_Max = Local_Health;
Local_Character.Health_Current = Local_Character.Health_Max;
// Position and rotate character
dbPositionObject (Local_Character.Mesh, Local_Character.Position[0], Local_Character.Position[1], Local_Character.Position[2]);
dbRotateObject (Local_Character.Mesh, 0, Local_Character.Rotation, 0);
return Local_Character;
}
// Function to create a cover object
struct Cover_Struct Create_Cover (char Local_Mesh[], float Local_X, float Local_Y, float Local_Z, float Local_Rot, float Local_Health)
{
struct Cover_Struct Local_Cover;
// Load cover mesh
Local_Cover.Mesh = Load_3D (Local_Mesh, 1);
// Set position and rotation
Local_Cover.Position[0] = Local_X;
Local_Cover.Position[1] = Local_Y;
Local_Cover.Position[2] = Local_Z;
Local_Cover.Rotation = Local_Rot;
// Set health
Local_Cover.Health_Max = Local_Health;
Local_Cover.Health_Current = Local_Cover.Health_Max;
// Position and rotate cover object
dbPositionObject (Local_Cover.Mesh, Local_Cover.Position[0], Local_Cover.Position[1], Local_Cover.Position[2]);
dbRotateObject (Local_Cover.Mesh, 0, Local_Cover.Rotation, 0);
// Update collision info
SC_UpdateObject (Local_Cover.Mesh);
return Local_Cover;
}
// Function to create a hazard
struct Hazard_Struct Create_Hazard (char Local_Mesh[], float Local_X, float Local_Y, float Local_Z, float Local_Rot, float Local_Damage)
{
struct Hazard_Struct Local_Hazard;
// Load hazard mesh
Local_Hazard.Mesh = Load_3D (Local_Mesh, 2);
//-------------------------------TEMPORARY-------------------------------//
//------------------------Delete this eventually-------------------------//
dbGhostObjectOn(Local_Hazard.Mesh);
//-----------------------------------------------------------------------//
//-----------------------------------------------------------------------//
// Set position and rotation
Local_Hazard.Position[0] = Local_X;
Local_Hazard.Position[1] = Local_Y;
Local_Hazard.Position[2] = Local_Z;
Local_Hazard.Rotation = Local_Rot;
// Set Damage
Local_Hazard.Damage = Local_Damage;
// Position and rotate cover object
dbPositionObject (Local_Hazard.Mesh, Local_Hazard.Position[0], Local_Hazard.Position[1], Local_Hazard.Position[2]);
dbRotateObject (Local_Hazard.Mesh, 0, Local_Hazard.Rotation, 0);
// Update collision info
SC_UpdateObject (Local_Hazard.Mesh);
return Local_Hazard;
}
// Function to create a terminal
struct Terminal_Struct Create_Terminal (char Local_Mesh[], float Local_X, float Local_Y, float Local_Z, float Local_Rot)
{
struct Terminal_Struct Local_Terminal;
// Load cover mesh
Local_Terminal.Mesh = Load_3D (Local_Mesh, 0);
// Set position and rotation
Local_Terminal.Position[0] = Local_X;
Local_Terminal.Position[1] = Local_Y;
Local_Terminal.Position[2] = Local_Z;
Local_Terminal.Rotation = Local_Rot;
// Position and rotate cover object
dbPositionObject (Local_Terminal.Mesh, Local_Terminal.Position[0], Local_Terminal.Position[1], Local_Terminal.Position[2]);
dbRotateObject (Local_Terminal.Mesh, 0, Local_Terminal.Rotation, 0);
return Local_Terminal;
}
// Function to load the current level
struct Level Load_Level (char Local_Mesh[], char Local_Player_Mesh[], float Local_X, float Local_Y, float Local_Z, float Local_Rot)
{
struct Level Local_Level;
// Load world mesh
Local_Level.Mesh = Load_3D (Local_Mesh, 1);
// Create player character
Local_Level.Character[0] = Create_Character (Local_Player_Mesh, 0, Local_X, Local_Z, Local_Y, Local_Rot, 10);
// Create allies
// Create neutrals
// Create enemies
// Create cover objects
Local_Level.Cover[0] = Create_Cover ("Data/3D/Objects/testcover/mesh.x", -60.00, 2.5, -52.00, 0, -1);
// Create hazards
Local_Level.Hazard[0] = Create_Hazard ("Data/3D/Objects/testhazard/mesh.x", 10.00, 0, -64.00, 0, 1);
return Local_Level;
}
// End_Level
//-------------------------------------------------------------------------
// Main function
//-------------------------------------------------------------------------
void DarkGDK (void)
{
//-------------------------------------------------------------------------
// Initialization
//-------------------------------------------------------------------------
dbSyncOn ();
dbSetDisplayMode (dbDesktopWidth (), dbDesktopHeight(), 32);
dbSetWindowOff ();
dbAutoCamOff ();
dbHideMouse ();
dbColorBackdrop (dbRGB(0, 0, 0));
dbSetCameraRange (.001, 3000);
SC_Start();
//-------------------------------------------------------------------------
// Variables
//-------------------------------------------------------------------------
struct Level Current_Level;
float Camera_Initial_X;
float Camera_Initial_Y;
float Camera_Initial_Z;
float Speed_Mult;
// Main Loop
for (int Main_Loop = 1; Main_Loop > 0;)
{
switch (Game_Mode)
{
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Main Menu
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
case 0:
Game_Mode = 1; // TEMPORARY
break;
//-------------------------------------------------------------------------
// Load Level
//-------------------------------------------------------------------------
case 1:
// Determine which level to load
// Create the level
Current_Level = Load_Level ("Data/3D/World/TestLevel/mesh.x", "Data/3D/Characters/TestPlayer/mesh.x", -85.00, -64.00, 2.00, 90.00);
// Proceed to gameplay
Game_Mode = 2;
break;
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Gameplay
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
case 2:
// If escape is pressed, go to pause menu
if (dbKeyState(1) == 1)
{
Game_Mode = 4;
}
// If the player is in the end area, execute Level_End
// Character Loop
for (int Local_Loops = 0; dbObjectExist(Current_Level.Character[Local_Loops].Mesh) == 1; ++Local_Loops)
{
// Initial position of the character
float Initial_X = dbObjectPositionX(Current_Level.Character[Local_Loops].Mesh);
float Initial_Y = dbObjectPositionY(Current_Level.Character[Local_Loops].Mesh);
float Initial_Z = dbObjectPositionZ(Current_Level.Character[Local_Loops].Mesh);
// Character controls and AIs
switch (Current_Level.Character[Local_Loops].AI)
{
// Player controls
case 0:
dbRotateObject (Current_Level.Character[Local_Loops].Mesh, 0, dbObjectAngleY(Current_Level.Character[Local_Loops].Mesh) + (dbMouseMoveX() * .25), 0);
if (dbKeyState(42) == 1) // Sprint
{
Speed_Mult = 3;
}
else
{
Speed_Mult = 1;
}
if (dbKeyState(17) == 1) // Forward
{
dbMoveObject (Current_Level.Character[Local_Loops].Mesh, .10 * Speed_Mult);
}
if (Speed_Mult == 1)
{
if (dbKeyState(31) == 1) // Backward
{
dbMoveObject (Current_Level.Character[Local_Loops].Mesh, -.10 * Speed_Mult);
}
if (dbKeyState(30) == 1) // Left
{
dbRotateObject (Current_Level.Character[Local_Loops].Mesh, 0, dbObjectAngleY(Current_Level.Character[Local_Loops].Mesh) - 90, 0);
dbMoveObject (Current_Level.Character[Local_Loops].Mesh, .10 * Speed_Mult);
dbRotateObject (Current_Level.Character[Local_Loops].Mesh, 0, dbObjectAngleY(Current_Level.Character[Local_Loops].Mesh) + 90, 0);
}
if (dbKeyState(32) == 1) // Right
{
dbRotateObject (Current_Level.Character[Local_Loops].Mesh, 0, dbObjectAngleY(Current_Level.Character[Local_Loops].Mesh) + 90, 0);
dbMoveObject (Current_Level.Character[Local_Loops].Mesh, .10 * Speed_Mult);
dbRotateObject (Current_Level.Character[Local_Loops].Mesh, 0, dbObjectAngleY(Current_Level.Character[Local_Loops].Mesh) - 90, 0);
}
}
dbPositionCamera ( dbObjectPositionX(Current_Level.Character[Local_Loops].Mesh),
dbObjectPositionY(Current_Level.Character[Local_Loops].Mesh) + .75,
dbObjectPositionZ(Current_Level.Character[Local_Loops].Mesh));
dbRotateCamera (dbCameraAngleX() + (dbMouseMoveY() * .25), dbObjectAngleY(Current_Level.Character[Local_Loops].Mesh), 0);
Camera_Initial_X = dbCameraPositionX();
Camera_Initial_Y = dbCameraPositionY();
Camera_Initial_Z = dbCameraPositionZ();
dbMoveCamera (-5);
dbRotateCamera (dbCameraAngleX(), dbCameraAngleY() + 90, 0);
dbMoveCamera (1.5);
dbRotateCamera (dbCameraAngleX(), dbObjectAngleY(Current_Level.Character[Local_Loops].Mesh), 0);
// Camera Collision
if (SC_SphereCastGroup(1, Camera_Initial_X, Camera_Initial_Y, Camera_Initial_Z, dbCameraPositionX(), dbCameraPositionY(), dbCameraPositionZ(), .5,
Current_Level.Character[Local_Loops].Mesh) > 0)
{
dbPositionCamera (SC_GetStaticCollisionX(), SC_GetStaticCollisionY(), SC_GetStaticCollisionZ());
}
break;
// Ally AI
case 1:
//TEMPORARY
break;
// Neutral AI
case 2:
//TEMPORARY
break;
// Enemy AI
case 3:
//TEMPORARY
break;
}
// Character Collision
if (SC_SphereSlideGroup (1, Initial_X, Initial_Y, Initial_Z, dbObjectPositionX(Current_Level.Character[Local_Loops].Mesh),
dbObjectPositionY(Current_Level.Character[Local_Loops].Mesh), dbObjectPositionZ(Current_Level.Character[Local_Loops].Mesh),
2, Current_Level.Character[Local_Loops].Mesh) > 0)
{
dbPositionObject (Current_Level.Character[Local_Loops].Mesh, SC_GetCollisionSlideX(), SC_GetCollisionSlideY(), SC_GetCollisionSlideZ());
SC_UpdateObject (Current_Level.Character[Local_Loops].Mesh);
}
}
break;
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Pause Menu
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
case 4:
Main_Loop = 0; // TEMPORARY
}
//-------------------------------------------------------------------------
// Update Screen
//-------------------------------------------------------------------------
dbSync ();
}
return;
}
Then I changed this line:
Local_Level.Character[0] = Create_Character (Local_Player_Mesh, 0, Local_X, Local_Z, Local_Y, Local_Rot, 10);
to this:
Local_Level.Character[0] = Create_Character (Local_Player_Mesh, 0, Local_X, Local_Z, Local_Y, Local_Rot, 100);
It now crashes instantly, like in the attached image. The weirdest thing is that even if I restore the line I changed back to what it was (so the code as a whole is returned to a state in which it previously did work) it still doesn't work. No matter what I do to the code, it still crashes instantly. I have absolutely no idea why it is doing this, so I really need help.
Hail to the king baby
I love Evil Dead.