Game Skill Framework Code (Java Edition)

Source: Internet
Author: User

In game development, you often encounter a variety of skill processing, such as

Sky fire: Release the Monster in the area of the initial buckle blood, and attach persistent damage.

Freeze: Release mobs from the initial buckle of blood, and attach persistent deceleration.

Lightning: Release the area of the monster initial buckle blood, and attach persistent vertigo.

Attribute change: Attack increased by 50%, defense decreased by 30%, lasted n seconds. Attacks permanently increase or decrease and so on.

This article provides a simple skill design framework to achieve the above effect, heavy in its design ideas can be reused.

1. Skill Effect:

Whether it is the blood, deceleration, attack, and defense, we see it as a skill effect,

public interface iskilleffect {public boolean act  (Float delta,SkillTarget  target);} public abstract class baseskilleffect implements iskilleffect {//  Action Target Protected skilltarget target;public skilltarget gettarget ()  {return target;} Public void settarget (Skilltarget target)  {this.target = target;} Public void reset ()  {this.target = null;}} /** *   *  time-based processing of skill effects  *  @author  haocao * */public  abstract class temporalskilleffect extends baseskilleffect {//  Duration, Current Progress Time private float duration, time;private boolean began, complete;public  Boolean act (Float delta, skilltarget target)  {if  (Gettarget ()  == null)  {settarget (target);} if  (complete) return true;if  (!began) &nbsP {begin (); began = true;} time += delta;complete = time >= duration;float percent;if  ( complete) percent = 1;else {percent = time / duration;} Update (percent);if  (complete) end (); return complete;} Public abstract void begin ()/** called the last time {@link   #act (float)}  is called. */public abstract void end ();/** * called each  Frame. */abstract protected void update (float percent);/** Skips to  The end of the transition. */public void finish ()  {time =  Duration;} Public float getduration ()  {return duration;} Public void setduration (float duration)  {this.duration = duration;}}

2. Skills (aggregate of skill effects):

Includes skills start, end, and effective processes.

A skill can have different skill effects, so you can combine multiple skills.

Public interface iskill {public void addskilleffect (ISkillEffect skillEffect); Public void active (Float delta);p ublic void finish ();p Ublic void start (); Public void init ();} Public abstract class baseskill implements iskill {private skilltarget  skilltarget;public arraylist<iskilleffect> skilleffects = new arraylist <ISkillEffect> ();p rivate boolean firstactive = false, finished =  false; @Overridepublic  void addskilleffect (Iskilleffect skilleffect)  {skilleffects.add ( Skilleffect);} @Overridepublic  void active (Float delta)  {if  (finished) return;if  (!firstactive)  {firstactive = true;start ();} if  (Skilleffects.size ()  == 0)  {finished = true;finish (); Arraylist<iskilleffect> removearraylist = new arRaylist<iskilleffect> ();for  (iskilleffect skilleffect : skilleffects)  {if  (Skilleffect.act (Delta, getskilltarget ()))  {removearraylist.add (Skilleffect);}} Skilleffects.removeall (removearraylist);} Public skilltarget getskilltarget ()  {return skilltarget;} Public void setskilltarget (Skilltarget skilltarget)  {this.skillTarget =  Skilltarget;} Public arraylist<iskilleffect> getskilleffects ()  {return skilleffects;} Public boolean isfinished ()  {return finished;}}

3. Skill Carrier:

Can hang a number of skills.

Public abstract class Skilltarget {private arraylist<baseskill> skills = new arraylist<baseskill> ();p ublic float attack,blood,defense,movespeed;public void Addskill (Baseskill skill) {Skill.setskilltarget (this); Skills.add ( skill);} Execute public void Act per frame (float delta) {arraylist<baseskill> skills = This.skills;if (skills.size () > 0) {for (int i = 0; I < skills.size (); i++) {Baseskill Baseskill = Skills.get (i); if (!baseskill.isfinished ()) {baseskill.active (delta);} Else{skills.remove (i); i--;}}} Public arraylist<baseskill> Getskills () {return skills;}}


How to use: create many skill effects (attack bonus, defense bonus, deceleration, etc.) to create different skills by combining skill effects.

Then, under certain conditions, the skill is added to the Action object. The action object can be executed as long as each frame executes the Act method.




Game Skill Framework Code (Java Edition)

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.