View Full Version : Multilevel platforms for Double Dragon styled game
Skribble
September 1st, 2008, 02:16 AM
Hey guys! Long time no post. I've been a busy monkey working, I've had hardly any time to pursue my own projects other than on the weekends. But I've progressed to the point now where I have most basic things in the engine down, but theres a few things Im still planning to implement. One of which is jumping and multiple platforms.
Now usually jumping is a sinch! You subtract the objects _y by a decreasing number and it simulates the effect of gravity, easy. But this current project is in the vein of Double Dragon, and when you design your game so you can travel on the Y axis as well as the X axis, it becomes a little more problematic. You can't just say "you jump, then when you hit the ground, you land", because the player is always hitTesting the ground! I also wanted to be able to jump through certain platforms. So a little lateral thinking has to be used...
I was going to use the heros _y position as the "ground" point. When the hero jumps, register his current _y positon as the position used to tell him to go back to the stand animation. In theory this works fine, and would be ok to use if I didn't want to implement platforms that you can jump on. Using this would result in the object going through platforms and to the _y position that was registered.
I have a main hero movieclip spawn on to the screen, with an invisible "ground" movieclip (_root.g) making up the borders and "walls" of the game, while another "background"(_root.bg) movieclip is used as the graphic overlayed on the ground movieclip, and I attach platform movieclips inside "ground" movieclip, so platform paths would look like this. _root.g.platform01
So my question you all is, how should I proceed? Im not sure how I should be approaching this problem and would really appreciate any help. Thanks!
Charleh
September 1st, 2008, 06:20 AM
Simple: give the character a 3 dimension vector position and velocity. They should have an X/Y and a Z which can be the jump height (or X/Z and Y, whichever you are more comfortable with, but Z is ususally used for depth)
That way you can have the character jump around like a madman and not need to worry about messing about with variables. Then you just implement platforms as anyone would in a platform game - you may need to create a bigger 'landing' zone for the Z axis of the platforms to make sure people don't have to be pixel perfect on the Z axis to land on them
I've implemented the jumping in a double dragon style engine already - it's got jumping, combos and air moves/combos. It was just an example really, so it needs work but it's a start
Skribble
September 1st, 2008, 01:54 PM
If I have an object that can be above or below the heros depth depending on his position, how do I tell the object im standing on to be "behind" my hero when he is on top. Because he is on top he is technically behind the obejct in _y position, so is automatically moved back in depth.
Any ideas on how I can remedy this?
Also, what if I wanted to add hills/inclines. How could I "force" the hero's x and y to react to hills/inclines?
Charleh
September 1st, 2008, 03:23 PM
Your depth should work on the Z value, not the Y value - all items should be sorted according to Z depth.
I'm guessing you are using AS2.0
Remember that you don't actually need to display the object at it's actual coordinates
What you might want to do is seperate out your rendering code from your actual object code. You don't actually need to use the movieclip object as your game object.
By that I mean you can create a custom class which is a game 'object'. This class updates it's position and velocity based on user input and the game engine, however, what's actually drawn on screen can be calculated
i.e.
If your character is at position X:100, Z:0 and is on the ground (Y:0) they should be drawn at 100, 0 on screen.
If another character is at position X:100, Z:50 and is on the ground they should be drawn at 100, 50 on screen but sorted on the Z depth (so they would appear behind the first character as they are 'deeper' into the scene)
Another character at position X:100, Z:25 but who is jumping very high (Y:50) should be drawn at 100, 75 on screen - yes they are higher than the second character on the Y axis because we used a calculation to determine where they get drawn (Z depth + jump height: 25 + 50 = 75) but their Z value is still 25, which means they will be drawn in between the other two characters.
If you seperate out your rendering you will find all the math for the game logic very simple, then you won't have variables all over tracking jumping and platforms etc etc. In 3D space the characters are simply behaving as they would in the real world - the only difference is you are transforming the 3D space into 2D coordinates and sorting based on the 3D positions to get a 2D representation.
Need a demo?
Skribble
September 1st, 2008, 09:46 PM
That is so strange, I understood everything you said, but have absolutely NO idea what it meant hahah, sorry. You explained it well, it's just very early in the morning and there is a lot of new information there to take in. I would very much like a demo if you wouldn't mind providing one.
Is this AS3.0 you are talking about? Because I havent the faintest clue about OOT or anything like that. If it turns out to be too much of a hassle, I might just skip having platforms in the game and just use the backdrop to simulate hills/whatever. I've been wanting to get back in to programming for a while, and now I have and it's lots of fun, I don't think I want to learn a whole new language just yet, not that I don't fully appreciate your help :)
bluemagica
September 2nd, 2008, 01:50 AM
hmm, charleh is advanced user so his words may sometime go over your head, but what he said is really good!
Anyway, i am not so smart, so i will give a simple solution! Make a "shadow" object beneath the players feet! The shadow object can move only within a certain y range, meaning, your ground. Now, just make your guy jump normally, like y-=5 or something, and whenever you want to move, move the shadow, and add/subtract the same x,y value from the player. So say, you press "space" and your guy jumps, then, when in air, say you press up arrow key( y-4), so just add -4 to both the shadow and your guy's y! Also, the shadow should determine the depth of your player, and that way, you will have no problem jumping or moving!
Charleh
September 2nd, 2008, 06:15 AM
That's kind of similar to the post I've made - however the only downside of this is that your game will be keeping track of more objects, and it also complicates the code a little more.
Skribble, object orientated programming is readily available in AS2.0 - in fact you can't really get away from OOP when using flash as the whole flash actionscript language has it's own set of OOP objects - what do you think a movieClip is?
OOP is a farily simple concept with powerful features - the basic premise is that most of your code will be contained in classes, which are just a collection of variables and functions which describe how an object should act
So for your example above you may have a 'Player' class which contains variables which hold the position of the player, the players health, the players animation frames etc etc.
You can create an 'instance' of objects - which means you are basically creating a new copy of that object. You can create as many instances of the same object as you like - similar to having a library symbol in flash and dropping it onto the stage multiple times. The class is the library symbol and the instances are the symbols that are on the stage.
However, each instance is self contained and can be altered freely by any code and will not reflect on the other objects of the same class
For example you could have two instances of your Player object which had different positions and amounts of health
Classes are declared in .as files and look like this
// Class definition
class Player {
// These are the variables this class contains - they can be of any type, even other classes...
var health:Number;
var position:Vector; // Vector could be a 3 component class to hold position i.e. x,y,z, similar to flashes Point class but with an extra component
var someOtherVar:String;
// Constructor - this function is always named the same as the class and is
// automatically run when you create a new instance of this object - you can
// pass variables into the constructor, here I've added a variable so you can
// set the players health upon creating him.
function Player(newhealth:Number) {
health = newHealth;
position = new Vector(100, 100, 100); // Here I'm creating a new vector for use with the position variable
// As you can see to create an instance of a class you use the 'new' keyword, you are basically just running
// the constructor function for that class so you would run "new Player(100);" to create a new player object
// with a health of 100. Of course you need to be able to manipulate this object further, so you just create a
// var with the same type as the class and assign to it
// var somePlayer:Player = new Player(100);
// then you can manipulate as if it was any other object
// somePlayer.health -= 50;
}
// Here's a function definition - you call this using playerVar.Punch() as you would call a method on any other instantiated object
function Punch() {
}
// This function would for instance draw the character to the screen
function Render() {
}
}
As you can see it's not difficult to write a class nor difficult to understand. Your movieclips and flash classes are all objects which you manipulate in the same way. When you drop a movieclip on the stage, the flash IDE is simply making a call to a function which instantiates a new movieClip class and sets the properties to place that MC in the correct place on screen. (Of course there's probably a little more to it than that!)
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.