5 Replies - 1338 Views - Last Post: 01 September 2013 - 05:53 PM Rate Topic: -----

#1 Delacar   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 40
  • Joined: 31-July 12

Question for rpg menu

Posted 01 September 2013 - 12:06 PM

Hi there guys, I'm back with another plea for help. The game that I have been working on (and that all of my questions have been for) is a rpg (which happen to be one of my favorite types of games). I am working on the formation of your the characters. My problem comes in when I try to move them, for example you choose character 1 and then select character 2. Character moves to where character 1 was also stays where character 2 was. And then when I try to change the formation again it will not work. Here is the code and I am attaching a folder that has my graphics (please note that unless the image has a the name "menu" in it then i borrowed it from the internet for the purpose of expedience)

Mywindow.cpp

#include "MyDirectX.h"
using namespace std;
bool gameover = false;

LRESULT WINAPI WinProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
    switch( msg )
    {
        case WM_DESTROY:
            gameover = true;
            PostQuitMessage(0);
            return 0;
			
		case WM_SETCURSOR:
			SetCursor(NULL);
			d3ddev->ShowCursor(false);
			return true;
    }
    return DefWindowProc( hWnd, msg, wParam, lParam );
}


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    //initialize window settings
    WNDCLASSEX wc;
    wc.cbSize = sizeof(WNDCLASSEX); 
    wc.style         = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc   = (WNDPROC)WinProc;
    wc.cbClsExtra	 = 0;
    wc.cbWndExtra	 = 0;
    wc.hInstance     = hInstance;
    wc.hIcon         = NULL;
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName  = NULL;
    wc.lpszClassName = APPTITLE.c_str();
    wc.hIconSm       = NULL;
    RegisterClassEx(&wc);

    //create a new window
    HWND window = CreateWindow( APPTITLE.c_str(), APPTITLE.c_str(),
       WS_OVERLAPPEDWINDOW, 0, 0,
       SCREENW, SCREENH, NULL, NULL, hInstance, NULL);
    if (window == 0) return 0;

    //display the window
    ShowWindow(window, nCmdShow);
    UpdateWindow(window);
	
	//initialize the game
    if (!Game_Init(window)) return 0;

    // main message loop
	MSG message;
	while (!gameover)
    {
        if (PeekMessage(&message, NULL, 0, 0, PM_REMOVE)) 
	    {
		    TranslateMessage(&message);
		    DispatchMessage(&message);
	    }

        //process game loop 
        Game_Run(window);
    }

    //shutdown
    Game_End();
	return message.wParam;
}




MyDirectX.cpp

#include "MyDirectX.h"
#include <iostream>
#include <string>
using namespace std;

//Direct3D variables
LPDIRECT3D9 d3d = NULL; 
LPDIRECT3DDEVICE9 d3ddev = NULL; 
LPDIRECT3DSURFACE9 backbuffer = NULL;
LPD3DXSPRITE spriteobj;

//DirectInput variables
LPDIRECTINPUT8 dinput = NULL;
LPDIRECTINPUTDEVICE8 dimouse = NULL;
LPDIRECTINPUTDEVICE8 dikeyboard = NULL;
DIMOUSESTATE mouse_state;
char keys[256];
XINPUT_GAMEPAD controllers[4];


bool Direct3D_Init(HWND window, int width, int height, bool fullscreen)
{
    //initialize Direct3D
    d3d = Direct3DCreate9(D3D_SDK_VERSION);
    if (!d3d) return false;

    //set Direct3D presentation parameters
    D3DPRESENT_PARAMETERS d3dpp; 
    ZeroMemory(&d3dpp, sizeof(d3dpp));
    d3dpp.hDeviceWindow = window;
    d3dpp.Windowed = (!fullscreen);
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    d3dpp.EnableAutoDepthStencil = 1;
    d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
    d3dpp.Flags = D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL;
    d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
    d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
    d3dpp.BackBufferCount = 1;
    d3dpp.BackBufferWidth = width;
    d3dpp.BackBufferHeight = height;

    //create Direct3D device
    d3d->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window,
        D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev);
    if (!d3ddev) return false;


    //get a pointer to the back buffer surface
    d3ddev->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);

    //create sprite object
    D3DXCreateSprite(d3ddev, &spriteobj);

    return 1;
}

void Direct3D_Shutdown()
{
    if (spriteobj) spriteobj->Release();

    if (d3ddev) d3ddev->Release();
    if (d3d) d3d->Release();
}

void DrawSurface(LPDIRECT3DSURFACE9 dest, float x, float y, LPDIRECT3DSURFACE9 source)
{
    //get width/height from source surface
    D3DSURFACE_DESC desc;
    source->GetDesc(&desc);

    //create rects for drawing
    RECT source_rect = {0, 0, (long)desc.Width, (long)desc.Height };
    RECT dest_rect = { (long)x, (long)y, (long)x+desc.Width, (long)y+desc.Height};
    
    //draw the source surface onto the dest
    d3ddev->StretchRect(source, &source_rect, dest, &dest_rect, D3DTEXF_NONE);

}

LPDIRECT3DSURFACE9 LoadSurface(string filename)
{
    LPDIRECT3DSURFACE9 image = NULL;
    
    //get width and height from bitmap file
    D3DXIMAGE_INFO info;
    HRESULT result = D3DXGetImageInfoFromFile(filename.c_str(), &info);
    if (result != D3D_OK)
        return NULL;

    //create surface
    result = d3ddev->CreateOffscreenPlainSurface(
        info.Width,         //width of the surface
        info.Height,        //height of the surface
        D3DFMT_X8R8G8B8,    //surface format
        D3DPOOL_DEFAULT,    //memory pool to use
        &image,             //pointer to the surface
        NULL);              //reserved (always NULL)

    if (result != D3D_OK) return NULL;

    //load surface from file into newly created surface
    result = D3DXLoadSurfaceFromFile(
        image,                  //destination surface
        NULL,                   //destination palette
        NULL,                   //destination rectangle
        filename.c_str(),       //source filename
        NULL,                   //source rectangle
        D3DX_DEFAULT,           //controls how image is filtered
        D3DCOLOR_XRGB(0,0,0),   //for transparency (0 for none)
        NULL);                  //source image info (usually NULL)

    //make sure file was loaded okay
    if (result != D3D_OK) return NULL;

    return image;
}


LPDIRECT3DTEXTURE9 LoadTexture(std::string filename, D3DCOLOR transcolor)
{  
    LPDIRECT3DTEXTURE9 texture = NULL;

    //get width and height from bitmap file
    D3DXIMAGE_INFO info;
    HRESULT result = D3DXGetImageInfoFromFile(filename.c_str(), &info);
    if (result != D3D_OK) return NULL;

    //create the new texture by loading a bitmap image file
	D3DXCreateTextureFromFileEx( 
        d3ddev,                //Direct3D device object
        filename.c_str(),      //bitmap filename
        info.Width,            //bitmap image width
        info.Height,           //bitmap image height
        1,                     //mip-map levels (1 for no chain)
        D3DPOOL_DEFAULT,       //the type of surface (standard)
        D3DFMT_UNKNOWN,        //surface format (default)
        D3DPOOL_DEFAULT,       //memory class for the texture
        D3DX_DEFAULT,          //image filter
        D3DX_DEFAULT,          //mip filter
        transcolor,            //color key for transparency
        &info,                 //bitmap file info (from loaded file)
        NULL,                  //color palette
        &texture );            //destination texture

    //make sure the bitmap texture was loaded correctly
    if (result != D3D_OK) return NULL;

	return texture;
}

