Welcome to Dream.In.Code
Getting Help is Easy!

Join 107,163 Programmers for FREE! Ask your question and get quick answers from experts. There are 1,361 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



xScale make it take more than the default -- or ++

 
Reply to this topicStart new topic

xScale make it take more than the default -- or ++

cadeownz
post 26 Jul, 2008 - 05:45 PM
Post #1


New D.I.C Head

*
Joined: 12 Jul, 2008
Posts: 27

Hey,
I have a movieclip/rectangle 100x14 and its a health bar it works, when my character hits the enemy it decreases the health bar.. BUT i wont it to take more (or less) off than the default speed of -- lets say a specific amount of like 10 or something. Any help guys? heres the code for the enemy..
CODE
onClipEvent(enterFrame) {
if(_root.char.hitTest(this)){
_root.hp--;
}
}

see on line 3 its _root.hp--; i need the to make it take off a specific amount like _root.hp-20; or something any help guys?
thanks in advance..
User is offlineProfile CardPM

Go to the top of the page


BetaWar
post 26 Jul, 2008 - 10:03 PM
Post #2


#include <soul.h>

Group Icon
Joined: 7 Sep, 2006
Posts: 1,093



Thanked 37 times

Dream Kudos: 675
My Contributions


how about _root.hp -= 20; it will take off the specific amount (say 20) and everything there. If you want it to take off a rage try something like so:

CODE

onClipEvent(enterFrame){
  if(_root.char.hitTest(this)){
    var max_damamge:Number = 20;
    var min_damage:Number = 15;
    var damage:Number = (Math.rand()*(max_damage-min_damage))+min_damage;
    _root.hp -= damage;
  }
}


Where max damage is a number of the max amount of damage the enemy can do, and min damage is the min amount of damage that an account can do.

REALIZE - at this point this range includes decimals down quite far. As such your character can have a fraction of a hit pioint remaining.

If you want to make this whole numbers you could wrap the damage alculations in a Math.floor or Math.ciel to round up or down to the nearest integer.

Hope that helps.
User is offlineProfile CardPM

Go to the top of the page

cadeownz
post 27 Jul, 2008 - 09:50 PM
Post #3


New D.I.C Head

*
Joined: 12 Jul, 2008
Posts: 27

OMG ur a legend thanx sooo much u js savd mi RPG game. THANX
User is offlineProfile CardPM

Go to the top of the page

BetaWar
post 27 Jul, 2008 - 10:48 PM
Post #4


#include <soul.h>

Group Icon
Joined: 7 Sep, 2006
Posts: 1,093



Thanked 37 times

Dream Kudos: 675
My Contributions


Just here to help. biggrin.gif
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 8/27/08 09:34PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month