Penboy
18 posts
|
People have been asking how to make games using Flash, so I've decided to make a 'Kongregate Forum Tutorial'. In this tutorial I'm going to teach you how to make a very basic Mouse-Avoider game.
What is a mouse avoider?
-It is usually a game where you can't touch walls, and you have to get to the end of the level.
What do I need?
-Flash 8
-Basic knowledge of the program
Lets get started...
======================
First of draw a SMALL circle. Highlight all of it and press F8. Select the option 'Movie clip' and name it accordingly. Now double click on your MC and make sure the little '+' is in the center of you circle. Double click anywhere to go back to your main timeline.
Select your MC and press F9 to bring up your Properties box. Give your circle the instance-name of cursor. Now open the panel directly above named 'Actions - Movie clip' and paste this code into it:
onClipEvent (enterFrame) {
//x movement
mx=_root._xmouse;
if (mx<_x><_x><_x><_x><_y><_y>
That tells the MC 'cursor' to follow the (invisible) normal mouse sluggishly, creating a cool effect.
Now insert a new layer and draw your walls. Select everything (Ctrl>A) and make it into a new MC. Name it accordingly. This new MC doesn't require an instance name, so just go directly to the AS (Action-Script) box and paste in this code:
onClipEvent(enterFrame){
if(this.hitTest(_root.cursor._x, _root.cursor._y, true)){
_root.gotoAndStop("2");
}
}
This tells Flash that when 'cursor' hits the wall MC, it will take you to frame 2.
On your Timeline press F7. This will make a clear key frame. In this key frame draw a message such as 'Game Over'. Insert a new layer, and put this command into it:
stop();{
Stage.showMenu=false;
}
This will make sure that the game will not stop on frame 1 and 2, whilst hiding the right-click menu.
Go back to your cursor layer and draw a square. Turn it into a MC and put this code into it:
onClipEvent(enterFrame){
if(this.hitTest(_root.cursor._x, _root.cursor._y, true)){
_root.gotoAndStop("3");
}
}
That tells Flash to take you to frame 3 when cursor hits it. On your Timeline insert another blank key frame (F7) and put a message in it such as 'You Won'
Hit Ctrl>Enter to test your game.
======================
In a nutshell, thats how you make basic mouse avoiders. Remember these hints though:
+Don't make your walls too thin, or your cursor can go through them!
+Don't make your levels impossible, otherwise people will gave up!
+Make the winning square go to different frames (levels)
EXTRA:
-VCAM-
If you have a V-Cam, put this code into it:
onClipEvent (enterFrame) {
_y += (_root.cursor._y-_y)/4;
_x += (_root.cursor._x-_x)/4;
}
That tells the camera to follow cursor.
======================
Happy gaming! Tell me what you think :D
~Penboy
_Edited by arcaneCoder. Reason: Added code formatting tags. Hope that helps!_
|
|
|
Penboy
18 posts
|
Ahh shoot! The script didn’t post vertically! My apologies :’(
(Just press enter in the AS box to make a new line for the code when necessary, if you know where :( )
|
|
|
arcaneCoder
1326 posts
|
Thanks for the contribution :)
Suggestion: Dont ever ever use onClipEvents. They became obsolete several versions ago for very good reasons. If you are using Flash 8 especially, you should be using the updated events. For example:
onClipEvent ( enterFrame ){
}
is replaced with
MovieClip.onEnterFrame = function (){
}
PS please see this post regarding formatting code in the forums. It will help keep your code from bunching up like that ;)
|
|
|
Penboy
18 posts
|
ok this is just a test:
(pre)Stage.showMenu=false;(pre)
shoot! I’m such a noob a Kong’s coding…
I’ll try again (pre)Stage(/pre)
o….m…..g this is giving me high blood pressure
(pre)
function doStuff () : Void
(/pre)
function doStuff () : Void
</pre)
Edited by arcaneCoder. Reason: Triple post consolidation :)
|
|
|
arcaneCoder
1326 posts
|
You gotta enclose your “pre” tags in <> on your comma and period buttons to get the code formatting working, just like html tags. The second tag also needs a “/” in it. I posted a sample in your post above, so if you hit the edit button you will see what I mean.
Like so:
<pre>put code in between these tags
|
|
|
Woad
99 posts
|
Also. There is actually a way to edit your own posts. So you may want to do that instead of triple posting.
|
|
|
Eggy
1427 posts
|
I still only use onClipEvent (enterFrame)
It’s from habit….I know its bad but…I dont wanna change yet :(
|
|
|
IndieFlashAr...
433 posts
|
This is an interesting post and I’m sure it will help some people who are starting out in Flash. Nice one, Penboy :)
I only wanted to say that it’s also an example of bad coding practice. If you’re not programming in OOP style (i.e. entirely in classes), you should at least keep all your code in the same place, on the same frame (at the _root level), and this means never using onClipEvents. As Coder mentioned, they have been depreciated.
It may work fine for a simple mouse avoider, but you will run into problems if you try to do something more complex using onClipEvents.
Anyway this is not a ‘slam,’ it’s just my two cents :)
|
|
|
arcaneCoder
1326 posts
|
Wow Eggy, you gotta move on! onClipEvents will hold you back and create way more work for you in many situations. Its real easy to move away from them and its worth it.
|
|
|
dazzer
730 posts
|
wait till you have to do
this.addEventListener(Event.ENTER_FRAME, onEnterFrame, false, 0, true);
private function onEnterFrame(e:Event)
{
trace("Howdy I'm a new frame");
}
Awesome fun.
|
|
|
arcaneCoder
1326 posts
|
Thats why I use a custom framework for all my games. All I have to do is type resume() or resume ( method ) and I’m done :D. The whole AS 3.0 event system requires a lot more work – some say too much work (unless you build your own code base to ease the pain).
People are gonna have a heck of a time learning it, thats also why I always push to drop the onClipEvents since it will be a harder transition.
|
|
|
IndieFlashAr...
433 posts
|
In order to illustrate some AS 2.0 coding, I made a tutorial which I also think is a fun project for beginners.
SimpleShip Tutorial
|
|
|
Mauser
25 posts
|
Thanks for the walk through! =)
|
|
|
doomdoom24
14 posts
|
Can I use this code in a game?
|
|
|
breadfish
9 posts
|
How do i give something an instance name in cs3?
EDIT-Nevermind, found it lol
|
|
|
colbzter
1 post
|
its not working for me its just replaying a video of the three frames over and over again
|
|
|
Frogmanex
3485 posts
|
If you click on the object after you’ve placed it on the stage, you should see a “Properties” tab where there is an input box that says “Instance name”.
Alternatively, I think you can use the name property in script… I’m not sure ‘cause I’ve never done it. But I think you can.
Edit:
Originally posted by breadfish:
How do i give something an instance name in cs3?
EDIT-Nevermind, found it lol
Originally posted by colbzter:
how do you give somthing an instance name in cs3 o nvm u just go down to the properties panel by the picture of a gear
I lol’d. -.-
|