Home Tutorials Forums Articles Blogs Movies Library Employment Press Buy templates

Go Back   ActionScript.org Forums > General > Gaming and Game Development

Reply
 
Thread Tools Rate Thread Display Modes
Old 11-13-2001, 11:47 AM   #1
sumei
Registered User
 
Join Date: Nov 2001
Location: London
Posts: 3
Question Help writing Actionscript for game

Hi There

I hope somebody can lend me thier expertise. I need to make a game, It's simple in concept, but I'm struggling to put the action and variables and random maths, together.

The game is chopping kings and queens heads off, it's for a history site.

So you have 5 different heads, popping up behind 5 chopping boards at random and using the ax attached to the mouse._x._Y
you got to hit them, and hence earn points.

But I can't seem to get the heads to pop up at random intervals or appear at random chopping boards.

Your Help will be greatly appreciated.

Ryan
sumei is offline   Reply With Quote
Old 11-13-2001, 02:57 PM   #2
wangbar
Registered User
 
Join Date: Oct 2001
Location: london
Posts: 39
Default

Try this, maybe it will help...

Set up your five "head" movieclips with instance names "head1" through "head5", then add this script to a dummy movieclip on the main timeline-

onClipEvent (load) {
// sets random time based on current value of getTimer()
function setRandomTime () {
now = getTimer();
delay = Math.floor(Math.random()*10000);
popTime = now+delay;
return popTime;
}
// initialise head positions and set random pop up times
for (i=1; i<=5; i++) {
head = _root["head"+i];
head._y = 200;
head.upTime = setRandomTime();
}
}
onClipEvent (enterFrame) {
for (i=1; i<=5; i++) {
head = _root["head"+i];
// pop up head
if (head.upTime<getTimer() && head.upTime+3000>getTimer()) {
head._y = 100;
} else {
// put head down again and calculate next pop up time
head._y = 200;
head.upTime = setRandomTime();
}
}
}
wangbar is offline   Reply With Quote
Old 11-13-2001, 03:02 PM   #3
mad_A
The Zen of ActionScript
 
mad_A's Avatar
 
Join Date: Mar 2001
Location: Dublin, Ireland
Posts: 713
Default

OK, say you have 5 heads, 10 locations.
Heads called H1, H2, H3...
Locations called L1, L2, L3,...
numHeads=5;
numLocs=10;


function showhead(){
// get random head
head = random(5)+1;
head="_root.H" add head;
// get random location
location=random(10)+1;
// get location for the head from the location
locationX = Eval("L" add location add "._x";
locationY = Eval("L" add location add "._y";
// set the position for the head
setProperty(head, _x, locationX);
setProperty(head, _y, locationY);
Eval(head add "._visible")=true;
}


you can clean up the code a bit, but that'll do it for ye
mad_A is offline   Reply With Quote
Old 11-14-2001, 10:14 AM   #4
sumei
Registered User
 
Join Date: Nov 2001
Location: London
Posts: 3
Talking Thanx

I'd really like to thank both of you for you speedy replies.

Mad A I couldn't get yours to work, I pasted the script on Frame2 with a gotoAndPlay (1) on frame 3, I put the variables on frame1.
but had no luck. I couldn't get my head round why the location variables were needed, along with the location _x, when all I want is the _y value.

This is the error in output

Scene=Scene 1, Layer=Layer 2, Frame=2: Line 8: ')' or ',' expected
locationX = Eval("L" add location add "._x";

Scene=Scene 1, Layer=Layer 2, Frame=2: Line 9: ')' or ',' expected
locationY = Eval("L" add location add "._y";

if you know what I could have done wrong, which is probably not realistic, help would be appreciated.
sumei is offline   Reply With Quote
Old 11-14-2001, 11:09 AM   #5
sumei
Registered User
 
Join Date: Nov 2001
Location: London
Posts: 3
Talking Thanx

I'd really like to thank both of you for you speedy replies.

Mad A I couldn't get yours to work, I pasted the script on Frame2 with a gotoAndPlay (1) on frame 3, I put the variables on frame1.
but had no luck. I couldn't get my head round why the location variables were needed, along with the location _x, when all I want is the _y value.

This is the error in output

Scene=Scene 1, Layer=Layer 2, Frame=2: Line 8: ')' or ',' expected
locationX = Eval("L" add location add "._x";

Scene=Scene 1, Layer=Layer 2, Frame=2: Line 9: ')' or ',' expected
locationY = Eval("L" add location add "._y";

if you know what I could have done wrong, which is probably not realistic, help would be appreciated.
sumei is offline   Reply With Quote
Old 11-14-2001, 03:41 PM   #6
tg
done
 
Join Date: Jun 2001
Location: portland, or
Posts: 8,048
Default

the error you are getting from mad_a's code is cause there is no closing paran on the eval statement... put one of these ")"right before the semi-colon (on the code for both the location X and location Y ).
__________________
tg
---
what the hell was i thinking?
tg is offline   Reply With Quote
Old 11-14-2001, 03:45 PM   #7
evilregis
Registered User
 
Join Date: Nov 2001
Posts: 47
Default

you are simply missing the closing bracket ')' at the end of the eval statement. add that into both lines and you should lose those errors.

.:er:.
evilregis is offline   Reply With Quote
Old 11-16-2001, 11:41 AM   #8
mad_A
The Zen of ActionScript
 
mad_A's Avatar
 
Join Date: Mar 2001
Location: Dublin, Ireland
Posts: 713
Default

Opps!
Sorry about that. As the lads said - I left out the closing brackets...

....had to leave you something to do!
mad_A is offline   Reply With Quote
Old 11-16-2001, 11:45 AM   #9
mad_A
The Zen of ActionScript
 
mad_A's Avatar
 
Join Date: Mar 2001
Location: Dublin, Ireland
Posts: 713
Default

gee...my code iks getting worse and worse...another error, the value for random should be one less as I am adding one to it (BECAUSE RANDOM INCLUDES ZERO)..so here is the modified code:

function showhead(){
// get random head
head = random(4)+1;
head="_root.H" add head;
// get random location
location=random(9)+1;
// get location for the head from the location variable
locationX = Eval("L" add location add "._x");
locationY = Eval("L" add location add "._y");
// set the position for the head
setProperty(head, _x, locationX);
setProperty(head, _y, locationY);
Eval(head add "._visible")=true;
}
mad_A is offline   Reply With Quote
Old 11-16-2001, 12:52 PM   #10
wangbar
Registered User
 
Join Date: Oct 2001
Location: london
Posts: 39
Default

Yeah, I had a look through my code too and made a couple of tweaks.

Here's the update:

onClipEvent (load) {
// sets random time based on current value of getTimer()
function setRandomTime () {
now = getTimer();
delay = Math.floor(Math.random()*10000);
popTime = now+delay;
return popTime;
}
// initialise head positions and set random pop up times
upPosition = 120;
downPosition = 200;
for (i=1; i<=5; i++) {
head = _root["head"+i];
head._y = downPosition;
head.upTime = setRandomTime();
}
}
onClipEvent (enterFrame) {
for (i=1; i<=5; i++) {
head = _root["head"+i];
// pop up head
if (head.upTime<getTimer() && head.upTime+2000>getTimer()) {
head._y -= (head._y-upPosition)/2;
} else {
// put head down again and calculate next pop up time
head._y += (downPosition-head._y)/2;
head.upTime = setRandomTime();
}
}
}

I'm sure that if you combine this and Mad A's together you'll have something that works the way you want, in the meantime I put a demo of the above up at:

chopping demo
wangbar is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
writing actionscript so flash acts like a screensaver cherie ActionScript 1.0 (and below) 4 03-28-2004 12:41 AM
ActionScript Learning StormStrikes Other Flash General Questions 12 03-04-2004 04:28 AM
Writing to a text file using actionscript sharadha ActionScript 1.0 (and below) 1 08-01-2002 08:08 AM
french writing in ActionScript panel micardi ActionScript 1.0 (and below) 1 01-07-2002 12:01 PM


All times are GMT. The time now is 03:20 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2009 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.