Sunday, December 11, 2011

2D C++ Game: Part 7 - Game Plot

Game Plot:
The whole idea is to make a clone of old classic game "Pacman".

Game Objects:
▪ Pacman - The main character you will be controlling.
▪ Food - To be eaten by Pacman.
▪ Level Blocks - Pacman cannot pass through these blocks.
▪ Monsters - On collision Pacman looses life.
▪ Power Ups - Makes Monsters weak for a certain period of time.

Game Objective: You have to eat all the food in the level avoiding the enemies, on completion of food, level will be completed.

Technicalities Involved:
Process plan
 Loading map file and drawing all the objects on to the screen.
 Updating Pacman direction according to keypresses.
 Check for collisions occurring in between level objects and Pacman.
 Update monster AI.
 Make monsters weak for a certain period of time when Pacman consumes Power ups.
 Load next level upon completion of food.
Level loading and drawing process:
We will be doing a tile map approach where all object/images will be of maximum dimension of 32 X 32 plotted on a imaginary grid on the screen.
Object Width = 32
Object Height = 32
Game window size = 800 X 600, i.e width = 800, height = 600
Total no. of objects along x-axis = window width / object width = 800 / 32 = 25
Total no. of objects along y-axis = window height / object height = 600 / 32 = 18
Thus, maximum no. of objects on the screen = 25 + 18 = 43
The contents of the level file is loaded into a 2D array:

2DArray[Total no. of objects along x-axis][Total no. of objects along y-axis]

The imaginary grid on the screen looks like this,

This is how the contents of level data file looks like,

Constants:
 Food - 0
 Block - 1
 Power up - 2

Lets take a small part of the data from the level file

Now plotting the selected data stored in the array on to the imaginary grid we get,
Similarly, all other objects are drawn on to imaginary grid on the screen,

Class Diagram:

0 comments:

Post a Comment