Tag Archives: PHP Games Series

Planning is Important

Planning is important, damn it!

I had a conversation with peer in the CIT 125 (Game Design) class about planning. I told him basically that after working on several games where the development was ad hoc, that planning is very important. The more planning, the better the game will be and the less planning, the more terrible it will come out.

However, I couldn’t really tell him how much planning is needed. The professional commercial games, the last time I read from Gaming Mag. takes about 6 months and several games have every detail planned, from speech to missions, to how everything interacts with each other.

The ideal game means that everything is seamless and fluid. That means that everything has a function. Why is this component in the game? Does it enhance the player’s enjoyment or allow more ease to the overall experience.

The discussion came up in class about difficultly in planning games. I stated that you can create the flow to where the game is only as difficult as the player competence. A game should be difficult and require strategy, but should be so difficult that it requires the best gamers to beat it. It would cease to be fun at that point.

Playing Two Worlds has been fun and because it is the right level of complexity. It is easy in most cases, yes, but requires strategy and you can easily die if you enter a situation you’re not prepared for. It has been fun to me, because it took a while to get a feel for how to play the game and beat the monsters and enemies. It also wasn’t so difficult like some games where it is impossible to get passed the first level.

Why Planning is difficult

As a developer, my focus wants to be on development and not planning. “Okay, I have two pages, lets start cranking out some code!” Not exactly the best idea. Thoughts of spending several months on planning is depressing to the point of extreme despair. “You mean I can’t program for three months until this is done! Just kill me now and revive me when it is time to start.”

I think the experience will be refreshing however, because I can go into the game and have a firm plan on features and know when the game is finished and ready for players to join in. Also, if it is a team effort, the other developers will know which tasks to complete and know when the game is finished also.

Wouldn’t that be refreshing? Not having to communicate your goal in abstractions and expect the others to know what you mean and not what you say. They won’t by the way, they will do what you say and not what you mean and things will start to break down from there.

Having a massive document saying this is where we are at, this is where we are heading, and this is what you will and this is what I will do.

There has to be a Story!

What is the point of playing a game without a story? For what purpose am I playing this crap, when I could be doing homework, or watching TV?

A story would partly answer those questions. People can become captivated by stories and the desire to get the ending can be enough motivation for them to continue playing. The answer is at the end of the game. Having a good story can be difficult, as can be having a good game play. If you have a really good story and adequate game play, then it might mean more than having no story and functional game play.

The goal must be to strive for both a great story and fun game play. Functional means that when a player clicks a button, something expected happens. Having fun game play means that they enjoy clicking buttons and are placed in the magic circle of the game. They do not fully realize that clicking a button is merely clicking a button, but doing some function to continue the game play.

Hmm, difficult to explain, but mostly clicking a button is work, but if the game is fun, then clicking the button is fun. If at some point they realize that they are merely clicking a button and think it sucks, then more focus should be made to cure that painful experience from the game play.

Background Story

Really difficult. At least for myself. I’ve tried it for Mecha Asylum and did a couple of drafts, but never wrote anything fascinating. I would say it isn’t needed, but would enhance the game play. Revealing the story’s background through interaction with characters is easier, in my opinion.

It might also help to develop the background story by doing so. Part of the complexity could be in part to what the background story should contain. Should you speak to the player as a player or as a person in the story? I would assume the latter would be the case. However, in what way should it be written to meet that? Should the background story include part of the history? How long should it be?

For Mecha Asylum, I wanted to have several pages for the story, but it became boring really fast. I became disillusioned by the crap that was typed. A good writer I am not. Doesn’t mean I’m going to try, but I shouldn’t expect it to become a best seller. Nor should anyone else. I think readers and players are forgiving or enough will be.

Providing Freedom

I am a firm believer that the player should be given the freedom to do whatever he or she wants within the confines of the game play. If providing a story and missions, this would require a great deal of planning as to what the final act will be. I would assume that if the game is online, that there shouldn’t be a final act. However, providing a story that continues is perhaps difficult.

For Robotechnik, I would want to develop it as having reputations with not only other human players, but also other computer players. I would also add computer players, so that the game isn’t boring with only a few active players. Lets say that there is dialogue between computer players, before and after the battles. Then when the same computer players meet the same human player, the computer player remembers the human and the dialogue reflects this.

This would probably require some degree of AI in some cases, but I would expect it to adds some unique style and excitement to the game. If AI is used, it shouldn’t be the primary focus, it should be used as a tool where it is needed to enhance how the player plays the game.

Possibly Related Posts:


Absidon Games Game Goals