D3DXVECTOR2 GetBitmapSize(string filename)
{
	D3DXIMAGE_INFO info;
	D3DXVECTOR2 size = D3DXVECTOR2(0.0f, 0.0f);
	HRESULT result = D3DXGetImageInfoFromFile(filename.c_str(), &info);
	if(result == D3D_OK)
		size = D3DXVECTOR2((float)info.Width, (float)info.Height);
	else
		size = D3DXVECTOR2((float)info.Width, (float)info.Height);
	return size;
}

void Sprite_Draw_Frame(LPDIRECT3DTEXTURE9 texture, int destx, int desty, int framenum, int framew, int frameh, int columns)
{
	D3DXVECTOR3 position( (float)destx, (float)desty, 0 );
	D3DCOLOR white = D3DCOLOR_XRGB(255,255,255);

	RECT rect;
 	rect.left = (framenum % columns) * framew;
	rect.top = (framenum / columns) * frameh;
	rect.right = rect.left + framew;
	rect.bottom = rect.top + frameh;

	spriteobj->Draw( texture, &rect, NULL, &position, white);
}

void Sprite_Animate(int &frame, int startframe, int endframe, int direction, int &starttime, int delay)
{
	if ((int)GetTickCount() > starttime + delay)
	{
		starttime = GetTickCount();

		frame += direction;
		if (frame > endframe) frame = startframe;
		if (frame < startframe) frame = endframe;
	}	
}
void Sprite_Transform_Draw(LPDIRECT3DTEXTURE9 image, int x, int y, int width, int height, 
    int frame, int columns, float rotation, float scaling, D3DCOLOR color)
{
    //create a scale vector
    D3DXVECTOR2 scale( scaling, scaling );

    //create a translate vector
    D3DXVECTOR2 trans( x, y );

    //set center by dividing width and height by two
    D3DXVECTOR2 center( (float)( width * scaling )/2, (float)( height * scaling )/2);

    //create 2D transformation matrix
    D3DXMATRIX mat;
    D3DXMatrixTransformation2D( &mat, NULL, 0, &scale, &center, rotation, &trans );
    
    //tell sprite object to use the transform
    spriteobj->SetTransform( &mat );

    //calculate frame location in source image
    int fx = (frame % columns) * width;
    int fy = (frame / columns) * height;
    RECT srcRect = {fx, fy, fx + width, fy + height};

    //draw the sprite frame
    spriteobj->Draw( image, &srcRect, NULL, NULL, color );
}

//bounding  box collision detection
int Collision(SPRITE sprite1, SPRITE sprite2)
{
    RECT rect1;
    rect1.left = (long)sprite1.x;
    rect1.top = (long)sprite1.y;
	rect1.right = (long)sprite1.x + sprite1.width * sprite1.scaling;
	rect1.bottom = (long)sprite1.y + sprite1.height * sprite1.scaling;

    RECT rect2;
    rect2.left = (long)sprite2.x;
    rect2.top = (long)sprite2.y;
	rect2.right = (long)sprite2.x + sprite2.width * sprite2.scaling;
	rect2.bottom = (long)sprite2.y + sprite2.height * sprite2.scaling;

    RECT dest; //ignored
    return IntersectRect(&dest, &rect1, &rect2);
}


bool CollisionD(SPRITE sprite1, SPRITE sprite2)
{
    double radius1, radius2;

    //calculate radius 1
    if (sprite1.width > sprite1.height)
		radius1 = (sprite1.width * sprite1.scaling) / 2.0;
    else
		radius1 = (sprite1.height * sprite1.scaling) / 2.0;

    //center point 1
    double x1 = sprite1.x + radius1;
    double y1 = sprite1.y + radius1;
	D3DXVECTOR2 vector1(x1, y1);

    //calculate radius 2
    if (sprite2.width > sprite2.height)
		radius2 = (sprite2.width * sprite2.scaling) / 2.0;
    else
		radius2 = (sprite2.height * sprite2.scaling) / 2.0;

    //center point 2
    double x2 = sprite2.x + radius2;
    double y2 = sprite2.y + radius2;
    D3DXVECTOR2 vector2(x2, y2);

    //calculate distance
	double deltax = vector1.x - vector2.x;
	double deltay = vector2.y - vector1.y;
    double dist = sqrt((deltax * deltax) + (deltay * deltay));

    //return distance comparison
	return (dist < radius1 + radius2);
}

