PLEX Screenshots

Leave a comment Standard

The loading screen

loading_screenshot.jpg

The new game screen

startgame_screenshot.jpg

The mode screen

mode_screenshot.jpg

The load a game screen

loadggame_screenshot.jpg

The build game screen (what I have working)

buildlogin_screenshot.jpg

The build game screen (what it will look like)

buildlogin_screenshot2.jpg

The exit game popup

exitgame_screenshot.jpg

PLEX Source Code Version 0.01

Comments 2 Standard

What works so far:

1) Loading screen (you can’t see this because the game loads very quickly right now)

2) Start a new game screen

* you can use your mouse and left click, or the arrow keys and the enter key

3) Load a game screen

* you can use your mouse and left click, or the arrow keys and the enter key

4) Build mode screen

* you can use your mouse and left click, or the arrow keys and the enter key

All code is available under the GNU public license: download it here

Error FIX: Segmentation Fault in Allegro OOP Classes

Comments 3 Standard

Okay so I’ve been setting up the skeleton of my code for this game. What I’m trying to do is setup one class that will manage all the resources of all other classes in the game. That way I can call one function to pause the game, start the game, launch menus, play sounds, and so forth and so on. To do this I’m making all the sub classes of the game write to a buffer in the manging class which I call the game engine. The game engine will then call other subclasses as the game is being played so the appropriate information is written to the buffer at different parts of the game. Everything was going great until I tried to allocate the bitmap in the game engine class using the create_bitmap(int width, int height) function.

Problematic Code

Game Engine .h File

#include <allegro.h> 
#include <linalleg.h> 

class gameegine { 

public: 
gameengine(); //default constructor 
BITMAP *getBuffer(); //returns the gameengine buffer 

private: 
BITMAP *buffer; 

};

Game Engine .cpp File

#include "gameengine.h" 

gameengine::gameengine() 
{ 

buffer; //this will work just fine 

buffer = create_bitmap(SCREENWIDTH, SCREENHEIGHT); //this crashes and burns 
clear(buffer); //this crashes and burns because buffer wasn't allocated 

}

Main .cpp File

#include <allegro.h> 
#include <linalleg.h> 
#include "gameengine.h" 

int main() 
{ 

init_alleg(); //start allegro 

gameengine *plex = new gameengine(); //start the game engine 

plex->loading(); //show the loading screen until everything is setup to start 

while (!key[KEY_ESC]) //play the game until ESC key is pressed 
{ 

scare_mouse(); //hide the mouse 

plex->draw(); //all the game stuff goes on in here 

vsync(); //remove flicker 
acquire_screen(); ///lock the screen for drawing 
show_mouse(plex->getBuffer()); //draw the mouse to the buffer 
blit(plex->getBuffer(), screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); //draw the buffer to the screen 
release_screen(); //unlock the screen 
unscare_mouse(); //show the mouse before 

} //the game is done 

if (plex->mode() == BUILDMODE) //they are in the online game 
plex->disconnect(); //disconnect from the database 

deinit(); //release all allocated resources 

} END_OF_MAIN()

What I found is that Allegro will let you declare bitmaps in classes but it can’t allocate them. When I try to allocate the bitmap I get a shared resources of threads when compiling (on my Linux box). After several days of tearing my hair out I finally found a way to get this working. Instead of allocating the bitmap I’m going to pass it into the class constructor. That way the allocation is done outside of the class itself. The same will have to be done with the graphics class which deals with loading and drawing the graphics of the game to the game engine buffer. Not exactly the optimal solution but I’m not ready to give up on using classes in this project yet. I would have to change a lot of the program’s skeleton structure if I converted it all over to c and quite frankly I don’t have the time for that. I have a lot to get done in only a few weeks!

Working Solution

Game Engine .h File

#include <allegro.h> 
#include <linalleg.h> 

class gameegine { 

public: 
gameengine(BITMAP *newbuffer); //default constructor 
BITMAP *getBuffer(); //returns the gameengine buffer 

private: 
BITMAP *buffer; 

};

Game Engine .cpp File

#include "gameengine.h" 

