Corrected classpath, new (and clearer) package arrangement.

This commit is contained in:
François Autin
2021-05-27 17:45:02 +02:00
parent b98d1908f6
commit de721b59ab
17 changed files with 42 additions and 29 deletions

View File

@ -0,0 +1,42 @@
package gameplay.Match;
import gameplay.input.InputBuffer;
import gameplay.entities.*;
import gameplay.entities.Character;
/**
* Main class that describes the base structure of the match, with characters, timer and such
* @author Victor Azra
*
*/
public class match {
/**
* the number of inputs read for each character, a.k.a. for how many frames the inputs are saved in memory.
*/
private static final int inputBufferSize = 120;
private int timer;
private InputBuffer inputsP1, inputsP2;
private int hpP1, hpP2;
private int roundsWonP1, roundsWonP2;
private Character p1, p2; //characters of player 1 and 2
/**
* base constructor of the match class.
* Initiates a new match with with two given characters
*/
public match(Character p1, Character p2) {
this.timer = 99;
this.inputsP1 = new InputBuffer(inputBufferSize);
this.inputsP2 = new InputBuffer(inputBufferSize);
this.p1 = p1;
this.p2 = p2;
this.hpP1 = p1.getMaxHP();
this.hpP2 = p2.getMaxHP();
this.roundsWonP1 = 0;
this.roundsWonP2 = 0;
}
}

View File

@ -0,0 +1,18 @@
package gameplay.actions;
import gameplay.input.*;
public class Attack {
/**
* Defines if the attack is a special one (E.G. a fireball) or a normal one (a punch)
*/
private static boolean isSpecial;
/**
* The suite of Inputs to have the move come out.
* For example, a classic fireball would be something like
* {{DOWN},{DOWN,RIGHT},{RIGHT},{A}}
*/
private static Button[][] command;
}

View File

@ -0,0 +1,31 @@
package gameplay.entities;
import gameplay.frames.Frame;
/**
* Character class, which is a sub-class of an entity
* @author Victor
*
*/
public class Character extends Entity {
private static int maxHP;
/**
* Main constructor for a character. By default its max health is 1000 if not specified
*/
public Character() {
super();
this.maxHP = 1000;
}
public Character(int posx, int posy, Frame f, int maxHP) {
super(posx, posy, f);
this.maxHP = maxHP;
}
public void setMaxHP(int HP) {
this.maxHP = HP;
}
public int getMaxHP() { return this.getMaxHP();}
}

View File

@ -0,0 +1,50 @@
package gameplay.entities;
import gameplay.frames.Frame;
/**
* Entity class, which is the main class regrouping characters and projectiles
* @author Victor
*
*/
public class Entity {
private int posx;
private int posy;
private Frame currentFrame;
/**
* base constructor of the entity class
*/
public Entity() {
this.posx = 0;
this.posy = 0;
this.currentFrame = new Frame();
}
/**
* constructor of the entity class with parameters
* @param posx the position of the entity on the x axis
* @param posy the position of the entity on the y axis
* @param f the current frame of the new entity
*/
public Entity(int posx, int posy, Frame f) {
this.posx = posx;
this.posy = posy;
this.currentFrame = f;
}
public void setPos(int x, int y) {
this.posx = x;
this.posy = y;
}
public void setCurrentFrame(Frame f) {
this.currentFrame = f;
}
public int getPosX() {return this.posx;}
public int getPosY() {return this.posy;}
public Frame getCurrentframe() {return this.currentFrame;}
}

View File

@ -0,0 +1,4 @@
package gameplay.entities;
public class Projectile extends Entity{
}

View File