bool DirectInput_Init(HWND hwnd)
{
    //initialize DirectInput object
    DirectInput8Create(
        GetModuleHandle(NULL), 
        DIRECTINPUT_VERSION, 
        IID_IDirectInput8,
        (void**)&dinput,
        NULL);

    //initialize the keyboard
    dinput->CreateDevice(GUID_SysKeyboard, &dikeyboard, NULL);
    dikeyboard->SetDataFormat(&c_dfDIKeyboard);
    dikeyboard->SetCooperativeLevel(hwnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
    dikeyboard->Acquire();

    //initialize the mouse
    dinput->CreateDevice(GUID_SysMouse, &dimouse, NULL);
    dimouse->SetDataFormat(&c_dfDIMouse);
    dimouse->SetCooperativeLevel(hwnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
    dimouse->Acquire();
    d3ddev->ShowCursor(false);

    return true;
}

void DirectInput_Update()
{
    //update mouse
    dimouse->Poll();
    if (!SUCCEEDED(dimouse->GetDeviceState(sizeof(DIMOUSESTATE),&mouse_state)))
    {
        //mouse device lose, try to re-acquire
        dimouse->Acquire();
    }

    //update keyboard
    dikeyboard->Poll();
    if (!SUCCEEDED(dikeyboard->GetDeviceState(256,(LPVOID)&keys)))
    {
        //keyboard device lost, try to re-acquire
        dikeyboard->Acquire();
    }

    //update controllers
    for (int i=0; i< 4; i++ )
    {
        ZeroMemory( &controllers[i], sizeof(XINPUT_STATE) );

        //get the state of the controller
        XINPUT_STATE state;
        DWORD result = XInputGetState( i, &state );

        //store state in global controllers array
        if (result == 0) controllers[i] = state.Gamepad;
    }
}


int Mouse_X()
{
    return mouse_state.lX;
}

int Mouse_Y()
{
    return mouse_state.lY;
}

int Mouse_Button(int button)
{
    return mouse_state.rgbButtons[button] & 0x80;
}

bool Key_Down(int key) 
{
    return (bool)(keys[key] & 0x80);
}


void DirectInput_Shutdown()
{
    if (dikeyboard) 
    {
        dikeyboard->Unacquire();
        dikeyboard->Release();
        dikeyboard = NULL;
    }
    if (dimouse) 
    {
        dimouse->Unacquire();
        dimouse->Release();
        dimouse = NULL;
    }
}

bool XInput_Controller_Found()
{
    XINPUT_CAPABILITIES caps;
    ZeroMemory(&caps, sizeof(XINPUT_CAPABILITIES));
    XInputGetCapabilities(0, XINPUT_FLAG_GAMEPAD, &caps);
    if (caps.Type != 0) return false;
    
    return true;
}

void XInput_Vibrate(int contNum, int amount)
{
    XINPUT_VIBRATION vibration;
    ZeroMemory( &vibration, sizeof(XINPUT_VIBRATION) );
    vibration.wLeftMotorSpeed = amount;
    vibration.wRightMotorSpeed = amount; 
    XInputSetState( contNum, &vibration );
}

LPD3DXFONT MakeFont(string name, int size)
{
    LPD3DXFONT font = NULL;

    D3DXFONT_DESC desc = {
        size,                   //height
        0,                      //width
        0,                      //weight
        0,                      //miplevels
        false,                  //italic
        DEFAULT_CHARSET,        //charset
        OUT_TT_PRECIS,          //output precision
        CLIP_DEFAULT_PRECIS,    //quality
        DEFAULT_PITCH,          //pitch and family
        ""                      //font name
    };

    strcpy(desc.FaceName, name.c_str());

    D3DXCreateFontIndirect(d3ddev, &desc, &font);

    return font;
}

void FontPrint(LPD3DXFONT font, int x, int y, string text, D3DCOLOR color)
{
    //figure out the text boundary
    RECT rect = { x, y, 0, 0 };
    font->DrawText( NULL, text.c_str(), text.length(), &rect, DT_CALCRECT, color); 

    //print the text
    font->DrawText(spriteobj, text.c_str(), text.length(), &rect, DT_LEFT, color); 
}




MyDirectX.h

#pragma once

//header files
#define WIN32_EXTRA_LEAN
#define DIRECTINPUT_VERSION 0x0800
#include <windows.h>
#include <d3d9.h>
#include <d3dx9.h>
#include <dinput.h>
#include <xinput.h>
#include <ctime>
#include <iostream>
#include <iomanip>
using namespace std;

//libraries
#pragma comment(lib,"winmm.lib")
#pragma comment(lib,"user32.lib")
#pragma comment(lib,"gdi32.lib")
#pragma comment(lib,"dxguid.lib")
#pragma comment(lib,"d3d9.lib")
#pragma comment(lib,"d3dx9.lib")
#pragma comment(lib,"dinput8.lib")
#pragma comment(lib,"xinput.lib")

//program values
extern const string APPTITLE;
extern const int SCREENW;
extern const int SCREENH;
extern bool gameover;

//macro to detect key presses
#define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)

//Direct3D objects
extern LPDIRECT3D9 d3d; 
extern LPDIRECT3DDEVICE9 d3ddev; 
extern LPDIRECT3DSURFACE9 backbuffer;
extern LPD3DXSPRITE spriteobj;

//sprite structure
struct SPRITE
{
	float x,y;
	int frame, columns;
	int width, height;
	float scaling, rotation;
	int startframe, endframe;
	int starttime, delay;
	int direction;
	float velx, vely;
	D3DCOLOR color;

	SPRITE() 
	{
		frame = 0;
		columns = 1;
		width = 0;
		height = 0;
		scaling = 1.0f;
		rotation = 0.0f;
		startframe = endframe = 0;
		direction = 1;
		starttime = 0;
		delay = 100;
		velx = vely = 0.0f;
		color = D3DCOLOR_XRGB(255,255,255);
	}
};

//Direct3D functions
bool Direct3D_Init(HWND hwnd, int width, int height, bool fullscreen);
void Direct3D_Shutdown();
LPDIRECT3DSURFACE9 LoadSurface(string filename);
void DrawSurface(LPDIRECT3DSURFACE9 dest, float x, float y, LPDIRECT3DSURFACE9 source);
D3DXVECTOR2 GetBitmapSize(string filename);
LPDIRECT3DTEXTURE9 LoadTexture(string filename, D3DCOLOR transcolor = D3DCOLOR_XRGB(0,0,0));
void Sprite_Draw_Frame(LPDIRECT3DTEXTURE9 texture, int destx, int desty, 
    int framenum, int framew, int frameh, int columns);
void Sprite_Animate(int &frame, int startframe, int endframe, int direction, int &starttime, int delay);

//*** ADDED in chapter 7
void Sprite_Transform_Draw(LPDIRECT3DTEXTURE9 image, int x, int y, int width, int height, 
    int frame = 0, int columns = 1, float rotation = 0.0f, float scaling = 1.0f, 
    D3DCOLOR color = D3DCOLOR_XRGB(255,255,255));

//bounding box collision detection
int Collision(SPRITE sprite1, SPRITE sprite2);

//distance based collision detection
bool CollisionD(SPRITE sprite1, SPRITE sprite2);

//DirectInput objects, devices, and states
extern LPDIRECTINPUT8 dinput;
extern LPDIRECTINPUTDEVICE8 dimouse;
extern LPDIRECTINPUTDEVICE8 dikeyboard;
extern DIMOUSESTATE mouse_state;
extern XINPUT_GAMEPAD controllers[4];

//DirectInput functions
bool DirectInput_Init(HWND);
void DirectInput_Update();
void DirectInput_Shutdown();
bool Key_Down(int);
int Mouse_Button(int);
int Mouse_X();
int Mouse_Y();
void XInput_Vibrate(int contNum = 0, int amount = 65535);
bool XInput_Controller_Found();

//game functions
bool Game_Init(HWND window);
void Game_Run(HWND window);
void Game_End();


//font functions
LPD3DXFONT MakeFont(string name, int size);
void FontPrint(LPD3DXFONT font, int x, int y, string text, D3DCOLOR color = D3DCOLOR_XRGB(255,255,255));



MyGame.cpp

#include "MyDirectX.h"
#include <sstream>
using namespace std;

const string APPTITLE = "Tile-Based Static Scrolling";
const int SCREENW = 1280;
const int SCREENH = 720;
SPRITE Fayt, MenuI, MenuS, MenuE, MenuF, StandardC, FormC,
FormC2, FaytFace, MariaFace, AlbelFace;

LPDIRECT3DTEXTURE9 imgFayt = NULL;
LPDIRECT3DTEXTURE9 imgFaytFace = NULL;
LPDIRECT3DTEXTURE9 imgMariaFace = NULL;
LPDIRECT3DTEXTURE9 imgAlbelFace = NULL;
LPDIRECT3DTEXTURE9 imgMenuItems = NULL;
LPDIRECT3DTEXTURE9 imgMenuStatus = NULL;
LPDIRECT3DTEXTURE9 imgMenuEquip = NULL;
LPDIRECT3DTEXTURE9 imgMenuForm = NULL;
LPDIRECT3DTEXTURE9 imgFormC = NULL;
LPDIRECT3DTEXTURE9 imgFormC2 = NULL;
LPDIRECT3DTEXTURE9 imgStandardC = NULL;
LPD3DXFONT font;


// so you can't have more than one menu open
bool MenuOpen = false;
bool MenuEquipment = false;
bool MenuStatus = false;
bool MenuItems = false;
bool MenuForm = false;
bool position = false;
bool pos = false;
bool pos_1 = false;
bool pos1 = false;
bool pos1_1 = false;
bool pos1_2 = false;
bool pos2 = false;
bool pos2_1 = false;
bool pos2_2 = false;
bool pos3 = false;
bool pos3_1 = false;
bool pos3_2 = false;

//settings for the scroller
const int IMenuTileW = 80;
const int IMenuTileH = 80;
const int IMenuMapW = 16;
const int IMenuMapH = 9;

const int SMenuTileW = 80;
const int SMenuTileH = 80;
const int SMenuMapW = 16;
const int SMenuMapH = 9;

const int EMenuTileW = 80;
const int EMenuTileH = 80;
const int EMenuMapW = 16;
const int EMenuMapH = 9;

const int MENUTILEW = 80;
const int MENUTILEH = 80;
const int MENUMAPW = 16;
const int MENUMAPH = 9;
const int TILEWIDTH = 64;
const int TILEHEIGHT = 64;
const int MAPWIDTH = 22;
const int MAPHEIGHT = 25;

//scrolling window size
const int IMenuWindowW = (SCREENW / IMenuTileW) * IMenuTileW;
const int IMenuWindowH = (SCREENH / IMenuTileH) * IMenuTileH;

const int SMenuWindowW = (SCREENW / SMenuTileW) * SMenuTileW;
const int SMenuWindowH = (SCREENH / SMenuTileH) * SMenuTileH;

const int EMenuWindowW = (SCREENW / EMenuTileW) * EMenuTileW;
const int EMenuWindowH = (SCREENH / EMenuTileH) * EMenuTileH;

const int MenuWindowW = (SCREENW / MENUTILEW) * MENUTILEW;
const int MenuWindowH = (SCREENH / MENUTILEH) * MENUTILEH;
const int WINDOWWIDTH = (SCREENW / TILEWIDTH) * TILEWIDTH;
const int WINDOWHEIGHT = (SCREENH / TILEHEIGHT) * TILEHEIGHT;

//entire game world dimensions
const int ItemsMenuWidth = IMenuTileW * IMenuMapW;
const int ItemsMenuHeight = IMenuTileH * IMenuMapH;

const int StatusMenuWidth = SMenuTileW * SMenuMapW;
const int StatusMenuHeight = SMenuTileH * SMenuMapH;

const int EquipMenuWidth = EMenuTileW * EMenuMapW;
const int EquipMenuHeight = EMenuTileH * EMenuMapH;

const int GameMenuWidth = MENUTILEW * MENUMAPW;
const int GameMenuHeight = MENUTILEH * MENUMAPH;
const int GAMEWORLDWIDTH = TILEWIDTH * MAPWIDTH;
const int GAMEWORLDHEIGHT = TILEHEIGHT * MAPHEIGHT;

int ScrollX, ScrollY;	
int SpeedX, SpeedY;					
long start;
LPDIRECT3DSURFACE9 gameworld = NULL;
LPDIRECT3DSURFACE9 menu = NULL;
LPDIRECT3DSURFACE9 IMenu = NULL;
LPDIRECT3DSURFACE9 SMenu = NULL;
LPDIRECT3DSURFACE9 EMenu = NULL;

int Item_Menu[IMenuMapW*IMenuMapH] = {
	0,9,9,9,9,9,9,9,9,9,9,9,9,9,9,2,
	6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,4,
	6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,4,
	6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,4,
	6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,4,
	6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,4,
	6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,4,
	6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,4,
	8,1,1,1,1,1,1,1,1,1,1,1,1,1,1,10
};

int Status_Menu[SMenuMapW*SMenuMapH] = {
	0,9,9,11,9,9,9,9,9,9,9,9,9,9,9,2,
	6,5,5,4,5,5,5,5,5,5,5,5,5,5,5,4,
	6,5,5,4,9,9,9,11,9,9,9,9,9,9,9,11,
	7,9,9,9,5,5,5,4,5,5,5,5,5,5,5,4,
	6,5,5,5,5,5,5,4,5,5,5,5,5,5,5,4,
	6,5,5,5,5,5,5,4,5,5,5,5,5,5,5,4,
	6,5,5,5,5,5,5,4,5,5,5,5,5,5,5,4,
	6,5,5,5,5,5,5,4,5,5,5,5,5,5,5,4,
	8,1,1,1,1,1,1,12,1,1,1,1,1,1,1,10
};

int Equip_Menu[EMenuMapW*EMenuMapH] = {
	0,9,9,9,9,9,9,9,9,9,9,9,9,9,9,2,
	6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,4,
	7,9,9,9,9,9,9,11,9,9,9,9,9,9,9,11,
	6,5,5,5,5,5,5,4,5,5,5,5,5,5,5,4,
	6,5,5,5,5,5,5,4,5,5,5,5,5,5,5,4,
	6,5,5,5,5,5,5,4,5,5,5,5,5,5,5,4,
	6,5,5,5,5,5,5,4,5,5,5,5,5,5,5,4,
	6,5,5,5,5,5,5,4,5,5,5,5,5,5,5,4,
	8,1,1,1,1,1,1,12,1,1,1,1,1,1,1,10
};

int MENU_MAP[MENUMAPW*MENUMAPH] = {
	0,9,9,9,9,9,9,9,9,9,9,9,7,9,9,2,
	6,5,5,5,5,5,5,5,5,5,5,5,6,5,5,4,
	6,5,5,5,5,5,5,5,5,5,5,5,6,5,5,4,
	6,5,5,5,5,5,5,5,5,5,5,5,6,5,5,4,
	6,5,5,5,5,5,5,5,5,5,5,5,6,5,5,4,
	6,5,5,5,5,5,5,5,5,5,5,5,6,5,5,4,
	6,5,5,5,5,5,5,5,5,5,5,5,6,5,5,4,
	6,5,5,5,5,5,5,5,5,5,5,5,7,9,9,11,
	8,1,1,1,1,1,1,1,1,1,1,1,3,1,1,10
};

int MAPDATA[MAPWIDTH*MAPHEIGHT] = {
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3
};

void DrawTile(LPDIRECT3DSURFACE9 source,	// source surface image
				int tilenum,				// tile #
				int width,					// tile width
				int height,					// tile height
				int columns,				// columns of tiles
				LPDIRECT3DSURFACE9 dest,	// destination surface
				int destx,					// destination x
				int desty)					// destination y
{
    
    //create a RECT to describe the source image
    RECT r1;
    r1.left = (tilenum % columns) * width;
    r1.top = (tilenum / columns) * height;
    r1.right = r1.left + width;
    r1.bottom = r1.top + height;
    
    //set destination rect
	RECT r2 = {destx,desty,destx+width,desty+height};
    
    //draw the tile 
    d3ddev->StretchRect(source, &r1, dest, &r2, D3DTEXF_NONE);
}

void BuildGameWorld()
{
	HRESULT result;
    int x, y;
    LPDIRECT3DSURFACE9 tiles;
    
    //load the bitmap image containing all the tiles
    tiles = LoadSurface("groundtiles.bmp");
    
    //create the scrolling game world bitmap
    result = d3ddev->CreateOffscreenPlainSurface(
		GAMEWORLDWIDTH,         //width of the surface
		GAMEWORLDHEIGHT,        //height of the surface
		D3DFMT_X8R8G8B8,		
		D3DPOOL_DEFAULT,		
		&gameworld,             //pointer to the surface
		NULL);
	
    if (result != D3D_OK)
	{
        MessageBox(NULL,"Error creating working surface!","Error",0);
		return;
	}
    
    //fill the gameworld bitmap with tiles
    for (y=0; y < MAPHEIGHT; y++)
        for (x=0; x < MAPWIDTH; x++)
            DrawTile(tiles, MAPDATA[y * MAPWIDTH + x], 64, 64, 16, 
            gameworld, x * 64, y * 64);
        
    //now the tiles bitmap is no longer needed
    tiles->Release();
}

void BuildMenu()
{
	HRESULT result;
    int x, y;
    LPDIRECT3DSURFACE9 tiles;
    
    //load the bitmap image containing all the tiles
    tiles = LoadSurface("Menu.bmp");
    
    //create the scrolling game world bitmap
    result = d3ddev->CreateOffscreenPlainSurface(
		GameMenuWidth,         //width of the surface
		GameMenuHeight,        //height of the surface
		D3DFMT_X8R8G8B8,		
		D3DPOOL_DEFAULT,		
		&menu,             //pointer to the surface
		NULL);
	
    if (result != D3D_OK)
	{
        MessageBox(NULL,"Error creating working surface!","Error",0);
		return;
	}
    
    //fill the gameworld bitmap with tiles
    for (y=0; y < MENUMAPH; y++)
        for (x=0; x < MENUMAPW; x++)
            DrawTile(tiles, MENU_MAP[y * MENUMAPW + x], 80, 80, 4, 
            menu, x * 80, y *80);
        
    //now the tiles bitmap is no longer needed
   tiles->Release();
}

void BuildItemMenu()
{
	HRESULT result;
    int x, y;
    LPDIRECT3DSURFACE9 Itiles;
    
    //load the bitmap image containing all the tiles
    Itiles = LoadSurface("IMenu.bmp");
    
    //create the scrolling game world bitmap
    result = d3ddev->CreateOffscreenPlainSurface(
		ItemsMenuWidth,         //width of the surface
		ItemsMenuHeight,        //height of the surface
		D3DFMT_X8R8G8B8,		
		D3DPOOL_DEFAULT,		
		&IMenu,             //pointer to the surface
		NULL);
	
    if (result != D3D_OK)
	{
        MessageBox(NULL,"Error creating working surface!","Error",0);
		return;
	}
    
    //fill the gameworld bitmap with tiles
    for (y=0; y < IMenuMapH; y++)
        for (x=0; x < IMenuMapW; x++)
            DrawTile(Itiles, Item_Menu[y * IMenuMapW + x], 80, 80, 4, 
            IMenu, x * 80, y *80);
        
    //now the tiles bitmap is no longer needed
   Itiles->Release();
}

void BuildStatusMenu()
{
	HRESULT result;
    int x, y;
    LPDIRECT3DSURFACE9 Stiles;
    
    //load the bitmap image containing all the tiles
    Stiles = LoadSurface("SMenu.bmp");
    
    //create the scrolling game world bitmap
    result = d3ddev->CreateOffscreenPlainSurface(
		StatusMenuWidth,         //width of the surface
		StatusMenuHeight,        //height of the surface
		D3DFMT_X8R8G8B8,		
		D3DPOOL_DEFAULT,		
		&SMenu,             //pointer to the surface
		NULL);
	
    if (result != D3D_OK)
	{
        MessageBox(NULL,"Error creating working surface!","Error",0);
		return;
	}
    
    //fill the gameworld bitmap with tiles
    for (y=0; y < IMenuMapH; y++)
        for (x=0; x < IMenuMapW; x++)
            DrawTile(Stiles, Status_Menu[y * SMenuMapW + x], 80, 80, 4, 
            SMenu, x * 80, y *80);
        
    //now the tiles bitmap is no longer needed
   Stiles->Release();
}

void BuildEquipMenu()
{
	HRESULT result;
    int x, y;
    LPDIRECT3DSURFACE9 Etiles;
    
    //load the bitmap image containing all the tiles
    Etiles = LoadSurface("EMenu.bmp");
    
    //create the scrolling game world bitmap
    result = d3ddev->CreateOffscreenPlainSurface(
		EquipMenuWidth,         //width of the surface
		EquipMenuHeight,        //height of the surface
		D3DFMT_X8R8G8B8,		
		D3DPOOL_DEFAULT,		
		&EMenu,             //pointer to the surface
		NULL);
	
    if (result != D3D_OK)
	{
        MessageBox(NULL,"Error creating working surface!","Error",0);
		return;
	}
    
    //fill the gameworld bitmap with tiles
    for (y=0; y < EMenuMapH; y++)
        for (x=0; x < EMenuMapW; x++)
            DrawTile(Etiles, Equip_Menu[y * EMenuMapW + x], 80, 80, 4, 
            EMenu, x * 80, y *80);
        
    //now the tiles bitmap is no longer needed
   Etiles->Release();
}

bool Game_Init(HWND window)
{
    Direct3D_Init(window, SCREENW, SCREENH, true);

	// initialize Direct3D
    DirectInput_Init(window);

    //create pointer to the back buffer
    d3ddev->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);

    //create a font
    font = MakeFont("Arial", 24);

    BuildGameWorld();

	BuildMenu();

	BuildItemMenu();

	BuildStatusMenu();

	BuildEquipMenu();

	start = GetTickCount();

	imgMenuItems = LoadTexture("MenuItems.tga");
	if(!imgMenuItems) return false;

	imgMenuStatus = LoadTexture("MenuStatus.tga");
	if(!imgMenuStatus) return false;

	imgMenuEquip = LoadTexture("MenuEquipment.tga");
	if(!imgMenuEquip) return false;

	imgMenuForm = LoadTexture("MenuFormation.tga");
	if(!imgMenuEquip) return false;

	imgStandardC = LoadTexture("StandardCursor.tga");
	if(!imgStandardC) return false;

	imgFormC = LoadTexture("StandardCursor.tga");
	if(!imgFormC) return false;

	imgFormC2 = LoadTexture("StandardCursor.tga");
	if(!imgFormC2) return false;

	// load transparent image
	imgFayt = LoadTexture("Fayt.tga");
	if (!imgFayt) return false;

	imgFaytFace = LoadTexture("FaytFace.tga");
	if (!imgFaytFace) return false;

	imgMariaFace = LoadTexture("MariaFace.tga");
	if (!imgMariaFace) return false;

	imgAlbelFace = LoadTexture("AlbelFace.tga");
	if (!imgAlbelFace) return false;

	Fayt.x = 0;
	Fayt.y = 0;
	Fayt.width = 50;
	Fayt.height = 75;
	Fayt.columns = 4;

	FaytFace.x = 80;
	FaytFace.y = 60;
	FaytFace.width = 160;
	FaytFace.height = 160;

	MariaFace.x = 80;
	MariaFace.y = 280;
	MariaFace.width = 160;
	MariaFace.height = 160;

	AlbelFace.x = 80;
	AlbelFace.y = 500;
	AlbelFace.width = 160;
	AlbelFace.height = 160;

	MenuI.width = 104;
	MenuI.height = 40;

	MenuS.width = 112;
	MenuS.height = 40;

	MenuE.width = 192;
	MenuE.height = 40;

	MenuF.width = 176;
	MenuF.height = 40;

	FormC.x = 40;
	FormC.y = 140;
	FormC.width = 32;
	FormC.height = 32;

	FormC2.x = 40;
	FormC2.y = 140;
	FormC2.width = 32;
	FormC2.height = 32;

	StandardC.x = 1000;
	StandardC.y = 60;
	StandardC.width = 32;
	StandardC.height = 32;

    return true;
}

void ItemScreen()
{
    //update horizontal scrolling position and speed
    ScrollX += SpeedX;
    if (ScrollX < 0) 
	{
        ScrollX = 0;
        SpeedX = 0;
	}
    else if (ScrollX > ItemsMenuWidth - SCREENW)
	{
        ScrollX = ItemsMenuWidth - SCREENW;
        SpeedX = 0;
	}
    
    //update vertical scrolling position and speed
    ScrollY += SpeedY;
    if (ScrollY < 0)
	{
        ScrollY = 0;
        SpeedY = 0;
	}
    else if (ScrollY > ItemsMenuHeight - SCREENH)
	{
        ScrollY = ItemsMenuHeight - SCREENH;
        SpeedY = 0;
	}
    
    //set dimensions of the source image
	RECT r1 = {ScrollX, ScrollY, ScrollX+SCREENW-1, ScrollY+SCREENH-1};
    
    //set the destination rect
	RECT r2 = {0, 0, SCREENW-1, SCREENH-1};
    
    //draw the current game world view
    d3ddev->StretchRect(IMenu, &r1, backbuffer, &r2, 
        D3DTEXF_NONE);

}

void StatusScreen()
{
    //update horizontal scrolling position and speed
    ScrollX += SpeedX;
    if (ScrollX < 0) 
	{
        ScrollX = 0;
        SpeedX = 0;
	}
    else if (ScrollX > StatusMenuWidth - SCREENW)
	{
        ScrollX = StatusMenuWidth - SCREENW;
        SpeedX = 0;
	}
    
    //update vertical scrolling position and speed
    ScrollY += SpeedY;
    if (ScrollY < 0)
	{
        ScrollY = 0;
        SpeedY = 0;
	}
    else if (ScrollY > StatusMenuHeight - SCREENH)
	{
        ScrollY = StatusMenuHeight - SCREENH;
        SpeedY = 0;
	}
    
    //set dimensions of the source image
	RECT r1 = {ScrollX, ScrollY, ScrollX+SCREENW-1, ScrollY+SCREENH-1};
    
    //set the destination rect
	RECT r2 = {0, 0, SCREENW-1, SCREENH-1};
    
    //draw the current game world view
    d3ddev->StretchRect(SMenu, &r1, backbuffer, &r2, 
        D3DTEXF_NONE);

}

void EquipmentScreen()
{
    //update horizontal scrolling position and speed
    ScrollX += SpeedX;
    if (ScrollX < 0) 
	{
        ScrollX = 0;
        SpeedX = 0;
	}
    else if (ScrollX > EquipMenuWidth - SCREENW)
	{
        ScrollX = EquipMenuWidth - SCREENW;
        SpeedX = 0;
	}
    
    //update vertical scrolling position and speed
    ScrollY += SpeedY;
    if (ScrollY < 0)
	{
        ScrollY = 0;
        SpeedY = 0;
	}
    else if (ScrollY > EquipMenuHeight - SCREENH)
	{
        ScrollY = EquipMenuHeight - SCREENH;
        SpeedY = 0;
	}
    
    //set dimensions of the source image
	RECT r1 = {ScrollX, ScrollY, ScrollX+SCREENW-1, ScrollY+SCREENH-1};
    
    //set the destination rect
	RECT r2 = {0, 0, SCREENW-1, SCREENH-1};
    
    //draw the current game world view
    d3ddev->StretchRect(EMenu, &r1, backbuffer, &r2, 
        D3DTEXF_NONE);

}

void MenuScreen()
{
    //update horizontal scrolling position and speed
    ScrollX += SpeedX;
    if (ScrollX < 0) 
	{
        ScrollX = 0;
        SpeedX = 0;
	}
    else if (ScrollX > GameMenuWidth - SCREENW)
	{
        ScrollX = GameMenuWidth - SCREENW;
        SpeedX = 0;
	}
    
    //update vertical scrolling position and speed
    ScrollY += SpeedY;
    if (ScrollY < 0)
	{
        ScrollY = 0;
        SpeedY = 0;
	}
    else if (ScrollY > GameMenuHeight - SCREENH)
	{
        ScrollY = GameMenuHeight - SCREENH;
        SpeedY = 0;
	}
    
    //set dimensions of the source image
	RECT r1 = {ScrollX, ScrollY, ScrollX+SCREENW-1, ScrollY+SCREENH-1};
    
    //set the destination rect
	RECT r2 = {0, 0, SCREENW-1, SCREENH-1};
    
    //draw the current game world view
    d3ddev->StretchRect(menu, &r1, backbuffer, &r2, 
        D3DTEXF_NONE);

}

void ScrollScreen()
{
    //update horizontal scrolling position and speed
    ScrollX += SpeedX;
    if (ScrollX < 0) 
	{
        ScrollX = 0;
        SpeedX = 0;
	}
    else if (ScrollX > GAMEWORLDWIDTH - SCREENW)
	{
        ScrollX = GAMEWORLDWIDTH - SCREENW;
        SpeedX = 0;
	}
    
    //update vertical scrolling position and speed
    ScrollY += SpeedY;
    if (ScrollY < 0)
	{
        ScrollY = 0;
        SpeedY = 0;
	}
    else if (ScrollY > GAMEWORLDHEIGHT - SCREENH)
	{
        ScrollY = GAMEWORLDHEIGHT - SCREENH;
        SpeedY = 0;
	}
    
    //set dimensions of the source image
	RECT r1 = {ScrollX, ScrollY, ScrollX+SCREENW-1, ScrollY+SCREENH-1};
    
    //set the destination rect
	RECT r2 = {0, 0, SCREENW-1, SCREENH-1};
    
    //draw the current game world view
    d3ddev->StretchRect(gameworld, &r1, backbuffer, &r2, 
        D3DTEXF_NONE);

}

void Game_Run(HWND window)
{
    if (!d3ddev) return;
    DirectInput_Update();
    d3ddev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,100), 1.0f, 0);

    //keep the game running at a steady frame rate
    if (GetTickCount() - start >= 30)
    {
        //reset timing
        start = GetTickCount();

		//start rendering
		if (d3ddev->BeginScene())
		{
			
            //update the scrolling view

			if(MenuOpen == false)
			{
					ScrollScreen();

					spriteobj->Begin(D3DXSPRITE_ALPHABLEND);

					Sprite_Transform_Draw(imgFayt, Fayt.x, Fayt.y, 
					Fayt.width, Fayt.height, Fayt.frame, Fayt.columns);
	
					//stop drawing
					 spriteobj->End();

				if (Key_Down(DIK_W))
				{
					Fayt.y -= 10.0f;
					if (Fayt.y < 0) 
					{
						Fayt.y = 0;
						ScrollY -= 1;
					};

					Sprite_Animate(Fayt.frame, 12, 15, 
					Fayt.direction, Fayt.starttime, Fayt.delay);
				}

				if (Key_Down(DIK_S)) 
				{
					Fayt.y += 10.0f;
					if (Fayt.y > SCREENH - Fayt.height)
					{
						Fayt.y = SCREENH - Fayt.height;
						ScrollY += 1;
					};

					Sprite_Animate(Fayt.frame, 0, 3, 
					Fayt.direction, Fayt.starttime, Fayt.delay);
				}

				if(Key_Down(DIK_A))
				{
					Fayt.x -= 10.0f;
					if (Fayt.x < 0)
					{
						Fayt.x = 0;
						ScrollX -= 1;
						};

					Sprite_Animate(Fayt.frame, 4, 7, 
					Fayt.direction, Fayt.starttime, Fayt.delay);
				}

				if(Key_Down(DIK_D))
				{		
					Fayt.x += 10.0f;
					if (Fayt.x > SCREENW - Fayt.width)
					{
						Fayt.x = SCREENW - Fayt.width;
						ScrollX += 1;
					};
	
					Sprite_Animate(Fayt.frame, 8, 11, 
					Fayt.direction, Fayt.starttime, Fayt.delay);
				}


				if(Key_Down(DIK_M))
				{
					MenuOpen = true;
					if(!pos1_1 && !pos1_2)
					{
						pos1 = true;
					}
					
					if(!pos2_1 && !pos2_2)
					{
						pos2 = true;
					}

					if(!pos3_1 && !pos3_2)
					{
						pos3 = true;
					}
				}
			}

			if(MenuOpen == true)
			{
				MenuScreen();

				spriteobj->Begin(D3DXSPRITE_ALPHABLEND);

				if (pos1 == true)
				{
					Sprite_Transform_Draw(imgFaytFace, FaytFace.x, FaytFace.y, 
						FaytFace.width, FaytFace.height, FaytFace.frame, FaytFace.columns);
				};

				if (pos1_1 == true)
				{
					Sprite_Transform_Draw(imgFaytFace, FaytFace.x, 280,
						FaytFace.width, FaytFace.height, FaytFace.frame, FaytFace.columns);
				};

				if (pos1_2 == true)
				{
					Sprite_Transform_Draw(imgFaytFace, FaytFace.x, AlbelFace.y, 
						FaytFace.width, FaytFace.height, FaytFace.frame, FaytFace.columns);
				};

				if (pos2 == true)
				{
					Sprite_Transform_Draw(imgMariaFace, MariaFace.x, MariaFace.y, 
						MariaFace.width, MariaFace.height, MariaFace.frame, MariaFace.columns);
				};

				if (pos2_1 == true)
				{
					Sprite_Transform_Draw(imgMariaFace, MariaFace.x, 60, 
						MariaFace.width, MariaFace.height, MariaFace.frame, MariaFace.columns);
				};

				if (pos2_2 == true)
				{
					Sprite_Transform_Draw(imgMariaFace, MariaFace.x, AlbelFace.y, 
						MariaFace.width, MariaFace.height, MariaFace.frame, MariaFace.columns);
				};

				if (pos3 == true)
				{
					Sprite_Transform_Draw(imgAlbelFace, AlbelFace.x, AlbelFace.y, 
						AlbelFace.width, AlbelFace.height, AlbelFace.frame, AlbelFace.columns);
				};

				if (pos3_1 == true)
				{
					Sprite_Transform_Draw(imgAlbelFace, AlbelFace.x, FaytFace.y, 
						AlbelFace.width, AlbelFace.height, AlbelFace.frame, AlbelFace.columns);
				};

				if (pos3_2 == true)
				{
					Sprite_Transform_Draw(imgAlbelFace, AlbelFace.x, MariaFace.y, 
						AlbelFace.width, AlbelFace.height, AlbelFace.frame, AlbelFace.columns);
				};

				Sprite_Transform_Draw(imgMenuItems, 1037, 50, 
					MenuI.width, MenuI.height, MenuI.frame, MenuI.columns);

				Sprite_Transform_Draw(imgMenuStatus, 1037, 100, 
					MenuS.width, MenuS.height, MenuS.frame, MenuS.columns);

				Sprite_Transform_Draw(imgMenuEquip, 1037, 150, 
					MenuE.width, MenuE.height, MenuE.frame, MenuE.columns);

				Sprite_Transform_Draw(imgMenuForm, 1037, 200, 
					MenuF.width, MenuF.height, MenuF.frame, MenuF.columns);

				Sprite_Transform_Draw(imgStandardC, StandardC.x, StandardC.y, 
						StandardC.width, StandardC.height, StandardC.frame, StandardC.columns);

				if(MenuForm != true)
				{
					if (Key_Down(DIK_W)) 
					{
						StandardC.y = StandardC.y - 50;
						if (StandardC.y < 60)
						{
							StandardC.y = 60;
							ScrollY -= 1;
						};
					}

					if (Key_Down(DIK_S)) 
					{
						StandardC.y = StandardC.y + 50;
						if (StandardC.y > 210)
						{
							StandardC.y = 210;
							ScrollY += 1;
						};
					}
				}

				if(StandardC.y == 60)
				{
					if (Key_Down(DIK_RETURN))
					{
						MenuItems = true;
					}
				};

				if(StandardC.y == 110)
				{
					if (Key_Down(DIK_RETURN))
					{
						MenuStatus = true;
					}
				};

				if(StandardC.y == 160)
				{
					if (Key_Down(DIK_RETURN))
					{
						MenuEquipment = true;
					}
				};

				if(StandardC.y == 210)
				{
					if (Key_Down(DIK_RETURN))
					{
						MenuForm = true;
					}
				};
				
				if (MenuItems == true)
				{
					ItemScreen();
				};

				if (MenuStatus == true)
				{
					StatusScreen();
				};
		
				if (MenuEquipment == true)
				{
					EquipmentScreen();
				};	

				if(MenuForm == true)
				{
					if (position == false)
					{
						if (Key_Down(DIK_W)) 
						{
							FormC.y = FormC.y - 220;
							if (FormC.y < 140)
							{
								FormC.y = 140;
								ScrollY -= 1;
							};
						}

						if (Key_Down(DIK_S)) 
						{
							FormC.y = FormC.y + 220;
							if (FormC.y > 580)
							{
								FormC.y = 580;
								ScrollY += 1;
							};
						}

						if (FormC.y == 140)
						{
							if(Key_Down(DIK_O))
							{
								pos = true;
							}
						}
					}

					spriteobj->Begin(D3DXSPRITE_ALPHABLEND);

					Sprite_Transform_Draw(imgFormC, FormC.x, FormC.y, 
					FormC.width, FormC.height, FormC.frame, FormC.columns);

					spriteobj->End();
				}

				if (pos == true)
				{
					position = true;

					if (Key_Down(DIK_W)) 
					{
						FormC2.y = FormC2.y - 220;
						if (FormC2.y < 140)
						{
							FormC.y = 140;
							ScrollY -= 1;
						};
					}

					if (Key_Down(DIK_S)) 
					{
						FormC2.y = FormC2.y + 220;
						if (FormC2.y > 580)
					{
							FormC2.y = 580;
							ScrollY += 1;
						};
					}

					spriteobj->Begin(D3DXSPRITE_ALPHABLEND);

					Sprite_Transform_Draw(imgFormC2, FormC2.x, FormC2.y, 
					FormC2.width, FormC2.height, FormC2.frame, FormC2.columns);

					spriteobj->End();
		
					if(FormC2.y == 360)
					{
						if(Key_Down(DIK_RETURN))
						{ 
							pos_1 = true;
							
						}
					}

					if(FormC2.y == 580)
					{
						if(Key_Down(DIK_RETURN))
						{ 
							pos_1 = true;
							
						}
					}
				}

				if (pos_1 == true)
				{
					pos1_1 = true;
					pos2_1 = true;

					pos = false;
					position = false;
					pos1 = false;
				}

				spriteobj->End();
		}

		if (Key_Down(DIK_B)/>/>)
		{
			MenuForm = false;
			MenuEquipment = false;
			MenuStatus = false;
			MenuItems = false;
		}
			
		if(Key_Down(DIK_C))
		{
			MenuOpen = false;
		}
			

			//stop rendering
			d3ddev->EndScene();
            d3ddev->Present(NULL, NULL, NULL, NULL);
		}
	}

    //to exit 
    if (KEY_DOWN(VK_ESCAPE) || 
        controllers[0].wButtons & XINPUT_GAMEPAD_BACK)
        gameover = true;

}

