From e593e6d9ec80a41db3b50296ac85fd861b973242 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Sat, 4 Jun 2022 05:44:05 -0500 Subject: [PATCH] Add fall,idle, jump states Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com> Co-authored-by: sigonasr2 --- README.md | 2 +- sprites/erina.gif | Bin 0 -> 1750 bytes sprites/erina_jump_fall.gif | Bin 0 -> 1540 bytes sprites/erina_jump_rise.gif | Bin 0 -> 1502 bytes sprites/erina_walk.gif | Bin 0 -> 2176 bytes src/sig/DrawLoop.java | 8 +- src/sig/engine/AnimatedSprite.java | 29 +++--- src/sig/engine/Sprite.java | 9 ++ src/sig/objects/Erinoah.java | 2 +- src/sig/objects/LevelRenderer.java | 7 +- src/sig/objects/Player.java | 143 ++++++++++++++++++++++------- src/sig/objects/actor/State.java | 11 +++ 12 files changed, 158 insertions(+), 53 deletions(-) create mode 100644 sprites/erina.gif create mode 100644 sprites/erina_jump_fall.gif create mode 100644 sprites/erina_jump_rise.gif create mode 100644 sprites/erina_walk.gif create mode 100644 src/sig/objects/actor/State.java diff --git a/README.md b/README.md index 1d3176e..582bd01 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ Mizue (みずえ) 水恵 Turn off inline hints: (F1, search "Preferences: Open Settings (JSON)) "editor.inlayHints.enabled": false Profont: 7x14 per tile. -Animated Sprites +Movement Systems Collectibles Combat Systems Storyboarding / Event Systems \ No newline at end of file diff --git a/sprites/erina.gif b/sprites/erina.gif new file mode 100644 index 0000000000000000000000000000000000000000..6b2c3eb3e939358c581cffafaedcd09e7e387363 GIT binary patch literal 1750 zcmcJ^{W}u~0KoC7nIRWqb`tXzO{8>U*Nc~V*|Oy&qU7f7=4F!Fyv$^qEu63wlH-Xo zFCm+GOC^h9HSh8kVq7F*x)j6i?vJ?7^Zo7Xf^xR84Ft%+030abQW+^yNT`|&*;>hz zH76_v1&JI29-8`+w0vw8T>_yVslRxadH*K7etqrnJz4wOm+ZGgS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2`Y|@E5njB5-WBxc=%Axx&7b?3>K6OPWUS&L9@EXb3>0rnFrb zENQ-#yKl7VekQ>(!UilXr2;W(qX7vAP%gs+SB8tctv(B`y)=$Y>x?U2RT2a59PrBk*y^BUh)O!xrBXT)8gEoNBlt)cRe>I6qo)4LnO=Gty$Z z{Bo5yF#2@TEe8=<0wAv}Y@*g_+pi1`XW`q&66Zm3woG>_!Px<;T>;FRJpgywa!Bn1 zQGX18G|Qv`07ehcl04zT zZpYAce8>>3i@CW90yZN60-yga@*h%DSi0#H1aQFL16-L?tTqTwyz#Tc zpghvWC(}cx&5-7|?&_I2!SD7iGr;g47jMWA%zPhm0OF%TzW3mx&-eo5TMz#E1ISS< z5D*UF_u|^<{X_oyBTfH=06@thV1NWPK=I5+0R7SCe)v>*fg%ziJOXm!52NTqt*L@bMzq{}0sxRQAx4mkP4wag!PvtEWU*=i zDOMGWK*ln*Q3!A3(i?*iM>Nb)2+EKm6990>Bk<7)e_R3oOr#J EJDtzUzW@LL literal 0 HcmV?d00001 diff --git a/sprites/erina_walk.gif b/sprites/erina_walk.gif new file mode 100644 index 0000000000000000000000000000000000000000..9b2c032885b1367852cf4d3adfb78da9c6cec090 GIT binary patch literal 2176 zcmV-`2!HoSNk%w1VSoWZ0OJe*eJ!AeK7@l!#HLkWgk|h)fcnXEbEbu#jko{uu9?}r z$p6Fg|NsC0|NsC0|NsC0A^s6Va%Ew3Wn>_CX>@2HM@dak03rDV0SW*Q04x9i004ji zKmY&){_x33tGzhu&Ab0#D2`-lo@lDBZ0o*oEYEap-*~R?eDD9jpm0bm8jr}Na>;Bu zpU|juO08P2*sONT?Rvl9uy{-^o6kRk0j*NFGwL;at}(pR@r!}MkTcakZhQ<1dV_^@ zF=~i`aex$ie2hDhe0~y@eSr#&hMGHWnU|P@gm|5Lc9S}8oTw9(tE{DYn0ALeqK^-8 zgQGbLrIr<$vNM9EuDiXstjM$$#XP~nwY;~IJ=Bs02MPz^i^(}^!rD#|G&xFdb z<;^ti@7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6RlJl0YsV5CWQdAYEI^LTXh#-q z4*>|M-kZRsL%xMkj8>c^QnEP1EoL%F0g#{m+{XX{T#AegK!7*WXstVXK!a=&Kod1Z z00|;Mg+9tqDg#+YRx-?$QvAsv5P&`}{Ze}j8Kdh$>C0A*a*L-_WGW5lNVE{sl!?TJ z5P`V?{0)FjbF5-5iCMb~<`OO6lw|=fMF2=9pqYiBnF@sYM?QQL1EU+F0@_K=96f-U z&E%wdG&lfkHj$hN@TEX!_!D9xAe>H2;xKl96QP85arzbqoTcHGNY` zsb0{x#a=U{Qd;a*CrPTz~e=df+YiJsbRX#CBk~H3tR0%YquTs zXtIi{QRCuN2qwFcMfCbxnDOFG&n2&5_ZeT=J;%7+J;L_5+bZfRLKyY+fyg{n#sGuD zy?G135h9VKU?>>9$>=W>yngfcqVyMl0=f2-@> zc*KFkL6}JKU<_f&WV93;<_AJhJ7Of1k;X$=p.length||sprite.getBi_array()[Y*sprite.getWidth()+X]==32||p[index]==sprite.getBi_array()[Y*sprite.getWidth()+X]) { + if (index<0||index>=p.length||sprite.getBi_array()[Y*sprite.getCanvasWidth()+X]==32||p[index]==sprite.getBi_array()[Y*sprite.getCanvasWidth()+X]) { continue; } else { - Draw(p,index,sprite.getBi_array()[Y*sprite.getWidth()+X],Alpha.ALPHA0); + Draw(p,index,sprite.getBi_array()[Y*sprite.getCanvasWidth()+X],Alpha.ALPHA0); } } } @@ -111,10 +111,10 @@ public class DrawLoop { continue; } else { int index = (Y-(int)yOffset+(int)y)*RabiClone.BASE_WIDTH+X-(int)xOffset+(int)x; - if (index<0||index>=p.length||sprite.getBi_array()[Y*sprite.getWidth()+X]==32||p[index]==sprite.getBi_array()[Y*sprite.getWidth()+X]) { + if (index<0||index>=p.length||sprite.getBi_array()[Y*sprite.getCanvasWidth()+X]==32||p[index]==sprite.getBi_array()[Y*sprite.getCanvasWidth()+X]) { continue; } else { - Draw(p,index,col==PaletteColor.NORMAL?sprite.getBi_array()[Y*sprite.getWidth()+X]:(byte)col.ordinal(),alpha); + Draw(p,index,col==PaletteColor.NORMAL?sprite.getBi_array()[Y*sprite.getCanvasWidth()+X]:(byte)col.ordinal(),alpha); } } } diff --git a/src/sig/engine/AnimatedSprite.java b/src/sig/engine/AnimatedSprite.java index d1cf540..3996439 100644 --- a/src/sig/engine/AnimatedSprite.java +++ b/src/sig/engine/AnimatedSprite.java @@ -3,20 +3,22 @@ package sig.engine; import java.io.File; public class AnimatedSprite extends Sprite{ - int frameWidth; - int frameHeight; + int originalWidth; + int originalHeight; int frames; Rectangle[] frames_to_Rectangle; AnimatedSprite(File filename, int width, int height){ super(filename); - this.frameWidth = width; - this.frameHeight = height; - frames = (this.width/width)*(this.height/height); + this.originalWidth=this.width; + this.originalHeight=this.height; + this.width = width; + this.height = height; + frames = (originalWidth/width)*(originalHeight/height); frames_to_Rectangle = new Rectangle[frames]; for(int i=0;i0) { + state = State.JUMP; + jumpCount--; + y_velocity = jump_velocity; + spacebarReleased=false; + //System.out.println("Jump"); + } + } else + if ((state == State.JUMP||state==State.FALLING) && jumpCount>0 && spacebarReleased && key == KeyEvent.VK_SPACE){ + jumpCount=0; + y_velocity = jump_velocity; + spacebarReleased=false; + } } @@ -152,56 +209,72 @@ public class Player extends Object{ :y_velocity+y_acceleration*updateMult; double displacement_y = y_velocity*updateMult; double displacement_x = x_velocity*updateMult; - boolean groundCollision = false; boolean sideCollision = false; - //System.out.println(x_velocity); - //System.out.println(((int)(getX()+getSprite().getWidth()/2+displacement_x)/Tile.TILE_WIDTH)+"//"+((int)(getY()+getSprite().getHeight()/2)/Tile.TILE_HEIGHT)); for(int i=0;i<4;i++){ - if (sideCollision&&groundCollision) { - break; - } - double check_distance_y = (displacement_y/4)*(i+1); double check_distance_x = (displacement_x/4)*(i+1); - Tile checked_tile_bottom_right = RabiClone.CURRENT_MAP.getTile((int)(getX()+getSprite().getWidth()/2-4)/Tile.TILE_WIDTH, (int)(getY()+getSprite().getHeight()/2+check_distance_y)/Tile.TILE_HEIGHT); - Tile checked_tile_bottom_left = RabiClone.CURRENT_MAP.getTile((int)(getX()-getSprite().getWidth()/2+4)/Tile.TILE_WIDTH, (int)(getY()+getSprite().getHeight()/2+check_distance_y)/Tile.TILE_HEIGHT); - //System.out.println((int)getX()/Tile.TILE_WIDTH); - if(checked_tile_bottom_right.getCollision()==CollisionType.BLOCK||checked_tile_bottom_left.getCollision()==CollisionType.BLOCK){ - setY((getY()-check_distance_y)); - if (y_velocity>0) { - jumpCount=maxJumpCount; - } - y_acceleration = 0; - y_velocity = 0; - groundCollision=true; - } - Tile checked_tile_top_right = RabiClone.CURRENT_MAP.getTile((int)(getX()+getSprite().getWidth()/2-4+check_distance_x)/Tile.TILE_WIDTH, (int)(getY()+getSprite().getHeight()/2)/Tile.TILE_HEIGHT); - Tile checked_tile_top_left = RabiClone.CURRENT_MAP.getTile((int)(getX()-getSprite().getWidth()/2+4+check_distance_x)/Tile.TILE_WIDTH, (int)(getY()+getSprite().getHeight()/2)/Tile.TILE_HEIGHT); + Tile checked_tile_top_right = RabiClone.CURRENT_MAP.getTile((int)(getX()+getAnimatedSpr().getWidth()/2-4+check_distance_x)/Tile.TILE_WIDTH, (int)(getY()+getAnimatedSpr().getHeight()/2)/Tile.TILE_HEIGHT); + Tile checked_tile_top_left = RabiClone.CURRENT_MAP.getTile((int)(getX()-getAnimatedSpr().getWidth()/2+4+check_distance_x)/Tile.TILE_WIDTH, (int)(getY()+getAnimatedSpr().getHeight()/2)/Tile.TILE_HEIGHT); if(checked_tile_top_right.getCollision()==CollisionType.BLOCK||checked_tile_top_left.getCollision()==CollisionType.BLOCK){ //System.out.println(checked_tile_top_right.getCollision()+"//"+checked_tile_top_left.getCollision()); if (checked_tile_top_right.getCollision()==CollisionType.BLOCK) { - setX(((int)(getX()-getSprite().getWidth()/2)/Tile.TILE_WIDTH)*Tile.TILE_WIDTH+Tile.TILE_WIDTH/2+3+check_distance_x); + setX(((int)(getX()-getAnimatedSpr().getWidth()/2)/Tile.TILE_WIDTH)*Tile.TILE_WIDTH+Tile.TILE_WIDTH/2+3+check_distance_x); } else { - setX(((int)(getX()+getSprite().getWidth())/Tile.TILE_WIDTH)*Tile.TILE_WIDTH-Tile.TILE_WIDTH/2-3+check_distance_x); + setX(((int)(getX()+getAnimatedSpr().getWidth())/Tile.TILE_WIDTH)*Tile.TILE_WIDTH-Tile.TILE_WIDTH/2-3+check_distance_x); } x_acceleration = 0; x_velocity = 0; sideCollision=true; } } + if (y_velocity==0) { + Tile checked_tile_bottom_right = RabiClone.CURRENT_MAP.getTile((int)(getX()+getAnimatedSpr().getWidth()/2-4)/Tile.TILE_WIDTH, (int)(getY()+getAnimatedSpr().getHeight()/2+0.5)/Tile.TILE_HEIGHT); + Tile checked_tile_bottom_left = RabiClone.CURRENT_MAP.getTile((int)(getX()-getAnimatedSpr().getWidth()/2+4)/Tile.TILE_WIDTH, (int)(getY()+getAnimatedSpr().getHeight()/2+0.5)/Tile.TILE_HEIGHT); + if (!(checked_tile_bottom_right.getCollision()==CollisionType.BLOCK||checked_tile_bottom_left.getCollision()==CollisionType.BLOCK)) { + groundCollision=false; + } else { + groundCollision=true; + jumpCount=maxJumpCount; + } + } else { + //System.out.println(x_velocity); + //System.out.println(((int)(getX()+getAnimatedSpr().getWidth()/2+displacement_x)/Tile.TILE_WIDTH)+"//"+((int)(getY()+getAnimatedSpr().getHeight()/2)/Tile.TILE_HEIGHT)); + boolean collisionOccured=false; + for(int i=0;i<4;i++){ + if (groundCollision) { + break; + } + double check_distance_y = (displacement_y/4)*(i+1); + Tile checked_tile_bottom_right = RabiClone.CURRENT_MAP.getTile((int)(getX()+getAnimatedSpr().getWidth()/2-4)/Tile.TILE_WIDTH, (int)(getY()+getAnimatedSpr().getHeight()/2+check_distance_y)/Tile.TILE_HEIGHT); + Tile checked_tile_bottom_left = RabiClone.CURRENT_MAP.getTile((int)(getX()-getAnimatedSpr().getWidth()/2+4)/Tile.TILE_WIDTH, (int)(getY()+getAnimatedSpr().getHeight()/2+check_distance_y)/Tile.TILE_HEIGHT); + //System.out.println((int)getX()/Tile.TILE_WIDTH); + if(checked_tile_bottom_right.getCollision()==CollisionType.BLOCK||checked_tile_bottom_left.getCollision()==CollisionType.BLOCK){ + setY((getY()-check_distance_y)); + if (y_velocity>0) { + jumpCount=maxJumpCount; + } + y_acceleration = 0; + y_velocity = 0; + groundCollision=true; + collisionOccured=true; + state = State.IDLE; + } + } + if (!collisionOccured) { + groundCollision=false; + } + } if (!groundCollision){ this.setY(this.getY()+displacement_y); y_acceleration = GRAVITY; + if(y_velocity>0){ + state = State.FALLING; + } if (!sideCollision) { handleKeyboardMovement(updateMult, right-left, horizontal_air_friction, horizontal_air_drag); this.setX(this.getX()+displacement_x); } } else { - if (KeyHeld(KeyEvent.VK_SPACE)&&jumpCount>0) { - jumpCount--; - y_velocity = jump_velocity; - //System.out.println("Jump"); - } if (!sideCollision) { handleKeyboardMovement(updateMult, right-left, horizontal_friction, horizontal_drag); this.setX(this.getX()+displacement_x); diff --git a/src/sig/objects/actor/State.java b/src/sig/objects/actor/State.java new file mode 100644 index 0000000..e505dbc --- /dev/null +++ b/src/sig/objects/actor/State.java @@ -0,0 +1,11 @@ +package sig.objects.actor; + +public enum State{ +IDLE, +SLIDE, +JUMP, +FALLING, +ATTACK, +STAGGER, +UNCONTROLLABLE +} \ No newline at end of file