The goal says nothing about the story, interface, or mechanics of the game. The story is very important, but focus can never be lost of the goal. If there is no goal, then it may very well go off in different directions and quickly become chaotic. The focus must be implementing elements will allow the player accomplish the goal.

I’m sure there are other games, that I’m forgetting.

Mecha Asylum

An universe where players build mecha suits and battle other players. The goal of the player is to build the “best” mecha suit for which to defend and attack effectively. The goal is to collect money to further upgrade their mecha suit. The player can collect money by: defeating other players, completing missions, and finding and selling metals.

Heat of the Race

The player’s goal is to win races against other players. The player does this by using the money to upgrade their vehicle.

Battle Machines

The player’s goal is to win battles against other players. The player can buy new robots, upgrade existing ones, and sell old ones. Robots can be destroyed and damaged, which means they may need to be repaired.

Earth 3045

A community sim, based on the goal that in a war torn world, the player’s goal is to help rebuild it. In that sense, the player’s mission revolves around their job and alliance. However, building is a fundamental goal, even for a thief or farmer.

Possibly Related Posts:


Game Logic should use Precision Math

Where applicable in PHP, such as float types, or values that could become float types. Given the dynamic typing of PHP, it would be wise to do so to prevent possible and most likely probable weird ass bugs during and after development. Even with the performance decrease, I would rather know that I covered enough systems that a potential bug won’t cause minor cheating mechanisms to be abused by players.

I remember a while back that there was a floating precision bug in Kingdom of Chaos that would allow for two for the price of one (or something of the lines where the number would ceil instead of floor). Their solution (if I remember correctly) was to floor, but I think if they had used bcmath or one of the others, it would have solved the problems of adding two float type numbers.

One problem with the solution, is that bcmath or any of the others can’t be counted to be installed on all PHP installations. Falling back to built in PHP floating math, is okay, because it might be the only solution that doesn’t involve superior complexity.

Possibly Related Posts:


PHP Blackjack

A Little History

The reason I’m revisiting blackjack is because I have a C++ version and I want to port it to PHP, for fun. If you want to have a simple project for learning a language, other than “Hello World,” then Blackjack is a good project.

The reasoning is that Blackjack is pretty simple, has few rules, deals with pesky randomization (which was a bitch back before STL days (God I love STL), damn compiler bastards, except for Microsoft and GCC). Anyway, Blackjack teaches and allows practice for:

  1. Randomization
  2. Handling input and output
  3. Looping
  4. Conditional Statements
  5. Procedural Programming (totally don’t want everything in Main)

Disclaimer: This code is from my friends project. I did Blackjack using OpenGL toolkit, it was crap, but was a great learning experience (even though I forgot most of what it was that I learned).

Guidelines

Procedural Programming

Okay, it is generally a bad idea to have everything in the main(), gets cluttered and just amateurish. For a project of this size, it is a good idea to break things down into reusable functions to help with debugging and development. It is also good practice.

Keeping it Simple

The friend’s project broke it down to the principle that the card was not important, but the value was. The only problem with this, was that you couldn’t say, deal an Ace and have it either equal 1 or 10. The nice thing was that it kept from building a deck, keeping track of the cards, and keeping track of the players hand. Good stuff and I would had spent a great deal of time building it to where there was a deck. The idea is quick and simple, so it is good stuff, no matter how much I disagreed with the implementation.

1. Intro

The intro states the games intention and gets the game started.

cout < < "Welcome to BlackJack!" <<endl <<endl;
cout << "Press Any Key to Start a Game." <<endl <<endl;
getch();

The interesting part worth noting is getch(), which gets a character for a variable. Since there is no variable, it will pause the console until one is pressed and then continue the execution. Nice trick!

echo "Welcome to Blackjack!\n\n";
echo "Press Any Key to Start a Game.\n\n";

fgetc(STDIN); // same effect as getch().

Very similar.

2. Holding Stats

The original version held the stats in the main in separate variables and updated the variables by passing by reference. I thought it would be useful to use a global struct instead.

struct bjStats
{
    int wins;
    int loses;
    int draws;
} Stats = { 0, 0, 0 };
class Stats
{
    static public $wins = 0, $loses = 0, $draws = 0;
}

The usage would be the similar for both languages. For C++, the access would use an period instead of the "->" symbol, in PHP.

3. Randomization

The nice thing about PHP is that you don't need to seed the random number using srand(). I usually seed in main() and leave rand() in another function.

return(rand() % 10 + 1);
return mt_rand(1, 11);

I like php better, because you don't have to worry about the tricky math related to the modulus symbol.

Possibly Related Posts:


AI in PHP Games

