Implement knife animation and attaching
Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com> Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
fe51c443c4
commit
e04ada04bc
BIN
sprites/knife-swing.gif
Normal file
BIN
sprites/knife-swing.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 434 B |
@ -11,6 +11,7 @@ public enum Action {
|
||||
MOVE_LEFT(new KeyBind(KeyEvent.VK_LEFT),new KeyBind(KeyEvent.VK_A)),
|
||||
JUMP(new KeyBind(KeyEvent.VK_SPACE),new KeyBind(KeyEvent.VK_W)),
|
||||
FALL(new KeyBind(KeyEvent.VK_DOWN),new KeyBind(KeyEvent.VK_S)),
|
||||
ATTACK(new KeyBind(KeyEvent.VK_Z)),
|
||||
SLIDE(new KeyBind(KeyEvent.VK_CONTROL)),
|
||||
LEVEL_EDITOR(new KeyBind(KeyEvent.VK_F2)),
|
||||
PLAY_GAME(new KeyBind(KeyEvent.VK_F1)),
|
||||
|
@ -26,6 +26,7 @@ public class Sprite{
|
||||
public static AnimatedSprite ERINA_JUMP_FALL = new AnimatedSprite(new File(new File("..","sprites"),"erina_jump_fall.gif"),32,32);
|
||||
public static AnimatedSprite ERINA_SLIDE1 = new AnimatedSprite(new File(new File("..","sprites"),"erina_slide1.gif"),32,32);
|
||||
public static AnimatedSprite ERINA_SLIDE = new AnimatedSprite(new File(new File("..","sprites"),"erina_slide.gif"),32,32);
|
||||
public static AnimatedSprite KNIFE_SWING = new AnimatedSprite(new File(new File("..","sprites"),"knife-swing.gif"),32,32);
|
||||
|
||||
|
||||
|
||||
|
@ -152,7 +152,8 @@ public class ConfigureControls extends Object{
|
||||
public void KeyPressed(Action a) {
|
||||
switch(a) {
|
||||
case PLAY_GAME:{
|
||||
RabiClone.OBJ.remove(RabiClone.level_renderer);
|
||||
RabiClone.OBJ.clear();
|
||||
RabiClone.ResetGame();
|
||||
RabiClone.OBJ.add(RabiClone.level_renderer = new LevelRenderer(RabiClone.p));
|
||||
RabiClone.StartGame();
|
||||
}break;
|
||||
|
@ -219,7 +219,8 @@ public class EditorRenderer extends LevelRenderer{
|
||||
int tileY = (int)(RabiClone.MOUSE_POS.getY()+getY())/Tile.TILE_HEIGHT;
|
||||
switch (a) {
|
||||
case PLAY_GAME:{
|
||||
RabiClone.OBJ.remove(RabiClone.level_renderer);
|
||||
RabiClone.OBJ.clear();
|
||||
RabiClone.ResetGame();
|
||||
RabiClone.OBJ.add(RabiClone.level_renderer = new LevelRenderer(RabiClone.p));
|
||||
RabiClone.StartGame();
|
||||
}break;
|
||||
|
@ -12,6 +12,7 @@ import sig.map.View;
|
||||
import sig.objects.actor.PhysicsObject;
|
||||
import sig.objects.actor.RenderedObject;
|
||||
import sig.objects.actor.State;
|
||||
import sig.objects.weapons.KnifeSwing;
|
||||
import sig.utils.TimeUtils;
|
||||
|
||||
public class Player extends PhysicsObject implements RenderedObject{
|
||||
@ -20,6 +21,9 @@ public class Player extends PhysicsObject implements RenderedObject{
|
||||
final static long jump_fall_AnimationWaitTime = TimeUtils.millisToNanos(200);
|
||||
final static long slide_AnimationWaitTime = TimeUtils.millisToNanos(100);
|
||||
final static long slide_duration = TimeUtils.millisToNanos(700);
|
||||
final static long weaponSwingAnimationTime = TimeUtils.millisToNanos(333);
|
||||
|
||||
long weaponSwingTime = 0;
|
||||
|
||||
State prvState = state;
|
||||
|
||||
@ -67,6 +71,9 @@ public class Player extends PhysicsObject implements RenderedObject{
|
||||
|
||||
switch (state) {
|
||||
case ATTACK:
|
||||
if (RabiClone.TIME - weaponSwingTime > weaponSwingAnimationTime) {
|
||||
state=State.IDLE;
|
||||
}
|
||||
break;
|
||||
case FALLING:
|
||||
if (prvState != State.FALLING) {
|
||||
@ -204,6 +211,11 @@ public class Player extends PhysicsObject implements RenderedObject{
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (a == Action.ATTACK&&(state==State.IDLE||state==State.FALLING||state==State.JUMP)&&(RabiClone.TIME-weaponSwingTime>=weaponSwingAnimationTime)) {
|
||||
RabiClone.OBJ.add(new KnifeSwing(Sprite.KNIFE_SWING,15,RabiClone.p,this));
|
||||
state=State.ATTACK;
|
||||
weaponSwingTime=RabiClone.TIME;
|
||||
}
|
||||
if (groundCollision) {
|
||||
if (spacebarReleased && (a == Action.JUMP) && jumpCount > 0) {
|
||||
state = State.JUMP;
|
||||
|
8
src/sig/objects/actor/Attachable.java
Normal file
8
src/sig/objects/actor/Attachable.java
Normal file
@ -0,0 +1,8 @@
|
||||
package sig.objects.actor;
|
||||
|
||||
import sig.engine.objects.Object;
|
||||
|
||||
public interface Attachable {
|
||||
Object getAttachedObject();
|
||||
void setAttachedObject(Object o);
|
||||
}
|
38
src/sig/objects/actor/AttachableObject.java
Normal file
38
src/sig/objects/actor/AttachableObject.java
Normal file
@ -0,0 +1,38 @@
|
||||
package sig.objects.actor;
|
||||
|
||||
import sig.engine.AnimatedSprite;
|
||||
import sig.engine.Panel;
|
||||
import sig.engine.objects.AnimatedObject;
|
||||
import sig.engine.objects.Object;
|
||||
|
||||
public abstract class AttachableObject extends AnimatedObject implements Attachable{
|
||||
Object attached;
|
||||
|
||||
protected AttachableObject(AnimatedSprite spr, double animationSpd, Panel panel, Object attachedObj) {
|
||||
super(spr, animationSpd, panel);
|
||||
setAttachedObject(attachedObj);
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected Object getAttached() {
|
||||
return attached;
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected void setAttached(Object attached) {
|
||||
this.attached = attached;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setAttachedObject(Object o) {
|
||||
this.attached=o;
|
||||
}
|
||||
|
||||
public Object getAttachedObject() {
|
||||
return this.attached;
|
||||
}
|
||||
|
||||
}
|
46
src/sig/objects/weapons/KnifeSwing.java
Normal file
46
src/sig/objects/weapons/KnifeSwing.java
Normal file
@ -0,0 +1,46 @@
|
||||
package sig.objects.weapons;
|
||||
|
||||
import sig.engine.AnimatedSprite;
|
||||
import sig.engine.Panel;
|
||||
import sig.engine.Transform;
|
||||
import sig.objects.actor.AttachableObject;
|
||||
import sig.objects.actor.RenderedObject;
|
||||
import sig.engine.objects.Object;
|
||||
|
||||
public class KnifeSwing extends AttachableObject implements RenderedObject{
|
||||
|
||||
final byte frameCount = 5; //Number of frames before animation ends.
|
||||
|
||||
public KnifeSwing(AnimatedSprite spr, double animationSpd, Panel panel, Object attachedObj) {
|
||||
super(spr, animationSpd, panel, attachedObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(double updateMult) {
|
||||
super.update(updateMult);
|
||||
if (getCurrentFrame()>frameCount) {
|
||||
setMarkedForDeletion(true);
|
||||
return;
|
||||
}
|
||||
if (getSpriteTransform()==Transform.HORIZONTAL) {
|
||||
setX(getAttachedObject().getX()-getAnimatedSpr().getWidth()/2);
|
||||
} else {
|
||||
setX(getAttachedObject().getX()+getAnimatedSpr().getWidth()/2);
|
||||
}
|
||||
setY(getAttachedObject().getY());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(byte[] p) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Transform getSpriteTransform() {
|
||||
return getAttached().getSpriteTransform()==Transform.HORIZONTAL||getAttached().getSpriteTransform()==Transform.HORIZ_VERTIC?Transform.NONE:Transform.HORIZONTAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFriendlyObject() {
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user