View Full Version : Helicopter Game?
mcdof001
06-18-2007, 05:45 PM
Hey,
I am also new to flash. I would like to create a helicopter game, just like the old style one. If you don't have a clue what I'm talking about, someone has already made it and I have posted it as an attachment. My question is, if I were to create a game like this what code would I need to use? Also, if anybody has a link to a tutorial on this, it would also be much appreciated.
Thank you in advance. :)
newblack
06-19-2007, 03:10 PM
You need to be more specific- both in your question and your experiments. Start with just trying to get a Sprite moving appropriately. Then move on to user-input and then collision detection etc.
Begin with the lowest common denominator of what you don't know how to do and we'll work through it!
mcdof001
06-19-2007, 06:06 PM
Sorry newblack, I know I should of been more specific. Firstly I ment the code needed to make the sprite go up. I cetainly don't know how to make the collision either, so it would be great if you could tell me how to create that too. I know a tiny bit about making something go up and down and that I will probably need a mouse listener. I have no idea of how to write it though!
This is what I have wrote so far, I know it works with a keyboard but I'm not too short about how to set it up with a mouse:
onClipEvent (load) {
power = 2;
yspeed = 0;
xspeed = 0;
gravity = 1
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.UP)) {
yspeed -= power;
}
yspeed += gravity;
_y += yspeed;
}
Can You Help Me Please?
whizkid1990
06-20-2007, 09:44 AM
Sorry newblack, I know I should of been more specific. Firstly I ment the code needed to make the sprite go up. I cetainly don't know how to make the collision either, so it would be great if you could tell me how to create that too. I know a tiny bit about making something go up and down and that I will probably need a mouse listener. I have no idea of how to write it though!
This is what I have wrote so far, I know it works with a keyboard but I'm not too short about how to set it up with a mouse:
onClipEvent (load) {
power = 2;
yspeed = 0;
xspeed = 0;
gravity = 1
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.UP)) {
yspeed -= power;
}
yspeed += gravity;
_y += yspeed;
}
Can You Help Me Please?
Well to make the copter move by the mouse-
You can do it something like this :
//movieclip helicopter
onClipEvent (load) {
power = 2;
yspeed = 0;
xspeed = 0;
gravity = 1
fly=false
}
onClipEvent (mouseDown)
{
fly = true;
}
onClipEvent (mouseUp)
{
fly=false;
}
onClipEvent (enterFrame)
{
if(fly==true){_y-=power;}
else if (fly==false){}
_y=_y+gravity;//gravity added for every fps
}
}
then you would have to code the collision for the barriers
(hittest maybe?? or perhaps a condition where the helicopter ._x coodinates overlap over the barriers) that crash your plane, and kind of duplicate the barriers dynamically(duplicatemovieclip) so they can be reused.
Also, instead of your helicopter._x increasing, you could try making the barriers._x decrease instead (move towards the helicopter), to give it the impression that your helicopter is moving forward while allowing you to remove and reduplicate the barrier movieclip when it falls below x coordinate 0.(makes things easier..)
Of course all these are just suggestions.... you can do it anyway you want.
mcdof001
06-20-2007, 05:36 PM
Thanks, that was just what I was looking for! For the collision part I like the sound of the first idea, but if the second is easier it must be done! Would I code it so the walls randomly appear in a certain area, making sure that the clip is tall enough to cover the top area. Does this include duplicatemovieclip? Or could I use tweened walls? Have I got the right idea?
mcdof001
06-21-2007, 04:40 PM
OK, I have had a good idea. To simplify the game, why don't I just use _root.wall.hitTest? I am not to bothered about moving top walls anyway. Heres my second (and hopefully final) problem. This is what i am now using:
onClipEvent (load) {
power = 15;
yspeed = 0;
xspeed = 0;
gravity = 7.5
fly=false
}
onClipEvent (mouseDown)
{
fly = true;
}
onClipEvent (mouseUp)
{
fly=false;
}
onClipEvent (enterFrame)
{
if(fly==true){_y-=power;}
else if (fly==false){}
_y=_y+gravity;
if (_root.wall.hitTest(_x, _y, true)) {
gotoAndStop(2)
}
}
When I deliberately drive into the wall it still remains at the same frame? Can somebody help me please?
Also, if anybody knows how to get up a timer or a way of getting a score for a certain distance that would be great.
P.S I plan to used tweened movie clips that come onto the stage.
whizkid1990
06-22-2007, 05:24 PM
gotoAndStop(2) should be changed to
gotoAndStop(2);
Also, to debug your flash application for errors, you can try using the trace inbuilt function to see if the condition is met.
if (_root.wall.hitTest(_x, _y, true)) {
trace("HIT!");
gotoAndStop(2);
}
this should make things easier in the process of developing your games.
mcdof001
06-22-2007, 07:49 PM
Thanks again whizkid1990 for your useful tips. Excuse my bad syntax! I had no idea there was was a code debugger! But there is some bad news, and that is that the code is still not working. When they do hit, it comes up with HIT! several times in the output panel. Can somebody help me please!!!???
:eek:
whizkid1990
06-22-2007, 09:41 PM
erm.... are you trying to stop at frame 2 of the copter movieclip or the
actual timeline of the flash document ?
If you are trying to stop at frame 2 of the helicopter movieclip, then the error could very well be
1) your helicopter movieclip having only 1 frame/keyframe
2) your helicopter movieclip having only 1 frame/keyframe
3) .........................................
If you are intending for it to stop at frame 2 of the timeline
(the final score screen ??), you can try changing the code
gotoAndStop(2); to _root.gotoAndStop(2);
mcdof001
06-23-2007, 12:29 PM
Thanks once more whizkid1990, yes I did want it to go to the second frame of the timeline of the movie, not the clip. I'm still getting used to Flash! Anyway, I hate to be a pain, but can somebody help me with a timer. So the longer the Copter survives, the larger the score. Thanks.
whizkid1990
06-26-2007, 01:27 PM
You don't actually HAVE TO implement a timer (use the timer class) in FLASH actionscript. As you will note from the
"onClipEvent (enterFrame) {if (Key.isDown(Key.UP)) {yspeed -= power;}"
function/method/class... whatever it is, everytime you press down a key, yspeed variable is still constantly decremented.
Thus, you can use the same concept for your timer.
To create a simple "timer" for your game, you can
1) Create a dynamic textbox
2) Name it whatever you want (in this case,i name it "timers") so it can be referenced
3)
time=0;
onEnterFrame=function(){
_root.time++;
_root.timers.text=""+_root.time;
}
MasalaFingers
07-22-2008, 02:49 PM
The scoring method works great, but how do i view it on a game over screen? When I try, the number just keeps rising. So basically what i'm asking is: how do i stop time?:confused:
evilexplorer
01-11-2009, 03:55 PM
this should stop it when the game is over
onEnterFrame=function(){
if(_root._currentframe == 1){
_root.time++;
}
_root.timers.text=""+_root.time;
}
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.