COCOS2DX 3d Open Source project Fantasywarrior3d 6 end from zero [Attackmanager&gamemaster]

Source: Internet
Author: User
Tags dota

[Attackcommand] 1. Declare the basic collider as the attack unit released by the role
Basiccollider = Class ("Basiccollider", function ()    Local node = cc. Node:create ()    node:setcascadecolorenabled (True)    return nodeend)

function Basiccollider:ctor ()    self.minrange = 0   --the min radius of the fan    self.maxrange =--the Max Radi US    of the fan self.angle    =--arc of attack, in radians    Self.knock =--default knock    , knocks Its     self.mask     = 1   --1 are heroes, 2 is enemy, 3??    Self.damage   =    self.facing    = 0--this is radians    self.duration = 0    self.curduration = 0    self.speed = 0--traveling Speed}    Self.criticalchance = 0end


The specific parameters for each role are configured in Globalvariables.lua
Angle attack angle, very useful, related to the scope of skill and attack
The scope of the Maxrange attack

These two parameters can determine a "function area of the skill", it is convenient to achieve such as "fan" and other attack areas
This attack skill does not need to Basiccollider and target "collision" to trigger, as long as the enemy standing in the attack area can be counted.

The speed at which the attack body moves, the attack on the warrior or the Mage's "Ice Wall" is 0.
Duration Duration
Dottimer Sustained Damage CD

You can also add an attribute maxtarget to determine whether a skill is monomer absorbed or penetrates the target,
function on multiple targets. Like the DotA "Shockwave" Lich's "serial frost", etc.

2. Attackmanager all released attack units are placed in the Attackmanager
Solveattacks the frame loop of an attacking unit

There are 3 main things to do:

[1] Judging whether "hit"
Oncollide attack Effective: The condition is that distance and angle meet

_mypos will continue to update with the game
function actor:baseupdate (DT)
Self._mypos = getpostable (self)
...
End


Calculate the angle of the attack unit to the target

Local angle = Radnormalize (Cc.ptoangleself (Cc.psub (Mpos,apos)))


Calculating the direction of attack units
Local afacing = Radnormalize (attack.facing)


Determine if the attack area

if (afacing + attack.angle/2) >angle and Angle > (AFACING-ATTACK.ANGLE/2) Then
Attack:oncollide (Monster)
End

[2] Judging time-outs according to duration
OnTimeOut removing attack units

[3] Update position according to speed
OnUpdate

3. Inherit basic attack units to achieve various role skills then look at the Mage's "Ice Wall".
Mage:specialattack ()
which
Local POS1 = getpostable (self) Local pos2 = getpostable (self) Local POS3 = Getpostable (self) pos1.x = pos1.x+130pos2.x = Pos2 . x+330pos3.x = POS3.X+530POS1 = Cc.protatebyangle (pos1, Self._mypos, self._curfacing) Pos2 = Cc.protatebyangle (Pos2, Self._mypos, self._curfacing) Pos3 = Cc.protatebyangle (Pos3, Self._mypos, self._curfacing)

Protatebyangle The return point to POS1 with Self._mypos as the axis of rotation and rotate the self._curfacing radians in a counterclockwise direction.
This eventually gets three points, and they are on the line between the Mage and the target, and the distance to the Mage is 130 330 530, respectively. 3 Mageicespikes were created at these 3 points

Mageicespikes.create

Randomly consists of 10 ice spines and adds a particle effect


