PDA

View Full Version : How Should I Create this Game?



SmokeHacker
November 1st, 2004, 01:55 PM
( Sorry, I couldn't think up a more descriptive title )

I am working on a game and I cannot decide which method is better suited for what I would like to do. I will give a little background information on the game first, which will hopefully give you enough information to help me.

Basically my game is a turn-based version of the original Grand Theft Auto game. So the viewpoint is top down on a city and mostly involves driving a car around. There is also an ability to enter buildings to perform certain tasks.

As I mentioned my game is turn-based, so movement is based on steps ( instead of the usual real-time movement of a car ). When the player presses the arrow keys the car will move one step in the correct direction ( each step is 128 pixels, so everytime the 'Up' key is pressed I need the car to move 128 pixels upwards ).

I also need to keep the player on the road, they cannot drive off of it. But since my car movement is based on steps ( 128 pixels a step ) I cannot have the car move 40 pixels, hit a wall and stop. The game needs to know if the car can move a certain direction before it actually moves the car. So if the road is only going up and down, and the player presses 'right' I do not want the car to move at all.

The same idea of not driving off the road applies to entering buildings. If there is a building to the right of the road and the player presses the 'right' arrow I do not want the car to move at all, but I would like text or something else to appear. This, I'm assuming, can be accomplished the same way as keeping the car on the road, except with some added code to display the proper text.

So now to my actual question, what is the best method to create this game? Art based or tile based? ( Or any other method possible... )

I have created all of my graphics in tiles, except they're different sized tiles. So roads are 128x128 pixels, buildings and environment ( grass, dirt, water, etc ) tiles are 256x256 pixels ( I outlined them in red in the above image ). I am not sure if it is possible to create tile-based games with varying sized tiles. But if tile-based is the way to go I can always cut the 256x256 tiles into several 128x128 tiles.

I think I would prefer to make the game art based though, so the artwork wouldn't appear repititious and I could add various details without worrying about them tiling. But I have been trying a few tests in Flash and have been unsuccessful. I am attempting to use hittest's to stop the car from driving off the road, but I have noticed that the hittest code only works after the car intersects the hittest area. So the car drives off the road, then the code to stop the car is executed.

I am new to Flash, so this could be a very easy problem that I simply do not know how to solve. I would appreciate any input on how to create this game. Once I know which direction to go ( art-based, tile-based, or other ) I will be able to look at sample code or tutorials for what method I'll be using, but I'm sure I will still need plenty of help here.

Thank you for any help you can offer me.

Dr Warm
November 1st, 2004, 11:39 PM
you'll probably want to make a tile based game, but if you're just starting out, it'll be pretty difficult...... so it's up to u. have a read of these tute's here (http://www.tonypa.pri.ee/tbw/index.html) on tile-based, if you don't understand any of it go for the art-based

as for your hitTest you can apparently do object.hitTest(_x+carwidth, _y, true) so it doesn't haven't to already get there make sense?

Dr Warm
November 1st, 2004, 11:40 PM
sorry i just saw u had a map aswell, you should be able to do it with tiles, but the turning might be interesting, i've seen iso based car-racing tile games that worked ok though

SmokeHacker
November 2nd, 2004, 12:50 AM
Yes, I have read those tutorials on tile-based games. It seems my idea is more suited for tile-based, but if I could figure out the hittest problem I have a feeling that art-based would be easier.

And no, the object.hitTest(_x+carwidth, _y, true) doesn't make sense. I understand _x and _y refer to the horizontal and vertical axis respectively, so you're saying the current X position + the width of the car ( which is 64 pixels ), but I'm not entirely clear on how that would stop the car from moving if it intersected a hitTest area.

Dr Warm
November 2nd, 2004, 03:54 AM
well instead say you wanted to head forwards, i think this is how it goes:
with(car){
//_x and _y are current positions of the car
if(road.hitTest(_x, _y+carHeight, true)){
//don't move
trace("can't move upwards");
} else {
//move forward one square
}
}

dinner dog
November 2nd, 2004, 06:49 AM
why not set out the distance the car will move (in this case 128px) and use that instead of the width? eg:

if(road.hitTest(_x, _y+move_distance, true)){
//don't move
trace("can't move upwards");
} else {
//move forward one square
}
}

SmokeHacker
November 2nd, 2004, 04:20 PM
I would still like some input on whether I should do tile-based or art-based, but at the moment I am working on an art-based version to see if I can get the hittest's to work correctly. This is what I have so far:


