void LoadSprite(SPRITE *pSprite, LPSTR szFileName, int bitmapCount) { char szBuffer[255]; char szErrorBuffer[255]; BITMAP bitmapInfo; int i = 0; // Set the sprites bitmapCount so it knows when to start over when animating pSprite->bitmapCount = bitmapCount; // Initialize the currentBitmap to 0 (start at the first bitmap) pSprite->currentBitmap = 0; // Allocate enough dynamic memory to hold enough hBitmap's for each bitmap loaded in pSprite->pBitmaps = (HBITMAP *) malloc(sizeof(HBITMAP) * bitmapCount); // Loop until we have loaded in all the desired bitmaps for(i = 0; i < bitmapCount; i++) { // Store the name of the file and the number of the bitmap (ie, caust00.bmp) // The bitmaps must be named with 2 digits (ie, caust00.bmp caust01.bmp, etc..) sprintf_s(szBuffer, "%s%d%d.bmp", szFileName, i / 10, i % 10); // Call our load bitmap function and pass in the file name and number pSprite->pBitmaps[i] = LoadABitmap(szBuffer); // If we didn't receive a valid HBITMAP back, it didn't find the bitmap name if(!pSprite->pBitmaps[i]) { // Store the bitmap file name in a buffer with a sentence to display sprintf_s(szErrorBuffer, "Can't find the bitmap: %s!", szBuffer); // Display a dialog box that says the error message and file name MessageBox(NULL, szErrorBuffer, "Error!", MB_OK); // Quit the program exit(0); } } // Pass in the first bitmap in the list and fill in a BITMAP structure GetObject(pSprite->pBitmaps[0], sizeof(BITMAP), &bitmapInfo); // Set the width and height of the sprite pSprite->width = bitmapInfo.bmWidth; pSprite->height = bitmapInfo.bmHeight; }
BULLET::BULLET(int positionX, int positionY, int targetX, int targetY) { int i = targetX - (positionX + 45), j = targetY - (positionY + 24); int square = (i * i) + (j * j); float root = sqrt((float)square); velocityX = 5 * ((targetX - positionX) / root); velocityY = 5 * ((targetY - positionY) / root ); range = 0; display = LoadABitmap("graphics//UI//enemy.bmp"); posX = positionX + 45; posY = positionY + 24; }
void Infantry::setupSpecificVariables(float xPos, float yPos, Race unitRace, LPSTR imagePath) { bitmap = LoadABitmap(imagePath); if (!bitmap) { MessageBox(NULL, "File Not Loaded",imagePath, MB_OK); } hasMoved = false; hasAttacked = false; attackType = Unit::Melee; //shunts these 2 static consts down into noraml ints in Unit moveValue = moveRange; attackValue = attackRange; healthValue = health; attackDamageValue = attackDamage; x = xPos; y = yPos; findDimensions(); scaleFactorX = 2; scaleFactorY = 2; if(unitRace == Dwarf) { sourceX = 15; sourceY = 30; } else if(unitRace == Human) { sourceX = 15; sourceY = 64; } width = spriteWidth; height = spriteHeight; sourceWidth = spriteWidth; sourceHeight = spriteHeight; }
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; }
//LOADBITMAPSANDMASKS() FUNCTION///////////////////////////////////////////////////////////////////////////////////////// void Player::LoadBitMapsandMasks(void) { animations[0] = LoadABitmap("grnstill.bmp"); animations[1] = LoadABitmap("grnwlk1.bmp"); animations[2] = LoadABitmap("grnwlk2.bmp"); animations[3] = LoadABitmap("ylwstill.bmp"); animations[4] = LoadABitmap("ylwwlk1.bmp"); animations[5] = LoadABitmap("ylwwlk2.bmp"); animations[6] = LoadABitmap("orgstill.bmp"); animations[7] = LoadABitmap("orgwlk1.bmp"); animations[8] = LoadABitmap("orgwlk2.bmp"); animations[9] = LoadABitmap("redstill.bmp"); animations[10] = LoadABitmap("redwlk1.bmp"); animations[11] = LoadABitmap("redwlk2.bmp"); animations[12] = LoadABitmap("dead.bmp"); masks[0] = LoadABitmap("maskstill.bmp"); masks[1] = LoadABitmap("maskwalk1.bmp"); masks[2] = LoadABitmap("maskwalk2.bmp"); masks[3] = LoadABitmap("maskupdown.bmp"); }
void loadtiles() { tiles[0] = LoadABitmap("graphics//tiles//tile grass.bmp"); tiles[1] = LoadABitmap("graphics//tiles//metal_texture_3.bmp");//tile dirt.bmp"); tiles[2] = LoadABitmap("graphics//tiles//tile road.bmp"); tiles[3] = LoadABitmap("graphics//tiles//tile sand.bmp"); tiles[4] = LoadABitmap("graphics//tiles//tile water.bmp"); BMPW[0] = LoadABitmap("graphics//zombies//zombie w.bmp"); BMPW[1] = LoadABitmap("graphics//humans//human w.bmp"); BMPW[2] = LoadABitmap("graphics//bench w.bmp"); BMPW[3] = LoadABitmap("graphics//background_wall w.bmp"); BMPB[0] = LoadABitmap("graphics//zombies//zombie b.bmp"); BMPB[1] = LoadABitmap("graphics//humans//human b.bmp"); BMPB[2] = LoadABitmap("graphics//bench b.bmp"); BMPW[3] = LoadABitmap("graphics//background_wall b.bmp"); UIPics[0] = LoadABitmap("graphics//bench b.bmp"); UIPics[1] = LoadABitmap("graphics//menu//main_menu.bmp"); //Greig_Main menu pics UIPics[2] = LoadABitmap("graphics//menu//new_game.bmp"); UIPics[3] = LoadABitmap("graphics//menu//settings.bmp"); UIPics[4] = LoadABitmap("graphics//menu//tutorials.bmp"); UIPics[5] = LoadABitmap("graphics//menu//quit_game.bmp"); UIPics[6] = LoadABitmap("graphics//menu//load_game.bmp"); UIPics[7] = LoadABitmap("graphics//menu//load_game1.bmp"); UIPics[8] = LoadABitmap("graphics//menu//load_game2.bmp"); UIPics[9] = LoadABitmap("graphics//menu//load_game3.bmp"); UIPics[10] = LoadABitmap("graphics//menu//key_bindings.bmp"); UIPics[11] = LoadABitmap("graphics//menu//full_screen.bmp"); UIPics[12] = LoadABitmap("graphics//menu//tutorials1.bmp"); UIPics[13] = LoadABitmap("graphics//menu//tutorials2.bmp"); UIPics[14] = LoadABitmap("graphics//menu//tutorials3.bmp"); UIPics[15] = LoadABitmap("graphics//menu//back.bmp"); UIPics[16] = LoadABitmap("graphics//menu//yes.bmp"); UIPics[17] = LoadABitmap("graphics//menu//no.bmp"); UIPics[18] = LoadABitmap("graphics//menu//audio.bmp"); UIPics[19] = LoadABitmap("graphics//menu//game_menu.bmp"); MiniMap[0] = LoadABitmap("graphics//UI//Temp_Mini.bmp"); MiniMap[1] = LoadABitmap("graphics//UI//enemy.bmp"); MiniMap[2] = LoadABitmap("graphics//UI//player.bmp"); MiniMap[3] = LoadABitmap("graphics//UI//overlay.bmp"); for (int x = 0; x < 4; x++) { if (!MiniMap[x]) { MessageBox(NULL, "failed to load", (LPCSTR) x, MB_OK); } } MiniMap[4] = LoadABitmap("graphics//decking.bmp"); MiniMap[5] = LoadABitmap("graphics//bench b.bmp"); }