Main.cpp

 #include "mvx.h"

LRESULT CALLBACK WindowProc(HWND hwnd,
    UINT msg,
                            WPARAM wparam,
                            LPARAM lparam)
{
// this is the main message handler of the system
PAINTSTRUCT ps; // used in WM_PAINT
HDC hdc; // handle to a device context

// what is the message
switch(msg)
{
case WM_CREATE:
        {
// do initialization stuff here
        // return success
return(0);
} break;
  
case WM_PAINT:
{
// simply validate the window
   hdc = BeginPaint(hwnd,&ps);
       
// end painting
EndPaint(hwnd,&ps);

// return success
return(0);
   } break;

case WM_DESTROY:
{
// kill the application, this sends a WM_QUIT message
PostQuitMessage(0);

// return success
return(0);
} break;

default:break;

    } // end switch

// process any messages that we didn't take care of
return (DefWindowProc(hwnd, msg, wparam, lparam));

} // end WinProc

// the default viewport
mvxViewport View(D3DXVECTOR2(0, 0), D3DXVECTOR2(640, 480));

int WINAPI WinMain( HINSTANCE hinstance,
HINSTANCE hprevinstance,
LPSTR lpcmdline,
int ncmdshow)
{
ShowCursor(false);

// windows message
MSG msg;

mvxEngine Engine;

// set what you want
Engine.mvxWidth    =  640;
Engine.mvxHeight   =  480;

// we dont want a windowed app
Engine.mvxWindowed = false;

// set to true if you want to use them
// we dont need any for this example
Engine.mvxAudio    = false;
Engine.mvxDInput   = false;
Engine.mvxDebug    = false;

// then init the engine
Engine.mvxInit(hinstance);


// create your mvxImages here
mvxImage myImage;
// load the image
myImage.mvxCreate(Engine.mvxDevice, "happyball.bmp");
// set the rotate center of the image
myImage.mvxSetCenter(16, 16);
// simple as that

// create a coordinate for the ball
D3DXVECTOR2 location(0, 0);
// create a velocity
D3DXVECTOR2 velocity(.5, .5);
// and an  angle
float ang = 0;

// enter main event loop
while(TRUE)
{
// test if there is a message in queue, if so get it
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
// test if this is a quit
if (msg.message == WM_QUIT)
break;

// translate any accelerator keys
TranslateMessage(&msg);

// send the message to the window proc
DispatchMessage(&msg);
} // end if

// prepare to render
Engine.mvxClear(mvxRGB(0,0,0));

Engine.mvxBegin();

// render stuff here
// now here we render out happy ball
myImage.mvxRenderThis(NULL, NULL, &myImage.mvxRotationCenter, ang, &location, D3DCOLOR_ARGB(255, 255, 255, 0));

location += velocity;

if (location.x < 0)
{
velocity.x *= -1;
}
if (location.x + 32 > 640)
{
velocity.x *= -1;
}

if (location.y < 0)
{
velocity.y *= -1;
}
if (location.y + 32 > 480)
{
velocity.y *= -1;
}

// rotate the ball
ang += .007f;

Engine.mvxEnd();

Engine.mvxShow();

// exit
if (mvxKEYDOWN(VK_ESCAPE))
SendMessage(Engine.mvxMWH, WM_CLOSE, 0, 0);
}

// now destroy the ball
myImage.mvxDestroy();
// thats all

Engine.mvxDestroy();

// return to Windows like this
return(msg.wParam);
}

Project Homepage: