PLEX Source Code Version 0.03

Leave a comment Standard

Build ScreenI’ve done several things this week. The game now checks to see if you have a correct login, and only lets you login if it matches a login found in the game database. Once the player is logged in it checks to see if they are standing in a valid location (ie no block on top of them, and no block that will hurt their health like a water block) and moves them if they are not in a valid location to a valid one. Then the board and graphics for the build game are loaded onto the screen. So far the player cannot select and move blocks yet, but that will be the next thing I tackle.

One of the problems I was having had to do with the online board. It’s 100 x 100 and 5 levels deep. At first I was manually typing all of the blocks in and then I realized to do that would be incredibly stupid (at least I didn’t realize it half way through adding the blocks in!) so I wrote the script in PHP below to automatically populate the database for me.



* File Name: plex_functions.php

* Author: G. J. Krafsig

* Date: October 16, 2007

* Purpose: populate the plex database with random blocks

*		   for the online board


*          !!! IMPORTANT !!!







mysql_connect("localhost", "root", "") or die ('Database connection error: ' . mysql_error());

//use the database for this game for the queries below


//call the function to fill the database table


for ($i = 0; $i < 100; $i++)

 for ($j = 0; $j < 100; $j++)

 	mysql_query("INSERT INTO board (x, y, depth, type) VALUES ('$i', '$j', '4', '-1')")

 	or die ('cannot insert board blocks');


* Purpose: Loop for all the depths, EXCEPT THE TOP ONE,

*		   to fill the board with blocks

* Precondition: database connection is open, database named plex exists, table named board exists


* SQL for board table:

* 		CREATE TABLE `board` (

*			`id` int(11) NOT NULL auto_increment,

*			`x` int(11) NOT NULL,

*			`y` int(11) NOT NULL,

*			`depth` int(11) NOT NULL,

*			`type` int(11) NOT NULL,

*			`locked` tinyint(1) NOT NULL,

*			UNIQUE KEY `id` (`id`)



* Postcondition: online board table is now fully populated with values


function populate()


 for ($depth = 0; $depth <= 3; $depth++)

 	for ($i = 0; $i <= 100; $i++)

 		for ($j = 0; $j <= 100; $j++)


//blocks at depth 0 should all be the same kind originally

 			if ($depth == 0)


 				$block = 1;

 				mysql_query("INSERT INTO board (x, y, type, depth) VALUES ('$i', '$j', '$block', '$depth')")

 				or die ('cannot insert a block here');


 			//for all other depths



//generate a random block

 				$block = rand(0, 9);

//no tall block below this one taking up two spaces on the board, add a block here

 				if (!getTallBlock($i, $j, $depth-1))

 					mysql_query("INSERT INTO board (x, y, type, depth) VALUES ('$i', '$j', '$block', '$depth')")

 					or die ('cannot insert a block here');

else //there is a tall block in this spot, put a NOBLOCK value there (-1)

 					mysql_query("INSERT INTO board (x, y, type, depth) VALUES ('$i', '$j', '-1', '$depth')")

 					or die ('cannot insert a block here');

 			} //end else

 		} //end for loop

} //end function populate


* Purpose: check to see if the block at this location and depth

*		   is tall and takes up two spaces on the board

* Precondition: the x and y position, and the depth of the block

* Postcondition: return true if the block here is tall and takes up 2 depth spaces


function getTallBlock($x, $y, $depth)


 //get the type of block from the database

 $result = mysql_query("SELECT type FROM board WHERE x='$x' AND y='$y' AND depth='$depth'")

 		  or die ("cannot select block in this place");

//store the results

 $row = mysql_fetch_array($result);

//if this is a tall block, return true, otherwise return false

 switch ($row['type'])


 	case 5: case 7: return 1; break;

 	default: return 0; break;




Another problem I had was with the images. A lot of them have drop shadows, so when I put the transparent pink color makecol(255, 0, 255) behind them they still bleed pink around the shadows and edges of the pictures. To correct this I have been going in manually and editing all of the images which takes forever. So I tried to make a function that manually goes through all of the colors close to makecol(255, 0, 255) and replace them with shades of gray and black. I had some success with this, but because I’m a stickler for perfection and I couldn’t get it replacing 100% of the bleeding pink I’m going back to fixing them all manually. But I’m including the code here because it is a pretty nifty function and someone else down the road might find some use for it:

You can download the new source code for PLEX here.

* Purpose: Remove the pink bleed from images with transparent background
* Precondition: The image to change
* Postcondition: The pink has been removed
BITMAP *removePink(BITMAP *image)
    int oldpixel, newpixel;
    int r, g, b;

    for (int i = 0; i < image->w; i++)
        for (int j = 0; j < image->h; j++)

            oldpixel = getpixel(image, i, j);
            r = getr(oldpixel);
            g = getg(oldpixel);
            b = getb(oldpixel);

            //replace pixels that are close to 255, 0, 255
            //ignore pixels where g is not set to 0
            if (g == 0) //make these pixels shades of gray

                //almost black
                if (r >= 55 && r < 65 && b >= 55 && b < 65)
                    newpixel = makecol(0, 0, 0);

                //dark dark gray
                else if (r >= 65 && r < 85 && b >= 65 && b < 85)
                    newpixel = makecol(25, 25, 25);

                //dark medium gray
                else if (r >= 85 && r < 100 && b >= 85 && b < 100)
                    newpixel = makecol(35, 35, 35);

                //dark light gray
                else if (r >= 100 && r < 125 && b >= 100 && b < 125)
                    newpixel = makecol(55, 55, 55);

                //medium dark gray
                else if (r >= 125 && r < 155 && b >= 125 && b < 155)
                    newpixel = makecol(75, 75, 75);

                //medium medium gray
                else if (r >= 155 && r < 185 && b >= 155 && b < 185)
                    newpixel = makecol(105, 105, 105);

                //medium light gray
                else if (r >= 185 && r < 200 && b >= 185 && b < 200)
                    newpixel = makecol(115, 115, 115);

                //dark gray
                else if (r >= 200 && r < 215 && b >= 200 && b < 215)
                    newpixel = makecol(125, 125, 125);

                //medium gray
                else if (r >= 215 && r < 235 && b >= 215 && b < 235)
                    newpixel = makecol(135, 135, 135);

                //light gray
                else if (r >= 235 && r < 255 && b >= 235 && b < 255)
                    newpixel = makecol(155, 155, 155);

                //only replace semi-transparent blocks
                if (r != 255 && b != 255 && newpixel)
                    putpixel(image, i, j, newpixel);
                    newpixel = 0;

                oldpixel = 0;


    return image;

Envisioning PLEX

Leave a comment Standard

I realized that I never wrote up the storyboard and notes I drew up when I decided to make PLEX. Of course it has changed a little bit since then, but the rules and concepts still stand. It includes pictures of how the game works, gameplay rules and restrictions, the game map, and so forth and so on. I originally got the idea for PLEX when I was reading Danc’s Lost Garden blog. He gives out free artwork for gamers to use when making their own game in his prototyping challenges. He also includes a mock up of how the game could actually work. I decided to take his graphics and build my own version of a game with them: PLEX.

Origin of the Game Name

The title PLEX comes from the word complex. This game is a complex puzzle rpg. Therefore I took the last four letters of the first word and I had the game’s title.

Object of the Game
Story Mode

Moving a block on the board

1) Arrange the blocks so the characters can get to the correct positions on the board

2) As they get the characters to the correct places the game story unfolds

3) Clicking on a block selects it and moves it up to the highest block position

Game Rules

1) Blocks can move in four directions as long as:

* the block is movable

* the block is moving to a valid position

* the block position its moving to is no more then one level higher than the blocks current height

2) When the block is moved it drops down until it hits the block below it

3) There is no time limit to moving blocks

4) When a block is put into the correct position (of a bigger puzzle) a sound plays

5) Characters loose health if they walk into water, hit a monster, or fall through the bottom of the block board

6) Character movement


7) Block movement

Moving a block, top down view

8 ) Blocks cannot be moved if they have a rock, character, chest, key, monster, or jewel on them

Single Player ScreenshotGame Layout

*digging uncovers jewels

* rocks can be destroyed by explosives

* shovel can dig up brown, grass, and ground blocks

* left clicking on a character on the board make it repeat its story dialog

* right clicking on a character brings up an options menu

* rocky ground blocks require using the shovel twice

* only stone blocks can be placed over water blocks to allow the character to cross water

* character can walk on all blocks except water blocks and blocks with other items on them

* clicking on the store picture will bring up the store buying menu where characters can use their jewels to buy items

* click on the star will bring up the save menu

Game Scrolling Map


* A town with a character in it means that character starts in that position when a new game is started and they are picked as the playing character, or they can be found in that location when another character is playing the game.

only in story mode


Motto: a world where building is half the fun

Alex – was born in the builder’s guild town. His family comes from a long line of builders. On his 16th birthday his parents decided to give him his very own building project. Only something goes wrong and his supplies are never delivered. Now he has to travel around the towns and villages of PLEX to figure out what happened.

Kitty – her family runs a store in Mercy Falls. When they run out of shovels they ask her to go to the other towns and villages to buy some more.

Tanya – was born on a boat out at sea. When the waters of Waterville drop and the boats can no longer sail the village council sends her to make a wish in Wishing Well Falls to bring the water back into town.

Lisa – is a shepherd in Merryfield. One morning she falls asleep and her flock wanders off. Now she has to get them back before they’re lost forever.

Raven – is the princess of PLEX. After spending the summer with her uncle she decides life is too boring! Raven wants a little adventure off on her own…

Bella – is the daughter of the best item makers in PLEX. Only she ruins everything she touches. When some kids in town make fun of her latest attempt to make dynamite with explosive consequences, she decides she’s had enough and runs away from home.

New Game Tutorial

1) Teaches player to use the mouse

* left mouse button selects a block

– selected block lifts up into the air

* left mouse button click on a space with a selected block in the air drops it into its new place

– plays a sound if the block can’t move there

* right mouse click opens the place block menu

– if they have blocks from the store

2) Teaches them that some blocks can’t be moved

3) Teaches them that some blocks will give jewels if they are successfully repositioned in the puzzle

4) Teaches them how to buy items and blocks from the store

5) Teaches them to move their character with the keyboard keys

6) Teach them that hitting water blocks will hurt their character’s health

7) Teach them they can’t move past rocks and trees

8 ) teach them they can’t fall over ledges

9) Shows them how they can use ramps to move their character where they couldn’t before

Game Features
in story mode

1) save game

2) load game

3) play as one of six characters. Each character has its own set of puzzles and mini-missions, and map layout

Game Statistics

1) Blocks moved

2) Blocks dug up

3) Rocks destroyed

4) House pieces placed

5) Shovels used

6) Bombs used

Build Mode

The object of this part of the game is to make patterns with the blocks on a much larger board (100 x 100 x 6) to build houses and bridges and things like that. This is a multiplayer version, so you can talk to other people who are online playing PLEX at the same time you are. As you play in build mode you get jewels for digging up some blocks and a lot more for creating a pattern or house. Players with the most points are listed on a high point player list. There is no save capability, everything is updated in the online database so when they logout of the game they don’t loose their old data. However the board can change drastically from the time they leave to the time they come back.

How to Make a Game Fun

Comments 2 Standard

Sooo, we know we want to make a game. But if the game isn’t any fun to play, or its too hard/easy to play, or to hard to learn then we find ourselves back at square one. How do we balance out what we want to accomplish in a way that’s entertaining and holds our interest?

The secret is that any game can be fun. How many times have you played a game that had a lot of potential but it lacked story line, or character development, or it had too much fighting, too much blood and guts (or not enough!) or was too hard to control…. This is the reason people stop playing a game, this is the reason we don’t think its fun.

The best way to make a fun game is to think about all the games you’ve ever played. Especially the ones you didn’t like. Why didn’t you like them? The answer to this question will be different for everyone, but that leaves a happy medium somewhere out there. If you thought a game was too cutesy, then it needs different graphics. If the game had too much fighting in it maybe it would benefit from a story line, or smaller missions and objectives, or little puzzle games. If you think about it, all the games that you LIKE are fun. They’re fun because they have a good balance of everything you like in a game. You may like being able to play an entire game in only a few minutes, or spending weeks getting to the big boss that’s terrorizing the town.

So the secret is to make a game fun is that has similar features and concepts of games you LIKE to play and none of the features or concepts you DON’T LIKE in games you DON’T play — but doesn’t copy those game. This is a lot harder then it sounds but originality is one of the biggest selling points in a new game, a game that sets new trends for the gaming industry. To make a fun game, take what you like, and leave out what you don’t like, and make it original; this will put you on a path to success.

Conceptual Reality

Leave a comment Standard

Although most of the games I’ve made are online text based games, they’ve taught me a lot of valuable knowledge. How do you make a game that keeps people addicted? Some developers spend years on a single game only to have their million dollar budgets blown when they can’t get it off the shelves and into people’s houses. Some places over-price their products, like the PS3 and the iphone whose prices have dropped dramatically from their initial 8 and 900 dollars.

So the secret really is balance. If you make something too graphical, then sometimes the story line is lost in the process. If its too hard to level up, or learn a fighting system, or beat a boss, or even get the hang of camera usage or movement then you’ll find the game left in the dust after hours of hard work for something you thought was the next best thing to come to video games.

How do you balance something out? How do you make something fun thats easy enough to play and hard enough to work at without loosing player’s interest? How do you take advantage of your target audience, or how do you make your game appeal to a larger audience? In my most successful online game I did something that no other online horse games had tried before my game came around (and yes there are a lot of copycats now, and my biggest competitors have changed their games to reflect my strategy) — I made it realistic. This simple concept keeps my game challenging, yet interesting at the same time. The game reflects real challenges, hardships, and the REWARDS you would find in real life. Not only does this give my game a huge advantage over competitors, it appeals to people of all ages and genders. I’ve talked to 70 year old men and women, 6 year old boys and girls, and teen boys and girls of all ages. The online connectivity means that people from Australia who share a passion for horses can talk to someone from the United Kingdom and Asia and South America. I get hits from places all over the world from people of all ages and genders because I took one single concept and put it into action.

Did I think about my target audience? Of course I did! I try to use colors and pictures and wording that is easy for children and teens to understand. But at the same time there are several different levels of complexity within the game. Younger children grow ecstatic when they buy their own virtual horse and learn how to feed it and care for it and breed it. Then they scream and shout when they come online one day and there is a little baby foal waiting for them. Teenagers show and race their horses like they would in real world. They learn how to barter and sell, and train their horses to beat out the top competition. Adults and older teens learn the real mechanics of the game as they figure out how EVERYTHING they do in the game effects their horse’s performance and potential. Using this model kids are drawn back to the game again and again as they learn first the mechanics of play when they are younger, the competition as they grow older, and finally the challenge of figuring out how everything is connected. This game follows them from one stage of life to the other and it shows no signs of stopping anytime soon.

What about profit?! It seems like in today’s society everyone is worried about making a profit. If you put millions of dollars into a game you want to see the return — twofold. I think we’re forgetting something simple. If you can make a game that is fun, and enjoyable, and addicting, the profit is already there. Focusing on the profit of the game seems to take away from what we really should be looking at. Can we play this? Do we want to play it again? Is it too challenging, too easy, does it take so long to reach the next level that we loose interest? Is this FUN? Really, that is one of the biggest things game developers should be asking. If the game isn’t fun to play, then who is going to want to play it? If video games are like doing math homework — repetitive and boring —  there’s no point playing the game when we really should be doing our math homework.

So where does this leave us? Video games are becoming repetitive and predictable. Yes, we all still run out to the store to get the newest Final Fantasy or Resident Evil, and so forth and so on. But we’re getting tired of having the same thing again and again. We need to take chances, stop focusing on the profit, and we’ll find the new game that steps outside of the box can take us much farther then video game remakes ever have.

PLEX Source Code Version 0.02

Leave a comment Standard

So here is the new source code (available under gpl license) and a screenshot of the new layout on the build screen due to the problems I had with the allegro GUI system.


The Downfalls of Allegro GUI

Leave a comment Standard

Okay, so after hours of torturous tutorials and lots of headaches over code that is making my brain hurt, I’ve finally found a way to get my GUI login working for PLEX. Because Allegro GUI’s steal the focus until they are closed, this presented me with a few problems.

1) I couldn’t figure out how to get the focus back to my own coding

2) Once I got the focus back, I had to find a way to draw what was on the screen before (and wasn’t showing up because the focus was lost)

3) Changing fonts for password protection

Now, the best solution I came up with — with a little help from Chris Martin — was to incorporate a lot of what I had planned outside of the GUI into the GUI itself. This means that instead of having clickable text in the background I made that text into buttons on the GUI.

Sooo… how to get the focus back after you’ve started the GUI dialog? The answer isn’t as simple as it should be. I’m going to end up using a flag. When the flag is set then I’ll show the dialogs (and loose the focus of my background scripts) and once the mouse has been clicked outside of any of the GUI boxes then I’m going to swap the flag and give the focus back to my scripts.

One of the issues with this is that when you bring the focus off of the dialog then it disappears from the screen. In order to fix that, I’ll have to capture the screen before the dialog is closed and then blit that to the screen in its place. That way it will look like the dialog is still there, even after the do_dialog function has ended.

Then, once the user clicks in an area with the dialog boxes, I’ll toggle the flags and have the dialog boxes show up again. Since the user’s name and passwords are saved to the strings passed into the dialog when its started they will still be there once the focus returns to the dialogs.

Finally, the password box issue. My first thought was to create two dialogs and then change the font as the focus changed back and forth to the password box and the login box. However, I decided that I didn’t want to worry about keeping track of the focus on the other GUI items and the password dialog and the background things I wanted to do as well as switching the fonts back and forth. Instead I’ve decided that as of now I’m going to leave the password box as regular text.