void Game_End()
{
	imgFayt->Release();
	imgFaytFace->Release();
	imgMariaFace->Release();
	imgAlbelFace->Release();
	imgStandardC->Release();
	imgFormC->Release();
	imgMenuForm->Release();
	imgMenuEquip->Release();
	imgMenuStatus->Release();
	imgMenuItems->Release();
	if (EMenu) EMenu->Release();
	if (SMenu) SMenu->Release();
	if (IMenu) IMenu->Release();
	if (menu) menu->Release();
    if (gameworld) gameworld->Release();
    DirectInput_Shutdown();
    Direct3D_Shutdown();
}



Thanks for all your help with my previous questions. :)

Attached File(s)



Is This A Good Question/Topic? 0
  • +

Replies To: Question for rpg menu

#2 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Question for rpg menu

Posted 01 September 2013 - 02:12 PM

So boiling down your post (which had no question).... Your question is: Would you do my debugging for me, scrub through 1200+ line of my code for and fix my architecture for me? Does that sum it up?

No. The volunteers here are you're debug monkeys. That's your job.

This is where the *work* part of working on code comes in. Making a game is work. Its not playing a game, which so many people think it will be; which is why they go into game development to begin with. They think it will be just fun and play all day long with a paycheck at the end of the week.

In the FAQ below are links to several good debugging tutorials. But essectially there is nothing magical to be done. You have to walk through your code line by line and check the values of your variable to see if they are what you think they should be. Walk it through on paper.

