How to make a simple Avoiding game

Update: Part 2 released!

FrozenHaddock Tutorials: Simple Avoiding Game

In this tutorial you will learn how to create a simple dodge game, this will help learn about hittesting, whilst allowing new flash developers to get a quick and easy game.

You will be making a game like this;

The first thing we will do is set up our flash document. I’m setting mine up as 300×300px, 24fps and I’ve chosen grey as a background colour. You can choose different dimensions, but you will have to change the actionscript to reflect that.

Now we need to setup our character. Draw your character onstage and convert it to a movie clip (F8). Name it accordingly and make sure the registration point is in the centre. Then open up the properties bar for your player and set the instance name to player.

Charsetup

Now, open the character’s actions panel and give it these actions;

  1. onClipEvent(enterFrame){
  2. Mouse.hide();//hides the mouse
  3. this._x=_root._xmouse;//sets the x of the player to the x of the mouse
  4. this._y=_root._ymouse;//sets the y of the player to the y of the mouse
  5. }

Now test your movie, the player mc will now follow the mouse, good. So lets move onto some enemies.

Draw your enemy on the stage, and convert this to a movie clip. As with the character name it accordingly and set the registration point to the centre.

enemysetup

Open up the actions panel for your enemy and add these actions;

  1. onClipEvent (load) {
  2. this._x = random(300);//sets the horizontal position randomly
  3. this._y = random(-50);//sets the y position above the stage
  4. speed = random(5)+1;//sets the speed randomly
  5. }
  6. onClipEvent (enterFrame) {
  7. this._y += speed;//moves the enemy downwards
  8. if (this.hitTest(_root.player)) {//if the enemy hits the player
  9. _root.gotoAndStop(2);//goto the second frame, which will be a gameover screen
  10. }
  11. if (this._y>=310) {//if the player reaches 10 pixels below the stage
  12. this._x = random(300);//randomly set the x, y and speed again.
  13. this._y = random(-50);
  14. speed = random(5)+1;
  15. }
  16. }

Test your movie now, and see your enemy fall down the stage. You can copy and paste this enemy for multiple enemies.

Now, before we setup a game over screen, we’ll setup a timer. (For a more indepth tutorial on creating this, see here)

Draw anything, and convert it to a movie clip. Move it off the stage.

offscreentimer

Now, double click this to get inside the mc, and add a frame in at 24, or whatever value you set your fps at. open the actions of this frame and enter;

_root.clock+=1;

Double click anywhere to return to the main timeline, and click on your frame. Add these actions in;

  1. stop();
  2. clock=0

Right, so now the clock is timing, we need a way to see it. Use the text tool to add a new text box onstage. Open the properties bar for this text box, and change the drop down menu from ’static’ to ‘dynamic’

synamic

Then, keeping the bar open, change the var: input box to clock

varbox

Test your movie, you’ll see the clock time as you play.

Right, now for the game over screen, giving users their time and an option to replay.

Add a new blank keyframe on the main timeline. On this new frame setup the way you want it to look. Make sure to copy the dynamic textbox from the other frame wherever you want your players time to show. I have this;

gameoverscreen

(NOTE: I just realised, you’ll want to put Mouse.show(); on the frame here so you can actually click your button.)

Of course, we need to give our players the option to play the game again, so we need to setup a button. More information on setting up a button can be found on the site.

The actions we want on this button are these;

  1. on(release){
  2. gotoAndStop(1);
  3. }

Now test your movie, and play your fully functioning avoision game!

If you learn more about hittests and variables, you will be able to setup scoring and powerups etc. But that’s for you to learn yourself!

Download the source file

Remember, post your creations on the Forum!

-->

