PDA

View Full Version : OverView Slice 'n Dice Game ActionScript Needed


RedLeader001
07-18-2005, 04:50 PM
im new to flash gaming and action script but this is wat i want for my game-

1.move and with arrow keys rotate with mouse. (wen up arrow is down move forward in the angle that the MC in /turnedrotated)
2. press left mouse and swings sword hurting enemys.
3. Enemy AI ( if u just feel like add it but dont feel like u have to)

i think thats all i want basicly. (no blood and they dont have to fly back just maybe fade out) this kinda game sorta-

http://www.t45ol.com/play_flash_us.php?ID=1310 (http://www.t45ol.com/play_flash_us.php?ID=1310)

thanks in advance!

-RedLeader001

mitchinator1
07-18-2005, 04:53 PM
wow..your
1. going to get uber flamed
and 2. asking a lot, resulting in number 1^.

RedLeader001
07-18-2005, 05:14 PM
ok im sorry. lets start with this-

1.move and with arrow keys rotate with mouse

Lui
07-18-2005, 05:24 PM
i can help with that!!
here's the code

if(question)
{
Do search();
if(search()=="no result")
{
makeNewThread();
}
}

mitchinator1
07-18-2005, 05:29 PM
lol good one..i'll say it once..either google, or a flash site, like flashkit.com or actionscript.org

Lui
07-18-2005, 05:49 PM
i know how to do the game..
http://www.geocities.com/luivillarias2002/lvrpg.html
yep, its my game.
[/offtopic]

RedLeader001
07-18-2005, 06:10 PM
yea i played it. its COOL. do u think u can tell me how u did it? and if u know how to replace a gun shot with a sword slash? like Stick RPG Demo. thanx!

-RedLeader001