Quote

If I move 'a' to here, then x should be come blah blah...
Then see if that is what happens.



tlhIn`toq's FAQ list

Learning to debug one's own code is an essential skill. Sadly, one that apparently few college courses teach. Silly if you ask me.

Placing breakpoints and walking through the code line by line allows you to actually WATCH it execute.

Visualizing what your code does will let you see why it behaves the way it does.

It would be well worth your time to do the tutorials on FAQ 2. A couple hours learning this skill will save you hundreds of hours of confusion in one project alone.



TOP most asked:
What does this error message mean?
FAQ 2: How do I debug
FAQ 3: How do I make Class1/Form1 talk to Class2/Form2


FAQ (Frequently Asked Questions - Updated July 2013
Spoiler



Was This Post Helpful? 1
  • +
  • -

#3 Delacar   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 40
  • Joined: 31-July 12

Re: Question for rpg menu

Posted 01 September 2013 - 04:26 PM

View PosttlhIn`toq, on 01 September 2013 - 04:12 PM, said:

So boiling down your post (which had no question).... Your question is: Would you do my debugging for me, scrub through 1200+ line of my code for and fix my architecture for me? Does that sum it up?

No. The volunteers here are you're debug monkeys. That's your job.

This is where the *work* part of working on code comes in. Making a game is work. Its not playing a game, which so many people think it will be; which is why they go into game development to begin with. They think it will be just fun and play all day long with a paycheck at the end of the week.