With the next generation of PHP games using Ajax, the developer can afford to allow better user interaction with battling and Non-Player Characters. Some work can make a game seem more life-like and harder for the player to figure out.

For AI usage, testing and CPU, memory, and storage issue might sway developers away from the more advanced techniques. Not every problem needs a neural tree or genetic encoding for the solution and would be better served with a little bit of creative engineering with traditional means.

Traditional methods have the disadvantage of handling only a known set and can’t be trained for unknown habits that users might exploit. Calculations have the disadvantage of reverse-engineering and possible float bugs. So it would be useful to research AI methods to handle some problems.

The following is a list of problems and possible solutions for current and future PHP games. It is my goal with a few projects to see just how much can be accomplished in the field of online browser PHP games. Another focus is to see how much of a cost is added by using AI.

Problem 1: Calculating Distances in Real Time

Description

There are games that have you wait on moving objects across distances. The traditional approach has been to just use a set calculations which is easily figured by the player. The paths through enemy territory, which would otherwise be avoided (unless initiating a battle) are passed through in all instances.

Solution

There are path finding algorithms, such as Dijkstra, A*, and so on that could be used to accurately find the distance around enemy territory and other blocked locations, say a black hole.

Little can be given on the speed of large proportions, however small sizes are quite fast (logically of course). I plan on doing tests are larger sizes, such as 10k fields and 100k fields, when the classes are passed the testing stage.

There is a completed example for which to work with. My implementation is a lot different and not completely finish.

Problem 2: Enemy Behavior – Shifting Strategy

Description

The problem I’ve came across in RPG games is that the monster just pounds you with randomized attacks. It would make more sense for the monster if it changed its attack pattern for when you are low on health during the start of the battle or grow weaker. It should also try to prepare for spells and try to block attacks whenever it is low on health or run away.

Solution

Giving the enemy life wouldn’t all that difficult to do with traditional methods, but it would require a whole lot of conditional statements. A better method if it could be afforded, is to use Fuzzy Logic or at the very least finite state machines. Fuzzy Logic does require a lot of math and knowledge of set theory (or books and other resources that offer that information instead :-) ).

Problem 3: Enemy Behavior – Learning

Description

How fun would it be that along with the enemy shifting it’s behavior it evolved in it’s technique? If the player is more inclined to use physical attacks, the enemy would start using physical blocking and spells for which to minimize the effects of physical attacks.

Solution

This can also be done using the traditional methods, but it would also be a very long list of conditional statements. A CPU extensive approach, but neater would be to use either genetics or neural networks for the learning. You could also spend time teaching the enemies yourself before the game goes live. Having the game available to what could be a massive amount of people would allow the enemy to well adapt to the players differing strategies.

Problem 4: NPC Interaction – Dialogue

Description

While not important in all games (should be anyway), it would be nice in RPGs, if you received your some of your missions from talking with NPCs. Say a NPC is missing a child and needs for you to search for the missing person. Most of the time, that discussion is fixed and scripted far before hand, and in most computer games as well. The difference is that in PHP games, there is no disconnection between the possible missions and which NPC gives the mission. It is that NPC gives that mission and nothing else.

Something else would be for NPCs that don’t have any missions to give. What about them? I would rather have them be a little bit more intelligent than old 2D RPGs, and have an open discussion depending on how far along you are and if you choose good or evil side. It would get pretty old to have the conversation with the NPC go on longer than 30 minutes or 10 minutes.

Solution

Very intelligent developers and scientists have already developed and worked on this for more than a decade. There is already an PHP library for which to use it in an application. So really, the only thing the developer has to do is spend time writing for which the library will use. It will require work, however not as much as the time it took to write the library in the first place. It would also add that special touch that other games wouldn’t have.

References

  • AI Game Programming Wisdom 1
  • Data Structures and Algorithm Analysis in C++. Pgs 339-346.

Possibly Related Posts:


Next Generation Browser Games, Part 1

Series Introduction

I have been trying to develop online browser games for over a year now and I’ve been playing them for about two years. The one thing that I have noticed is that they are fairly simple in graphical form. Offering static images and forms to manage the game inputs.

For the most part, all of the games are stuck in the early era of video game development where MUDs and simple game play was offered. This series will deal with the developmental stages that browser games can take and will have to take to achieve the next level.

Part 1: An introduction at what it takes to develop current generation browser games.

Part 2: Discussion on what it is going to take and the complexity involved with creating a fully “Web 2.0″ browser game.

Current Browser Games

There is only one known AJAX browser game that exists. All of the other browser games are simple in that they modeled after text MUDs. I have been contemplating the state of browser games and where the future holds.