gameengine::gameengine(BITMAP *newbuffer) 
{ 

buffer = newbuffer; //now this all works 
clear(buffer);  

}

Main .cpp File

#include <allegro.h> 
#include <linalleg.h> 
#include "gameengine.h" 

int main() 
{ 

init_alleg(); //start allegro 
BITMAP *buffer = create_bitmap(SCREEN_W, SCREEN_H); 

gameengine *plex = new gameengine(buffer); //start the game engine 

plex->loading(); //show the loading screen until everything is setup to start 

while (!key[KEY_ESC]) //play the game until ESC key is pressed 
{ 

scare_mouse(); //hide the mouse 

plex->draw(); //all the game stuff goes on in here 

vsync(); //remove flicker 
acquire_screen(); ///lock the screen for drawing 
show_mouse(plex->getBuffer()); //draw the mouse to the buffer 
blit(plex->getBuffer(), screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); //draw the buffer to the screen 
release_screen(); //unlock the screen 
unscare_mouse(); //show the mouse before 

} //the game is done 

if (plex->mode() == BUILDMODE) //they are in the online game 
plex->disconnect(); //disconnect from the database 

deinit(); //release all allocated resources 

} END_OF_MAIN()

Error FIX: Mysql.h Not Found

Leave a comment Standard

Okay, so I downloaded the mysql-dev pack from the software repositories on OpenSuse 10.2 and that fixed the problem I was having with the mysql.h file not found error. I’ve read a few websites that say you have to include -libmysql to the linker but every time I do that I get library not found. So I’m going to try getting the database stuff setup without the library linked in there (its probably included in one of my other linking libraries) and go from there. Worst comes to worse I can try mysql++ or qt which deals with mysql databases in Kdevelop projects. In order to get that working you have to turn it on by going to project options > c++ specific > then click on the qt tab and enable the qt databases. From there you can follow this tutorial I found on setting up mysql and qt databases in Kdevelop to get things working.

Allegro Tutorial: Threading

Comments 2 Standard

Here is a link to threading in Linux. That will be very interesting as my Linux skills are still fairly limited at this point! But in the meantime I conned this Windows example of threading from my good friend and Linux guru Chris Martin. I figured if I didn’t post a copy of it here in my blog I would forget about it and give myself a big headache later trying to remember how it works. Here’s an example on how to start two threads in Allegro on Windows.

Include the following headers into your project.

#include <process.h>
#include <allegro.h>
#include <winalleg.h>

These headers must be included in the exact order that they appear here. The winalleg.h header file allows the use of most functions and types defined in the windows.h header for the win32 API and it must be included only after including the allegro.h header. Once these headers are included in your project, you may begin to work with threading.

#include <process.h>
#include <allegro.h>
#include <winalleg.h>

void init( void );
void deinit( void );

/* thread callback functions */

void ThreadOne( void* data );
void ThreadTwo( void* data );

/* Mutex */

HANDLE hMutex;

int main( void )
{
     /* handle the initialization of allegro lib */
     init();
     /* create the mutex to lock and unlock resources
      * for each thread.
      */
     hMutex = CreateMutex( NULL, FALSE, NULL );
     /* start both threads */
     _beginthread( ThreadOne, 0, NULL );
     _beginthread( ThreadTwo, 0, NULL );
     /* start main application loop */
     while( !key[KEY_ESC] )
     {
      WaitForSingleObject( hMutex, INFINITE );
      textprintf_centre_ex( screen, font, SCREEN_W/2, 400, 0xffffff, -1,
      "Hello World from Main!!!" );
      ReleaseMutex( hMutex );
     }
     /* cleanup after allegro lib */
     deinit();
     /* return success or zero to OS */
     return 0;
}
END_OF_MAIN()

void init( void )
{
     int depth, res;
     allegro_init();
     depth = desktop_color_depth();
     if( depth == 0 )
          depth = 32;
     set_color_depth( depth );
     res = set_gfx_mode( GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0 );
     if( res != 0 )
     {
          allegro_message( allegro_error );
          exit( -1 );
     }
     install_keyboard();
}

void deinit( void )
{
     clear_keybuf();
}

