jlubeck
5 posts
|
Hi everybody, this is my first post here, I didn’t know where to get help and this looks like the right place.
I have experience programming some basic things in ActionScript3. But I never really made a proper game. Just very basic ones like a pong, a puzzle, and I’ve been lately following the series Staring with Starling from Hemanth Sharma at http://www.hsharma.com/tutorials/.
He’s teaching to make some sort of platformer, (you can see where I’m at with it at http://testing.fyrastudio.com/lab/starling/2012-07-01/) and I’m getting some nice game programming concepts from there, but until he releases the next one, I want to start making my own.
I already have the assets and it involves several concepts in the same game… but let’s begin with one…
The idea is for an athlete to be running forward. The “camera” is like a first person. I say “camera” because it’s 2D. You can see a still here: http://testing.fyrastudio.com/lab/running.jpg
Now, the problem is that I don’t know how to start… or how the logic would work… I’m not asking for anyone to code anything for me, just to help me turn my head around this to understand the logic that I would have to make in order for the character to be advancing forward, the obstacles coming up once in a while, and coming to a finish line…
I hope I could make myself clear, and that this is placed in the right forum with the right title. If any moderator seems it should be placed or named otherwise, just do it…
Thanks a lot and I hope anyone can help me, and that this post may be of help to anyone in the future…
Cheers!!
|
|
|
FlashGrenade
244 posts
|
Hi. jlubeck
You appear to be on the right track when it comes to studying and practicing the material, and I wish you the best of luck on this, I think what you might need is a tile based vector to symbolize the track.
http://www.ironcoding.com/2011/02/flash-as3-tile-based-game-tutorial-pt-1-intro/
Im just as new to this as you are, so don’t just rely on my word. But I’m sure that you’ll get
more accurate advice from the others since you are actually making the effort.
|
|
|
jlubeck
5 posts
|
Hi FlashGranade, thanks a lot for taking the time to answer!
That looks like a great tutorial! But it doesn’t seem to help for what I’m looking for… as tile-based games (from what I can tell) are more for top-down views, and what I’m looking for is some pseudo first-person view.
Think of OutRun, the concept I mean. The car stays always in the same spot and the road and obstacles come forward to the camera. That’s the part I dont know how to tackle.
|
|
|
JWBSoftware
106 posts
|
You need to know some 3D for that. You may be able to do, or need to do, a lot of the drawing in 2D by e.g. using fixed backgrounds, or using appropriately pre-calculated/pre-rendered assets, but you’re drawing a 3D scene. In particular it’s a perspective projected 3D scene, where things change size and shape based on how they’re viewed.
So have a look at 3D maths, especially perspective projection which is also an artistic technique. You do not need to use 3D rendering: especially in Flash people have made 3D looking games but with 2D rendering. But you need to understand how the 3D view and 2D rendering of it relate.
|
|
|
dragon_of_celts
279 posts
|
Increasing/decreasing the scaling properties for a Sprite/MovieClip will resize it, so if you start with it at the horizon with x and y scales set to 1 (or whatever minimum you’re going to use (see note below)) and increase them as it moves down the y axis (as y value increases), that should produce the illusion of an object moving toward the player (though how good or fluid it will look may vary, and it will always be oriented the same way). If your track is always going to be straight, and you don’t try to do too much with it, you could have the lines on the track do the same thing (you’d have to draw them receding into the background at the angle you want them, because that’s not going to change… unless you try to do images for different angles, which could become a mess if you aren’t careful). Make sure you remember to layer everything correctly (so the lines don’t appear over the hurdles, for example).
(aforementioned note:) You could also make the horizon a Sprite/MovieClip, and have objects start out layered underneath and slightly below the top; then, as player “approaches”, you would decrease the y value until the bottom of that Sprite/MovieClip is at the top of the horizon, where you would then change its layer to be over it, and start increasing the y value. This would make it appear that things are approaching from behind a hill. probably kind of complicated to implement, though, if you’re just starting out…
|
|
|
Shake_N_Baker
53 posts
|
I figured it might be worth mentioning that DisplayObjects have a z property along with x and y. You can also do a basic z sort to ensure objects closest to the screen appear in front of those further away (behind)
|
|
|
jlubeck
5 posts
|
dragon_of_celts, thanks a lot for your reply! I really like the idea of your note!!
After much thought, I came up with something but I don’t know if it’s the right way of doing…
As I won’t be coding in true 3D, the idea would be to think more abstractly right? The track is a constant Number of X units. Lets suppose I want the user to run with the forward button, everytime he presses that, the runner would increment its number. Once he reaches the X he reached the finish line… For the obstacles, its just a matter of placing them in various points throughout the X. I just program it like that, and then I think of a way of showing that with my assets… like when the player reaches obstacle – x, show the moviclip of the obstacle coming forward…
Is that the right way to go???
Thanks!!
|
|
|
dragon_of_celts
279 posts
|
For this example, we’ll have the track 350 units long, obstacle1 at 50, obstacle2 at 110, obstacle3 at 260, and the finish line at 350 (obviously… You did realize we need a finish line object to show, right?). We’ll keep the distances that obstacles should appear at in a var called “appear” in the obstacle object.
Using the simpler method, where the obstacles appear at the horizon rather than coming from behind it, when the player’s distance goes from <50 to >=50, you would place obstacle1 on the track at [horizon.y – (obstacle1.y – obstacle1.height) + (player.dist – obstacle.appear)] and add it as a child to the stage (While the parentheses aren’t necessary, I included them for readability — don’t forget to use the scaling variables of the obstacles!). You may be wondering why I did it in such a complicated manner. The answer is this: I can change the player’s movement distance increments at any time without having to further alter the code, including adjusting it during the game itself (meaning if I want to allow the player to speed up and slow down, I can do it without changing this part of the code. Further, I don’t have to worry about strict placement of obstacles: If player’s movement increments are, say, 10 units a step, I can have an obstacle at distance 77 and the code will still function as it should). While you don’t necessarily have to follow this process, it will allow you much greater flexibility.
Always remember that since you want the player to appear over everything else, obstacles should be added under the player’s image(s), but OVER everything else (and the most recent obstacle would need to be under all the other obstacles already on stage).
As the distance of the player increases, you would increase the y of all obstacles on the stage (ideally, the amount to increment would decrease the closer it is to the horizon — also, don’t forget to remove the obstacle once the player has passed it), and increase the scaling of the obstacle accordingly.
|
|
|
jlubeck
5 posts
|
Wow dragon, that was really helpful!!
I’ll start working and come back when I have something to show or I’m stuck again.
Thanks!!
|
|
|
dragon_of_celts
279 posts
|
Originally posted by dragon_of_celts:
[…] place obstacle1 on the track at [horizon.y – (obstacle1.y – obstacle1.height) + (player.dist – obstacle.appear)] and add it as a child to the stage […]
Wait… This should have been [horizon.y – obstacle1.height + (player.dist – obstacle.appear)]… obstacle1.y is what you’re setting.
Don’t know how I got that in there. Sorry about that.
|
|
|
Danishdragon
367 posts
|
I haven’t read the topic through (sorry!)
In my semester project I did some pseudo 3D in flash Which you can see here
I wouldn’t mind showing you the code and explaining it over Skype, msn or something if it is an effect like that you need (I used some very basic stuff!).
I used Flash’s own Z axis.
|
|
|
FlashGrenade
244 posts
|
flash has a z axis?
why am i learning this now?
|
|
|
qwerber
4717 posts
|
Originally posted by FlashGrenade:
flash has a z axis?
why am i learning this now?
came out with cs4 i think.
|
|
|
Danishdragon
367 posts
|
Originally posted by FlashGrenade:
flash has a z axis?
why am i learning this now?
It’s some of the newer stuff. It’s interesting enough to play around with
You can also rotate around each axis with ‘mcName.RotateY = valueInTheFormOfANumber’. if I remember correctly. Works with all 3 of the axes.
|
|
|
jlubeck
5 posts
|
Hi all!! Thanks to your comments I started with the logic. I’ll afterwards see how to show it.
You can see the progress here:
http://testing.fyrastudio.com/lab/tweetOlympics/v0.002/
The thing is that i have an athlete running and he must jump at the same time. A race with obstacles.
I have him running (with pressing the letter Q repeateadly). I also have him jumping (with letter P)
But the thing is that when he runs and jumps at the same time, he seems to be jumping at the same place, instead of going forward with the jump… any ideas how can I fix this??
This is the code I’m using for running and jumping on a continuos loop.
//if accelearing and the last time that he accelerated was less than X seconds ago, hes running an accelaring
if (athlete.accelerating && timeCurrent - athlete.last_acceleration > athlete.delay_acceleration) {
athlete.accelerating = false;
athlete.last_acceleration = timeCurrent;
athlete.running = true;
}
if (!athlete.accelerating && timeCurrent - athlete.last_acceleration > athlete.delay_acceleration) {
athlete.decelerating = true;
}
if(athlete.decelerating && timeCurrent - athlete.last_deceleration > athlete.delay_deceleration){
if(athlete.speed >= 1){
//athlete starts to decelarate
athlete.last_deceleration = timeCurrent;
athlete.decelerate();
}else {
athlete.running = false;
}
}
if (athlete.running) {
athlete.position += athlete.speed;
}
if (athlete.jumping) {
if (athlete.jump_height < 1) {
athlete.jump_height = 1;
}else {
if (athlete.jump_height >= athlete.jump_max_height) {
athlete.jump_height = athlete.jump_max_height;
athlete.jumping = false;
}else {
athlete.jump_height = athlete.jump_height * athlete.jump_speed;
}
}
}
if (!athlete.jumping) {
if(athlete.jump_height > 1){
athlete.jump_height = athlete.jump_height * 0.9;
}else {
athlete.jump_height = 1;
}
}
athlete.scaleX = athlete.scaleY = athlete.jump_height;
athlete.x = athlete.position;
Thanks!!
|