The excuse I have seen is that it would be require major architecture overhaul to support AJAX. Not true. Even the basic features such as updating player stats wouldn’t require all that much work and is fairly simple.

“Web 1.0″ Browser Game Development

Game Complexity

It takes a lot of planning and developmental skills to create a good game. Most of the games that I have played and enjoyed are fairly basic in the controls, but they are still fun. Some games offer to much for the players and they get overwhelmed, which is my problem with Mecha Asylum and the games I develop. For the player, to many options evaluates to a lot of time researching how to do stuff and most won’t take the time to ‘learn’ how to play your game.

About Game Design

It isn’t that bad graphics and web page design will drive the user away, but it leaves a bad impression. It is worth the money to invest in a custom or good design in my humble opinion, but it depends on how many players you can drive to your game in the first place. You can have the best game design, but if your game sucks, no one is going to play it.

The problem I have had is finding or creating a game design that is both functional and looks great. It seems that unless you go custom and professional, you’ll only get one. There are developers who are good at web design, such as Dragon Knight. Striving for that level, while it may not be the best, is still better than all of the designs that I have put together. Kudos to those blessed with skills of the web master.

The design overall is also basic. You have your area for player stats and links to other pages. You can and want to have multiple form pages for completing complex actions instead of placing all of the fields on one page. It is one of the reasons Mecha Asylum is confusing.

Game Development Time

Depends on how much time you put in and how much you know about programming. If you are a novice, you are looking at about two years at creating your own. Planning is part of browser game development, but not including it, you are probably looking at 6 months to create a stable working implementation if you put in 20 to 30 hours a week.

Mecha Asylum at its current and incomplete stage only took three months, coding full time (20 to 30 hours a week). The main part missing is the admin panel for game management. The game itself is functional, in the sense that it works, but has issues and needs tweaking. To finish it in the sense that it is ‘feature complete’ would probably take another 2 or 3 months.

Planning

With all major projects, browser games require planning. With each iteration of Mecha Asylum development I learned about what to plan and what I can and can’t develop. I’m not saying to draw out every form detail (it would help), but to write down a outline of the pages and what will be in them does help out.

Fun Factor

As I have said before I have played online games before and some are very addictive and fun. Which is what got me into trying to create my own. Some of these games have been cloned many times before with mixed results.

Kings Of Chaos

Well known and well played. This game is what initially got me started on wanting to create my own game and the game is really easy, which makes it all the more fun to play. It does take more than a month to get up there in the ranks, but it goes by very fast.

Evernight

I like this the best because it allows you to gain land and army troops to attack others. Faster paced than KOC and very fun to play also. Smaller player base, so you aren’t against the wall battling against large hordes after your life.

O Game

A Sci-fi galaxy game that is “real-time” stategy. It is common among games to have instant transactions for buying and creating supplies. Most actions have a time set for what you can do and you have to wait for it to expire before continuing. It does take longer to get to a level where the game is enjoyable.

Lots of Examples

There are hundreds others, some of which are great and fun, but most aren’t worth the effort to register.

Game Engines

If you don’t want to build a current generation game engine, there exists already developed ones for different genres.

Next Generation: AJAX Included

I think with JavaScript, games can start looking like old 2D games on Nintendo or gameboy consoles. Using XHTML and CSS as the presentation layer, you can combine JavaScript for interactivity with the user, and finally with PHP at the backend to provide the storage and connects to other players.

The primary problem with this approach is that JavaScript has many quirks that you can’t find all of them in textbooks. You wouldn’t and shouldn’t expect memory leakage but it does exist and you need to prevent it. There are tools that are expected to evolve to help achieve this goal.

The more games that take the next level, the more others will eventually follow. Not every game is going to be to players expectations, so more and better games will benefit everyone.

I still believe using HTML/CSS/JavaScript/PHP combination is easier than Flash or Java with UI and coding. Both Flash and Java are “stable” in that if it works for you, then it will work for most users. With JavaScript you do have to fine tune code to match different browsers and browser versions. No more different than with C/C++ game development with fine tuning for different GPU vendors and versions.

Conclusion

I’m not saying that current games have to take the next step up to be fun and enjoyable. There are plenty of games that are fun and are well featured. Just because 3D games exist doesn’t mean that 2D games are extinct.

The only set back for current generation games is having a great design, but they will still have a place even after more games are developed with “Web 2.0″ technologies. I believe it is better to focus on implementing a well established feature set over an awesome design. Players really only care about the features, but a cool graphics helps.

Possibly Related Posts:


PHP Game Programming Chapter 2: User Management

Planning