void ThreadOne( void* data )
{
     int i = 0;
     bool  done = false;
     /* run loop until we are done, just to show that the thread loop doesn't affect
      *  the main loop.
      */
     while( !done )
     {
          /* lock or wait for the mutex to be free before we write */
          WaitForSingleObject( hMutex, INFINITE );
          textprintf_ex( screen, font, 0, 50 + i, 0xffffff, -1, "Hello World from ThreadOne!!!" );
          if( i == 100 )
               done = true;
          else
               i += 10;
          /* for right now we are done using the mutex, so release it */
          ReleaseMutex( hMutex );
     }
}

void ThreadTwo( void* data )
{
     int i = 0;
     bool done = false;
     while( !done )
     {
          WaitForSingleObject( hMutex, INFINITE );
          textprintf_ex( screen, font, 200, 50 + i, 0x00ff00, -1, "Hello World from ThreadTwo!!!" );
          if( i == 200 )
               done = true;
          else
               i += 10;
          ReleaseMutex( hMutex );
     }
}

PLEX Specification Requirements Document

Comments 2 Standard

PLEX – Multiplayer Online Game
Specification Requirements

1. Introduction

I’m a senior at the University of Mary Washington and I’m going to me making a game in C/C++ using the Allegro API. The game, PLEX, will consist of two parts, an online multiplayer version and a single player version. I will be working on the multiplayer version during the fall semester and follow up with the single player version on my spring semester.

1.1 Purpose

The reason I’m creating PLEX is to help me understand the complexity of MMORPG, or massive multiplayer online role playing games. I hope to use the knowledge I’ve learned throughout this year to help me get a job in the gaming industry. PLEX will become one of the strongest portions of my portfolio when I apply for jobs. At the same time I can use the skill set I will develop from this project to help enhance my understanding of software engineering, networking, and the game development process.

1.2 Scope

PLEX will run on both windows 98/XP/NT and Linux operating systems. In multiplayer mode it will query a database setup on an Intel Celeron 1300MHz server with a 256KB cache. PLEX should allow for at least five concurrent users online without visible lag time. Users will have to download and possibly install the software before they can start playing PLEX. The total cost of this project is $0 and the investment into this project is $0.

1.3 Document Overview

This document will go over the project in detail, user characteristics, general constraints, and then requirements entailed.

2. Project Explained

PLEX will be written in C/C++ using the Allegro API. It will have access to a database for online play. There are two main modes for gameplay:

Story Mode – the user has decided to play the game as a single player. There is no online aspect of the game play. Users can start a new game or load a previous game. In story mode there are six characters the user can choose to play as. Each character will present a different set of puzzles the user has to beat in order to complete the game.

Build Mode – the user has decided to play the online multiplayer version of the game. They must create a user name and password and character before they can login and start playing. Once they have logged into the game a connection is established with the database that persistently sends information to the player and the game board. In this mode the user can see 6 blocks across, by 6 blocks down, by 4 blocks deep of a 100 x 100 x 4 block grid. They will be given a list of patterns and houses to make on the board. As they complete the patterns they will be awarded jewels. At any time they can click on a high score menu and see how they compare to the top players on the game.

Optional Feature: users will be able to talk to other users that are close to where their character is standing.

2.1 Project Functions

Game Engine – before mode is set. setup the game once the game .exe file has been started. Initialize all appropriate functions and connections to the database if necessary. Prompt the user to play a game in story mode (single player) or build mode (multiplayer). If they choose story mode then take them to create a new game or load a game. If they choose build mode take them to login to the online game or create a new username and password.

New Game – only available in story mode. If the user has decided to create a new game then prompt them to pick a character to play as.

Save Game – only available in story mode. If the user clicks on the save game button then prompt them to enter a file name. Once the file name is entered (and valid) then all of the games current variables, character positions, and block positions should be written to a file so they can be read back into the game at a later time.

Load Game – only available in story mode. Show a screen that allows the user to select the game file they would like to load. Once the file is chosen, load the information into PLEX by updating variables and graphics to the last position that character was in when they saved the game.

Play Driver – only available in story mode. Play and pause the game so the user can leave the game and come back at a later time.

Menu Driver – available in both modes. In charge of all of the game menu screens, including saving games, loading games, startup game selection, high scores and buying things from the game store.

Game Logic Driver – both story and build mode. How the game is actually played. All the legal and illegal rules of the game, block movement, character storylines for story mode, default puzzles, mini-puzzles and quests, as well as interface with the database connection to update online play. Checks to see if a username/password combo exists in the database, and then keeps track of the logic in online mode for that particular user.

Graphics Driver – both story and build mode. Loads all of the game graphics and returns the appropriate graphics formatted as needed to the buffer. Deals with any and all animation of blocks or graphics. No game logic is included in this driver, only things that have to do with graphical display on the screen.

Music Driver – both story and build mode. Loads all of the game music and returns the appropriate songs as needed. Should play, pause, mute, increase/decrease volume when asked to for any song that is currently playing.

Time Driver – both story and build mode. Keeps track of elapsed time. Can be reset to zero at any time, counts seconds based off of the clock time and not the screen refresh rate.

Database Connection – only available in build mode. Handles all the connectivity with the database. Fetches and returns query results. Will query based off of the time driver so PLEX doesn’t query with user’s screen refresh rate.

Connection Timeout Driver – only available in build mode. Check to see if the user is still actively playing the game in build mode. If the user hasn’t made a move in x amount of time they timeout their connection to free up database resources for other online players.

Movie Driver – only available in story mode. This is an optional thing because I’m not sure I’ll have time for it. This will handle little movies that play at the beginning and end of the story mode, as well as any little movies that will go on during the game for finishing certain puzzles, adventures, or quests. This would combine with the graphics drivers to play animated scenes with annotated text to explain what’s happening or show what characters are saying.

2.2 User Characteristics

The users of this game will have to have Windows 98/XP/NT or a LINUX operating system. PLEX will not be supported on Mac computers or cell phones. Users will come from a wide range of backgrounds and may have very limited experience with computers.

2.4 General Restraints

This system must be able to support at least five concurrent users in build mode. It may support more then that, but must support five as a minimum without noticeable lag in the gameplay. There will be no self-install feature for this game; it will run by clicking on an .exe file. PLEX will only run on Windows 98/XP/NT or a LINUX operating system. It should be targeted towards a teenage audience. It should be complex enough to be challenging, but not so hard that users get easily frustrated and give up.

3. Requirements

3.1 Game Engine Requirements

REQ 1: Must be the first thing that starts when the game is turned on.

Rationale: This will drive most of what happens in the entire game, it must be the first thing to start.

REQ 2: Will be the only thing that can write to the main game buffer.

Rationale: All the other drivers will have to go through this engine in order to have access to the components of the game. If only the engine writes to the buffer then nothing will be overwritten.

REQ 3: Must initialize all of the other drivers.

Rationale: Once this is started it will be responsible for setting up all other drivers.

REQ 4: Must handle all user input.

Rationale: Because this will be running the overall structure of the game it must behave appropriately according to where the game is and the user input being give (keystrokes, mouse clicks).

REQ 5: Will initialize the connection to the database if build mode is picked.

Rationale: This way a connection is only started once the user has decided to play in online mode.

REQ 5: Write the bugger to the screen.

Rationale: Blit the game engine buffer to the screen once all game logic has been applied to it, so the appropriate images are shown at all times.

3.2 New Game Requirements

REQ 1: Only works in story mode.

Rationale: In build mode they must login with a username/password or create one.

REQ 2: Must setup all the game variables and drivers so a new game can start.

Rationale: If the game isn’t setup for a new game, or an old game is already loaded, everything must be reset back to start a new game.

REQ 3: Must ask the user to select a character to play as.

Rationale: If they are playing a new game they need to select the set of puzzles they want to try which are based on the character they pick.

REQ 4: Once a character is picked, this must load all the appropriate puzzles for the different sections of the game map.

Rationale: Because all of the puzzles vary based on the character, load the appropriate ones for this particular character.

3.3 Save Game Requirements

REQ 1: Only works in story mode.

Rationale: Games cannot be saved in build mode.