185 Responses to “How to make a simple Avoiding game”

  1. Angela Says:

    Hey! I made a game (using this tutorial) , but the ‘enemies’ don’t ‘kill’ the player. AKA, no game over screen. I used the exact code. Help? >>;;

  2. Tazzydevil XIII Says:

    Make sure your instance names are correct, and capitalised the same in the code and in properties.

    So make sure your player has the instance name of ‘player’ exactly, with no capital p.

    That’s the most likely cause, if that doesn’t help email me the file and I’ll gladly take a look (Flash 8 pro or below, I don’t have CS3 yet)

    You can email me at alternateaccount [at] frozenhaddock.co.uk

    -Tom

  3. Carlin Says:

    my timer wont work :S

  4. Tazzydevil XIII Says:

    What exactly is wrong with it?

    Do you get any errors?

  5. ardavan Says:

    my 2nd frame timer wont work, i did the same thing as i did in frame 1.
    also the button dont work well. i converted it to a button but it wont work :(

  6. Tazzydevil XIII Says:

    What about your second frame timer doesn’t work?

    Make sure to check your variable names, and make sure they’re capitalised correctly, if you have any more trouble send me the file at the address above and I’ll have a looksee :)

  7. Tazzydevil XIII Says:

    Also, I’ve fixed the images, swf and fla links in the post.

    Those might help :)

  8. ardavan Says:

    wow your great you even responded ( no1 normmaly does that)
    the button works but on frame 2 the timer wont really work..all it say is 1.
    even though i play in 10 seconds, it still says 1….any ideas? can make a tutorial?
    ( btw i tryed the same thing as the other timer on frame 1)

  9. ardavan Says:

    and i made a wall so the smileys cant go under the wall…can give me a code so the smileys get destroyed when they touch it? its a bottom wall.

  10. Tazzydevil XIII Says:

    I’m not sure what’s wrong with the timer, I’ll have a think :)

    As for a wall, just swap out the current smiley code for this:

    onClipEvent (load) {
    this._x = random(300);//sets the horizontal position randomly
    this._y = random(-50);//sets the y position above the stage
    speed = random(5)+1;//sets the speed randomly
    }
    onClipEvent (enterFrame) {
    this._y += speed;//moves the enemy downwards
    if (this.hitTest(_root.player)) {//if the enemy hits the player
    _root.gotoAndStop(2);//goto the second frame, which will be a gameover screen
    }
    if (this._y>=310 || this.hitTest(_root.wall)) { /* if the player reaches 10px under the stage OR it hits a movie clip instanced as ‘wall’*/
    this._x = random(300);//randomly set the x, y and speed again.
    this._y = random(-50);
    speed = random(5)+1;
    }
    }

    Then just convert the wall to a movie clip, and make it’s instance name ‘wall’

    Let me know how it works :)

  11. ardavan Says:

    Thanks for all your help your just great :)
    you know players can cheat in the game by let the player (mouse) off the game screen so they never get killed…any idea how to make them prevent it, like some walls that will prevent the player getting off screen?

    The wall also works GREAT! thanks for it!
    i cant make the timer work atm..

  12. ardavan Says:

    the smileys are gone mad! i send you a email with my swf and you can chek it out (also the flash document)

  13. Tazzydevil XIII Says:

    I’ll take a look tomorrow :)

    As for stopping the player leaving the boundaries, I can do that whilst I fix your document :)

  14. ardavan Says:

    Wow thanks for the help :)
    your greeaaaaaat!
    thanks

  15. Tazzydevil XIII Says:

    There we go, sent you the fixed file, should all be ok :)

    Your timer wasn’t working ’cause you had it setting it back to 0 on the second frame. You just needed to take clock=0; out of the actions for the second frame.

    Your smileys went crazy, cause you had some inside each other. Instead of copying and converting to a movie clip (which leaves some inside others, and they go crazy) just hold control and drag one to duplicate it :)

    To keep the player onscreen you just had to add this to the player:

    if(this._x>=550){
    this._x=550;
    }
    if(this._x< =0){
    this._x=0;
    }

    if(this._y>=400){
    this._y=400;
    }
    if(this._y<=0){
    this._y=0;
    }

    Hope that helps!

  16. Ardavan Says:

    Thanks…your so great :)
    the first one that have ever helped me…ill add a credit page for you.. :)
    Thanks for all your help..

  17. Ardavan Says:

    I cant open the file :( im using flash mx….thanks anyway :)

  18. Ardavan Says:

    Hello again!
    What program you use for making fla files?

  19. Tazzydevil XIII Says:

    Flash MX?

    Ack, I’m using 8 pro and I saved the file as low as I could (MX2004)

  20. Ardavan Says:

    aww :( i cant open it :,(
    I got mx 2004 it just says: unexpected file…
    :( i googled it but so hard to understand.. .:(
    thanks for all your help anyway…

  21. Tazzydevil XIII Says:

    Well, my advice is to delete your smilies and draw one again, covert it to a movie clip and copy and paste it a few times with actions on :)

    Should make them work.

  22. Ardavan Says:

    No, i cant open the fixed version….its not the thing with the smileys…
    its the file you sent me it wont open…
    all your work is wasted..sorry for wasting your time :(
    thanks for all your help anyway.

  23. Tazzydevil XIII Says:

    I know you can’t open it, but that’s what I did to fix it :)

    Try it and see if you can get your fla to work

  24. ardavan Says:

    IT WORKS!!! THANKS!!! :DDDDDDDDD
    I learned a LOT from this tutorial, so i want to thank you for making it…and helping me so much..
    I learned how to make levels ( gotoandstop;1) something like that ( made a credit button and it worked!) you really helped me…..but looks like boundaries dosnt work that well, but its not necessary… :D thanks! But i have a request…..can you make me a script for a coin that pops up random and the player take them, then the points goes up….( a bar)
    but thanks for All your help….your the best ever! :D

  25. Tazzydevil XIII Says:

    ^.^

    I can indeed, perhaps Avoiding game pt.2?

    Coins are pretty easy, boundaries I can explain properly too.

    Anything else you’d like added in a second tutorial?

  26. ardavan Says:

    Levels…like when there are gone x seconds more enemys come when theres gone x seconds on wave 2 a new lvl again! :D
    also some background music (different looping)
    and when the game starts some time you die at the second, what if you could make a timer going down saying 3, 2, 1 GO then the enemys fall down…
    also the smileys are only of the LEFT side of the game…never on the right side :( my window is 550×400.

    also lifes, start like 3 lifes then when hit, the enemy stop comin and a life is gone ( a little heart) then the timer says again 3, 2, 1 Go then they come again.
    ill think of more ask if you want more clear info :D

  27. ardavan Says:

    and a song button that does so the player can mute the sound :)
    i keep find on more :D just tell me if its enough.

  28. Tazzydevil XIII Says:

    Sounds good!

    I’ll get onto this, I think music’ll be a separate tutorial though!

  29. ardavan Says:

    Okay cool enough :)
    also a menu button and pause button :D

  30. ardavan Says:

    http://www.kongregate.com/games/Ardavanski/smiley-avoider
    heres my game :D
    theres some bugs you can see you can just stick to the right never get hit and also if you hide at bottom you wont get hit..any ideas?

  31. Tazzydevil XIII Says:

    Change the numbers in the smiley code to fit your window:

    onClipEvent (load) {
    this._x = random(550);//sets the horizontal position randomly
    this._y = random(-50);//sets the y position above the stage
    speed = random(5)+1;//sets the speed randomly
    }
    onClipEvent (enterFrame) {
    this._y += speed;//moves the enemy downwards
    if (this.hitTest(_root.player)) {//if the enemy hits the player
    _root.gotoAndStop(2);//goto the second frame, which will be a gameover screen
    }
    if (this._y>=410) {//if the player reaches 10 pixels below the stage
    this._x = random(5500);//randomly set the x, y and speed again.
    this._y = random(-50);
    speed = random(5)+1;
    }
    }

  32. Ardavan Says:

    It works thanks :) could you give me a level code? like x seconds gone new lvl (frame) i know how to make the frames and stuff just not the script for x seconds…..and im sorry for asking for soooooooooooo much….. :(

  33. Tazzydevil XIII Says:

    No worries! You make me feel useful!

    if(clock>=X){
    _root.gotoAndStop(Y);
    }

    Where X is the number of seconds and Y is the level number/name :)

  34. Ardavan Says:

    Cool, thanks :)
    where you say Y isnt that frame?
    And i look forward to see part 2 :D
    thanks for all your help..you ARE useful!

  35. Ardavan Says:

    And is it okay if i call you my partner/friend/actionscripter? mostly friend :P is that okay?

  36. Tazzydevil XIII Says:

    S’all good :)

    (And yeah, frame number)

  37. Ardavan Says:

    Thanks, your great!

  38. Ardavan Says:

    The level code dont work, when i put it in frame 2, i put this in the frame if(clock>=20){
    _root.gotoAndStop(3);
    } but it dont the clock passes 20, but wont go to frame 3 wich is lvl 2

  39. Ardavan Says:

    Also when the timer on frame 2 ( level 1), reaches 20 the level code( if (clock>=20){
    _root.gotoAndStop(3);
    })

    makes it go to next level (frame 3) and the Timer WONT reset on lvl 2, it continues to 40 then it goes to lvl 3 and same….can you help me?

  40. Tazzydevil XIII Says:

    If you want it to reset just put:

    clock=0;

    On the 3rd frame :)

  41. Ardavan Says:

    Thanks, but i didnt want it to reset it should continue as it was, + the code dosnt work :(

  42. Tazzydevil XIII Says:

    Ah, then make sure there is no clock=0; on the 3rd frame.

    What code doesn’t work?

  43. ardavan Says:

    the level code you gave me, wont work proper. I set it to make the clock reach 20 seconds, then it should move to lvl 2 (frame 3) but it wont….the clock continues from 20 and rises without go to frame 3 :(

  44. Tazzydevil XIII Says:

    You need to put it inside an event handler :)

    onEnterFrame=function(){
    if(clock>=20){
    gotoAndStop(3);
    }
    }

    On the frame.

  45. ardavan Says:

    aaaaaaaaa thanks! your the best the best the beeeeeeeeeeeeeest in the whooole woooooooooorld!

  46. Tazzydevil XIII Says:

    Hooray!

  47. ardavan Says:

    Just tryed it and it works greaaat! just that when it reaches lvl 2, the timer wont continue from 20…just freeze there.. :( any idea?

  48. ardavan Says:

    Tazzydevil, while you are a sooooooooooooooooooooooooooooooooooooooooooooooooooooooooo good actionscripter and flasher why wont you make some more games? i have seen them at kongregate, and i liked them all, but i know that you can make something like the last stand…if you wanted to make a game, just tell me i could help you if you want! (somehow :D)
    just think about making a game that will take more than 2 weeks development..im sure you could get some cash from mochiads, if it gets good…just think about it :) im always at your side.

  49. Tazzydevil XIII Says:

    I’ve got 2 small games awaiting music before they’re released, I’m not idle over here!

    I’m also working on a cartoony style rocket game, I might post previews on the forum soonish :)

  50. Tazzydevil XIII Says:

    For the timer on level 2, you need to make sure you have the timing movieclip still in place on the frame :)

  51. ardavan Says:

    Cool, cant wait to try your games! :D
    & now the clock works but it goes 2 seconds up per sec…like this 1 real second is 2 in the game :O

  52. ardavan Says:

    It works now thanks :)

  53. ardavan Says:

    Hello again, i just made a new mode named Survival where you must survive as long as you can nonstop ( the other mode is normal play with levels :D)
    but the timer in survival mode wont work, all it say is NAN. The level frames are from 2 to 6. the survival mode frame is on one single frame; 11. everything else works in frame 11 just that the clock dont work ( i got the anything drawn thing there, the clock dynamic box, EVERYTHING just still says NaN. Can help me?

  54. Tazzydevil XIII Says:

    On the frame for survival mode, make sure that the line:

    clock=0;

    Is there. NaN is displayed in a box when the variable is altered but it hadn’t been set already :)

  55. ardavan Says:

    thanks! :D if theres a KING of flash…its you….
    your greaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaat the best best best in the whooole wooorld!

  56. ardavan Says:

    Can you help me make a highscore stat for my game in kongregate? i have the root_connect.kongergate thing but i dont understand how to make a MAX thing on there..its for max time survived

  57. Dannil Says:

    everything works well except when i put the mouse over the button, it doesnt give me a chance to click it cos the text that says “Retry” gets in the way! help!

  58. Tazzydevil XIII Says:

    Ardavan: I’ll look up the Kong API later, tired at the moment :P

    Dannil: Wha? The retry text should be part of the button.

  59. Jmax Says:

    Hey. I’m trying to make a screen at the front so I can click play now instead of going straight into the game. Any idea on how to do this? Also, with the replay button, I add the mouseshow but it doesn’t work it just says theres a script error. Any Help?

    Thanks

  60. Tazzydevil XIII Says:

    To make a frame at the start, just highlight all your current frames and drag them across one frame. That should create a blank frame. Then put stop(); on this frame.

    Then create a button on this frame with-

    on(release){
    gotoAndStop(2);
    }

    You’ll need to change the frame numbers on the smilies to the gameover screen (which will now be frame 3) and the replay button to frame 2.

    As for Mouse.show(); have you got it on the button? It should be on the frame :)

  61. ardavan Says:

    I understand that :)
    you done so much for me :D
    i wont ask you for questions for a long time:)

  62. ardavan Says:

    OKay last question; when the player complete my game, he go to a frame with congratulations you beat smiley avoider! then theres a menu button. when the player clicks that, he see 1 second on the menu and then it goes to the winner frame again! so he need to restart the page to play the game again can you help me?

  63. Tazzydevil XIII Says:

    Are you determining your win by the clock variable?

    If so, just put:

    on(release){
    _root.clock=0;
    _root.gotoAndStop(MENUFRAME);
    }

    And I don’t mind the questions, just I don’t know Kong’s API too well ;)

  64. ardavan Says:

    thanks :)

  65. Giel Says:

    When I enter the code to make your character move (charsetup), it gives an error. It says the error is located in the first line.
    “1087: Syntax error: extra characters found after end of program.”
    If you want, I can send you a screenshot.
    Thanks

  66. Tazzydevil XIII Says:

    Hmm… I’ve never had that error before…

    Are you sure you’re using the correct version of ActionScript?

  67. Mushyrulez Says:

    how do you make the enemies move right or left insdead of down?

    ps hey ardavan i love your game add walls to it!

  68. Giel Says:

    euhm, AS3.0 in Adobe Flash CS3
    thanks for quick response

  69. Tazzydevil XIII Says:

    Aha, there’s your problem!

    You need to be using AS2 :) CS3 can handle that too, just change the settings under publishing.

  70. Tazzydevil XIII Says:

    @Mushyrulez:

    You’ll have to change the code on the enemies. Instead of increasing Y, decrease X.

    Also, you’ll have to change the original positioning of them.

    Tell me if you need more help with this and I’ll write something tomorrow.

  71. Giel Says:

    ok thanks

  72. Toomin Says:

    the hittest won’t work my enemy just goes through it

  73. ardavan Says:

    thanks Mushyrulez

    good to hear that you like it :)
    how walls?

  74. Giel Says:

    I’ve found something easy for walls without using a wall movieclip.
    I don’t think someone already said this, if someone already said this sorry.

    Replace the old code of the player (cursor) by this:

    onClipEvent(enterFrame){
    Mouse.hide();
    this._x=_root._xmouse;//sets the x of the player to the x of the mouse
    this._y=_root._ymouse;//sets the y of the player to the y of the mouse

    if (this._y>=300) { //if the cursor moves to 300, it will automatically move to 300 (so you can’t go further than 300)
    this._y = 300;
    }
    if (this._y=300) {//same here
    this._x = 300;
    }
    if (this._x<=0) {//same here
    this._x = 0;
    }
    }

  75. Giel Says:

    oh sorry, you already said it :$ sorry

  76. Tazzydevil XIII Says:

    @Toomin

    Make sure you check the instance names on your player and in your enemies actions.

    They should match exactly, including capitalisation.

    @Giel

    No worries! :)

  77. Mushyrulez Says:

    how do you input lives in it? i think 1 life is too hard…

  78. Tazzydevil XIII Says:

    To add lives, you’d just create a variable on the frame for lives:

    lives=3;

    Then on the enemies:

    onClipEvent (load) {
    this._x = random(300);//sets the horizontal position randomly
    this._y = random(-50);//sets the y position above the stage
    speed = random(5)+1;//sets the speed randomly
    }
    onClipEvent (enterFrame) {
    this._y += speed;//moves the enemy downwards
    if (this.hitTest(_root.player)) {//if the enemy hits the player
    if(_root.lives< =0){
    gotoAndStop(GAMEOVERFRAME);
    } else{
    lives-=1;
    this._x = random(300);//randomly set the x, y and speed again.
    this._y = random(-50);
    speed = random(5)+1;
    }
    }
    if (this._y>=310){
    this._x = random(300);//randomly set the x, y and speed again.
    this._y = random(-50);
    speed = random(5)+1;
    }
    }

    That should do the trick :)

  79. Mushyrulez Says:

    thanks! i tried doing walls so that the player and the enemy can’t pass through them, and it doesn’t seem to work… do you know the problem?

  80. Mushyrulez Says:

    oh yeah the lives thing doesn’t really work… everytime the enemy hits me the enemy just restarts, so you’re kindof invincible….

    i have another question if you want to make different setttings for each “level” do we have to make a new frame?

  81. Tazzydevil XIII Says:

    It should take the life off before resetting…. Not really sure what the problem is.

    Perhaps you need _root.lives-=1; (I was in a hurry earlier :S)

    If you were duplicating enemies with AS rather than by hand you could set a variable for how many and do it in one frame, but with this method you’ll need to make new frames :)

  82. Mushyrulez Says:

    you can make the enemies move from the right side to the left side of the screen, and other directions like that right? but is it possible to make them be diagonal =D?

  83. Tazzydevil XIII Says:

    No reason why not!

    You’d just add/subtract the speed to both X -and- Y, but placing them originally and resetting them would need thinking out more :)

  84. Mushyrulez Says:

    hey can you check my fla file? i sent it to alternateaccount@frozenhaddock.co.uk under dontask@abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk.com

    thanks! can you check what’s wrong with the walls and the enemies? thanks again!

  85. lololol Says:

    I’m stuck on the timer part. You said “Now, double click this to get inside the mc, and add a frame in at 24, or whatever value you set your fps at. open the actions of this frame and enter”

    But it doesn’t give me a window to change the frame rate or anything :S

    Please help

  86. Tazzydevil XIII Says:

    @Mushyrulez

    I can do now, yesterday was a little dodgy for me, the SQL server died for a bit, as did my home network. Apologies for the delay :)

    @lololol

    Your frame rate is set at 12fps by default, so unless you’d changed this by clicked settings on the properties bar earlier, you’d put a frame in at 12 on the new timeline that should appear after double clicking the timer movie clip.

  87. falnex Says:

    hey i just made mine and it completely does not work (i cant move the character, enemies dont attack, timer doesn’t work)is there something wrong with the coding that i put in or something?

  88. Tazzydevil XIII Says:

    There’re a few things everyone should check if things aren’t working :)

    – Are you using AS3 instead of 2? This tutorial is for ActionScirpt 2, and if you’re using Flash CS3, it’ll be set to AS3 as default…. so check that.
    – Instance names, need to be exactly the same in the actions as they are on the movie clip, this includes capitalisation and missplaced spaces, so double check those too!
    – Is the coding in the right place? This tutorial has actions in several places, are the right pieces in the right place?

    If that doesn’t help, try sending me your fla file (In Flash 8 or below format please) and I’ll take a look :)

  89. Mai Says:

    I made a game with your tutorial xD

    http://maitealatte.deviantart.com/art/Flash-game-D-91421235

  90. Tomato xP Says:

    Hello! You need the game over screen, because the enemies wont ‘kill’ ye if ye don’t make it.

  91. Josh Says:

    Please Help Mine Wont Time And Cant Make Link :(

  92. Tom Says:

    I’m stuck adding the actions for the player I test it and it does nothing. I have Flash MX 2004..

  93. game103 Says:

    Hey, I am making the Game with the tuturiol and I am confused with the timer, I did what your tutriol said only on the frame that the outside object is on, and didnt put any script on the main icon and the main game page, the timer doesn’t work though? can you help!

  94. Tazzydevil XIII Says:

    @Mai

    Looking nice! Thanks for sharing :)

    @Josh

    Hmm, the timer seems to be a problem for a few people, I’ll make sure to show you guys a better way with part 2 of this tutorial coming soon. For now, what exactly is wrong with it? Do you get any errors? Remember to double-check your variables and your actions inside the timer need a _root. before the variable name!

    @Tom

    Are you definitely adding the actions in the right place? The player should be a movie clip, and the actions should be on that. Have a look over it and run through the tutorial again, and if that doesn’t work, email me your .fla (My address is on the contact me page) and I’ll have a look and see what I can do :)

    @gamer103

    I’m not quite sure I understand your problem, but I’m just now going to write a more indepth tutorial on making the timer itself, make sure to take a look and comment again if you’re still having trouble ;)

    Wow, lots of comments today! Welcome to all the new readers!

  95. Tazzydevil XIII Says:

    @Mushyrulez

    You’re using CS3, and it’s exported as such. I only have Flash 8 Pro, could you save it as a Flash 8 document and send it to me again? I can take a look then :)

  96. Making a simple timer in Flash | FrozenHaddock Says:

    [...] to create a timing system in Flash, and this is the way with less Actionscript that was used in the Create a Simple Avoiding Game tutorial, but several people have commented that they had trouble with it, so here’s a more in-depth [...]

  97. Josh Says:

    I Have Sent You My File Please Can You Make The Timer Work And And Walls Please Thanks

  98. Tazzydevil XIII Says:

    I shall do later when I have some more time, for now I suggest you take a look at the new tutorial on making this timer, it might help you out :)

    http://frozenhaddock.co.uk/2008/07/making-a-simple-timer-in-flash/

  99. game103 Says:

    hi! First thanks for the tutorial, and second, I am confused about the timer, how to add it that is, I opened up the object that goes offstage and added a frame, on that frame I put on the root clock+1 thing, then on the regular main frames script I wrote stop(); clock=0, can you tell me why this doesn’t work please!

  100. Tazzydevil XIII Says:

    I’m not sure.. it should work from what you say.

    If you email me the file (Flash 8 or before please) I can take a look for you, if you want?

    :)

  101. Bekka Says:

    Okay so!
    I have everything done, but the timer is going wild.

    Like it goes fast, and then stops D:

    im not sure why it’s doing this.. any tips?

  102. Tazzydevil XIII Says:

    Hmmm, I’m not sure what the problem might be. Did you try looking at the more detailed tutorial on it?

    If it’s still freaking out, you could email me the file (Flash 8 or below) and I’ll take a look :)

  103. Aaron Says:

    OK I am having these problems…

    Enemy’s won’t “kill” the player. (Code and properties match)
    Couldn’t get the timer to work so i deleted it for now.
    Also, I keep getting this error, “Statement must appear within on/onClipEvent handler
    Mouse.show()”

    It’s on my second frame.

  104. Tazzydevil XIII Says:

    Hmm, first of all, are you using AS2? Some people are using CS3 and it defaults to AS3… which is a problem.

    There’s a more indepth tutorial on the timer on the frontpage currently, if you want to take a look. I’ll be showing another method of timing in a soon-to-arrive tutorial.

    If your problems persist with Mouse.show(); Then replace it with:

    onEnterFrame = function(){
    Mouse.show();
    }

    That should fix it. If that doesn’t help, email me your file and I’ll take a look :)

  105. Aaron Says:

    I am using Macromedia Flash Pro 8. I JUUUUST started getting into flash so I am not sure what AS2 and CS3 are…

    I learn things very quickly so once I learn a few tricks I should be rolling right along.

  106. Aaron Says:

    okok. If you meant Action Script 2 then on the drop down menu it says Action Script 1.0 and 2.0. So I am assuming I am using it….

  107. Aaron Says:

    Sorry for all the comments, I just keep experimenting with it.

    I deleted the 2nd frame and it works fine, minus the enemies not killing the player. So I started the whole 2nd keyframe from scratch (except the clock). I inserted it right next to frame one and set up the game over screen. Now when I test the movie it flashes back and forth really fast and never stops…..hmmmmm.

  108. Aaron Says:

    bah, I wish I could delete my other comments….

    So I remade it….it works…sorta…although I have new problems.

    If I copy and paste the enemy, only the original enemy can kill the player. Both enemies have the same AS and instance name. Also, the enemy won’t go to the bottom of the screen. I changed the AS to

    this._x = random(400) because that is the height of my document…

    Lastly, I can’t get the retry button to work now on the game over screen.

  109. Oskar Says:

    Hi!

    Thanks for a GREAT tutorial! =)

    I’m trying to do following:

    When the enemy hits the player I want the enemy to go UP instead of down…

    I’ve tried to do it like this:
    onClipEvent (load) {
    this._x = random(300);//sets the horizontal position randomly
    this._y = random(-50);//sets the y position above the stage
    speed = random(5)+1;//sets the speed randomly
    }
    onClipEvent (enterFrame) {
    this._y += speed;//moves the enemy downwards
    if (this.hitTest(_root.player)) {//if the enemy hits the player
    if(_root.lives=310){
    this._x = random(300);//randomly set the x, y and speed again.
    this._y = random(-50);
    speed = random(5)+1;
    }
    }

    That works… but not perfect =) I guess you can understand why…… It goes UP on hit, but after that I can hit it again, and again… I want the enemy to be “disabled” when I hit it…

    Hope you understand =)

  110. Oskar Says:

    =) I have another question:

    I know that the following line of code tell the game where to put the enemey horisontally:
    this._x = random(300);//sets the horizontal position randomly

    The game area is 300px wide… and if I change it to random(150) it will only put enemies on the left side of the game… but how do I change it to only put enemies on the RIGHT side of the game?

    I want different enemies on every side =)

  111. Tazzydevil XIII Says:

    @Aaron

    The enemy itself shouldn’t have an instance name, the player should. If you remove instance names from the enemies they should work.

    You need to have a semi-colon on the end of that line of AS.

    Aaand, what about the button doesn’t work? Have you checked the frame labels?

  112. Tazzydevil XIII Says:

    @Oskar

    Thanks! I’ll see what I can do to help…

    I’m not sure I understand what you want for the first part, You mean hit the player and -immediately- start going up? Or spawn below the stage and move upwards then?

    As for problem two, that I can help with ;)

    this._x=random(150)+150; will make them appear on the right only.

    random(150) will return any value between 0 and 150, then +150 will make the range 150 to 300. :)

  113. Aaron Says:

    I finally got it to work. I thought the enemy had to have an instance name for some reason. Got rid of that and it worked fine. (Had to edit my enemy a little since everything works in boxs, because you could die without actually touching the enemy.

    As for the button, I had the text set to Dynamic still. So I changed it to Static and it worked fine.

    Now I am going to attempt a start screen. I’ll post it when I finish it. Thanks for this tutorial….I have learned so much! XD

  114. Aaron Says:

    Can’t seem to get it to work… here’s what it looks like…

    Frame One - Title screen with “play button” with these actions

    on(release){
    gotoAndStop(2);
    }

    Frame Two - Actual Game with timer
    Frame Three - Game over with timer

    It just skips to frame two when I test it and the enemies won’t kill the player.

  115. Tazzydevil XIII Says:

    Make sure you have stop(); on frame 1.

    Aaand, that button should work…

    Did you name the frames?

  116. Aaron Says:

    Yeah, I read through the comments, (which have been helpful in their own respect), and figured that out. I now have a full working game with 8 levels and more enemies on each lvl. Everything works.

    Now I am working on getting music to play. one for the menu, one in game, and maybe game over screen. My AIM name is UrbanMcAaronson if you would like to help me that way….otherwise I will continue to scour the net aimlessly for a good tutorial on it.

  117. Aaron Says:

    Alright, I did the best I could. My game is posted in the forum. Let me know what you think!

    http://www.tutorialized.com/view/tutorial/How-to-make-a-simple-avoiding-game/36119

  118. Aaron Says:

    wrong link. It’s in the forum under avoiding games.

  119. Tazzydevil XIII Says:

    I don’t use AIM, apologies :)

    If you have skype, I’m tdxiiifrozenhaddock on that.

  120. Oskar Says:

    Tazzy!

    You mean hit the player and -immediately- start going up?
    Answer: Yes! =)

  121. Jon Says:

    Great tutorial! :D

    I tried to make an avoiding game, but the character won’t move, I put the codes that you gave me on this website.

    Sorry for bad English, I’m from Sweden

  122. Tazzydevil XIII Says:

    @Oskar

    In thaaaat case, you’ll want something along these lines :)

    onClipEvent (load) {
    this._x = random(300);//sets the horizontal position randomly
    this._y = random(-50);//sets the y position above the stage
    speed = random(5)+1;//sets the speed randomly
    }
    onClipEvent (enterFrame) {
    this._y += speed;
    if (this.hitTest(_root.player)) {
    if(_root.lives==310){ //if lives are exactly equal to 310
    speed = random(-5)-1; //set the speed to a minus number
    this._y -= 10; //Jump the enemy upwards a bit so the player doesn’t hit it more than once.
    }
    }

    Try that and see how it comes out, and comment again if you need any more help!

  123. Tazzydevil XIII Says:

    @Jon

    Are you using ActionScript 2? It sounds like you have it set to AS3, and it won’t work with that. You can check under publishing settings, and you can change it there if need be :)

  124. CookiemagiK Says:

    Hi, I don’t know if you still read the comments, but I just wanted to say that this is a great tutorial that taught me a lot about action scripting in Flash! :D

    I also have a problem, and I’m wondering if you could help: Only the first enemy is killing my character. The others are just passing through. I copied all the other enemies from the first one by holding down the Ctrl-key and dragging, so they should be exactly alike. So I don’t understand this problem. It would be really nice if you could help (I also understand if this question has been asked a million times before and you’re just tired of answering. If that’s the case I am sorry) :)

    -CookiemagiK

  125. Tazzydevil XIII Says:

    Course I read the comments, I’m here to help :)

    Thanks for the praise! I’ll hopefully be adding a second tutorial to this, which should help people to add more features so if you have any suggestions for that I’d love to hear them!

    As for your current problem, does your enemy have an instance name? If so, it shouldn’t do ;) (Or each enemy should have a different one)

    That sounds like it’s the problem, give it a shot and tell me how it goes.

  126. CookiemagiK Says:

    Hi!
    Yes that was the problem. Everything is working great now!! \(^0^)/
    Thanks again!

    I don’t have any suggestion for your next tut. Since I’m really new to this, I still don’t know what’s possible to do with this powerful program. But I’ll definitely read it if you ever write one! :D

  127. Tazzydevil XIII Says:

    No worries!

    Glad to be of help :)

  128. qw3rty Says:

    hello im very new to flash and this is my very first game

    I am having a bit of trouble with the character- ti wont die! Pls help :)

  129. Tazzydevil XIII Says:

    Hi!

    Make sure you have an instance name on the player, and that it matches the one in the code exactly!

    (As for double posting, I have to approve peoples comments until at least one is approved :))

  130. Aaron Says:

    Suggestions on the next tutorial avoiding game.

    Powerups
    A coin/box that you have to collect to get to the next stage.
    Maybe certain enemies that follow the character around.
    Maybe an attack of some sort?

  131. Tazzydevil XIII Says:

    Good ideas!

  132. qw3rty Says:

    what code are you talking about? is it the action script because there isnt a name in the actionscript

  133. Tazzydevil XIII Says:

    No, no, no.

    Under properties on the player, to the left, there is a box asking for an instance name :)

  134. qw3rty Says:

    still doesnt work :(

  135. Tazzydevil XIII Says:

    Hmmm, do you want to email me the file and I’ll take a look?

    (Gotta be Flash 8 or below)

  136. qw3rty Says:

    ok may i have ur email adress?

  137. jay Says:

    Try downloading the source file and editing it from there.

  138. Tazzydevil XIII Says:

    @qw3rty

    alternateaccount [AT] frozenhaddock.co.uk

    :)

  139. Tazzydevil XIII Says:

    Apologies for dodgy email returns, my email doesn’t seem to like writing any text at the moment… I’ve attached the fixed file. It was an instance name issue, you had it at ‘character’ whilst the code had it as ‘player’ :)

  140. Oskar Says:

    Tazzy! That worked out very well! But the enemey wont respawn! So I tried to make it respawn with this code:

    onClipEvent (load) {
    this._x = random(300);//sets the horizontal position randomly
    this._y = random(-50);//sets the y position above the stage
    speed = random(5)+1;//sets the speed randomly
    }
    onClipEvent (enterFrame) {

    this._y += speed;

    if (this.hitTest(_root.player)) {
    speed = random(-5)-1; //set the speed to a minus number
    this._y -= 10; //Jump the enemy upwards a bit so the player doesn’t hit it more than once.

    if (this._y<=100){
    this._x = random(300);//sets the horizontal position randomly
    this._y = random(-50);//sets the y position above the stage
    speed = random(5)+1;//sets the speed randomly
    }
    }
    }

    It didn’t turn out well =( =)

  141. Tazzydevil XIII Says:

    onClipEvent (load) {
    this._x = random(300);//sets the horizontal position randomly
    this._y = random(-50);//sets the y position above the stage
    speed = random(5)+1;//sets the speed randomly
    }
    onClipEvent (enterFrame) {

    this._y += speed;

    if (this.hitTest(_root.player)) {
    speed = random(-5)-1; //set the speed to a minus number
    this._y -= 10; //Jump the enemy upwards a bit so the player doesn’t hit it more than once.

    if (this._y<=-100){
    this._x = random(300);//sets the horizontal position randomly
    this._y = random(-50);//sets the y position above the stage
    speed = random(5)+1;//sets the speed randomly
    }
    }

    Try that! You need it to be less than minus 100 :)

  142. Aaron Says:

    Have an ETA on when the next tutorial might arise?

    Or any other beginning flash tutorials that you recommend in the mean time?

    I just did an OK shooter one, but it doesn’t really let me expand on it unless I know how to do my own AS.

  143. Tazzydevil XIII Says:

    I shall point you toward http://jdog053.blogspot.com/2008/06/create-game-like-heavy-weapon-part-1.html (3 parts released as of writing) for a good tutorial that’ll help expand your knowledge.

    As for an ETA… I shall try and get it close to finishing by today :)

  144. Oskar Says:

    Tazzy… no… I’m sorry… I can’t make it work… It still doesn’t respawn…

  145. Tazzydevil XIII Says:

    Aha, silly me ;)

    onClipEvent (load) {
    this._x = random(300);//sets the horizontal position randomly
    this._y = random(-50);//sets the y position above the stage
    speed = random(5)+1;//sets the speed randomly
    }
    onClipEvent (enterFrame) {

    this._y += speed;

    if (this.hitTest(_root.player)) {
    speed = random(-5)-1; //set the speed to a minus number
    this._y -= 10; //Jump the enemy upwards a bit so the player doesn’t hit it more than once.

    if (this._y< =-100 || this._y>=350){
    this._x = random(300);//sets the horizontal position randomly
    this._y = random(-50);//sets the y position above the stage
    speed = random(5)+1;//sets the speed randomly
    }
    }

    Now, THAT should work :)

  146. Oskar Says:

    Thanks! It worked with some modification!

    Here is my game: http://www.otechdesign.com/charlie.swf
    Hehe :D It’s not finished… Please tell me what you think!

  147. Oskar Says:

    The mission:
    Get the white balls into the goal = 10pts
    If you let a red ball into the goal = -10pts
    Touch the red balls to make them go away
    You have 20sec!

    D:

  148. Tazzydevil XIII Says:

    Nice! Looking good!

    It looks like you’ve taken the ideas and used them to create a new game, which is excellent!

  149. Oskar Says:

    Thanks =)

    Yeah. I came up with the ideas as I read and tried out the tutorial! Thanks a lot for the tutorial, again! =)

    The game is not so hard though… It doesn’t give the player a challenge…

  150. Building on the avoiding game (Avoiding game Pt.2) | FrozenHaddock Says:

    [...] in Flash, Games, Tutorials with No Comments Welcome to the first part of the second parts of the Avoiding game tutorial (Blimey, that’s a mouthful!) This tutorial will expand on the game you will have already made [...]

  151. Eric Says:

    Hmm… I cant get the player and the enemy to hit each other. They just slide tru and the movie stays on frame one.
    Iv checked so that the names are the same in the script and the symbols, and as far as I can see they are!?

    I even made a hole new “movie” with just some crappy drawn lines that were player and enemy, but the problem persisted.

    //Ecce

  152. Oskar Says:

    Wohoo!

    I’ve added a keeper to the game :D You can control the keeper with the arrow keys!

    http://www.otechdesign.com/charlie_2.swf

    Please note that I’ve never done anything like this before!

  153. flipper Says:

    Hi, thanx for a cool tutorial.
    My game just flipps like crazy between frame one and two… Everything seemd to work Ok untill I added the secont frame with the “game over” screen. I didnt ad the timer, but that cant have anything to do with it, right?

  154. qw3rty Says:

    qwerty here again
    how do i add music to the game? its a little boring without any mood :D and ty again tazz for your help with my “unable to die” stiuation

  155. Tazzydevil XIII Says:

    @Eric

    No idea what’s wrong, do you want to email me the file so I can take a look?

    @flipper

    Make sure you have a stop(); action on both frames :)

    @qw3rty

    Music is a whole different tutorial ;) I’ll try to get one up soonish.

  156. eric Says:

    Hi again… have been doing your tutorial over and over and over and over again, without getting the “kill” to work. By accident I klicked “test scene” instead of “test movie” and there the gameover workt just fine… so i tryed to export the file and run it outside of macromedia flash and it works just fine!
    Strange!?
    Well… apart from soundeffects and music there are a couple of features Id like to add to the game. First it wold be cool if u culd animate the enemies, so that they behave some way when they crash into out hero =)
    I would also like the enemies only to be able to hit the player. What I mean is that theres a box around the player, and the enemy only have to hit this invisible box in order to launch the game-over frame. How do you make it so that its only just the charaters oulines that trigger the enemy?

    Thanx alot again!
    Ecce

  157. Tazzydevil XIII Says:

    That is strange indeed!

    Soudeffects and music are going to be explained in a soon-to-be written tutorial :)

    Animation of enemies will most definitely be in part 3 of this tutorial, if you check out part 2 then you’ll see a quick fix for the bounding box problem ;)

  158. Aaron Says:

    Yeah I can’t wait for 3. I will hopefully have my new game posted tonight. There will be a couple things I might ask if I can’t find other means to do it. I think you will be proud of this one!

  159. Tazzydevil XIII Says:

    Sounds awesome!

    I’ll be glad to help with anything :)

  160. Mushyrulez Says:

    hey tazzy your email is alternateaccount@frozenhaddock.