Add fall,idle, jump states

Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com>
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
main
sigonasr2 3 years ago
parent 8ba9307465
commit e593e6d9ec
  1. 2
      README.md
  2. BIN
      sprites/erina.gif
  3. BIN
      sprites/erina_jump_fall.gif
  4. BIN
      sprites/erina_jump_rise.gif
  5. BIN
      sprites/erina_walk.gif
  6. 8
      src/sig/DrawLoop.java
  7. 29
      src/sig/engine/AnimatedSprite.java
  8. 9
      src/sig/engine/Sprite.java
  9. 2
      src/sig/objects/Erinoah.java
  10. 7
      src/sig/objects/LevelRenderer.java
  11. 133
      src/sig/objects/Player.java
  12. 11
      src/sig/objects/actor/State.java

@ -30,7 +30,7 @@ Mizue (みずえ) 水恵
Turn off inline hints: (F1, search "Preferences: Open Settings (JSON)) "editor.inlayHints.enabled": false Turn off inline hints: (F1, search "Preferences: Open Settings (JSON)) "editor.inlayHints.enabled": false
Profont: 7x14 per tile. Profont: 7x14 per tile.
Animated Sprites Movement Systems
Collectibles Collectibles
Combat Systems Combat Systems
Storyboarding / Event Systems Storyboarding / Event Systems

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

@ -84,10 +84,10 @@ public class DrawLoop {
continue; continue;
} else { } else {
int index = (Y-(int)yOffset+(int)y)*RabiClone.BASE_WIDTH+X-(int)xOffset+(int)x; 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; continue;
} else { } 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; continue;
} else { } else {
int index = (Y-(int)yOffset+(int)y)*RabiClone.BASE_WIDTH+X-(int)xOffset+(int)x; 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; continue;
} else { } 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);
} }
} }
} }

@ -3,20 +3,22 @@ package sig.engine;
import java.io.File; import java.io.File;
public class AnimatedSprite extends Sprite{ public class AnimatedSprite extends Sprite{
int frameWidth; int originalWidth;
int frameHeight; int originalHeight;
int frames; int frames;
Rectangle[] frames_to_Rectangle; Rectangle[] frames_to_Rectangle;
AnimatedSprite(File filename, int width, int height){ AnimatedSprite(File filename, int width, int height){
super(filename); super(filename);
this.frameWidth = width; this.originalWidth=this.width;
this.frameHeight = height; this.originalHeight=this.height;
frames = (this.width/width)*(this.height/height); this.width = width;
this.height = height;
frames = (originalWidth/width)*(originalHeight/height);
frames_to_Rectangle = new Rectangle[frames]; frames_to_Rectangle = new Rectangle[frames];
for(int i=0;i<frames;i++){ for(int i=0;i<frames;i++){
int x_tile = i%(this.width/width); int x_tile = i%(originalWidth/width);
int y_tile = i/(this.width/width); int y_tile = i/(originalWidth/width);
frames_to_Rectangle[i] = new Rectangle(x_tile*width, y_tile*height, width, height); frames_to_Rectangle[i] = new Rectangle(x_tile*width, y_tile*height, width, height);
} }
} }
@ -26,10 +28,15 @@ public class AnimatedSprite extends Sprite{
public int getFrame_count(){ public int getFrame_count(){
return frames; return frames;
} }
public int get_original_width(){
return this.width; @Override
public int getCanvasHeight() {
return originalHeight;
} }
public int get_original_height(){
return this.height; @Override
public int getCanvasWidth() {
return originalWidth;
} }
} }

@ -18,6 +18,7 @@ public class Sprite{
public static Sprite BACKGROUND2 = new Sprite(new File(new File("..","backgrounds"),"back2.gif")); public static Sprite BACKGROUND2 = new Sprite(new File(new File("..","backgrounds"),"back2.gif"));
public static Sprite BACKGROUND3 = new Sprite(new File(new File("..","backgrounds"),"back3.gif")); public static Sprite BACKGROUND3 = new Sprite(new File(new File("..","backgrounds"),"back3.gif"));
public static AnimatedSprite ERINOAH = new AnimatedSprite(new File(new File("..","sprites"),"erinoah.gif"),48,48); public static AnimatedSprite ERINOAH = new AnimatedSprite(new File(new File("..","sprites"),"erinoah.gif"),48,48);
public static AnimatedSprite ERINA = new AnimatedSprite(new File(new File("..","sprites"),"erina.gif"),32,32);
@ -85,6 +86,10 @@ public class Sprite{
return height; return height;
} }
public int getCanvasHeight() {
return height;
}
public void setHeight(int height) { public void setHeight(int height) {
this.height = height; this.height = height;
} }
@ -93,6 +98,10 @@ public class Sprite{
return width; return width;
} }
public int getCanvasWidth() {
return width;
}
public void setWidth(int width) { public void setWidth(int width) {
this.width = width; this.width = width;
} }

@ -7,7 +7,7 @@ import sig.engine.Sprite;
public class Erinoah extends AnimatedObject{ public class Erinoah extends AnimatedObject{
public Erinoah(Panel panel) { public Erinoah(Panel panel) {
super(Sprite.ERINOAH, 4, panel); super(Sprite.ERINOAH, 6.5, panel);
} }
@Override @Override

@ -2,6 +2,7 @@ package sig.objects;
import sig.RabiClone; import sig.RabiClone;
import sig.engine.Alpha; import sig.engine.Alpha;
import sig.engine.AnimatedObject;
import sig.engine.Object; import sig.engine.Object;
import sig.engine.Panel; import sig.engine.Panel;
import sig.engine.Sprite; import sig.engine.Sprite;
@ -36,7 +37,7 @@ public class LevelRenderer extends Object{
} }
} }
if (RabiClone.player!=null) { if (RabiClone.player!=null) {
Draw_Object(RabiClone.player); Draw_Animated_Object(RabiClone.player);
} }
} }
@ -65,6 +66,10 @@ public class LevelRenderer extends Object{
super.Draw_Sprite(object.getX()-this.getX()-object.getSprite().getWidth()/2, Math.round(object.getY()-this.getY()-object.getSprite().getHeight()/2), object.getSprite()); super.Draw_Sprite(object.getX()-this.getX()-object.getSprite().getWidth()/2, Math.round(object.getY()-this.getY()-object.getSprite().getHeight()/2), object.getSprite());
} }
protected void Draw_Animated_Object(AnimatedObject object) {
super.Draw_Animated_Sprite(object.getX()-this.getX()-object.getAnimatedSpr().getWidth()/2, Math.round(object.getY()-this.getY()-object.getAnimatedSpr().getHeight()/2), object.getAnimatedSpr(), object.getCurrentFrame());
}
private void DrawTile(double x, double y, Tile tile) { private void DrawTile(double x, double y, Tile tile) {
Draw_Sprite_Partial(x,y, tile.getSpriteSheetX()*tile.getTileWidth(), tile.getSpriteSheetY()*tile.getTileHeight(), tile.getTileWidth(), tile.getTileHeight(), getSprite(), 0); Draw_Sprite_Partial(x,y, tile.getSpriteSheetX()*tile.getTileWidth(), tile.getSpriteSheetY()*tile.getTileHeight(), tile.getTileWidth(), tile.getTileHeight(), getSprite(), 0);
} }

@ -1,6 +1,7 @@
package sig.objects; package sig.objects;
import sig.RabiClone; import sig.RabiClone;
import sig.engine.AnimatedObject;
import sig.engine.Object; import sig.engine.Object;
import sig.engine.Panel; import sig.engine.Panel;
import sig.engine.Sprite; import sig.engine.Sprite;
@ -8,10 +9,11 @@ import sig.map.CollisionType;
import sig.map.Map; import sig.map.Map;
import sig.map.Tile; import sig.map.Tile;
import sig.map.View; import sig.map.View;
import sig.objects.actor.State;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
public class Player extends Object{ public class Player extends AnimatedObject{
final double GRAVITY = 890; final double GRAVITY = 890;
final double NORMAL_FRICTION = 6400; final double NORMAL_FRICTION = 6400;
@ -29,27 +31,82 @@ public class Player extends Object{
double horizontal_air_drag = 600; double horizontal_air_drag = 600;
double horizontal_air_friction = 180; double horizontal_air_friction = 180;
double jump_velocity = -400; double jump_velocity = -200;
int maxJumpCount=1; int maxJumpCount=2;
int jumpCount=maxJumpCount; int jumpCount=maxJumpCount;
State state = State.IDLE;
final double viewBoundaryX=RabiClone.BASE_WIDTH/3; final double viewBoundaryX=RabiClone.BASE_WIDTH/3;
final double viewBoundaryY=RabiClone.BASE_HEIGHT/3; final double viewBoundaryY=RabiClone.BASE_HEIGHT/3;
View lastCameraView = View.FIXED; View lastCameraView = View.FIXED;
boolean groundCollision = false;
boolean spacebarReleased = true;
long spacebarPressed = System.currentTimeMillis();
int jumpHoldTime = 150;
public Player(Panel panel) { public Player(Panel panel) {
super(panel); super(Sprite.ERINA,5,panel);
this.setSprite(Sprite.NANA_SMALL); setX(RabiClone.BASE_WIDTH/2-getAnimatedSpr().getWidth()/2);
setX(RabiClone.BASE_WIDTH/2-getSprite().getWidth()/2); setY(RabiClone.BASE_HEIGHT*(2/3d)-getAnimatedSpr().getHeight()/2);
setY(RabiClone.BASE_HEIGHT*(2/3d)-getSprite().getHeight()/2);
} }
@Override @Override
public void update(double updateMult) { public void update(double updateMult) {
super.update(updateMult);
handleMovementPhysics(updateMult); handleMovementPhysics(updateMult);
handleCameraRoomMovement(); handleCameraRoomMovement();
switch(state){
case ATTACK:
break;
case FALLING:
break;
case IDLE:
break;
case JUMP:
break;
case SLIDE:
break;
case STAGGER:
break;
case UNCONTROLLABLE:
break;
default:
break;
}
System.out.println(state);
}
@Override
protected void KeyReleased(int key) {
if (key==KeyEvent.VK_SPACE) {
spacebarReleased=true;
}
}
@Override
protected void KeyPressed(int key) {
if (groundCollision) {
if (spacebarReleased&&key==KeyEvent.VK_SPACE&&jumpCount>0) {
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,18 +209,44 @@ public class Player extends Object{
:y_velocity+y_acceleration*updateMult; :y_velocity+y_acceleration*updateMult;
double displacement_y = y_velocity*updateMult; double displacement_y = y_velocity*updateMult;
double displacement_x = x_velocity*updateMult; double displacement_x = x_velocity*updateMult;
boolean groundCollision = false;
boolean sideCollision = false; boolean sideCollision = false;
for(int i=0;i<4;i++){
double check_distance_x = (displacement_x/4)*(i+1);
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()-getAnimatedSpr().getWidth()/2)/Tile.TILE_WIDTH)*Tile.TILE_WIDTH+Tile.TILE_WIDTH/2+3+check_distance_x);
} else {
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(x_velocity);
//System.out.println(((int)(getX()+getSprite().getWidth()/2+displacement_x)/Tile.TILE_WIDTH)+"//"+((int)(getY()+getSprite().getHeight()/2)/Tile.TILE_HEIGHT)); //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++){ for(int i=0;i<4;i++){
if (sideCollision&&groundCollision) { if (groundCollision) {
break; break;
} }
double check_distance_y = (displacement_y/4)*(i+1); 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()+getAnimatedSpr().getWidth()/2-4)/Tile.TILE_WIDTH, (int)(getY()+getAnimatedSpr().getHeight()/2+check_distance_y)/Tile.TILE_HEIGHT);
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()-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()-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); //System.out.println((int)getX()/Tile.TILE_WIDTH);
if(checked_tile_bottom_right.getCollision()==CollisionType.BLOCK||checked_tile_bottom_left.getCollision()==CollisionType.BLOCK){ if(checked_tile_bottom_right.getCollision()==CollisionType.BLOCK||checked_tile_bottom_left.getCollision()==CollisionType.BLOCK){
setY((getY()-check_distance_y)); setY((getY()-check_distance_y));
@ -173,35 +256,25 @@ public class Player extends Object{
y_acceleration = 0; y_acceleration = 0;
y_velocity = 0; y_velocity = 0;
groundCollision=true; groundCollision=true;
collisionOccured=true;
state = State.IDLE;
} }
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);
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);
} else {
setX(((int)(getX()+getSprite().getWidth())/Tile.TILE_WIDTH)*Tile.TILE_WIDTH-Tile.TILE_WIDTH/2-3+check_distance_x);
} }
x_acceleration = 0; if (!collisionOccured) {
x_velocity = 0; groundCollision=false;
sideCollision=true;
} }
} }
if (!groundCollision){ if (!groundCollision){
this.setY(this.getY()+displacement_y); this.setY(this.getY()+displacement_y);
y_acceleration = GRAVITY; y_acceleration = GRAVITY;
if(y_velocity>0){
state = State.FALLING;
}
if (!sideCollision) { if (!sideCollision) {
handleKeyboardMovement(updateMult, right-left, horizontal_air_friction, horizontal_air_drag); handleKeyboardMovement(updateMult, right-left, horizontal_air_friction, horizontal_air_drag);
this.setX(this.getX()+displacement_x); this.setX(this.getX()+displacement_x);
} }
} else { } else {
if (KeyHeld(KeyEvent.VK_SPACE)&&jumpCount>0) {
jumpCount--;
y_velocity = jump_velocity;
//System.out.println("Jump");
}
if (!sideCollision) { if (!sideCollision) {
handleKeyboardMovement(updateMult, right-left, horizontal_friction, horizontal_drag); handleKeyboardMovement(updateMult, right-left, horizontal_friction, horizontal_drag);
this.setX(this.getX()+displacement_x); this.setX(this.getX()+displacement_x);

@ -0,0 +1,11 @@
package sig.objects.actor;
public enum State{
IDLE,
SLIDE,
JUMP,
FALLING,
ATTACK,
STAGGER,
UNCONTROLLABLE
}
Loading…
Cancel
Save