@ -0,0 +1,57 @@
package gameplay.frames;
import java.util.ArrayList;
import gameplay.hitboxes.*;
/**
* Main class for frames
* @author Victor Azra
*
*/
public class Frame {
private Double move_y;
private Double move_x;
private ArrayList<Passive_HitBox> passHitBox;
private ArrayList<Active_HitBox> actHitBox;
private ArrayList<Passive_throw_HitBox> passThrowHitBox;
private ArrayList<Active_throw_Hitbox> actThrowHitBox;
private Push_HitBox pushHitBox;
public Frame() {
this.move_y = 0.0;
this.move_x = 0.0;
this.passHitBox = new ArrayList<Passive_HitBox>();
this.actHitBox = new ArrayList<Active_HitBox>();
this.passThrowHitBox = new ArrayList<Passive_throw_HitBox>();
this.actThrowHitBox = new ArrayList<Active_throw_Hitbox>();
this.pushHitBox = new Push_HitBox();
}
public Frame(Double move_y, Double move_x, ArrayList<Passive_HitBox> passHitBox, ArrayList<Active_HitBox> actHitBox,
ArrayList<Passive_throw_HitBox> passThrowHitBox, ArrayList<Active_throw_Hitbox> actThrowHitBox,
Push_HitBox pushHitBox) {
this.move_y = move_y;
this.move_x = move_x;
this.passHitBox = passHitBox;
this.actHitBox = actHitBox;
this.passThrowHitBox = passThrowHitBox;
this.actThrowHitBox = actThrowHitBox;
this.pushHitBox = pushHitBox;
}
/*
* Mainly use for projectiles
*/
public Frame(Double move_y, Double move_x, ArrayList<Passive_HitBox> passHitBox, ArrayList<Active_HitBox> actHitBox) {
this.move_y = move_y;
this.move_x = move_x;
this.passHitBox = passHitBox;
this.actHitBox = actHitBox;
this.passThrowHitBox = new ArrayList<Passive_throw_HitBox>();
this.actThrowHitBox = new ArrayList<Active_throw_Hitbox>();
this.pushHitBox = new Push_HitBox();
}
}

View File

@ -0,0 +1,70 @@
package gameplay.frames;
/**
* This will handle the next frames to be played by each entity.
* @author Victor Azra
*/
public class nextFrameBuffer {
private Frame current;
private nextFrameBuffer next;
/**
* creates a new framebuffer, empty for now
*/
public nextFrameBuffer() {
this.current = null;
this.next = null;
}
public void setCurrentFrame(Frame f) {
this.current = f;
}
public void clone(nextFrameBuffer f) {
this.current = f.current;
this.next = f.next;
}
public void setNext(nextFrameBuffer f) {
this.next.clone(f);
}
public void emptyQueue() {
this.next = null;
}
public void empty() {
this.current = null;
this.next = null;
}
public void goToNext() {
this.current = this.next.current;
this.next = this.next.next;
}
public Frame getCurrentFrame() {
return this.current;
}
public Frame getNextframe() {
return this.next.current;
}
/**
* Adds a frame at the end of the buffer
* @param f the frame to add at the end
*/
public void addFrameToQueue(Frame f) {
if(this.current == null) {
this.current = f;
} else if(this.next == null){
nextFrameBuffer fb = new nextFrameBuffer();
fb.current = f;
this.next = fb;
} else {
this.next.addFrameToQueue(f);
}
}
}

View File

@ -0,0 +1,5 @@
package gameplay.hitboxes;
public class Active_HitBox extends HitBox {
}

View File

@ -0,0 +1,5 @@
package gameplay.hitboxes;
public class Active_throw_Hitbox extends HitBox {
}

View File

@ -0,0 +1,100 @@
package gameplay.hitboxes;
public class HitBox {
private Double position_x;
private Double position_y;
private Double size_x;
private Double size_y;
public HitBox() {
this.position_x = 0.0;
this.position_y = 0.0;
this.size_x = 0.0;
this.size_y = 0.0;
}
public void setPosition_x(Double position_x){
this.position_x = position_x;
}
public void setPosition_y(Double position_y){
this.position_y = position_y;
}
public HitBox(Double position_x, Double position_y, Double size_x, Double size_y) {
if(position_x < 0.0) {
position_x = 0.0;
}else if(position_x > 1.0) {
position_x = 1.0;
}
this.position_x = position_x;
if(position_y < 0.0) {
position_y = 0.0;
}else if(position_y > 1.0) {
position_y = 1.0;
}
this.position_y = position_y;
if(size_x < 0.0) {
size_x = 0.0;
}else if(size_x > 1.0) {
size_x = 1.0;
}
this.size_x = size_x;
if(size_y < 0.0) {
size_y = 0.0;
}else if(size_y > 1.0) {
size_y = 1.0;
}
this.size_y = size_y;
}
/*
* @param hb an Hitbox
* @return true if HitBox overlap else return false
*/
public Boolean hit(HitBox hb) {
Boolean horiz = false;
Boolean ver = false;
Double horizontal1 = this.position_x + this.size_x;
Double vertical1 = this.position_y + this.size_y;
Double horizontal2 = hb.position_x + hb.size_x;
Double vertical2 = hb.position_y + hb.size_y;
/*
* HitBox overlap horizontally
*/
if(this.position_x < hb.position_x) { //this is at left of hb
if(hb.position_x < horizontal1) {
horiz = true;
}
}else {//this is at left of hb
if(this.position_x < horizontal2) {
horiz = true;
}
}
/*
* HitBox overlap vertically
*/
if(this.position_y < hb.position_y) { //this is at top of hb
if(hb.position_y < vertical1) {
ver = true;
}
}else {//this is at left of hb
if(this.position_x < vertical2) {
ver = true;
}
}
return horiz && ver;
}
}