In the FAQ below are links to several good debugging tutorials. But essectially there is nothing magical to be done. You have to walk through your code line by line and check the values of your variable to see if they are what you think they should be. Walk it through on paper.

Quote

If I move 'a' to here, then x should be come blah blah...
Then see if that is what happens.



tlhIn`toq's FAQ list

Learning to debug one's own code is an essential skill. Sadly, one that apparently few college courses teach. Silly if you ask me.

Placing breakpoints and walking through the code line by line allows you to actually WATCH it execute.

Visualizing what your code does will let you see why it behaves the way it does.

It would be well worth your time to do the tutorials on FAQ 2. A couple hours learning this skill will save you hundreds of hours of confusion in one project alone.



TOP most asked:
What does this error message mean?
FAQ 2: How do I debug
FAQ 3: How do I make Class1/Form1 talk to Class2/Form2


FAQ (Frequently Asked Questions - Updated July 2013
Spoiler





After reading you reply I went back and reread my post, and I could see where 1: I have not asked a question and 2: (based on my post) I wanted someone to debug my program. I sincerely apologize as this was not my intention, I have struggled to hard to get this far, and in my opinion it is the program designers job to debug his own work. Even though I ask for help here I continue to work on my own to figure out my problem (though most time sad to say I fail to figure them out). Thank you for pointing out what I have tried to avoid doing, and once again I sincerely apologize for asking others to do my work for me as that is not was not my intention.
Was This Post Helpful? 0
  • +
  • -

#4 anonymous26   User is offline

  • D.I.C Lover

Reputation: 2
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: Question for rpg menu

Posted 01 September 2013 - 04:32 PM

To be honest I don't think you should be attempting code like this right now. The actual code that you are presenting doesn't reflect your level of understanding, so clearly you are just copying code, see what happens, then try to modify it to your own ends. You will quickly find out that this is not the way to learn developing games.
Was This Post Helpful? 1
  • +
  • -

#5 Java Student   User is offline

  • D.I.C Regular
  • member icon

Reputation: 21
  • View blog
  • Posts: 498
  • Joined: 05-February 10

Re: Question for rpg menu

Posted 01 September 2013 - 05:22 PM

When your game develops from hundreds-thousands of lines of code, you have past the point of no return. At this point you have 2 options:

#1: Don't ask how to solve the error and take a more time to solve it urself, which you should be able to do at this point.

#2: Take some time to make a very simplified version of your error that runs, then present that code to us.
Was This Post Helpful? 0
  • +
  • -

#6 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Question for rpg menu

Posted 01 September 2013 - 05:53 PM

No... YOu are not past the point of no return. Bad design is bad design. Don't try to fix it. Its not worth 1,000 to try to fix something that can be created from scratch in 500 hours. Its just a silly use of manpower because you don't want to let go of what you did already.

Learn from your previous work. Learn what was good and what was bad.

Then start with revision 2 ON A WHITE BOARD. Problems occur from bad design. There is a reason why the first scrum of any project is DESIGN. If you hope to be a software engineer you need to accept that ENGINEERING the software has to happen.

You don't start welding together a bridge, then decide half way across the river that it isn't going well. You have to architect first, the entire thing, from start to finish, before you type the first line of code.

As Dean said, this code is clearly copy/paste from a lot of sources. You can't slap together a bunch of stuff from the internet and call it a program or yourself a programmer. It just doesn't work that way. If you can't design it don't think you're going to build it.

Software development is like any other high-skill position: You have to start small and work your way up to something of this magnitude. You have to 'pay your dues' on your way to the top.

This post has been edited by tlhIn`toq: 01 September 2013 - 05:55 PM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1