REQ 2: The file name for the game must be valid so it can be read back in at a later time.

Rationale: Strange characters in the file name make cause problems when opening the file for loading.

REQ 3: If the file already exists, the file will be written over.

Rationale: If the user is trying to save the game with the same file name then it is probably a continuation of that previously saved game.

REQ 4: If the file doesn’t exist it must be created.

Rationale: The game can’t write to a file that’s not there.

REQ 5: The file must be saved in a particular format and include all the game data that needs to be read back in at a later time so the game can continue.

Rationale: If the file isn’t in a certain format then the game won’t be able to load all the information back in at a later date.

3.4 Load Game Requirements

REQ 1: Only works in story mode.

Rationale: Game data in online mode is loaded from the database.

REQ 2: The file exists.

Rationale: The game can’t load a file that isn’t there.

REQ 3: The file must be in the particular format so that the data can be read back into the game.

Rationale: If the format is off then the game will store wrong information in variables, or crash all together.

3.5 Play Driver Requirements

REQ 1: Only works it story mode.

Rationale: You can’t pause the game in online mode, its constantly running whether the user is there or not.

REQ 2: Pause the game.

Rationale: Keep things from happening while the user is gone.

REQ 3: Resume the game if it has been paused.

Rationale: The user has returned, the game can continue like it was before.

3.6 Menu Driver Requirements

REQ 1: Load the appropriate menu when asked.

Rationale: This way the game will always show the correct menu at the right time.

REQ 1: Keep track of where the selector is.

Rationale: This way the game knows what option is being picked from which menu.

3.7 Game Logic Requirements

REQ 1: In charge of ALL the game logic, game boards, and game play variables.

Rationale: Logic is separate from graphics so it can be changed easily. In games the graphic never change, only the logic behind them does.

3.8 Graphic Driver Requirements

REQ 1: Load all of the game graphics.

Rationale: Game graphics will be ready to go before the user starts playing the game to decrease loading times.

REQ 2: Return graphics to the engine buffer.

Rationale: The engine will be in charge of requesting the appropriate graphics so that they don’t overwrite what’s already on the buffer.

3.9 Music Driver Requirements

REQ 1: Load all of the game music.

Rationale: Game music will be ready to go before the user starts playing the game to decrease loading times.

REQ 2: Play music.

Rationale: Will always play the most current music selection.

REQ 3: Stop music.

Rationale: Stop whatever music is currently playing.

REQ 4: Mute music.

Rationale: Turn off the volume for whatever music is playing.

REQ 5: Play music.

Rationale: Will always play the most current music.

REQ 6: Adjust volume if music is playing and not muted.

Rationale: User can turn volume up or down at any time.

3.10 Timer Requirements

REQ 1: Start the timer when the game is started.

Rationale: Timer should always be running.

REQ 2: Restart timer.

Rationale: So time can be measured against some pre-determined start point.

3.11 Database Connection Requirements

REQ 1: Only works in build mode.

Rationale: You don’t have to be online in story mode.

REQ 2: Connect to the database.

Rationale: Must be able to connect in order for people to play in build mode.

REQ 3: Return query results in string format.

Rationale: Must be able to return a string result from a query.

REQ 4: Return query results in integer/boolean format.

Rationale: Must be able to return a integer result from a query.

3.12 Database Timeout Driver Requirements

REQ 1: Only works in build mode.

Rationale: You don’t have to be online in story mode.

REQ 2: Check to see how much time has passed since the user last entered some kind of input and log them out if that time surpasses x seconds.

Rationale: Free up database resources by kicking out idle users.

3.13 Movie Driver Requirements

REQ 1: Load information about movies.

Rationale: Game movies will be ready to go before the user starts playing the game to decrease loading times.

REQ 2: Play movie.

Rationale: Play the current movie.

REQ 3: Pause movie.

Rationale: The game has been paused, pause the play of the movie as well.

REQ 4: Stop/skip movie.

Rationale: User has decided not to watch the particular movie, game control returns to whatever called this.

3.14 Non-Functional Requirements

REQ 1: PLEX will come with a HTML and CHM instruction manual.

