From ff38cfec5e09d6e4201582a173d71b17be630f0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Rativel?= Date: Sat, 5 Jun 2021 01:48:11 +0200 Subject: [PATCH] Added the interface Action and implemented the class Attack, Dash, Jump, Throw, ThrowPart --- src/gameplay/actions/Action.java | 10 ++++ src/gameplay/actions/Attack.java | 25 +++++++- src/gameplay/actions/Dash.java | 28 +++++++++ src/gameplay/actions/Jump.java | 28 +++++++++ src/gameplay/actions/Throw.java | 53 +++++++++++++++++ src/gameplay/actions/ThrowPart.java | 90 +++++++++++++++++++++++++++++ 6 files changed, 233 insertions(+), 1 deletion(-) create mode 100644 src/gameplay/actions/Action.java create mode 100644 src/gameplay/actions/Dash.java create mode 100644 src/gameplay/actions/Jump.java create mode 100644 src/gameplay/actions/Throw.java create mode 100644 src/gameplay/actions/ThrowPart.java diff --git a/src/gameplay/actions/Action.java b/src/gameplay/actions/Action.java new file mode 100644 index 0000000..8ae6805 --- /dev/null +++ b/src/gameplay/actions/Action.java @@ -0,0 +1,10 @@ +package gameplay.actions; + +import gameplay.frames.*; +import java.util.ArrayList; + +public interface Action { + + ArrayList getFrame(); + +} diff --git a/src/gameplay/actions/Attack.java b/src/gameplay/actions/Attack.java index ba72498..9c1eb41 100644 --- a/src/gameplay/actions/Attack.java +++ b/src/gameplay/actions/Attack.java @@ -1,8 +1,11 @@ package gameplay.actions; +import java.util.ArrayList; + +import gameplay.frames.*; import gameplay.input.*; -public class Attack { +public class Attack implements Action { /** * Defines if the attack is a special one (E.G. a fireball) or a normal one (a punch) */ @@ -14,9 +17,29 @@ public class Attack { * {{DOWN},{DOWN,RIGHT},{RIGHT},{A}} */ private static Button[][] command; + /** * The different sections of the attack */ private attackPart[] parts; + + @Override + public ArrayList getFrame() { + ArrayList res = new ArrayList(); + + //browse parts + for(int i = 0; i < this.parts.length; i++) { + + //stock current tab of frames + Frame[] tmp = this.parts[i].getFrames(); + int size = tmp.length; + + //browse the tab of frames and add it into a list + for(int j = 0; j < size; j++) { + res.add(tmp[i]); + } + } + return res; + } } diff --git a/src/gameplay/actions/Dash.java b/src/gameplay/actions/Dash.java new file mode 100644 index 0000000..80e07fc --- /dev/null +++ b/src/gameplay/actions/Dash.java @@ -0,0 +1,28 @@ +package gameplay.actions; + +import java.util.ArrayList; + +import gameplay.frames.Frame; +import gameplay.input.Button; + +public class Dash implements Action { + /** + * The suite of Inputs to have the move come out. + * For example, a Front Dash would be something like + * {{RIGHT},{RIGHT}} + */ + private static Button[][] command; + + private Frame[] frames; + + + @Override + public ArrayList getFrame() { + ArrayList res = new ArrayList(); + + for(int i = 0; i < frames.length; i++) {res.add(frames[i]);} + + return res; + } + +} diff --git a/src/gameplay/actions/Jump.java b/src/gameplay/actions/Jump.java new file mode 100644 index 0000000..e1befd5 --- /dev/null +++ b/src/gameplay/actions/Jump.java @@ -0,0 +1,28 @@ +package gameplay.actions; + +import java.util.ArrayList; + +import gameplay.frames.Frame; +import gameplay.input.Button; + +public class Jump implements Action { + + /** + * The Input to have the move come out. + * For example, a Front Jump would be something like + * {UP,RIGHT} + */ + private static Button[] command; + + private Frame[] frames; + + @Override + public ArrayList getFrame() { + ArrayList res = new ArrayList(); + + for(int i = 0; i < frames.length; i++) {res.add(frames[i]);} + + return res; + } + +} diff --git a/src/gameplay/actions/Throw.java b/src/gameplay/actions/Throw.java new file mode 100644 index 0000000..6a9ed18 --- /dev/null +++ b/src/gameplay/actions/Throw.java @@ -0,0 +1,53 @@ +package gameplay.actions; + +import java.util.ArrayList; + +import gameplay.frames.Frame; +import gameplay.input.Button; + +public class Throw implements Action { + + /** + * Defines if the throw is a special one (E.G. a Moonsault Press ) or a normal one + */ + private static boolean isSpecial; + + /** + * The suite of Inputs to have the move come out. + * For example, a Moonsault Press would be something like + * {{LEFT},{DOWN,LEFT},{DOWN},{DOWN,RIGHT},{RIGHT},{RIGHT,UP},{UP},{A}} + */ + private static Button[][] command; + + /** + * The different sections of the throw + */ + private ThrowPart[] parts; + + @Override + public ArrayList getFrame() { + ArrayList res = new ArrayList(); + + //browse parts + for(int i = 0; i < this.parts.length; i++) { + + //stock current tab of frames + Frame[] tmp = this.parts[i].getFrames(); + int size = tmp.length; + if(this.parts[i].getisActive()) { + if(this.parts[i].hasHit()) { + for(int j = 0; j < size; j++) { + res.add(tmp[i]); + } + } + }else { + //browse the tab of frames and add it into a list + for(int j = 0; j < size; j++) { + res.add(tmp[i]); + } + } + } + return res; + } + +} diff --git a/src/gameplay/actions/ThrowPart.java b/src/gameplay/actions/ThrowPart.java new file mode 100644 index 0000000..e930c1c --- /dev/null +++ b/src/gameplay/actions/ThrowPart.java @@ -0,0 +1,90 @@ +package gameplay.actions; + +import gameplay.frames.Frame; + +public class ThrowPart { + private int damage, hitstun; + private double knockbackOnHit; + private Frame[] frames; + private boolean hasHit; + private boolean isActive; + + /** + * Constructor with most parameters for an attack part, generally a hit + * @param damage the damage dealt to the enemy if the throw part connects + * @param hitstun the amount of frames where the enemy is in hitstun if the throw part connects + * @param knockbackOnHit the distance the enemy gets moved back if throwed + * @param frames the array of frames for the part + * @param isActive true if the part is an active part + */ + public ThrowPart(int damage, int hitstun, double knockbackOnHit, Frame[] frames, boolean isActive) { + this.damage = damage; + this.hitstun = hitstun; + this.knockbackOnHit = knockbackOnHit; + this.frames = frames; + this.hasHit = false; + this.isActive = isActive; + } + + /** + * Constructor for an attack part with only a frames array as parameter. + * Generally for a move startup or recovery. + * @param frames the array of frames for the part + */ + public ThrowPart(Frame[] frames) { + this.frames = frames; + this.damage = 0; + this.hitstun = 0; + this.knockbackOnHit = 0.0; + this.hasHit = false; + this.isActive = false; + } + + public boolean hasHit() { + return hasHit; + } + + public void setHasHit(boolean hasHit) { + this.hasHit = hasHit; + } + + public int getDamage() { + return this.damage; + } + + public void setDamage(int damage) { + this.damage = damage; + } + + public int getHitstun() { + return hitstun; + } + + public void setHitstun(int hitstun) { + this.hitstun = hitstun; + } + + public double getKnockbackOnHit() { + return knockbackOnHit; + } + + public void setKnockbackOnHit(double knockback) { + this.knockbackOnHit = knockback; + } + + public Frame[] getFrames() { + return frames; + } + + public void setFrames(Frame[] frames) { + this.frames = frames; + } + + public boolean getisActive() { + return isActive; + } + + public void setisActive(boolean isActive) { + this.isActive = isActive; + } +} \ No newline at end of file