What do you want to gather from the player?
Do you have to conform to COPPA, based on what data you gather?
Do you want to keep the user data separate from the game data?
How are you going to authenticate the user and handle account recovering?
Does the user need to activate their account after they sign up?

Member Authentication

You will need to use a form, which could either be on every page or by itself on a separate page. You will also need a script to check the values then log the sign in.

Registering

Well? You want (re: need) people to be able to sign up. If you ask for the gender, address, or other personal information, then you will need to conform to the COPPA policies. It is easier to not take any of those and leave the COPPA out of it. It is always a good idea to make the extra check that the person is over 13, because you could be liable for damages or something.

If the input values don’t validate, then you need to spit the form back out at the person. Preferably with descriptions on what the user did wrong and solutions. Usage of JavaScript could help, but not required if the backend is done right. Most scripts run fast enough to where it isn’t needed. Even if you do use JavaScript, you still want the PHP script to check the values, in case the browser doesn’t support JavaScript or it is turned off.

Once a game gets popular, a person may consider sending bots to automate the registering process. It is a good idea to use some type of image creation (generally GD or ImageMagick) and requiring the user type it in before they can finish.

Recovering Password

It is always a good idea to encrypt a person’s password in the database. Which encrypt you use will depend on how easy it is to recover a user’s password. MD5 is impossible and better to send a random password. (My)SQL Password function is also impossible to recover the password (as far as I know). If you encrypt with another PHP encryption technique, then in most cases it is possible to decrypt the value and send it. If you want to take the time to develop all of that, then go ahead, it is easier and faster to use the SQL Password function for both validation and encryption. You can secure it easily but using the $clean_variable = mysql_real_escape_string($unclean_variable);, so it is a win/win. Better encryption would be using the PHP encryption technique as a few of the methods are fairly uncrackable (as much as encryption can be unhackable).

Activation

Email activation does irritate users, but it could save you from people trying to get in with bogus email accounts. There are a few ways of doing this, sending the password to the email address or sending a code for activation. It works by only allowing those who get the email to sign in. If they don’t get the email and can’t sign in, then they can’t play and you can delete their account.

For those that use the code activation technique, it would be a good idea to allow resending the code in case it got lost on the email server (outgoing on your end or incoming on the user’s end). It would allow those who really want to play another chance to sign up. Or you could just have it automatically delete the account after so many days and force the user to sign up again.

Possibly Related Posts:


PHP Game Programming Chapter 1: Introduction

What this is not

This is not a tutorial on how to use PHP, I’m not going to go into any basics. You are expected to understand functions, basic language syntax and usage, along with some knowledge of classes in some areas. If any parts outside of this introduction is confusing, then back out, learn PHP, and then come back.

Getting Help Rant

A person who wants to develop PHP games, either based off of prebuilt game engine, or from the start, should know some parts of PHP. It may should like common sense, but many who want to develop games do so wanting to start at the point where they are masters of coding and already several months into development. It just isn’t going to happen and will be quite frustrating, both to the person who they will ultimately try to get to help (or preferably do all the work) or to themself.

Learning PHP isn’t difficult, learning how to do it right is. When you develop something, there are going to be people who are going to try to break it and take advantage of coding and design flaws. Coding the “easy” way will sometimes lead to security flaws that will open the game up to just about anyone. PHP is great and easy language, but it will take some time to learn how to do it securely. Security techniques will be used in the following chapters, but better techniques can be found elsewhere (and should be looked at to gain a greater understanding of the problem and solution).

Reading, dreaming, and researching PHP for at least three months will change how code looks and what errors mean. The alterative is to spend the same amount of time going to chat rooms, forums, and emailing PHP developers, who won’t have the time or the patience to train you, so you would learn nothing. The alterative will also alienate those who may otherwise help you on your path of helping yourself. You learn nothing being spoon fed by other people and will be confused by even the simplest of syntax and coding problems. There will be those who may take pity, but they won’t be there to solve all of your problems.

PHP Game Programming

The primary focus is game engines. How to develop them, how to work with game engines that are already coded for you, and a general design understanding of them. Not all of the sections are coded by me, and I will be making assessments of other game engines built by other developers. Learning from another game engine and coding by example is a great, if not slow, way for learning.

The three game engines that will be used and discussed are:

  1. My Own
  2. Dragon Knight
  3. Gamers Fusion (v3 if I can get the source)

Chapters

  1. Introduction
  2. User Management
  3. Game Engine Development Parts
  4. Dragon Knight Core
  5. Dragon Knight Admin
  6. Dragon Knight Hacking
  7. Gamers Fusion
  8. What not to do

Possibly Related Posts: