PDA

View Full Version : Need help with vaules or something to count! >< (It's holding me back! Part2)



Drexegar
October 15th, 2004, 02:35 PM
Hiya again I'm stuck =-_-=. Well when I program games i used a of objects i like to call "counters" I thinking that varibles is what im suppose to use. Well its like i would use these to tell to perform a certain action like for example if

if red = 0 then end game
if red = 1 then run game

the problem i have here is that on my game Im trying to make my character punch but the problem is the action that stops him from running after letting go. but now thats stopping him from when i press anything I look at tutorial everywhere but you know none of them not even one teaches you how to change animations while moving a charcater.

Here the code as you probaly seen it already:

onClipEvent(load){
moveSpeed=10;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
this._x+=moveSpeed;this.gotoAndStop(2);
} else if (Key.isDown(Key.LEFT)) {
this._x-=moveSpeed;this.gotoAndStop(2);
}else {
this.gotoAndStop(1);
}
}

now you can see that if none of these keys are press on the keyboard then he stops but that also means if im press the z key to punch he going to still stop since i didnt press the left or right ;_;.

So I want to put a counter or something called "stoprun" that can tell him to stop when this is at a certain number so I can put the counter on another number.

So i really dont know how to set up anything with vaules like score, lives, and energy bars and etc. cause I dotn know how to do vaules and stuff cause i dont know script! >< this is the only thing i need left and i shouldnt have anymore problems making a game in flash.

Dr Warm
October 15th, 2004, 07:39 PM
theres a simple solution to ur fighting animation problem. have:
if(Key.isDown(Key.Z)){ //<-- whatever the code for 'z' is
//make fighting animation
fighting = true;
} else {
fighting = false;
}

and then in the direction moving code at the bottom

}else {
this.gotoAndStop(1);
} now have
}else {
if(!fighting){
this.gotoAndStop(1);
}
}

that should work

so what else do u want "score, lives, and energy bars" i can help u with these also, just tell me when, they're not particuarly difficult. and once again i'll refer u to a fighting game i'm making as a template, here (drwarm.freeserverhost.net/stuff/little%20fighter%202.zip), which now has health bars and health goes down for enemy when u punch him (control key)

Drexegar
October 15th, 2004, 11:22 PM
thanx a lot =^_^= everything is good there only one problem and i able to work with it but check it out heres the new code:

onClipEvent(load){

moveSpeed=10;

}

onClipEvent (enterFrame) {
if(Key.isDown(Key.SPACE)){this.gotoAndStop(3)
fighting = true;
}
if (Key.isDown(Key.RIGHT)) {
this._x+=moveSpeed;this.gotoAndStop(2);fighting = false
} else if (Key.isDown(Key.LEFT)) {
this._x-=moveSpeed;this.gotoAndStop(2);fighting = false
}else {
if(!fighting){
this.gotoAndStop(1);
}
}

}

Now the problem is when i go to walk(frame 2) i cant attack(frame 3) at the same time
I can iterrupt the walk movie clip but you will only see the first frame of the attack and then it goes back to walking movie clip. I sthere anyway I can stop it form walking while the person attacking? or disable the walking whiel teh persons attacking and renable it after the movie clip has finish which leads to my next question in part three.

Dr Warm
October 16th, 2004, 04:08 AM
I've been pondering this issue myself, and i can't think of a good solution, one way i had was having on attack:
if(Key.IsDown(Key.Z)){
if(!fighting){
//play fighting animation here
fighting = true;
}
}else{
fighting = false;
}
this makes it so if the clip is already playing it doesn't do it again

and then inside the movie clip have a loop so that at the end of the fighting animation, have on the last frame:
gotoAndPlay("standing");
and do something similar for walking

but i personally didn't like it

i think maybe u (and me) need to look at setInterval(); (look it up in flash help) which i've never used before