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 0000000..6b2c3eb Binary files /dev/null and b/sprites/erina.gif differ diff --git a/sprites/erina_jump_fall.gif b/sprites/erina_jump_fall.gif new file mode 100644 index 0000000..6635f68 Binary files /dev/null and b/sprites/erina_jump_fall.gif differ diff --git a/sprites/erina_jump_rise.gif b/sprites/erina_jump_rise.gif new file mode 100644 index 0000000..fc9fad1 Binary files /dev/null and b/sprites/erina_jump_rise.gif differ diff --git a/sprites/erina_walk.gif b/sprites/erina_walk.gif new file mode 100644 index 0000000..9b2c032 Binary files /dev/null and b/sprites/erina_walk.gif differ diff --git a/src/sig/DrawLoop.java b/src/sig/DrawLoop.java index 8c79738..ff00427 100644 --- a/src/sig/DrawLoop.java +++ b/src/sig/DrawLoop.java @@ -84,10 +84,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,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