Because the damage calculation has been written, it is quite easy to add the damage display.
First, let the damage value be displayed when the mouse moves to an enemy's character.
Copy another sphp on the framework that displays HP and MP, and change the color to sphp, named sphp1.
Then, when displaying HP and MP, add damage judgment and display as follows:
If (_ clickctrl! = "Hpmp_hert "){
If (! Querypeople ){
_ Hpmp. Visible = false;
} Else {
// Define the damage value. The initial value is 0.
VaR Hp2: Int = 0;
_ Hpmp. Visible = true;
_ Hpmp. x = _ mousebox. x- 102;
_ Hpmp. Y = _ mousebox. Y-48;
If (_ hpmp. x <0 ){
_ Hpmp. x = 0;
}
If (_ hpmp. Y <0 ){
_ Hpmp. Y = 0;
}
_Hpmp.txt hp. Text = _ character. nowhp + "/" + _ character. HP;
_ Hpmp. sphp. width = 100 * (_ character. nowhp/_ character. HP );
_Hpmp.txt MP. Text = _ character. nowmp + "/" + _ character. MP;
_ Hpmp. spmp. width = 100 * (_ character. nowmp/_ character. MP );
If (_ clickctrl = "attack "){
// If the current battlefield status is attack, start to judge whether the mouse is on the enemy's body. If yes, start to calculate the Damage Value
For (I = 0; I <_ roadsprite. numchildren; I ++ ){
VaR childsprite: SPRITE = sprite (_ roadsprite. getchildat (I ));
If (_ character. their = "enemy" & _ mousebox. X = math. floor (childsprite. x/48) * 48 & _ mousebox. y = math. floor (childsprite. y/48) * 48 ){
// Call the physical damage calculation method to start calculating the damage value
Hp2 = getatthurt (_ nowchatacter, _ character );
}
}
}
// If the damage value is greater than 0, the damage value is displayed.]
If (Hp2> 0 ){
_ Hpmp. sphp1.width = 100 * (Hp2/_ character. HP );
_ Hpmp. sphp1.x = _ hpmp. sphp. x + _ hpmp. sphp. Width-_ hpmp. sphp1.width;
} Else {
_ Hpmp. sphp1.width = 0;
}
}
In this way, you can see the damage display,
Then, when the attack is processed, the damage value is displayed.
Add two variables to the battlefield.
// Damage Value
Private VaR _ herthp: int;
// Display and control the damage value
Private VaR _ herthpindex: int;
The _ herthpindex variable is used to control the Dynamic Reduction of HP when the damage value is displayed.
Next, in the control of enemy action events, when the enemy attacks, the user-defined function does not directly end the action,
However, when the damage value is displayed, the action ends after the damage value is displayed.
It turns out to be
_ Nowchatacter. character. _ fun = function (){
_ Clickctrl = "null ";
_ Nowchatacter. actionctrl = true;
_ Enemyactionctrl = 0;
Addeventlistener (event. enter_frame, onen
}
-> -〉
_ Nowchatacter. character. _ fun = function (){
_ Clickctrl = "hpmp_hert ";
_ Hpmp. Visible = true;
_ Hpmp. x = _ nowchatacter. character. _ rival. X-102;
_ Hpmp. Y = _ nowchatacter. character. _ rival. Y-48;
If (_ hpmp. x <0 ){
_ Hpmp. x = 0;
}
If (_ hpmp. Y <0 ){
_ Hpmp. Y = 0;
}
_Hpmp.txt hp. Text = _ nowchatacter. character. _ rival. nowhp + "/" + _ nowchatacter. character. _ rival. HP;
_ Hpmp. sphp. width = 100 * (_ nowchatacter. character. _ rival. nowhp/_ nowchatacter. character. _ rival. HP );
_Hpmp.txt MP. Text = _ nowchatacter. character. _ rival. nowmp + "/" + _ nowchatacter. character. _ rival. MP;
_ Hpmp. spmp. width = 100 * (_ nowchatacter. character. _ rival. nowmp/_ nowchatacter. character. _ rival. MP );
_ Hpmp. sphp1.width = 0;
}
In the same region, our army also handles attacks in the same way.
After modification
_ Nowchatacter. character. _ fun = function (){
_ Clickctrl = "hpmp_hert ";
_ Hpmp. Visible = true;
_ Hpmp. x = _ nowchatacter. character. _ rival. X-102;
_ Hpmp. Y = _ nowchatacter. character. _ rival. Y-48;
If (_ hpmp. x <0 ){
_ Hpmp. x = 0;
}
If (_ hpmp. Y <0 ){
_ Hpmp. Y = 0;
}
_Hpmp.txt hp. Text = _ character. nowhp + "/" + _ character. HP;
_ Hpmp. sphp. width = 100 * (_ character. nowhp/_ character. HP );
_Hpmp.txt MP. Text = _ character. nowmp + "/" + _ character. MP;
_ Hpmp. spmp. width = 100 * (_ character. nowmp/_ character. MP );
_ Hpmp. sphp1.width = 0;
}
Then, dynamically display the damage in the drive event
// If the status is damage display, the damage value is dynamically displayed.
If (_ clickctrl = "hpmp_hert "){
// Judge _ herthpindex. If it is smaller than the damage value, HP is dynamically reduced; otherwise, the action is terminated.
If (_ herthpindex <_ herthp ){
_ Nowchatacter. Rival. nowhp-= 1;
_Hpmp.txt hp. Text = _ nowchatacter. Rival. nowhp + "/" + _ nowchatacter. Rival. HP;
_ Hpmp. sphp. width = 100 * (_ nowchatacter. Rival. nowhp/_ nowchatacter. Rival. HP );
_ Herthpindex ++;
} Else {
// End the attack based on our attack or enemy attack, and add the corresponding event
If (_ roundctrl = ""){
_ Clickctrl = "null ";
_ Nowchatacter. actionctrl = true;
Addeventlistener (event. enter_frame, onclickframe );
} Else {
_ Clickctrl = "null ";
_ Nowchatacter. actionctrl = true;
_ Enemyactionctrl = 0;
Addeventlistener (event. enter_frame, onenemyframe );
}
}
}
OK. The damage value ^ 0 ^ is displayed!
Next, let's look at the retreat.
After everyone completes the action, add an HP to judge.
When HP is set to 0, the characters will not be displayed. Because the scripts include commands such as the resurrection of the martial arts, you cannot delete them from the character array. You can only hide the characters.
For convenience, I separated the dynamic display of the damage value into a method.
// Dynamically display the Damage Value
Private function hpmphert (): void {
// Judge _ herthpindex. If it is smaller than the damage value, HP is dynamically reduced; otherwise, the action is terminated.
If (_ herthpindex <_ herthp ){
_ Nowchatacter. Rival. nowhp-= 1;
_Hpmp.txt hp. Text = _ nowchatacter. Rival. nowhp + "/" + _ nowchatacter. Rival. HP;
_ Hpmp. sphp. width = 100 * (_ nowchatacter. Rival. nowhp/_ nowchatacter. Rival. HP );
_ Herthpindex ++;
} Else {
// End the attack based on our attack or enemy attack, and add the corresponding event
If (_ roundctrl = ""){
_ Clickctrl = "check ";
_ Nowchatacter. actionctrl = true;
} Else {
_ Clickctrl = "check ";
_ Nowchatacter. actionctrl = true;
_ Enemyactionctrl = 0;
}
}
}
Here, after the action is completed, _ clickctrl is changed from null to check to determine HP
In the initial event
If (_ clickctrl = "check "){
If (_ nowchatacter. Rival. nowhp <= 0 ){
// Retreat
Characterremove ();
}
}
// Retreat
Private function characterremove (): void {
If (_ retreatctrl = 0 ){
_ Nowchatacter. Rival. setalpha (0 );
} Else if (_ retreatctrl = 3 ){
_ Nowchatacter. Rival. setalpha (1 );
} Else if (_ retreatctrl = 6 ){
_ Nowchatacter. Rival. setalpha (0 );
} Else if (_ retreatctrl = 9 ){
_ Nowchatacter. Rival. setalpha (1 );
} Else if (_ retreatctrl = 12 ){
_ Nowchatacter. Rival. setalpha (0 );
If (_ roundctrl = ""){
_ Clickctrl = "null ";
_ Retreatctrl =-1;
Addeventlistener (event. enter_frame, onclickframe );
This. contextmenu = _ roundmenu;
} Else {
_ Clickctrl = "null ";
_ Retreatctrl =-1;
Addeventlistener (event. enter_frame, onenemyframe );
}
}
_ Retreatctrl ++;
}
Here _ retreatctrl is used to flash the character
It's easy to run the program. When the character HP becomes 0, it will flash a few times and then disappear.
Next we will study the counterattack. The time for counterattack is after the attack, that is, after the HP judgment, if the HP is greater than 0, then the target of the military commander's counterattack is within the scope of his attack.
Okay, let's determine the HP location in the drive event.
If (_ clickctrl = "check "){
If (_ nowchatacter. Rival. nowhp <= 0 ){
// Retreat
Characterremove ();
} Else {
// Counterattack judgment
Countercheck ();
}
}
// Counterattack judgment
Private function countercheck (): void {
VaR isok: Boolean = false;
VaR attroundarr: array;
// Check whether the target is within the attack range
For each (VAR roundment: XML in _ arms ["arms" + _ nowchatacter. Rival. armsindex] ["rangeattack"]. Elements ()){
Attroundarr = roundment. tostring (). Split (",");
If (INT (attroundarr [0]) + _ nowchatacter. Rival. locationx) = _ nowchatacter. locationx &&
(INT (attroundarr [1]) + _ nowchatacter. Rival. locationy) = _ nowchatacter. locationy ){
Isok = true;
Break;
}
}
If (_ roundctrl = ""){
If (! _ Counter & isok ){
_ Counter = true;
_ Clickctrl = "counter ";
} Else {
_ Clickctrl = "null ";
_ Counter = false;
Addeventlistener (event. enter_frame, onclickframe );
This. contextmenu = _ roundmenu;
}
} Else {
If (! _ Counter & isok ){
_ Counter = true;
_ Clickctrl = "counter ";
} Else {
_ Clickctrl = "null ";
_ Counter = false;
Addeventlistener (event. enter_frame, onenemyframe );
}
}
// Meets the counterattack conditions for counterattack
If (_ clickctrl = "counter "){
_ Character = _ nowchatacter;
_ Nowchatacter = _ nowchatacter. Rival;
_ Nowchatacter. Rival = _ character;
_ Herthp = math. Floor (getatthurt (_ nowchatacter, _ nowchatacter. Rival) * 0.75 );
_ Herthpindex = 0;
_ Nowchatacter. character. _ fun = function (){
_ Clickctrl = "hpmp_hert ";
_ Hpmp. Visible = true;
_ Hpmp. x = _ nowchatacter. character. _ rival. X-102;
_ Hpmp. Y = _ nowchatacter. character. _ rival. Y-48;
If (_ hpmp. x <0 ){
_ Hpmp. x = 0;
}
If (_ hpmp. Y <0 ){
_ Hpmp. Y = 0;
}
_Hpmp.txt hp. Text = _ nowchatacter. Rival. nowhp + "/" + _ nowchatacter. Rival. HP;
_ Hpmp. sphp. width = 100 * (_ nowchatacter. Rival. nowhp/_ nowchatacter. Rival. HP );
_Hpmp.txt MP. Text = _ nowchatacter. Rival. nowmp + "/" + _ nowchatacter. Rival. MP;
_ Hpmp. spmp. width = 100 * (_ nowchatacter. Rival. nowmp/_ nowchatacter. Rival. MP );
_ Hpmp. sphp1.width = 0;
}
_ Nowchatacter. Attack ();
}
}
It is easy to fight back here. You only need to exchange the original attack with the attacked person.
Run the code. Everything is OK.
Next time, we will try to study double-click, grid blocking, burst attacks, and other events ,! ^ 0 ^!
Next we will study double-click and fatal blow
Based on the calculation formula of Cao Zhuan
First, write two methods.
/*
Double-click Probability Calculation
If SA/SD <1, H = 1;
H = 2 + 18 * (SA/Sd-1) if 1 <= sa/SD <2 );
H = 20 + 80 * (SA/Sd-2) If 2 <= sa/SD <= 3 );
If SA/SD> = 3, H = 100;
*/
Private function getdoubleatt (attchara: character, hertchara: character): int {
VaR H: int;
// Obtain the explosive power of both parties
VaR attbreakout: Int = int (_ pxml ["Peo" + attchara. charaindex]. breakout );
VaR hertbreakout: Int = int (_ pxml ["Peo" + hertchara. charaindex]. breakout );
VaR rate: Number = attbreakout/hertbreakout;
If (rate <1 ){
H = 1;
} Else if (rate> = 1 & rate <2 ){
H = 2 + 18*(rate-1 );
} Else if (rate> = 2 & rate <3 ){
H = 20 + 80*(rate-2 );
} Else if (rate> = 3 ){
H = 100;
}
If (math. Random () * 100 <= h ){
Return 2;
}
Return 1;
}
/*
Fatal Probability Calculation
If SA/SD <1, H = 1;
H = 2 + 18 * (SA/Sd-1) if 1 <= sa/SD <2 );
H = 20 + 80 * (SA/Sd-2) If 2 <= sa/SD <= 3 );
If SA/SD> = 3, H = 100;
*/
Private function getfatalatt (attchara: character, hertchara: character): Boolean {
VaR H: int;
// Get the morale of both parties
VaR attmorale: Int = int (_ pxml ["Peo" + attchara. charaindex]. Morale );
VaR hertmorale: Int = int (_ pxml ["Peo" + hertchara. charaindex]. Morale );
VaR rate: Number = attmorale/hertmorale;
If (rate <1 ){
H = 1;
} Else if (rate> = 1 & rate <2 ){
H = 2 + 18*(rate-1 );
} Else if (rate> = 2 & rate <3 ){
H = 20 + 80*(rate-2 );
} Else if (rate> = 3 ){
H = 100;
}
If (math. Random () * 100 <= h ){
Return true;
}
Return false;
}
The method has been defined, and now the problem is where to use it.
Double-click to determine the number of attacks before they are attacked. The advantage of this is that, in the future, if you get a trick, three hits, five hits, or something, you can set the number of attacks to a corresponding number, and then you can turn it into a combo trick.
The fatal judgment occurs during attacks or counterattacks, so we put it in the attack method,
If an attack occurs, you can determine whether a fatal blow has occurred.
Before the enemy or our army attacks, double-click to judge
// Double-click
_ Attcount = getdoubleatt (_ nowchatacter, _ nowchatacter. Rival );
Then, modify the attack method
In this case, we do not double-click the counterattack, so we need to add another control.
}
// Attack
Private function toattack (hert: Boolean = true): void {
// Determine whether it is a counterattack
If (hert ){
_ Herthp = getatthurt (_ nowchatacter, _ nowchatacter. Rival );
}
If (_ clickctrl = "attack "){
_ Attcount-= 1;
}
_ Herthpindex = 0;
// Judge the fatal blow
_ Nowchatacter. Fatal = getfatalatt (_ nowchatacter, _ nowchatacter. Rival );
If (_ nowchatacter. Fatal ){
_ Herthp = math. Floor (_ herthp * 1.25 );
If (_ herthp> _ nowchatacter. Rival. nowhp ){
_ Herthp = _ nowchatacter. Rival. nowhp;
}
}
_ Nowchatacter. character. _ fun = function (){
_ Clickctrl = "hpmp_hert ";
_ Hpmp. Visible = true;
_ Hpmp. x = _ nowchatacter. Rival. X-102;
_ Hpmp. Y = _ nowchatacter. Rival. Y-48;
If (_ hpmp. x <0 ){
_ Hpmp. x = 0;
}
If (_ hpmp. Y <0 ){
_ Hpmp. Y = 0;
}
_Hpmp.txt hp. Text = _ nowchatacter. Rival. nowhp + "/" + _ nowchatacter. Rival. HP;
_ Hpmp. sphp. width = 100 * (_ nowchatacter. Rival. nowhp/_ nowchatacter. Rival. HP );
_Hpmp.txt MP. Text = _ nowchatacter. Rival. nowmp + "/" + _ nowchatacter. Rival. MP;
_ Hpmp. spmp. width = 100 * (_ nowchatacter. Rival. nowmp/_ nowchatacter. Rival. MP );
_ Hpmp. sphp1.width = 0;
}
_ Nowchatacter. Attack ();
}
In this way, you can determine double-click and fatal.
Add the corresponding display when the action is displayed.
In a fatal blow, the characters must shine
Set the light color first
_ Fatalcolor = new color;
_ Fatalcolor. brightness = 0.5;
// Convert it into a fatal blow
Public Function startfatalcolor (): void {
This. Transform. colortransform = _ fatalcolor;
}
// End the fatal blow
Public Function endfatalcolor (): void {
This. Transform. colortransform = _ runcolor;
}
Then, when the characters are attacked, determine whether the color is fatal.
// When a person attacks
If (DIR = characterindex. attack_up | dir = characterindex. attack_dwon |
Dir = characterindex. attack_left | dir = characterindex. attack_right ){
_ Peoplebitmap. x =-8;
_ Lelebitmap. Y =-8;
// In the first action of the attack, determine whether the attack is a fatal blow.
If (_ fatal ){
If (_ pointer = 0 & _ fatalctrl <10 ){
If (_ fatalctrl = 0 ){
Startfatalcolor ();
}
_ Pointer = 0;
_ COUNT = 0;
_ Fatalctrl ++;
} Else {
_ Fatal = false;
_ Fatalctrl = 0;
Endfatalcolor ();
}
}
// In the third action of the attack, the attacked person is displayed as attacked.
If (_ pointer = 2 ){
// Obtain the action display class of the attacked person
_ Rivalmc = _ rival. character;
// Set the direction of the attacked person based on the direction of the person being attacked.
If (_ rivalmc. X-This. x> 0 ){
This. _ direct = characterindex. Right;
_ Rivalmc. _ direct = characterindex. Left;
} Else if (_ rivalmc. X-This. x <0 ){
This. _ direct = characterindex. Left;
_ Rivalmc. _ direct = characterindex. Right;
} Else if (_ rivalmc. Y-This. Y> 0 ){
This. _ direct = characterindex. down;
_ Rivalmc. _ direct = characterindex. up;
} Else if (_ rivalmc. Y-This. Y <0 ){
This. _ direct = characterindex. up;
_ Rivalmc. _ direct = characterindex. down;
}
_ Rivalmc. setdir (characterindex. take_a_beat );
}
} Else {
_ Peoplebitmap. x = 0;
_ Lelebitmap. Y = 0;
}
Well, it is generally like this. I changed the explosive power and morale of Cao to high, and it is easy to see the effect.
I wrote double-click and counterattack, so I won't talk much about it. You can view my code directly.
Finally, the game source code is provided. Thank you for your support.
Http://download.csdn.net/source/2650035