Rationale: The user must be able to understand how to navigate and work the game otherwise they won’t bother playing.

REQ 2: PLEX graphics should be cartoons and appeal to people of all ages, but especially to teenager and pre-teens.

Rationale: This way PLEX will attract an audience who wants to play the game, especially people from the targeted age group.

3.15 Non-Requirements

NR 1: Users do not HAVE to have a chat feature. This is an optional feature for build mode.

Rationale: If I run out of time programming everything else, this is something that can always be added on at a later date.

NR 2: There does not HAVE to be a movie driver. This is an optional feature for story and build mode.

Rationale: If I run out of time programming everything else, this is something that can always be added on at a later date.

4. Assumptions

If the user selects build load the game will assume they already have an open internet connection. All users have a graphic card that can support PLEX. All users have sound drivers installed on their computer that can play the sounds in PLEX. All users have a mouse and keyboard when they play. Users do not have any visual imparity such as being color blind (since the color of the blocks will matter).

5. Appendix

5.1 Glossary of Terms

Allegro API – A multi-platform game programming library that can be programmed using c and c++. Includes functions for drawing to the screen, animation, key and mouse input, music and rendering support.

Browser – A program that lets you view documents in popular internet formats such as HTML.

C/C++ – A popular industry programming language.

CHM – Compiled HTML Manual, a Windows program that makes reading and searching through an online manual easy.

Database – Software that quickly stores and retrieves large volumes of information.

HTML – Hypertext Markup Language, the format of documents on the Internet. Easily viewable using a browser.

Intel Celeron 1300MHz server with a 256KB cache – A computer accessible by the Internet so people who are online can access the information stored there.

Linux – An operating system alternately to Windows 98/XP/NT.

MMORPG – Massive multiplayer online role playing game. A game that several people can play online at the same time, where interaction between the players is a large part of the game.

PLEX – The name of the game being developed. Originally comes from the word comPLEX, because the game involves puzzles and moving blocks into certain patterns before you can proceed through it.

Introduction To PLEX

Leave a comment Standard

Single Player Screenshot

This game is a type of puzzle. In the online version, players will create an account and login to the game. Once they are logged on they will be randomly placed on a 100 tiles wide x 100 tiles long x 4 tiles deep tiled board. At any time they will only see the board as 6 tiles wide x 6 tiles long x 4 tiles deep. As they move around the screen other parts of the board are revealed. The game will interact with an online database to show other player’s moves in a FIFO schema. Players cannot use blocks near a block another other player is using. This way one player cannot overwrite a move another player is making.

The object of the game is to arrange the blocks to create specific landscapes and houses. Only certain blocks can be moved, and only in a specific way:

1) A block can be moved one space forward, backwards, to the left or right.

Moving a block on the board

Top down view of a PLEX board.
X shows a selected block, arrows show the possible places it can be moved to.

 

2) A block can only be moved if the space it is moving to is no more then two blocks higher then its current height, or two blocks lower then its current height.

Moving a block, top down view

 

3) In order to move or take some blocks they will need to dig up, or blow up other things that are in the way (rocks, trees, rocky ground). To remove obstacles they need to buy dynamite and shovels from the store with their gems. Only certain blocks and obstacles can be dug up or blown up. They cannot move to a block that another player is standing on.

4) If they touch certain blocks with their playing character they loose a health heart (bugs, prickly trees, water blocks). If they loose all of their hearts they are logged out, their gems are set to zero, their items are set to zero, and they have to login again to continue playing. Their hearts are restored to full health when they log back in.

As players create the specific houses and landscapes they earn gems. Once a house or landscape is complete the blocks are re-scrambled on that part of the board. Players can view the top scoring players on a high score list to see where they compare against others. They can also view a list of people who are online at the same time they are.

An option that I’m playing with is the ability for them to talk to other players that are near where their character is standing. Then they could possibly trade dynamite and shovels and gems with other players.

In another independent study in the spring I’d like to continue to expand upon this game by adding a single player version that allows for loading/saving games and playing as one of a few characters in a story mode. When the user loaded PLEX they would choose to play the multiplayer version or the single player version.