Property:
    _specialattack   = {        Minrange = 0,        maxrange =        angle    = Degrees_to_radians,        knock    =        Damage = +   ,        mask     = Enumracetype.hero,        duration = 4.5, speed    = 0,        Criticalchance = 0.05,        Dottimer = 0.75,--it would be able to hurt every 0.5 seconds        curdottime = 0.75,        DOTA Pplied = False    




[Gamemaster]

Gamemaster:init () from which you can see

Unify the characters and put them in batches.

Self:addheros ()
Self:addmonsters ()

Logicupdate Frame Loops
Mainly responsible for controlling the hero's advance and the Little Monster's refresh

Local Battlesitex = { -2800,-1800,-800}
Set the trigger location and refresh location

Stage for 1~7
Random spawner or run right

stage = = 7 clear off the little monster
stage = = 8 Give warning

The boss is displayed when the warning is over Showboss ()
Can not be configured too strong, so there is no specific analysis of the code

[Particlemanager]plist contains two parts: Particle system properties and particle textures

1. Particle properties load and create quad particle object at startup call Addplistdata load particle's plist file, and cache to map format
From the interface implementation, if the particle is created directly from the cached map, the time to read the file is omitted and the function of optimization is achieved.
Particlesystemquad * Particlesystemquad::create (ValueMap &dictionary)
{
Particlesystemquad *ret = new (Std::nothrow) Particlesystemquad ();
if (ret && ret->initwithdictionary (dictionary))
{
Ret->autorelease ();
return ret;
}
Cc_safe_delete (ret);
return ret;
}


2. Particle textures are provided by fx.plist and Fx.png
Setting textures for the generated quad
Magic:settexturewithrect (Magicf:gettexture (), Magicf:getrect ())


3. About the error in the console when debugging, the console has been reported bug, and then went to see the source of the current, by the way, see how the LUA function Particlesystemquad:create overload is how to achieve
Error
Cc. Particlesystemquad:create argument #2 is ' table '; ' String ' expected.

int lua_cocos2dx_particlesystemquad_create (lua_state* tolua_s) {int argc = 0; bool OK = true; #if cocos2d_debug >= 1 tolua_error tolua_err; #endif # if Cocos2d_debug >= 1 if (!tolua_isusertab Le (tolua_s,1, "CC.    Particlesystemquad ", 0,&tolua_err)) goto tolua_lerror; #endif argc = Lua_gettop (tolua_s)-1;            do {if (argc = = 1) {std::string arg0; OK &= luaval_to_std_string (tolua_s, 2,&arg0, "CC.            Particlesystemquad:create ");            if (!ok) {break;}            Cocos2d::P articlesystemquad* ret = cocos2d::P articlesystemquad::create (arg0); Object_to_luaval<cocos2d::P articlesystemquad> (tolua_s, "CC.            Particlesystemquad ", (cocos2d::P articlesystemquad*) ret);        return 1;    }} while (0);    OK = true; do {if (argc = = 0) {cocos2d::P articlesystemquad* ret = cocos2d::P articlesystemquad::create (            ); Object_to_luaval<cocos2d::P articlesystemquad> (tolua_s, "CC.            Particlesystemquad ", (cocos2d::P articlesystemquad*) ret);        return 1;    }} while (0);    OK = true;            do {if (argc = = 1) {Cocos2d::valuemap arg0; OK &= luaval_to_ccvaluemap (tolua_s, 2, &arg0, "CC.            Particlesystemquad:create ");            if (!ok) {break;}            Cocos2d::P articlesystemquad* ret = cocos2d::P articlesystemquad::create (arg0); Object_to_luaval<cocos2d::P articlesystemquad> (tolua_s, "CC.            Particlesystemquad ", (cocos2d::P articlesystemquad*) ret);        return 1;    }} while (0); OK = true;


See the source code overload of the idea is more clear: first determine the number of parameters, and then through the function luaval_to_std_string to the L stack of parameters to be taken, until a type is correctly taken to the value of

OK &= luaval_to_std_string (tolua_s, 2,&arg0, "CC. Particlesystemquad:create ");

And the error log is the function Luaval_to_native_err reported in the process of the attempt.

    if (!tolua_iscppstring (l,lo,0,&tolua_err))    {#if cocos2d_debug >=1        luaval_to_native_err (L, "#ferror: ", &tolua_err,funcname); #endif        ok = false;    }

Think about it a little bit, in fact, this code can be optimized, you can first try all the branches, if not correct again error.

[Manager]
Maintains all role objects and is primarily responsible for handling collision events

Collisiondetect Frame Loops
Collision (Sprite)->solvecollision
Make sure that the distance between the two characters is less than the _radius of the "waist circumference", and calculates the distance of the bounce based on the "weight" _mass.

Isoutofbound (Sprite) ensures that the character does not go out of the screen
G =
{
Winsize = cc. Director:getinstance (): Getwinsize (),
Bloodpercentdropspeed = 2,
Activearea = {left = -2800, right = +, bottom = +, top = 700},
}

Getfocuspointofheros gets the "average position" of the hero as the camera focus


Reference:


Particle

COCOS2DX 3d Open Source project Fantasywarrior3d 6 end from zero [Attackmanager&gamemaster]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.