onClipEvent (load) {
// declare and set variables
speed = 128;
hitBuidingRight = false;
}
onClipEvent (enterFrame) {
// declare and set variables
nextX = _x+speed;
// hitTest for building
if (nextX, _y, hitTest(_root.hittest_building)) {
hitBuildingRight = true;
} else {
hitBuildingRight = false;
}
trace(this._x);
trace(nextX);
trace(hitBuildingRight);
// move up, down, left, or right
if (Key.isDown(Key.LEFT) && !Key.isDown(Key.RIGHT)) {
_x -= speed;
_rotation = 90;
}
if (Key.isDown(Key.RIGHT) && !Key.isDown(Key.LEFT) && !hitBuildingRight) {
_x += speed;
_rotation = 270;
}
if (Key.isDown(Key.UP) && !Key.isDown(Key.DOWN)) {
_y -= speed;
_rotation = -180;
}
if (Key.isDown(Key.DOWN) && !Key.isDown(Key.UP)) {
_y += speed;
_rotation = -0;
}
}


Let me explain a little about what's going on in that .fla file. The building located towards the center/right has a rectangle on top of it ( Alpha 0% so it doesn't show up in-game ) used as a hittest. If the car is next to that building and the player tries to move right I do not want the car to move at all ( as there is a building there ).

The problem I'm running in to is that the hittest doesn't work the way I want. If I move to the right I drive onto the building, then if I try to move right again it doesn't allow me. So the hittest code is working after I move, and I need it to somehow know before I move if it's possible.

Any help is appreciated as always! Thanks.

mad_man
November 2nd, 2004, 04:50 PM
can u please save in MX so i can take a look and try to help you.

SmokeHacker
November 2nd, 2004, 08:13 PM
Yeah, no problem.

dinner dog
November 3rd, 2004, 08:30 AM
Ok, I had a look at it and I think I've fixed it, you needed to declare your variables as a shape flag.

I really butchered your code to shrink and simplify it a bit but I also had to delete the background so I could upload to Kirupa, But you could easily copy and paste the code back into your old (graphic heavy) file. I also added quick and dirty console because I really hate the trace function in an enterFrame, but that's a personal thing and it should be fairly wasy to revert back to a trace instead.

Anyway I think, personally, you will either need to look into tile based or make your speed incriments smaller. I think it would benefit from a smoothing of the turning... But that's just me being picky.

Good luck
-dinner dog

The attachment is in MX for anyone else wanting a look.

Once again sorry for having to remove the background, but it was the only way to upload it.

SmokeHacker
November 3rd, 2004, 11:30 AM
Thank you very much, it works perfectly! I'm looking over the code now to see if I understand everything you did.

I'll probably have a few more questions as I get further into this project, but thanks again!

EDIT - Ok, I looked through the code and understand it all, but what did you mean when you said that I needed to declare my variables as a shape flag?

dinner dog
November 4th, 2004, 06:39 AM
Yeah Sorry man, Wha I ment was where you have

if (nextX, _y, hitTest(_root.hittest_building)) {

you need to kindof flip it around so the car uses a shapflag (wher it says true in the hittest) this allows the hitTest to test from a point, rather than the bounding box of the object.

(_root.hittest_building.hitTest(_x + speed, _y, true))

Sorry about that my mind was on other things and now 'declare variables as a shape flag' doesn't even make sense to me...

bpalermo
November 5th, 2004, 10:04 AM
Actually, if you're going to use tiles, shapeflags won't matter...

And you could put it like:


(_root.hittest_building.hitTest(_x + speed, _y, false))

Which I believe improves processing speed.

Just in case you wanna know a bit more about Shapeflags. The true or false up there tells Flash to hitTest the coordinates (x, y) to the object (_root.hittest_building, in this case) shape (whats actually drawn into it) or the bounding box (the smaller square or rectangle where the movie clip could fit). Since building tiles are already square, using shapeflags would only tell flash to look for an unecessary shapeflag...

Hope it helps...

SmokeHacker
November 6th, 2004, 05:39 PM
Thank you for the explaination on Shapeflags.

Now, I need the car to hittest more than just 1 building in the game though, so with this code,

(_root.hittest_building.hitTest(_x + speed, _y, true))

can I somehow substitute "_root.hittest_building.hitTest" with an array? Not sure I'm wording that properly, but can I enter 3 buildings into an array then call them up with the hittest code above and make sure the car doesn't move into any of them?