sorry never posted on this board before this is the code i have so far
this is my main bit of code to run the game egg.cpp
CODE
#include "egg.h"
HWND hWnd;
GameFramework AdventureGame(0); //You must create a new instance of the game for every new game.
CreateNewScreenItem RABBIT(0,-1 ,8 ,1); //When a new character or baddie is needed.
CreateNewScreenItem SNAIL (0,1,23,0);
int APIENTRY WinMain(HINSTANCE Now,HINSTANCE,LPSTR ,int)
{
AdventureGame.StartGame(Now); //starts game loop
AdventureGame.PlayMusic(L"be.mid",true); //plays midi files for music.
if(AdventureGame.Running()) // game loop just include.
return true;
else
return false;
}
void GameFramework::LoadGameGraphics()
{
RABBIT.LoadImages("Graphics/Rabbit/playerl1.png","Graphics/Rabbit/playerl2.png",
"Graphics/Rabbit/playerr1.png","Graphics/Rabbit/playerr2.png",
"Graphics/Rabbit/playerb1.png","Graphics/Rabbit/playerb2.png",
"Graphics/Rabbit/playerf1.png","Graphics/Rabbit/playerf2.png");
SNAIL.LoadImage("Graphics/Snail/snailf1.png");
AdventureGame.LoadBackgroundImage("Graphics/Screens/SplashScreen.jpg",splash_screen);
AdventureGame.LoadBackgroundImage("Graphics/Screens/Options.jpg",option_screen);
AdventureGame.LoadBackgroundImage("Graphics/Screens/MainGame.jpg",main_game_screen);
AdventureGame.LoadBackgroundImage("Graphics/Screens/GameOver.jpg",game_over_screen);
AdventureGame.LoadBackgroundImage("Graphics/Screens/HighScore.jpg",high_score_screen);
}
void GameFramework::DisplayMainGame()
{
RABBIT.DisplayItem(); //display RABBIT
SNAIL.DisplayItem(); //dislays GHOST
AdventureGame.DisplayScore(-15,-12); //Displays a score at the relevant x,y coordiantes.
}
//This section checks for keyboard, mouse or joystick input.
void GameFramework::MainGameInput()
{
if (AdventureGame.keypressed[DIK_UP] & KEY_PRESSED_DOWN)
RABBIT.MoveUp();
if (AdventureGame.keypressed[DIK_DOWN] & KEY_PRESSED_DOWN)
RABBIT.MoveDown();
if (AdventureGame.keypressed[DIK_LEFT] & KEY_PRESSED_DOWN)
RABBIT.MoveLeft();
if (AdventureGame.keypressed[DIK_RIGHT] & KEY_PRESSED_DOWN)
RABBIT.MoveRight();
if (AdventureGame.keypressed[DIK_SPACE] & 0x80)
AdventureGame.changeStage();
if (AdventureGame.keypressed[DIK_1] & 0x80)
AdventureGame.changeStage();
if (AdventureGame.JoyPresent == true)
{
if (AdventureGame.joy_state.lX > 0)
RABBIT.MoveRight();
if (AdventureGame.joy_state.lX < 0)
RABBIT.MoveLeft();
if (AdventureGame.joy_state.lY < 0)
RABBIT.MoveUp();
if (AdventureGame.joy_state.lY > 0)
RABBIT.MoveDown();
}
if (AdventureGame.Collision(&SNAIL,&RABBIT)) //Simple collision detection pass both objects as a pointer
AdventureGame.IncreaseScore(); // true returned if the 2 objects collide.
}
this is the header file for that
CODE
#pragma once
#include "resource.h"
#include "UseGameHelper.cpp"
this is my use gamehelper.cpp
CODE
#pragma once
#include "DXHELPER.h"
#include <mmsystem.h>
#include <d3dx9tex.h>
//The following defines are used simply for directions for game objects,
//so that items can be facing "left" instead of having to type 0 this aids in readbility.
// North etc added for developers who prefer cartesian style directions.
#define left 0
#define west 0
#define right 1
#define east 1
#define up 2
#define north 2
#define down 3
#define south 3
//because of multiple l;eft directions i.e. for animations, a number is appended
// 2,3,4 etc. This allows for easier work with animations.
#define left2 4
#define right2 5
#define up2 6
#define down2 7
#define left3 8
#define right3 9
#define up3 10
#define down3 11
//Some developers prefer to use diagnols such as up_left these would traditionally suit games
//such as asteroids.
#define up_left 12
#define north_west 12
#define down_left 13
#define south_west 13
#define down_right 14
#define south_east 14
#define up_right 15
#define north_east 15
#define up_left2 16
#define down_left2 17
#define down_right2 18
#define up_right2 19
#define up_left3 20
#define down_left3 21
#define down_right3 22
#define up_right3 23
#define screen_score 0
//The following allow for a number of game stages typicalof most games
#define splash_screen 0
#define option_screen 1
#define main_game_screen 2
#define game_over_screen 3
#define high_score_screen 4
#define pixel 0.1
#define mask_color 0xFFFF00FF
#define KEY_PRESSED_DOWN 0x80
extern directx_settings DX_structure; //the main DirectX Work
class Mesh
{
private:
LPD3DXMESH g_pMesh;
D3DMATERIAL9* g_pMeshMaterials;
LPDIRECT3DTEXTURE9* g_pMeshTextures;
DWORD g_dwNumMaterials;
float posx;
float posy;
float posz;
float rotx;
float roty;
int speed;
public:
Mesh()
{
posx=0;
posy=0;
posz=100;
rotx=-1.5f;
roty=-3.2f;
speed=1;
}
Mesh(float setx, float sety, float setz)
{
posx=setx;
posy=sety;
posz=setz;
rotx=0;
roty=0;
speed=1;
}
void MoveLeft(float unit)
{
posx=posx - float(unit*speed);
}
void MoveLeft()
{
posx=posx - float(pixel*speed);
}
void MoveRight(float unit)
{
posx=posx + float(unit*speed);
}
void MoveRight()
{
posx=posx + float(pixel*speed);
}
void MoveUp(float unit)
{
posy= posy + float(unit*speed);
}
void MoveUp()
{
posy= posy + float(pixel*speed);
}
void MoveDown(float unit)
{
posy= posy - float(unit*speed);
}
void MoveDown()
{
posy= posy - float(pixel*speed);
}
void RotateRight()
{
rotx=rotx+ float(pixel*speed);
}
void RotateLeft()
{
rotx=rotx- float(pixel*speed);
}
void RotateUp()
{
roty=roty+ float(pixel*speed);
}
void RotateDown()
{
roty=roty- float(pixel*speed);
}
void ZoomIn(float unit)
{
posz=posz + float(unit*speed);
}
void ZoomIn()
{
posz=posz + float(pixel*speed);
}
void ZoomOut(float unit)
{
posz=posz - float(unit*speed);
}
void ZoomOut()
{
posz=posz - float(pixel*speed);
}
float GetPositionX(void)
{
return posx;
}
float GetPositionY(void)
{
return posy;
}
float GetPositionZ(void)
{
return posz;
}
float GetRotationX(void)
{
return rotx;
}
float GetRotationY(void)
{
return roty;
}
Mesh LoadMesh(char filename[])
{
Mesh TempMesh;
LPD3DXBUFFER pD3DXMtrlBuffer=NULL;
D3DXLoadMeshFromX( filename, D3DXMESH_SYSTEMMEM, DX_structure.D3DDevice, NULL,
&pD3DXMtrlBuffer, NULL, &TempMesh.g_dwNumMaterials, &TempMesh.g_pMesh );
D3DXMATERIAL* d3dxMaterials = (D3DXMATERIAL*)pD3DXMtrlBuffer->GetBufferPointer();
TempMesh.g_pMeshMaterials = new D3DMATERIAL9[TempMesh.g_dwNumMaterials];
TempMesh.g_pMeshTextures = new LPDIRECT3DTEXTURE9[TempMesh.g_dwNumMaterials];
for( DWORD i=0; i<TempMesh.g_dwNumMaterials; i++ )
{
TempMesh.g_pMeshMaterials[i] = d3dxMaterials[i].MatD3D;
TempMesh.g_pMeshMaterials[i].Ambient = TempMesh.g_pMeshMaterials[i].Diffuse;
TempMesh.g_pMeshTextures[i] = NULL;
if( d3dxMaterials[i].pTextureFilename != NULL && lstrlen(d3dxMaterials[i].pTextureFilename) > 0 )
D3DXCreateTextureFromFile( DX_structure.D3DDevice , d3dxMaterials[i].pTextureFilename,
&TempMesh.g_pMeshTextures[i] );
}
pD3DXMtrlBuffer->Release();
return TempMesh;
}
void DisplayMesh(Mesh PassedMesh)
{
D3DXMATRIX rot_matrixx;
D3DXMATRIX rot_matrixy;
D3DXMATRIX rot_matrix;
D3DXMATRIX trans_matrix;
D3DXMatrixRotationY(&rot_matrixy,PassedMesh.roty);
D3DXMatrixRotationX(&rot_matrixx,PassedMesh.rotx);
D3DXMatrixMultiply(&rot_matrix,&rot_matrixx,&rot_matrixy);
D3DXMatrixTranslation(&trans_matrix,PassedMesh.posx ,PassedMesh.posy ,PassedMesh.posz);
D3DXMatrixMultiply(&DX_structure.MatrixWorld,&rot_matrix,&trans_matrix);
DX_structure.D3DDevice->SetTransform( D3DTS_WORLD, &DX_structure.MatrixWorld );
for( DWORD i=0; i<PassedMesh.g_dwNumMaterials; i++ )
{
DX_structure.D3DDevice->SetMaterial( &PassedMesh.g_pMeshMaterials[i] );
DX_structure.D3DDevice->SetTexture( 0, PassedMesh.g_pMeshTextures[i] );
PassedMesh.g_pMesh->DrawSubset( i );
}
}
};
class CreateNewScreenItem
{
private:
float positionX; // New Code controls George x position on screen.
float positionY; //New Code controls George y position on screen.
float positionZ; //New Code controls George y position on screen.
int speed;
int Direction;
bool ShowOnScreen;
int animation; //(0) no animation, (1)2 images for animation, (3) 3 images for animation;
int animatedcycle;
LPDIRECT3DTEXTURE9 D3DTextureItem[12]; //Create new instance of a Texture
public:
CreateNewScreenItem(float size, int ispeed,bool show)
{
speed = speed;
positionZ=size;
ShowOnScreen = show;
}
CreateNewScreenItem(float ipositionX, float ipositionY, float ipositionZ, UINT ispeed)
{
positionX=ipositionX;
positionY=ipositionY;
positionZ=ipositionZ;
speed = ispeed;
ShowOnScreen = true;
}
CreateNewScreenItem()
{
ShowOnScreen = true;
}
~CreateNewScreenItem(void)
{
ShowOnScreen=false;
}
public:
void MoveLeft(float unit)
{
positionX=positionX - float(unit*speed);
Direction = left;
animatedcycle++;
}
void MoveLeft()
{
positionX=positionX - float(pixel*speed);
Direction = left;
animatedcycle++;
}
void MoveRight(float unit)
{
positionX=positionX + float(unit*speed);
Direction = right;
animatedcycle++;
}
void MoveRight()
{
positionX=positionX + float(pixel*speed);
Direction = right;
animatedcycle++;
}
void MoveUp(float unit)
{
positionY= positionY + float(unit*speed);
Direction = up;
animatedcycle++;
}
void MoveUp()
{
positionY= positionY + float(pixel*speed);
Direction = up;
animatedcycle++;
}
void MoveDown(float unit)
{
positionY= positionY - float(unit*speed);
Direction = down;
animatedcycle++;
}
void MoveDown()
{
positionY= positionY - float(pixel*speed);
Direction = down;
animatedcycle++;
}
void ZoomIn(float unit)
{
positionZ= positionZ - unit;
}
void ZoomOut(float unit)
{
positionZ= positionZ + unit;
}
void IncreaseSpeed(void)
{
speed++;
}
void DecreaseSpeed(void)
{
if (speed > 1)
speed --;
else
speed = 1;
}
void SetSpeed(int spd)
{
speed=spd;
}
void SetPositionZ(float Z_temp)
{
positionZ=Z_temp;
}
void SetPosition(float X, float Y,float Z)
{
positionX=X;
positionY=Y;
positionZ=Z;
}
void SetPositionX(float X_temp)
{
positionX=X_temp;
}
void SetPositionY(float Y_temp)
{
positionY=Y_temp;
}
int GetDirection(void)
{
return Direction;
}
float GetPositionX(void)
{
return positionX;
}
float GetPositionY(void)
{
return positionY;
}
float GetPositionZ(void)
{
return positionZ;
}
bool getShowOnScreen(void)
{
if (ShowOnScreen==true)
return true;
else
return false;
}
void setShowOnScreen(bool show)
{
ShowOnScreen=show;
}
void LoadImages(char file[],char file2[],char file3[],char file4[])
{
D3DXCreateTextureFromFileEx(DX_structure.D3DDevice , file,D3DX_DEFAULT,D3DX_DEFAULT,D3DX_DEFAULT,
D3DUSAGE_RENDERTARGET , D3DFMT_UNKNOWN,D3DPOOL_DEFAULT , D3DX_DEFAULT ,D3DX_DEFAULT ,mask_color,NULL,NULL,&D3DTextureItem[left]);
D3DXCreateTextureFromFileEx(DX_structure.D3DDevice , file2,D3DX_DEFAULT,D3DX_DEFAULT,D3DX_DEFAULT,
D3DUSAGE_RENDERTARGET , D3DFMT_UNKNOWN,D3DPOOL_DEFAULT , D3DX_DEFAULT ,D3DX_DEFAULT ,mask_color,NULL,NULL,&D3DTextureItem[right]);
D3DXCreateTextureFromFileEx(DX_structure.D3DDevice , file3,D3DX_DEFAULT,D3DX_DEFAULT,D3DX_DEFAULT,
D3DUSAGE_RENDERTARGET , D3DFMT_UNKNOWN,D3DPOOL_DEFAULT , D3DX_DEFAULT ,D3DX_DEFAULT ,mask_color,NULL,NULL,&D3DTextureItem[up]);
D3DXCreateTextureFromFileEx(DX_structure.D3DDevice , file4,D3DX_DEFAULT,D3DX_DEFAULT,D3DX_DEFAULT,
D3DUSAGE_RENDERTARGET , D3DFMT_UNKNOWN,D3DPOOL_DEFAULT , D3DX_DEFAULT ,D3DX_DEFAULT ,mask_color,NULL,NULL,&D3DTextureItem[down]);
animation = 0;
}
void LoadImages(char file1a[],char file1b[],char file2a[],char file2b[],char file3a[],char file3b[],char file4a[],char file4b[])
{
D3DXCreateTextureFromFileEx(DX_structure.D3DDevice , file1a,D3DX_DEFAULT,D3DX_DEFAULT,D3DX_DEFAULT,
D3DUSAGE_RENDERTARGET , D3DFMT_UNKNOWN,D3DPOOL_DEFAULT , D3DX_DEFAULT ,D3DX_DEFAULT ,mask_color,NULL,NULL,&D3DTextureItem[left]);
D3DXCreateTextureFromFileEx(DX_structure.D3DDevice , file2a,D3DX_DEFAULT,D3DX_DEFAULT,D3DX_DEFAULT,
D3DUSAGE_RENDERTARGET , D3DFMT_UNKNOWN,D3DPOOL_DEFAULT , D3DX_DEFAULT ,D3DX_DEFAULT ,mask_color,NULL,NULL,&D3DTextureItem[right]);
D3DXCreateTextureFromFileEx(DX_structure.D3DDevice , file3a,D3DX_DEFAULT,D3DX_DEFAULT,D3DX_DEFAULT,
D3DUSAGE_RENDERTARGET , D3DFMT_UNKNOWN,D3DPOOL_DEFAULT , D3DX_DEFAULT ,D3DX_DEFAULT ,mask_color,NULL,NULL,&D3DTextureItem[up]);
D3DXCreateTextureFromFileEx(DX_structure.D3DDevice , file4a,D3DX_DEFAULT,D3DX_DEFAULT,D3DX_DEFAULT,
D3DUSAGE_RENDERTARGET , D3DFMT_UNKNOWN,D3DPOOL_DEFAULT , D3DX_DEFAULT ,D3DX_DEFAULT ,mask_color,NULL,NULL,&D3DTextureItem[down]);
D3DXCreateTextureFromFileEx(DX_structure.D3DDevice , file1b,D3DX_DEFAULT,D3DX_DEFAULT,D3DX_DEFAULT,
D3DUSAGE_RENDERTARGET , D3DFMT_UNKNOWN,D3DPOOL_DEFAULT , D3DX_DEFAULT ,D3DX_DEFAULT ,mask_color,NULL,NULL,&D3DTextureItem[left2]);
D3DXCreateTextureFromFileEx(DX_structure.D3DDevice , file2b,D3DX_DEFAULT,D3DX_DEFAULT,D3DX_DEFAULT,
D3DUSAGE_RENDERTARGET , D3DFMT_UNKNOWN,D3DPOOL_DEFAULT , D3DX_DEFAULT ,D3DX_DEFAULT ,mask_color,NULL,NULL,&D3DTextureItem[right2]);
D3DXCreateTextureFromFileEx(DX_structure.D3DDevice , file3b,D3DX_DEFAULT,D3DX_DEFAULT,D3DX_DEFAULT,
D3DUSAGE_RENDERTARGET , D3DFMT_UNKNOWN,D3DPOOL_DEFAULT , D3DX_DEFAULT ,D3DX_DEFAULT ,mask_color,NULL,NULL,&D3DTextureItem[up2]);
D3DXCreateTextureFromFileEx(DX_structure.D3DDevice , file4b,D3DX_DEFAULT,D3DX_DEFAULT,D3DX_DEFAULT,
D3DUSAGE_RENDERTARGET , D3DFMT_UNKNOWN,D3DPOOL_DEFAULT , D3DX_DEFAULT ,D3DX_DEFAULT ,mask_color,NULL,NULL,&D3DTextureItem[down2]);
animation = 1;
}
void LoadImages(char file1a[],char file1b[],char file1c[],char file2a[],char file2b[],char file2c[],
char file3a[],char file3b[],char file3c[],char file4a[],char file4b[],char file4c[])
{
D3DXCreateTextureFromFileEx(DX_structure.D3DDevice , file1a,D3DX_DEFAULT,D3DX_DEFAULT,D3DX_DEFAULT,
D3DUSAGE_RENDERTARGET , D3DFMT_UNKNOWN,D3DPOOL_DEFAULT , D3DX_DEFAULT ,D3DX_DEFAULT ,mask_color,NULL,NULL,&D3DTextureItem[left]);
D3DXCreateTextureFromFileEx(DX_structure.D3DDevice , file2a,D3DX_DEFAULT,D3DX_DEFAULT,D3DX_DEFAULT,
D3DUSAGE_RENDERTARGET , D3DFMT_UNKNOWN,D3DPOOL_DEFAULT , D3DX_DEFAULT ,D3DX_DEFAULT ,mask_color,NULL,NULL,&D3DTextureItem[right]);
D3DXCreateTextureFromFileEx(DX_structure.D3DDevice , file3a,D3DX_DEFAULT,D3DX_DEFAULT,D3DX_DEFAULT,
D3DUSAGE_RENDERTARGET , D3DFMT_UNKNOWN,D3DPOOL_DEFAULT , D3DX_DEFAULT ,D3DX_DEFAULT ,mask_color,NULL,NULL,&D3DTextureItem[up]);
D3DXCreateTextureFromFileEx(DX_structure.D3DDevice , file4a,D3DX_DEFAULT,D3DX_DEFAULT,D3DX_DEFAULT,
D3DUSAGE_RENDERTARGET , D3DFMT_UNKNOWN,D3DPOOL_DEFAULT , D3DX_DEFAULT ,D3DX_DEFAULT ,mask_color,NULL,NULL,&D3DTextureItem[down]);
D3DXCreateTextureFromFileEx(DX_structure.D3DDevice , file1b,D3DX_DEFAULT,D3DX_DEFAULT,D3DX_DEFAULT,
D3DUSAGE_RENDERTARGET , D3DFMT_UNKNOWN,D3DPOOL_DEFAULT , D3DX_DEFAULT ,D3DX_DEFAULT ,mask_color,NULL,NULL,&D3DTextureItem[left2]);
D3DXCreateTextureFromFileEx(DX_structure.D3DDevice , file2b,D3DX_DEFAULT,D3DX_DEFAULT,D3DX_DEFAULT,
D3DUSAGE_RENDERTARGET , D3DFMT_UNKNOWN,D3DPOOL_DEFAULT , D3DX_DEFAULT ,D3DX_DEFAULT ,mask_color,NULL,NULL,&D3DTextureItem[right2]);
D3DXCreateTextureFromFileEx(DX_structure.D3DDevice , file3b,D3DX_DEFAULT,D3DX_DEFAULT,D3DX_DEFAULT,
D3DUSAGE_RENDERTARGET , D3DFMT_UNKNOWN,D3DPOOL_DEFAULT , D3DX_DEFAULT ,D3DX_DEFAULT ,mask_color,NULL,NULL,&D3DTextureItem[up2]);
D3DXCreateTextureFromFileEx(DX_structure.D3DDevice , file4b,D3DX_DEFAULT,D3DX_DEFAULT,D3DX_DEFAULT,
D3DUSAGE_RENDERTARGET , D3DFMT_UNKNOWN,D3DPOOL_DEFAULT , D3DX_DEFAULT ,D3DX_DEFAULT ,mask_color,NULL,NULL,&D3DTextureItem[down2]);
D3DXCreateTextureFromFileEx(DX_structure.D3DDevice , file1c,D3DX_DEFAULT,D3DX_DEFAULT,D3DX_DEFAULT,
D3DUSAGE_RENDERTARGET , D3DFMT_UNKNOWN,D3DPOOL_DEFAULT , D3DX_DEFAULT ,D3DX_DEFAULT ,mask_color,NULL,NULL,&D3DTextureItem[left3]);
D3DXCreateTextureFromFileEx(DX_structure.D3DDevice , file2c,D3DX_DEFAULT,D3DX_DEFAULT,D3DX_DEFAULT,
D3DUSAGE_RENDERTARGET , D3DFMT_UNKNOWN,D3DPOOL_DEFAULT , D3DX_DEFAULT ,D3DX_DEFAULT ,mask_color,NULL,NULL,&D3DTextureItem[right3]);
D3DXCreateTextureFromFileEx(DX_structure.D3DDevice , file3c,D3DX_DEFAULT,D3DX_DEFAULT,D3DX_DEFAULT,
D3DUSAGE_RENDERTARGET , D3DFMT_UNKNOWN,D3DPOOL_DEFAULT , D3DX_DEFAULT ,D3DX_DEFAULT ,mask_color,NULL,NULL,&D3DTextureItem[up3]);
D3DXCreateTextureFromFileEx(DX_structure.D3DDevice , file4c,D3DX_DEFAULT,D3DX_DEFAULT,D3DX_DEFAULT,
D3DUSAGE_RENDERTARGET , D3DFMT_UNKNOWN,D3DPOOL_DEFAULT , D3DX_DEFAULT ,D3DX_DEFAULT ,mask_color,NULL,NULL,&D3DTextureItem[down3]);
animation = 2;
}
void LoadImages(char file1[],char file2[])
{
D3DXCreateTextureFromFileEx(DX_structure.D3DDevice , file1,D3DX_DEFAULT,D3DX_DEFAULT,D3DX_DEFAULT,
D3DUSAGE_RENDERTARGET , D3DFMT_UNKNOWN,D3DPOOL_DEFAULT , D3DX_DEFAULT ,D3DX_DEFAULT ,mask_color,NULL,NULL,&D3DTextureItem[0]);
D3DXCreateTextureFromFileEx(DX_structure.D3DDevice , file2,D3DX_DEFAULT,D3DX_DEFAULT,D3DX_DEFAULT,
D3DUSAGE_RENDERTARGET , D3DFMT_UNKNOWN,D3DPOOL_DEFAULT , D3DX_DEFAULT ,D3DX_DEFAULT ,mask_color,NULL,NULL,&D3DTextureItem[1]);
Direction = up;
}
void LoadImage(char file[])
{
D3DXCreateTextureFromFileEx(DX_structure.D3DDevice , file,D3DX_DEFAULT,D3DX_DEFAULT,D3DX_DEFAULT,
D3DUSAGE_RENDERTARGET , D3DFMT_UNKNOWN,D3DPOOL_DEFAULT , D3DX_DEFAULT ,D3DX_DEFAULT ,mask_color,NULL,NULL,&D3DTextureItem[up]);
Direction = up;
}
void DisplayItem()
{
switch (animation)
{
case 0:
if (!ShowOnScreen)
return;
DX_structure.D3DDevice->SetRenderState( D3DRS_ZENABLE, FALSE );
D3DXMatrixTranslation(&DX_structure.MatrixWorld,positionX,positionY,positionZ);
DX_structure.D3DDevice->SetTransform( D3DTS_WORLD, &DX_structure.MatrixWorld );
DX_structure.D3DDevice->SetTexture(0,D3DTextureItem[Direction]);
DX_structure.D3DDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 2 );
break;
case 1:
if (!ShowOnScreen)
return;
DX_structure.D3DDevice->SetRenderState( D3DRS_ZENABLE, FALSE );
if (animatedcycle>1)
animatedcycle = 0;
D3DXMatrixTranslation(&DX_structure.MatrixWorld,positionX,positionY,positionZ);
DX_structure.D3DDevice->SetTransform( D3DTS_WORLD, &DX_structure.MatrixWorld );
DX_structure.D3DDevice->SetTexture(0,D3DTextureItem[Direction+(animatedcycle*4)]);
DX_structure.D3DDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 2 );
break;
case 2:
if (!ShowOnScreen)
return;
DX_structure.D3DDevice->SetRenderState( D3DRS_ZENABLE, FALSE );
if (animatedcycle>2)
animatedcycle = 0;
D3DXMatrixTranslation(&DX_structure.MatrixWorld,positionX,positionY,positionZ);
DX_structure.D3DDevice->SetTransform( D3DTS_WORLD, &DX_structure.MatrixWorld );
DX_structure.D3DDevice->SetTexture(0,D3DTextureItem[Direction+(animatedcycle*4)]);
DX_structure.D3DDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 2 );
break;
}
}
void DisplayItem(bool zenable )
{
switch (animation)
{
case 0:
if (!ShowOnScreen)
return;
if (zenable == true)
DX_structure.D3DDevice->SetRenderState( D3DRS_ZENABLE, TRUE );
else
DX_structure.D3DDevice->SetRenderState( D3DRS_ZENABLE, FALSE );
D3DXMatrixTranslation(&DX_structure.MatrixWorld,positionX,positionY,positionZ);
DX_structure.D3DDevice->SetTransform( D3DTS_WORLD, &DX_structure.MatrixWorld );
DX_structure.D3DDevice->SetTexture(0,D3DTextureItem[Direction]);
DX_structure.D3DDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 2 );
break;
case 1:
if (!ShowOnScreen)
return;
if (zenable == true)
DX_structure.D3DDevice->SetRenderState( D3DRS_ZENABLE, TRUE );
else
DX_structure.D3DDevice->SetRenderState( D3DRS_ZENABLE, FALSE );
if (animatedcycle>1)
animatedcycle = 0;
D3DXMatrixTranslation(&DX_structure.MatrixWorld,positionX,positionY,positionZ);
DX_structure.D3DDevice->SetTransform( D3DTS_WORLD, &DX_structure.MatrixWorld );
DX_structure.D3DDevice->SetTexture(0,D3DTextureItem[Direction+(animatedcycle*4)]);
DX_structure.D3DDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 2 );
break;
case 2:
if (!ShowOnScreen)
return;
if (zenable == true)
DX_structure.D3DDevice->SetRenderState( D3DRS_ZENABLE, TRUE );
else
DX_structure.D3DDevice->SetRenderState( D3DRS_ZENABLE, FALSE );
if (animatedcycle>2)
animatedcycle = 0;
D3DXMatrixTranslation(&DX_structure.MatrixWorld,positionX,positionY,positionZ);
DX_structure.D3DDevice->SetTransform( D3DTS_WORLD, &DX_structure.MatrixWorld );
DX_structure.D3DDevice->SetTexture(0,D3DTextureItem[Direction+(animatedcycle*4)]);
DX_structure.D3DDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 2 );
break;
}
}
};
class GameFramework
{
private:
int currentscore;
int gamestage;
int option_selected;
bool keydown;
bool debugmode;
float zoom;
LPDIRECT3DTEXTURE9 D3DTextureScreen[10]; //Create new instance of a Texture
LPDIRECT3DTEXTURE9 D3DTextureNumbers[10];
LPDIRECT3DTEXTURE9 D3DTextureButtons[6];
LPDIRECT3DTEXTURE9 D3DTextureOnScreenLabel[5];
UCHAR keypressed[256];
DIJOYSTATE joy_state;
DIMOUSESTATE mouse_state;
RECT destRect1;
char count[25];
char name[50];
bool keyrepeat[50];
bool loaded;
bool JoyPresent;
public:
GameFramework (int set_gamestage)
{
gamestage=set_gamestage;
zoom=-2.5f;
loaded = false;
}
GameFramework (int set_gamestage, bool set_debug_mode)
{
gamestage=set_gamestage;
debugmode=set_debug_mode;
loaded = false;
}
GameFramework ()
{
gamestage=1;
loaded = false;
}
void StartGame( HINSTANCE Instance)
{
SetUp(Instance,"new game");
LoadScore();
LoadButtons();
LoadGameGraphics();
DIMOUSESTATE mouse_state = {0,0,0,2};
}
void StartGame( HINSTANCE Instance,bool includescore)
{
SetUp(Instance,"new game");
if (includescore)
LoadScore();
LoadButtons();
LoadGameGraphics();
}
void DisplayScore (float x, float y)
{
UINT thousands = 0;
UINT hundreds = 0;
UINT tens = 0;
UINT score = currentscore;
DX_structure.D3DDevice->SetRenderState( D3DRS_ZENABLE, TRUE );
if (score>999)
do
{
score = score - 1000;
thousands = thousands + 1;
}
while (score>999);
if (score>99)
do
{
score = score - 100;
hundreds = hundreds + 1;
}
while (score>99);
if (score>9)
do
{
score = score - 10;
tens = tens + 1;
}
while (score>9);
D3DXMatrixTranslation(&DX_structure.MatrixWorld,x,y,30.0f);
DX_structure.D3DDevice->SetTransform( D3DTS_WORLD, &DX_structure.MatrixWorld );
DX_structure.D3DDevice->SetTexture(0,D3DTextureOnScreenLabel[screen_score]);
DX_structure.D3DDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 2 );
D3DXMatrixTranslation(&DX_structure.MatrixWorld,x+2,y,30.0f);
DX_structure.D3DDevice->SetTransform( D3DTS_WORLD, &DX_structure.MatrixWorld );
DX_structure.D3DDevice->SetTexture(0,D3DTextureNumbers[thousands]);
DX_structure.D3DDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 2 );
D3DXMatrixTranslation(&DX_structure.MatrixWorld,x+3,y,30.0f);
DX_structure.D3DDevice->SetTransform( D3DTS_WORLD, &DX_structure.MatrixWorld );
DX_structure.D3DDevice->SetTexture(0,D3DTextureNumbers[hundreds]);
DX_structure.D3DDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 2 );
D3DXMatrixTranslation(&DX_structure.MatrixWorld,x+4,y,30.0f);
DX_structure.D3DDevice->SetTransform( D3DTS_WORLD, &DX_structure.MatrixWorld );
DX_structure.D3DDevice->SetTexture(0,D3DTextureNumbers[tens]);
DX_structure.D3DDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 2 );
D3DXMatrixTranslation(&DX_structure.MatrixWorld,x+5,y,30.0f);
DX_structure.D3DDevice->SetTransform( D3DTS_WORLD, &DX_structure.MatrixWorld );
DX_structure.D3DDevice->SetTexture(0,D3DTextureNumbers[score]);
DX_structure.D3DDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 2 );
}
void PlayMusic(WCHAR filename[], bool repeatmusic)
{
CHAR strPath[MAX_PATH];
GetCurrentDirectory(MAX_PATH,strPath);
strcat( strPath, "\\sounds" );
//Convert to Unicode.
WCHAR wstrSearchPath[MAX_PATH];
MultiByteToWideChar( CP_ACP, 0, strPath, -1,wstrSearchPath, MAX_PATH );
// Set the search directory.
DX_structure.g_pLoader->SetSearchDirectory( GUID_DirectMusicAllTypes, wstrSearchPath,FALSE);
DX_structure.g_pLoader->LoadObjectFromFile(CLSID_DirectMusicSegment,
IID_IDirectMus