Hello everyone, im trying to create a game for class and im having a couple of problems.
for example i cannot seem to figure out how to animate directional idle animations and shooting animations.
Having a idle animation in one direction was simple enough since i only animated one direction.
However i dont know how to tell the programm in what direction i have previously used as in to give my game information what idle or standing shooting animation to use.
Next Problem is, if i want to create an improved jump i am facing two problems.
First, i do not know how to program a jump in which i can control the high of so to give it that megaman feel.
Second, nor do i know if i am able to create such a jump how to tell the game to play a different animation after the apex of the jump and when landing rather then after some unchangable time .
The following is the entire code of my Character. It would be really nice if somebody could help me.
I know there are probably already threats about these problems but despite my hardest effort i was not able to understand them.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * This class is just an example. You can delete it or change the code. * It's not necessary for the scrolling system. */ public class Azure extends ScrollingActor { private int vSpeed = 0; private int acceleration = 1; private boolean jumping; private int jumpStrength = 20; private GreenfootImage Stand1 = new GreenfootImage("Stand_01.png"); private GreenfootImage Stand2 = new GreenfootImage("Stand_02.png"); private GreenfootImage Stand3 = new GreenfootImage("Stand_03.png"); private GreenfootImage Stand4 = new GreenfootImage("Stand_04.png"); private GreenfootImage Stand5 = new GreenfootImage("Stand_05.png"); private GreenfootImage Stand6 = new GreenfootImage("Stand_06.png"); private GreenfootImage Stand7 = new GreenfootImage("Stand_07.png"); private GreenfootImage Stand8 = new GreenfootImage("Stand_08.png"); private GreenfootImage Stand9 = new GreenfootImage("Stand_09.png"); private GreenfootImage WalkA1 = new GreenfootImage("Walk-A_01.png"); private GreenfootImage WalkA2 = new GreenfootImage("Walk-A_02.png"); private GreenfootImage WalkA3 = new GreenfootImage("Walk-A_03.png"); private GreenfootImage WalkA4 = new GreenfootImage("Walk-A_04.png"); private GreenfootImage WalkA5 = new GreenfootImage("Walk-A_05.png"); private GreenfootImage WalkA6 = new GreenfootImage("Walk-A_06.png"); private GreenfootImage WalkA7 = new GreenfootImage("Walk-A_07.png"); private GreenfootImage WalkA8 = new GreenfootImage("Walk-A_08.png"); private GreenfootImage WalkA9 = new GreenfootImage("Walk-A_09.png"); private GreenfootImage WalkA10 = new GreenfootImage("Walk-A_10.png"); private GreenfootImage WalkA11 = new GreenfootImage("Walk-A_11.png"); private int frame = 1; private int animationCounter = 0; /** * Here you can tell your actor what he has to do. */ public void act() { ceiling(); animationCounter ++; if (Greenfoot.isKeyDown("space")) { setLocation(getX(), getY() - 20); } if (Greenfoot.isKeyDown("down")) { setLocation(getX(), getY() + 10); } if (Greenfoot.isKeyDown("left") && (Greenfoot.isKeyDown("s"))) { setLocation(getX() - 15, getY()); } if (Greenfoot.isKeyDown("right") && (Greenfoot.isKeyDown("s"))) { setLocation(getX() + 15, getY()); } move(); canMoveRight(); canMoveLeft(); checkFall(); } public void move() { int y = getY(); int x = getX(); if(Greenfoot.isKeyDown("right") && canMoveRight()) x+=14; if(Greenfoot.isKeyDown("left") && canMoveLeft()) x-=14; if(Greenfoot.isKeyDown("right") && canMoveRight()){ if(animationCounter % 2 == 0) animateWalkA(); } else { if(animationCounter % 6 == 0) animateStand(); } setLocation(x,y); } public void fall() { setLocation(getX(), getY() +vSpeed); { vSpeed = vSpeed + acceleration; } jumping = true; } public boolean onGround() { int spriteHeight = getImage().getHeight(); int lookForGround = (int) (spriteHeight/2+30); Actor ground = getOneObjectAtOffset(0, lookForGround, Highway.class); if(ground == null) { jumping = true; return false; } else { moveToGround(ground); return true; } } public boolean ceiling() { int spriteHeight = getImage().getHeight(); int yDistance = (int) (spriteHeight/-2-30); Actor ceiling = getOneObjectAtOffset(0, yDistance, Highway.class); if(ceiling != null) { vSpeed =1; hitHead(ceiling); return true; } else { return false; } } public void hitHead(Actor ceiling) { int ceilingHeight = ceiling.getImage().getHeight(); int newY = ceiling.getY() + (ceilingHeight + getImage().getHeight())/2; setLocation(getX(), newY); } public boolean canMoveLeft() { boolean canMoveLeft = true; int imageWidth = getImage().getWidth(); int imageHeight = getImage().getHeight(); if (getOneObjectAtOffset(imageWidth/-2 -3, imageHeight/-2, Border.class) !=null || getOneObjectAtOffset(imageWidth/-2 -3, imageHeight/2, Border.class) !=null) canMoveLeft = false; return canMoveLeft; } public boolean canMoveRight() { boolean canMoveRight = true; int imageWidth = getImage().getWidth(); int imageHeight = getImage().getHeight(); if (getOneObjectAtOffset(imageWidth/2 +3, imageHeight/-2, Border.class) !=null || getOneObjectAtOffset(imageWidth/2 +3, imageHeight/2, Border.class) !=null) canMoveRight = false; return canMoveRight; } public void moveToGround(Actor ground) { int groundHeight = ground.getImage().getHeight(); int newY = ground.getY() - (groundHeight + getImage().getHeight())/2+30; setLocation(getX(), newY); jumping = false; } public void checkFall() { if(onGround()) { vSpeed = 0; } else { fall(); } } public void jump() { vSpeed = vSpeed - jumpStrength; jumping = true; fall(); } public void animateStand() { if(frame == 1) { setImage(Stand1); } else if(frame == 2) { setImage(Stand2); } else if(frame == 3) { setImage(Stand3); } else if(frame == 4) { setImage(Stand4); } else if(frame == 5) { setImage(Stand5); } else if(frame == 6) { setImage(Stand6); } else if(frame == 7) { setImage(Stand7); } else if(frame == 8) { setImage(Stand8); } else if(frame == 9) { setImage(Stand9); frame = 1; return; } frame ++; } public void animateWalkA() { if(frame == 1) { setImage(WalkA1); } else if(frame == 2) { setImage(WalkA2); } else if(frame == 3) { setImage(WalkA3); } else if(frame == 4) { setImage(WalkA4); } else if(frame == 5) { setImage(WalkA5); } else if(frame == 6) { setImage(WalkA6); } else if(frame == 7) { setImage(WalkA7); } else if(frame == 8) { setImage(WalkA8); } else if(frame == 9) { setImage(WalkA9); } else if(frame == 10) { setImage(WalkA10); } else if(frame == 11) { setImage(WalkA11); frame = 3; return; } frame ++; } }