View File

@ -0,0 +1,5 @@
package gameplay.hitboxes;
public class Passive_HitBox extends HitBox {
}

View File

@ -0,0 +1,5 @@
package gameplay.hitboxes;
public class Passive_throw_HitBox extends HitBox {
}

View File

@ -0,0 +1,13 @@
package gameplay.hitboxes;
public class Push_HitBox extends HitBox {
public Push_HitBox() {
super();
}
public Push_HitBox(Double position_x, Double position_y, Double size_x, Double size_y) {
super(position_x, position_y, size_x, size_y);
}
}

View File

@ -0,0 +1,19 @@
package gameplay.input;
public enum Button {
UP, DOWN, LEFT, RIGHT, A, B, C, D;
public int toInt() {
switch (this) {
case UP : return 0;
case DOWN : return 1;
case LEFT : return 2;
case RIGHT : return 3;
case A : return 4;
case B : return 5;
case C : return 6;
case D : return 7;
default : return -1;
}
}
}

View File

@ -0,0 +1,80 @@
package gameplay.input;
public class InputBuffer {
/**
* a list of various inputs being recorded, such as inputs pressed at each frame
* Each element is a tab where each element represent a possible input
* (UP, Down, Right, Left, A, B, C, D)
* if the value at the corresponding index is true, then the input is pressed
* By default, no input is pressed.
*/
private Inputs[] inputList;
/*
* the size of the input buffer
*/
private int size;
/*
* the current position in the tab of the last newest input recorded
* This should never bee accessed outside of this class.
*/
private int pos;
/**
* base constructor of the InputBuffer. Creates a buffer of size 1, with every input empty
*/
public InputBuffer() {
this.size = 1;
this.pos = 0;
this.inputList = new Inputs[1];
}
public InputBuffer(int size) {
this.size = size;
this.pos = 0;
this.inputList = new Inputs[this.size];
for(int i = 0; i < this.size; i++) {
this.inputList[i] = new Inputs();
}
}
/**
* @return the latest added inputs
*/
public Inputs getLatestInputs() {
return this.inputList[this.pos];
}
/**
* Sets the last input without moving the current position
* @param inputs
*/
private void setLatestInputs(Inputs inputs) {
this.inputList[pos] = inputs;
}
/**
* advances the current position to the next one (goes back to the first if at the end
*/
private void nextPos() {
this.pos++;
if(this.pos == size) {this.pos = 0;}
}
/**
* record a new input in the
* @param inputs a size 8 tab of inputs
*/
private void recordInputs(Inputs inputs) {
this.nextPos();
this.setLatestInputs(inputs);
}
}

View File

@ -0,0 +1,66 @@
package gameplay.input;
/**
* The class handling the parsing of one input.
* @author Victor
*
*/
public class Inputs {
private static final int numberOfInputs = 8;
private static boolean[] tab;
public Inputs() {
this.tab = new boolean[numberOfInputs];
for(int i = 0; i < numberOfInputs; i ++) {
this.tab[i] = false;
}
}
/**
* record one input
* @param i the integer value corresponding to the tab location
*/
public void recordOneInput(Button b) {
int i = b.toInt();
this.tab[i] = true;
}
/**
* Check if a specific input (for example UP) has been recorded
* @param i the integer value corresponding to the input
* @return
*/
public boolean containsInput(Button b) {
return this.tab[b.toInt()];
}
/**
* Check if a number of inputs are contained simultaneously
* @param in a number of inputs. Check if those are containes in this
* @return true if all inputs of in are also in this
*/
public boolean containsInputs(Inputs in) {
for(int i = 0; i < numberOfInputs; i++) {
if(this.tab[i] != in.getInputs()[i]) {return false;}
}
return true;
}
/**
* Check if a number of inputs are contained simultaneously, in the form of an array of Buttons
* @param bs a number of inputs. Check if those are contained in this
* @return true if all inputs of in are also in this
*/
public boolean containsButtonTab(Button[] bs) {
for(int i = 0; i < bs.length; i++) {
if(!this.containsInput(bs[i])) { return false;}
}
return true;
}
public boolean[] getInputs() {
return this.tab;
}
}