PS. please dont hate me. (it seems like u and the other guy does:( )

eatmorchikin6464
07-18-2005, 06:26 PM
Relax. They are just n00bs who think they can boss people around. Don't listen to them.

Lui
07-18-2005, 07:21 PM
dont listen to him, just ignore his posts, he flames everyone everytime u post.

now back to the topic,
yes i can replace it with a sword slash, pretty easly, i might get time to help you but not now.
i havent quite figured how to do x,y hitTests

Bodadem
07-18-2005, 08:10 PM
That. Sig. Is. HOT!

tatorhead
07-18-2005, 10:49 PM
Well two things, Lui

1. so far nothing in that game is your except for graphics, its mine and until you make it something new, orgional or most important: yours, quite calling it your game. Actually quit calling it a game

and

2. Emc owns you,

TO: the new guy

1. Don't come on here asking people to make games for you. Its just uncool. Instead learn to know actionscript and flash and then then post on here with specific stuff you need help with. Trust me, if someone did make the game for you, you wouldnt know what to do with it like Lui right now

RedLeader001
07-19-2005, 10:10 AM
ture tatorhead. fish for someone they'll be fed for one day. (if there anareksic) tech them how to fish, they'll be fed forever. (if they LOVE fish that much)

Iv'e been to ALOT of tutorial sites, I MEAN ALOT, and none of them really explain ow the the actionscript works. if someone could explain the actionscript for the basic movement with UP, DOWN, LEFT, RIGHT i would be utterly thankful. well thanx to everyone and thanx in advance!

-RedLeader001:mad:

Bodadem
07-19-2005, 10:30 AM
The code;

I'm making an assumption for this that you know how to make movieclips, and you've made whatever you want to move a movieclip, and for this example it's instance name will be 'man'. This code will be inside the actions panel for the movieclip 'man'.

onClipEvent(load) {
movespeed = 5
}
//Change '5' to a higher number to move faster, or lower to move slower.
onClipEvent(enterFrame) {
if(Key.isDown(Key.UP)) {
this._y -= moveSpeed;
}
if(Key.isDown(Key.DOWN)) {
this._y += moveSpeed;
}
if(Key.isDown(Key.LEFT)) {
this._x -= moveSpeed;
}
if(Key.isDown(Key.RIGHT)) {
this._x += moveSpeed;
}
}


Now, I explain;


onClipEvent(load) {
moveSpeed = 5
}

When the movieclip loads, it creates the variable 'moveSpeed' and sets it to 5.


if(Key.isDown(Key.UP)) {

If statements start with 'if(' and check the requirements set down in the brackets for either true, or false. If they return true, it continues to perform the actions found on the next line(s). In this case, we are testing to see if the 'up' arrow key is being pressed down. This is done in the format of 'Key.isDown(Key.xxxxx)' where 'xxxxx' is replaced with the name of they key, in capitol letters.


this._y -= moveSpeed;

and

this._y += moveSpeed;

and

this._x -= moveSpeed;

and

this._x += moveSpeed;


An objects _x and _y positions are it's vertical and horizontal positions relative to the upper-left corner. This code simply adds or subtracts to the 'man's _x or _y positions, an amount equal to the variable moveSpeed once each frame. If you subtract from the _y, this lessens the vertical distance away from the upper-left corner, therefore moving the object up. If you subtract from the objects _x, this lessens the horizontal distance away from the upper-left corner, therefore moving the object to the left. Adding to either of these will take the opposite affect as adding does.


I hope this helps! :)

RedLeader001
07-19-2005, 11:13 AM
thank u for posting that but it doesnt work. is it because i have flash MX 2004 professional?

Swas
07-20-2005, 02:38 AM
thank u for posting that but it doesnt work. is it because i have flash MX 2004 professional?

I havent tested it but it does work. Its a problem on your end, where are you placing the code? Put it in the a movieClip. Have you correctly named your instances?

Heres a hint (sort of) when coding actionscript, well coding in general, You must think of everything literally, you asked for enemy AI, what makes it artificial intelligence? being told exactly what to do.

this is what we call an if statement. if statements are the basis to nearly all games. Heres an example (Mouse Click, like you asked)


onClipEvent (mouseDown){
this.gotoAndStop ("animation");
}


This code presumes you have a frame called "animation" (to do this double click the frame, go to the properties panel, and name it)

Once you start to understand if statements anything is possible, if you put your mind to it.

tatorhead
07-20-2005, 02:39 AM
no, that wouldnt make a difference that code looks good to me

isnt that quote from the bible?

Swas
07-20-2005, 02:44 AM
no, that wouldnt make a difference that code looks good to me

isnt that quote from the bible?

Were you talking to me there, if not, what quote was from the bible?

tatorhead
07-20-2005, 02:48 AM
ture tatorhead. fish for someone they'll be fed for one day. (if there anareksic) tech them how to fish, they'll be fed forever. (if they LOVE fish that much)



that one, it sounds familiar

The Brown Cow
07-20-2005, 10:07 AM
Delete the spaces used to indent the text.

For some reason, MX 2004 is picky about spaces like that. It seems to think that they're part of the variable's name or something. It's stupid, but it happens.

RedLeader001
07-20-2005, 10:23 AM
Delete the spaces used to indent the text.

For some reason, MX 2004 is picky about spaces like that. It seems to think that they're part of the variable's name or something. It's stupid, but it happens.
I dont get it brown cow. what spaces do u mean?

well this is wat it looks like-
http://host.picturewizard.com/2004-12/216758/FlashMXjpg.jpg
(i hope its not right actually)(so its eaasyer to fix)
Swas u said this- "Have you correctly named your instances?" i only need 1 instance right?
thanx guys!

-RedLeader001

PS- Swas

onClipEvent (mouseDown){
this.gotoAndStop ("animation");
}

doesnt work. it only stops the animation wen i click and it doesnt play again.

supernerden
07-20-2005, 11:45 AM
*Is waiting for image to load...*

BOOORING....

*image fully loaded*

Should work. Try deleting the "//TEXT HERE" thingy

G3k0
07-20-2005, 12:41 PM
um. Notice how the declaring of the variable in the onClipEvent(load) function is named movespeed and later on its referred to as moveSpeed. Variables are cap sensitive so change the first one to moveSpeed

RedLeader001
07-20-2005, 12:56 PM
IT WORKS!!!!!!!! :D THANK YOU GUYS SOOOOO MUCH!!! :p W00t W00t!!! :D

*it was the caps prob* do u guys remember the acionscript? well now if not to much... rotation script and explanation? if u want to of course. can be mouse or arrow keys rotation. thanx again guys!!!

-Happy RedLeader001

G3k0
07-20-2005, 01:05 PM
I've got the code a mc to follow the mouse, but I dont know if you should use that one :\

I dont think you should use it though :\ maybe...


onClipEvent (load) {
_root.playerdead=0;
_root.punchcharge = 0;
_root.StickHead._alpha=0;
var drag:Number = 8;
R = Q1=QQ1=Q2=QQ2=0;
_root.Mouse.hide();
walkspeed = 10;
}
onClipEvent (enterFrame) {
if (_root.playerdead==0){
var distX:Number = this._x-this._parent._xmouse;
var distY:Number = this._y-this._parent._ymouse;
var radians:Number = Math.atan2(distY, distX);
targetRotation = ((radians/Math.PI)*180);
if (targetRotation<0) {
Q1 += (targetRotation-QQ1);
}
QQ1 = targetRotation;
if (targetRotation>0) {
Q2 += (targetRotation-QQ2);
}
QQ2 = targetRotation;
if (Q3-180>targetRotation) {
Q1 += 360;
}
Q3 = targetRotation;
if (Q4+180<targetRotation) {
Q2 -= 360;
}
Q4 = targetRotation;
Q5 = Q1+Q2;
rotateAmt = (Q5-this._rotation)/drag;
R += (Q5-R)/drag;
this._rotation = R;
} else {gotoAndPlay(dead);}
if (Key.isDown(Key.UP)) {
this._y -= walkspeed;
} else if (Key.isDown(Key.DOWN)) {
this._y += walkspeed;
}
if (Key.isDown(Key.LEFT)) {
this._x -= walkspeed;
} else if (Key.isDown(Key.RIGHT)) {
this._x += walkspeed;
}
}

RedLeader001
07-20-2005, 01:23 PM
the rotation point is not centered with the mouse. XD
oh yea one real quick thing, how do i put a flash file on my sig?

G3k0
07-20-2005, 01:31 PM
huh? what do you mean? if you put that in your mc and make sure that the part uyou want to face the mouse is pointing straight to the left. Or i think you can change the 0 at the end of this statement

R = Q1=QQ1=Q2=QQ2=0;

much easier just to rotate your mc around.

RedLeader001
07-20-2005, 03:08 PM
thank u that worked. but how do i change the rotating speed? i want it to be practicly instant. thanx so far G3ko!

-Red :mad: :D

G3k0
07-20-2005, 10:24 PM
ok. sorry. I pasted that code straight from something i was doing and it had some extra unneccesary components. This should work.


onClipEvent (load) {
var drag:Number = 1;
R = Q1=QQ1=Q2=QQ2=0;
_root.Mouse.hide();
walkspeed = 10;
}
onClipEvent (enterFrame) {
var distX:Number = this._x-this._parent._xmouse;
var distY:Number = this._y-this._parent._ymouse;
var radians:Number = Math.atan2(distY, distX);
targetRotation = ((radians/Math.PI)*180);
if (targetRotation<0) {
Q1 += (targetRotation-QQ1);
}
QQ1 = targetRotation;
if (targetRotation>0) {
Q2 += (targetRotation-QQ2);
}
QQ2 = targetRotation;
if (Q3-180>targetRotation) {
Q1 += 360;
}
Q3 = targetRotation;
if (Q4+180<targetRotation) {
Q2 -= 360;
}
Q4 = targetRotation;
Q5 = Q1+Q2;
rotateAmt = (Q5-this._rotation)/drag;
R += (Q5-R)/drag;
this._rotation = R;

if (Key.isDown(Key.UP)) {
this._y -= walkspeed;
} else if (Key.isDown(Key.DOWN)) {
this._y += walkspeed;
}
if (Key.isDown(Key.LEFT)) {
this._x -= walkspeed;
} else if (Key.isDown(Key.RIGHT)) {
this._x += walkspeed;
}
}




Please note the statements in bold. This script searches for the target rotation depending on the cursors position. It finds out how far that rotation is from the current rotation and it divides it by the drag variable for the ease effect. If you want to make it instant just make drag=1

Lui
07-20-2005, 11:47 PM
no dude, i got a more smaller code ill post back with it

>edit<
ok here's the code

onClipEvent (mouseMove) {
onMouseMove = function () { var angle = Math.atan2(_root._ymouse-this._y, _root._xmouse-this._x)/Math.PI*180;this._rotation = angle;updateAfterEvent();};
}
put it on your hero MC, and make sure that its drawn or pointing right if not the rotating will be screwed

i would like to see how the game looks like now

G3k0
07-21-2005, 12:05 AM
onClipEvent (load) {
R = 0;
_root.Mouse.hide();
walkspeed = 10;
}
onClipEvent (enterFrame) {
var distX:Number = this._x-this._parent._xmouse;
var distY:Number = this._y-this._parent._ymouse;
var radians:Number = Math.atan2(distY, distX);
targetRotation = ((radians/Math.PI)*180);
R = targetRotation;
this._rotation = R;

if (Key.isDown(Key.UP)) {
this._y -= walkspeed;
} else if (Key.isDown(Key.DOWN)) {
this._y += walkspeed;
}
if (Key.isDown(Key.LEFT)) {
this._x -= walkspeed;
} else if (Key.isDown(Key.RIGHT)) {
this._x += walkspeed;
}
}


Is that better? That wont work for the easing rotation though. Does that work?

Lui
07-21-2005, 12:20 AM
Well two things, Lui

1. so far nothing in that game is your except for graphics, its mine and until you make it something new, orgional or most important: yours, quite calling it your game. Actually quit calling it a game

and

2. Emc owns you,

TO: the new guy

1. Don't come on here asking people to make games for you. Its just uncool. Instead learn to know actionscript and flash and then then post on here with specific stuff you need help with. Trust me, if someone did make the game for you, you wouldnt know what to do with it like Lui right now
[/code]
ill reply to number 1, first of all, all you see is a demo nothing compared to what you will see on the finished version, so stop saying as if im not doing anything that i am doing.


replying to number 2, no he doesnt own me, he's just some guy on a forum not my king or owner. neither does he know much anything about me only something thats false and thats "lui is a n00b" first of all your calling someone a n00b when u dont even know what they're like in real life, all you know is that they either spam or whatever, plus it is just hurting people's feelings to say "your a n00b" as i just learned 5 mins ago , and also as you know there is some people who hate EMC, the only problem is they wont tell, i've spoken to people and they're reply is they hate him, im not gonna say names or anything.

ok number 1 to the new person reply
first of all he asked for help, isnt asking for help in flash game dev not allowed anymore? like what brown cow said

I just use this forum to talk about Flash, not to pick fights. Shame the rest of you can't do that.
so its either help or go away

Swas
07-21-2005, 03:48 AM
Lui, no-one reads your long pointless opinionated posts. Just give up, you got owned.

RedLeader001
07-21-2005, 09:27 AM
HEY! i read his long pointfull post! I respect Lui. although he didnt give the best 1st imprestion
--------------------------------
|*Quote*
| if(question)
| {
| Do search();
| if(search()=="no result")
| {
| makeNewThread();
| }
| }
--------------------------------

But it was FUNNY!!! hes helped me LOADS! thanx Lui! so have u swas, and G3ko, and Bodadem! thanx all! al im sorry if i forgot sum1. :o
-Yes G3ko it does work. the last code u gave me :D
-Lui, im using ur rataion code and i also added Bodadem's movement and the movement looks really botchy. (not smooth) do u kno why? is it just the code?
-U Actually wanna see the game? no way! all it is so far is a circle with a top that goes into like a triangle. and it moves a rotates. this is my 1st one im making it simple.
[B]-all i need now it the sword slash. :D
well thanx so far guys!! ty alot!

-Red LEader. (im gettitn a new sig up soon)

G3k0
07-21-2005, 12:39 PM
thats perfectly fine. I actually only expected a colored circle on a white back ground with maybe one working wall...

tatorhead
07-21-2005, 12:41 PM
somebody call the waaaaaahbulance

Red leader for the sword slash all you really need to do is animate the sword slash and then make the animation go once you hit whatever button and then do a hittest on the enemys with the sword mc

G3k0
07-21-2005, 12:51 PM
lol. Wasnt that a lil bad. Does RedLeader even know how to hitTest yet? All you have to do is make the animation of the sword slashing like tatorhead said. In the first frame of stickmanclip (standing) put stop(); in the action panel. Then in the rest of the frames is where you make the sword animation. Or you can make the whole animation in frame 2 with a movieclip sword. IshMae.... But if you do the first way then make one extra frame after the animation and put gotoAndStop(1); that'll take it back to standing. If you use the sword movieclip in frame two alone put this in the final frame of the sword animation: this._parent.gotoAndStop(1); the this._parent is so it goes back to frame 1 in your first mc instead of the sword one :\ ishmae.. thats the first step...

Lui
07-21-2005, 03:07 PM
maybe i should give him a .fla example?

RedLeader001
07-21-2005, 03:21 PM
yes please a flash example would be helpful lui. :D

G3k0
07-21-2005, 07:56 PM
I dont know. Why don't you show him?

Lui
07-21-2005, 08:40 PM
can i do it later...im too tired to do it

tatorhead
07-21-2005, 09:47 PM
Alright here is an example, just the swords and stuff, very badly animated

G3k0
07-21-2005, 10:32 PM
yup, a fla example makes so much more sense. ... Load

RedLeader001
07-22-2005, 12:29 AM
Its ok Lui. u dont have to make one. TatorHeads it GOOD. THANX TOTORHEAD!!! works perfecto! well u guys wanted to see it. here it is!
http://i16.photobucket.com/albums/b36/MooniKooni/MedievalGames.swf

enjoy! -i modifyed the graphics a bit for u guys. :D

-RedLeader001 (do u like my sigs)

tatorhead
07-22-2005, 01:14 AM
suggestions:

* the arm should move
* different slashes. if you understand what I gave you, you should be able to figure that out pretty easy.
* have it so you can only attack after the previous attack has finished. A simple varible should do this (I haven't tried, but I think it would)

Swas
07-22-2005, 04:05 AM
Its looking pretty good, nice work. Though i would give you this advice, learn why the code works. I (like others here) used to get code, and then pass off the game as my own actually thinking i'd made it. When you make a game from scratch with your own code, its so fufilling.

RedLeader001
07-22-2005, 10:53 AM
tator head i did the hand but i cant figure out the other 2. sorry. and Swas, do u think u could teach me action script? like what all the () and {} and . and = and _ thanx!!! or anyone else. just like ur teaching HTML :D. thanx.

-RedLeader001

The Brown Cow
07-22-2005, 11:23 AM
Hmmmm... kinda looks like he's slitting his own throat. Might want to make him reach out a bit.

Lui
07-22-2005, 04:55 PM
im still even having problems with the random frame code, i know swas gave me a proper example but the punching frame is way out on frames 43, 56 and 63..

G3k0
07-22-2005, 05:23 PM
Its looking pretty good, nice work. Though i would give you this advice, learn why the code works. I (like others here) used to get code, and then pass off the game as my own actually thinking i'd made it. When you make a game from scratch with your own code, its so fufilling.

Thats why i didnt want to do an example. I like the guy. But his swing is horrible.

Lui
07-22-2005, 07:12 PM
the guy's cool but the swing is a bit boring

G3k0
07-22-2005, 07:30 PM
im still even having problems with the random frame code, i know swas gave me a proper example but the punching frame is way out on frames 43, 56 and 63..

Sounds really simple to me, dude...

//Start of getting Punching animation
this.getpunch=Math.ceil(Math.random()*3);
if (this.getpunch>2){
gotoAndPlay(43){
}
if (this.getpunch>1){
gotoAndPlay(56){
}
else {
gotoAndPlay(63){
}
//End of getting random Punching



would that not work?

Lui
07-22-2005, 08:58 PM
thats ok, my last code was right, but i forgot to flip the other punching animation so that it would be the other arm, no wonder why it was punching left all the time o.0
<=Problem Solved=>
<=New Problem=>
X, Y hitTests

G3k0
07-22-2005, 09:38 PM
As interesting as that is... Why dont you try to make some movement and walls redleader?

Swas
07-23-2005, 03:28 AM
What do you mean by X,Y hitTests Lui? be a bit more specific and i'll probs help. You never thanked me for that code.

Lui
07-23-2005, 04:41 AM
cause i never thought it would worked xD thanks though,
X,Y HitTest are like it doesnt detect the bounding box of the mc it actually finds what is really in and detects that and not the bounding box.

RedLeader001
07-23-2005, 08:16 AM
G3ko i dont get how the code works. its not working. and how do I make a COOL swing? this better? i need a simple hittest. :D
http://i16.photobucket.com/albums/b36/MooniKooni/Slash.swf
(i dont know why its so big, it not usually)

-RedLeader001

Friendly Fire
07-24-2005, 02:20 PM
Good job red leader, the swing could be better though, but, overall, it is sweet!!!


right now, i would rate it 9/10. just fix the swing. (rating is just based on whats done)

G3k0
07-24-2005, 07:59 PM
Start off by trying to make some rectangular walls. Then you could learn the proper use of the hitTest() function.

The function hitTest returns a true or false value. If the boundary box of the mc specified before the .hitTest has come in contact with the bounding box of the mc specified in the ()'s

Proper syntax: 1stMovieClip.hitTest(2ndMovieClip)

Use it in a if statement

example:

This code would go into the Guy.

onClipEvent(load){
movespeed=5;
}
onClipEvent(enterframe){
if(key.isDown(Key.LEFT)){
this._x-=movespeed;
}
else if(key.isDown(Key.RIGHT)){
this._x+=movespeed;
}
if(key.isDown(Key.UP)){
this._y-=movespeed;
}
else if(key.isDown(Key.DOWN)){
this._y+=movespeed;
}
if(this.hitTest(wall1) || this.hitTest(wall2) || this.hitTest(wall3) || this.hitTest(wall4)){
this._y=oldy;
this._x=oldx;
}
oldy=this_y;
oldx=this_x;
}


onClipEvent(load){
whenever the mc loads this will return true

movespeed=5;
I've declared this variable that is later used in a statement.

}
I close the enterframe bracket

onClipEvent(enterframe){
even when the mc is stopped this returns true every time a frame should open
if(key.isDown(Key.LEFT)){
this._x-=movespeed;
}
If the user is holding left down the mc will move left at the distance in pixels specified as movespeed

else if(key.isDown(Key.RIGHT)){
this._x+=movespeed;
}
If the player is not holding down left and If the user is holding left down the mc will move left at the distance in pixels specified as movespeed

if(key.isDown(Key.UP)){
this._y-=movespeed;
}
If the user is holding up down the mc will move up at the distance in pixels specified as movespeed
else if(key.isDown(Key.DOWN)){
this._y+=movespeed;
}
If the player is not holding down up and If the user is holding down down the mc will move down at the distance in pixels specified as movespeed
if(this.hitTest(wall1) || this.hitTest(wall2) || this.hitTest(wall3) || this.hitTest(wall4)){
This if statement is activated if the mc has come in contact with a wall. This wont work unless you give them the instance names, wall1 - 4.

this._y=oldy;
this._x=oldx;
}
if The mc is touching a wall then the x and y coordinates will go back to there previous state which is specified by

oldy=this_y;
oldx=this_x;
}
these statements. It's important to set these variables after you check for the touching bounds.

Boy, I'm sure you didnt need it that in depth...

RedLeader001
08-04-2005, 06:38 PM
thanx guys. sorry i was gone. well im gonna put up another post soon... thanx again all of u guys!

arkhan
08-04-2005, 07:59 PM
about hitTest..it also works with shapeflag...wich is the shape of the clip instead of the bounding box..but it would be too processor intensive to check for colision within 2 shapes..so it will check for the shape and a chosen spot on screen(XY position)

its pretty easy syntax..
MC.hitTest(X,Y,true)
this will make the check, altought it works fine if you use it in the main stage, it will have some problems if you use it with nested movie clips..as it checks the XY for the XY shape, and...well..nothing you need to know right now..also, I answered this in my own thread XD