// Method to Initialize Level void level1() { Pacman.image = al_load_bitmap("Pacman_Sprite_Sheet.PNG"); // Loading pacman sprite sheet Pacman.X = SCREEN_W / 2; // Starting x-coordinate of pacman on the screen Pacman.Y = SCREEN_H / 2; // Starting y-coordinate of pacman on the screen Pacman.S = 2.0; // Movement S of pacman Pacman.NumbOfFrames = 2; // Total number of pacman animation frames in the sprite sheet Pacman.frameDelay = 7; // S of pacman animation Pacman.InitObject(); // Initialize pacman gameObject = new GameObject[(SCREEN_W / TILE_SIZE) * (SCREEN_H / TILE_SIZE)]; gameObjectCount = 0; Food = al_load_bitmap("food.png"); Block = al_load_bitmap("block.png"); Level = al_fopen("level_1.data", "r"); // Loading and initializing Level & Game Objects for (int R = 0; R < SCREEN_H / TILE_SIZE; R++) { for (int C = 0; C < SCREEN_W / TILE_SIZE; C++) { levelGrid[R][C] = al_fgetc(Level); switch (levelGrid[R][C]) { case 10: C--; break; case 49: gameObject[gameObjectCount].InitObject(Block, C * TILE_SIZE, R * TILE_SIZE, BLOCK); gameObjectCount++; break; case 48: gameObject[gameObjectCount].InitObject(Food, C * TILE_SIZE, R * TILE_SIZE, FOOD); gameObjectCount++; break; } } } }
// Method to Initialize Level void InitLevel() { Pacman.image = al_load_bitmap("Pacman_Sprite_Sheet.PNG"); // Loading pacman sprite sheet Pacman.posX = SCREEN_W / 2; // Starting x-coordinate of pacman on the screen Pacman.posY = SCREEN_H / 1.45; // Starting y-coordinate of pacman on the screen Pacman.speed = 2.0; // Movement speed of pacman Pacman.totalFrame = 2; // Total number of pacman animation frames in the sprite sheet Pacman.frameDelay = 7; // Speed of pacman animation Pacman.InitObject(); // Initialize pacman gameObject = new GameObject[(SCREEN_W / TILE_SIZE) * (SCREEN_H / TILE_SIZE)]; gameObjectCount = 0; foodSprite = al_load_bitmap("food.png"); blockSprite = al_load_bitmap("block.png"); levelData = al_fopen("level_2.data.txt", "r"); // Loading and initializing Level & Game Objects for (int row = 0; row < SCREEN_H / TILE_SIZE; row++) { for (int column = 0; column < SCREEN_W / TILE_SIZE; column++) { levelGrid[row][column] = al_fgetc(levelData); switch (levelGrid[row][column]) { case 10: column--; break; case 49: gameObject[gameObjectCount].InitObject(blockSprite, column * TILE_SIZE, row * TILE_SIZE, BLOCK); gameObjectCount++; break; case 48: gameObject[gameObjectCount].InitObject(foodSprite, column * TILE_SIZE, row * TILE_SIZE, FOOD); gameObjectCount++; break; } } } }