void Init(HWND hwnd) { // Create our double buffering CreateDoubleBuffering(&gBuffer, hwnd); // Load the monster LoadSprite(&gMonster, "monster.bmp", MONSTER_WIDTH, MONSTER_HEIGHT, MONSTER_FRAMES); // Set the sprites position SetSpritePosition(&gMonster, 100, 200); // Set the direction of the sprite SetSpriteState(&gMonster, EAST); // Set the X and Y speed of the monster SetSpriteSpeed(&gMonster, 8, 12); // Load the background image hBackground = LoadABitmap("background.bmp"); // Set the backbuffer to white first (This clears the backbuffer) ClearScreen(gBuffer.hdcBack, gBuffer.scrnRect, WHITE_BRUSH); // Display the background image DisplayBitmap(&gBuffer, hBackground, 0, 0); }
void LoadSprite(SPRITE *pSprite, LPSTR szFileName, int width, int height, int lastFrame) { char szBuffer[255]; int i = 0; // Set the sprites bitmapCount so it knows when to start over when animating pSprite->lastFrame = lastFrame - 1; // Initialize the currentFrame to 0 (start at the first frame) pSprite->currentFrame= 0; // Set the sprite animation to the first state (NORTH) SetSpriteState(pSprite, NORTH); // Set the sprites speed to default SetSpriteSpeed(pSprite, 5, 5); // Call our load bitmap function and pass in the bitmap to load pSprite->hBitmap = LoadABitmap(szFileName); // If we didn't receive a valid HBITMAP back, it didn't find the bitmap name if(!pSprite->hBitmap) { // Store the bitmap file name in a buffer with a sentence to display sprintf(szBuffer, "Can't find the bitmap: %s!", szFileName); // Display a dialog box that says the error message and file name MessageBox(NULL, szBuffer, "Error!", MB_OK); // Quit the program exit(0); } // Set the width and height of the sprite pSprite->width = width; pSprite->height = height; }
void LoadSprite(SPRITE *pSprite, LPSTR szFileName, int width, int height, int lastFrame) { char szBuffer[255]; int i = 0; // Set the sprites bitmapCount so it knows when to start over when animating pSprite->lastFrame = lastFrame - 1; // Initialize the currentFrame to 0 (start at the first frame) pSprite->currentFrame= 0; // Set the sprite animation to the first state (NORTH) SetSpriteState(pSprite, NORTH); // Set the sprites speed to default SetSpriteSpeed(pSprite, 5, 5); // Call our load bitmap function and pass in the bitmap to load pSprite->hBitmap = LoadABitmap(szFileName); // Set the width and height of the sprite pSprite->width = width; pSprite->height = height; }