An exploration system for my game.

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Mightywayne
Forum Contributor
Posts: 237
Joined: Sat Dec 09, 2006 6:46 am

An exploration system for my game.

Post by Mightywayne »

Well, the time has (sorta) come.

As some of you may remember, I am coding a game. I, however, am stumped with this one problem.

In the game, your character is able to "explore" the world. I was figuring I'd use "areas" to show where the character was in the world. So let's say you step right out of town, right? And you're now in some plains sorta area. You'd see your character at coordinates 1,1 on a rather large .jpg or .gif or .png file (honestly I don't know which is best for this) and then you hit the "down" arrow and - gasp! - your character is shown, on the same .png or whatever file, as actually going down.

So, basically, what happens is you have moved the image of your character OVER the image of the area itself.

I can figure out how to move my people in the database fine. You hit up? Update their x coord + 1 or something. That's the simple part.

I need to know how I can make PHP tell the server that their character is at that certain coord, put the character there, and when they move to a new area (say, they make it to 26, 26) a new area picture will show up and put their characters at 26,26 of that.

I hope I described the system well enough.. and I hope this counts as "theory" too, because I'm pretty theoretically challenged here. Hope someone can help me out...

-- Spencer
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

PHP doesn't tell the server anything. I think you need to look into AJAX.

When you mention the simple part being when you hit the down arrow you update the database - that's not simple.

If you have 10 people playing this game simultaneously, and they're all moving about in the game, perhaps even holding down the movement keys, then your database is going to be getting hammered. You won't want to update the database like that. Are the different players being controlled by different people going to be on the same playing surface on everyones screens? If so, PHP doesn't seem like a wise choice for something like this.
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

Take a peek around http://forums.astrumfutura.com and http://sf.net/projects/quantumstar . Both have a lot of code and discussion on PHP coordinate mapping to square cell and hex cell maps. Not entirely finished - it's on a break until late Summer for development - but should be informative from a PHP point of view. Jacob has even done some work on porting the A* and Dijkstra pathfinding algorithms to PHP...

On the user interface - AJAX. Only store new coordinates to the database periodically and make certain the player has a "save" option to use before closing the browser tab. Then always save to database at key locations (towns, creature encounters, places of interest). Pretty sure there's a few code samples on the forum for movement with Ajax - they just won't have the client side caching included unfotunately.
Mightywayne
Forum Contributor
Posts: 237
Joined: Sat Dec 09, 2006 6:46 am

Post by Mightywayne »

Well, it's just a single query, though, to update the user's position. I suppose I could think of another system for doing the movement queries if I needed to.

But I don't know what you mean by "hold down the movement keys". They're regular buttons, links, that just tell the server where to go. There's a chance they'll fight a monster and if they don't, they just move normally to the next spot. It's like a grid.

Edit: I'll look into AJAX, and thanks for the tip, Maug. I'll check that out.

Edit2: Okay, AJAX looks interesting.... but where do I start? Do you really suggest I learn another language just to do this? oo; I wouldn't imagine mapping two images over each other would be that difficult...

Edit3: So I checked out this other site that does it, and they use a giant table for their maps, with the background image of the table being the map itself. Their links to move look like:

http://alpha.pokemoncrater.com/map.php?x=18&y=5&map=9 (yes it's a pokemon game)

I'm actually leaning towards this idea more. I'm wondering, though, how they pick where the character will be with the php?x= stuff. That's what I really need to know - how to take from a GET and place onto the image itself.
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

Have you ever programmed a PHP application before? You're throwing yourself in at the deep-end by trying to create a game in PHP alone as one of your first PHP applications.

AJAX is not a different language, it's just a way to use Javascript. You will need to be very comfortable with Javascript before even attempting to build a game anyways.

Check out jQuery or scriptaculous, or you could find the thread around here where people voted for which AJAX/Javascript library they use and why.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

What you're thinking of is ultra slow, very bandwidth-intensive, and probably not worth the money it will cost to run. There are many mediums a lot more fit to handle live updates and such... PHP is not one of them.

I think you're misinterpreting what PHP does. It generates HTML, dynamically. That's pretty much it. Whatever PHP does can't be seen until someone loads that particular page. It's not a client-side technology.

Flash... AJAX... Shockwave... C++. Those are more suitable for game creation.
Mightywayne
Forum Contributor
Posts: 237
Joined: Sat Dec 09, 2006 6:46 am

Post by Mightywayne »

Hmm... but what I'm saying is, do I need to use Ajax? Or would the background-table-thing actually be Ajax?

I know a very little bit about JavaScript... but the PHP app thing I can't agree with. What "inspired" me to take up coding a game was that this guy has this really crappy game with like the crappiest code evar, yet still so many people played it, and he made so much money and stuff. Just thought I should say. :P
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

superdezign wrote:Flash... AJAX... Shockwave... C++. Those are more suitable for game creation.
I don't know why people consider AJAX a language in itself. Ajax is simply javascript making requests to server side technology.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Haha, yes, I'm aware. But JavaScript alone can't communicate with the server, so saying "AJAX" was supposed to prevent me from saying something incorrect. :-p
Mightywayne
Forum Contributor
Posts: 237
Joined: Sat Dec 09, 2006 6:46 am

Post by Mightywayne »

(sorry, dezign, I didn't catch your post; this wisdom tooth thing is killing me)

Yeah I tried to think of a way to do it with Flash, I'm actually not that bad with it. But I couldn't think of how to do random encounters and stuff and I'm not much of an artist. Also how fast everything would be moving... it just really wouldn't be the best medium for me. I really just need to figure out a way to smush two images together according to a URL. But what I'm saying is if I need to use AJAX to do it. I'm assuming I'm going to have to be using JavaScript for this, of course...
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Tried to think of a way? Did you get around to programming it? Your random encounters probably wouldn't be any different than in any other language. ActionScript, as of 2.0, is awesome.

And you want to do what to the images? Make them into ONE image? Or have one hover above the other?
Mightywayne
Forum Contributor
Posts: 237
Joined: Sat Dec 09, 2006 6:46 am

Post by Mightywayne »

One would hover over the other. The player's icon, and the area's image itself.

I am actually aware of how powerful it can be... hmm. It's just, the pace of Flash. It's like, okay, they hit a random encounter. Send them to the page stating who they are battling. They win, and then... send them to the Flash again? It'd have to pick up instantly where they were. And honestly, I'm not that amazing with ActionScript to know if it's even possible like that. I'd much prefer to have the hovering .jpg's than load it all in a big scary .swf, which I think might even be a security risk. (it's extremely easy to decompile .swf's, unfortunately =/)
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Why wouldn't you do the entire game inside of Flash? It's got more security than HTML and JavaScript, I can assure you that much. And anything that can be done as cheating in Flash can be fought.
Mightywayne
Forum Contributor
Posts: 237
Joined: Sat Dec 09, 2006 6:46 am

Post by Mightywayne »

Well you know the game is browser-based. o.o; If you want the link, it's right here:
http://www.monbre.burnttoastonline.com and don't pick on the layout problems, those are being worked on if you even see them. >_>;;

But yeah, it would be interesting, but... again, like, can you use Flash to grab the coords from the database and after the battle is done, bring that exact position back? The battle's not done in Flash. I'm just thinking it would be a lot easier to do the backgrounds thing. =o I mean I don't know Flash THAT well, I use it more for design, but I can do the basic things. I don't want to learn AS simply for creating the exploration system. (which frankly doesn't even need to be this pretty, but I would prefer it a lot if it were; text can only be so exciting)

Would it be easy (gasp!) to do it in JavaScript? I mean honestly I don't think it'll be so tough that I'd just choose Flash over it.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Well, it wouldn't be easy either way, but if you did it in Flash it just may look more like a game. :-p

ActionScript 2.0+ is very similar to JavaScript, PHP, and C/C++. You just have to be familiar with the purpose of MovieClips and such.


I'm making a game in Flash (on the side of course... I'm not being paid to do it) and the random encounters is the easy part. The hard part is coming up with a scripting system so that I can easily create maps with complex events. Otherwise, it'd be a boring game. (NOTE: I'm not doing anything multi-player. I'm sure I couldn't afford it bandwidth-wise.)
Post Reply