This site requires JavaScript, please enable it in your browser!
Greenfoot back
Unlimited
Unlimited wrote ...

2018/12/26

Game Creation: Directional Idle, Shooting and Jumping.

2
3
4
5
6
7
8
Unlimited Unlimited

2018/12/27

#
Ok now the animations work great, though i still have the problem of him teleporting into nowhere.
Unlimited Unlimited

2018/12/27

#
Oh yes also, when i keep walking left or right the first frame repeats as well as its an inbetween. Should i remove that one?
danpost danpost

2018/12/27

#
Unlimited wrote...
Oh yes also, when i keep walking left or right the first frame repeats as well as its an inbetween. Should i remove that one?
All I can say on that is to try it. If you are fine with the results, go with it.
Unlimited wrote...
Ok now the animations work great, though i still have the problem of him teleporting into nowhere.
That could have something to do with other actors whose images are huge (like full window sized).
Unlimited Unlimited

2018/12/27

#
i mean for now i only have two objects in my world and that is the platform and border, which disapears whenever i run the program. Also what i wanted to ask is there a limit to how many animations the game can take?
danpost danpost

2018/12/27

#
Unlimited wrote...
i mean for now i only have two objects in my world and that is the platform and border, which disapears whenever i run the program.
1) besides the Azure actor; and 2) "unwantingly" disappears.
is there a limit to how many animations the game can take?
No. However, you may be forced to limit the number to prevent lagging. By "border", are you saying that you have a single border object that depicts borders around all four edges of the world?
Unlimited Unlimited

2018/12/27

#
No by border i mean like a big square that fuctions as a "wall" on the left side, it is not much of a walla anyway since one can see the edge when jumping. Also yes when i move right, it seems that i teleport up as i fall back onto the plattform, when pressing left i teleport eitehr down or far left and then fall down.
Unlimited Unlimited

2018/12/27

#
The Problem still happens when i remove the border object.
Unlimited Unlimited

2018/12/27

#
It happens the moment the character touches the plattform and i press eitehr left or right, jumping has no change.
danpost danpost

2018/12/27

#
Unlimited wrote...
The Problem still happens when i remove the border object.
Please show your horizontalMovement method. (to start with?)
Unlimited Unlimited

2018/12/27

#
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 int jumpStrength = 20;
    
    
    
    
 
    
    
    private static GreenfootImage[] standAnim = new GreenfootImage[9];
    private static GreenfootImage[] rightAnim = new GreenfootImage[11];
    private static GreenfootImage[] leftAnim = new GreenfootImage[11];
    private static GreenfootImage[] standleftAnim = new GreenfootImage[9];
    private static GreenfootImage[] runAnim = new GreenfootImage[10];
    private static GreenfootImage[] runleftAnim = new GreenfootImage[10];
    
    static
    {
        for (int i=0; i<standAnim.length; i++) standAnim[i] = new GreenfootImage("Stand_0"+(i+1)+".png");
        for (int i=0; i<standAnim.length; i++) standleftAnim[i] = new GreenfootImage("StandLeft_0"+(i+1)+".png");
        for (int i=0; i<rightAnim.length; i++) rightAnim[i] = new GreenfootImage("Walk-A_"+(i < 10 ? "0" : "")+(i+1)+".png");
        for (int i=0; i<rightAnim.length; i++) leftAnim[i] = new GreenfootImage("WalkLeft-A_"+(i < 10 ? "0" : "")+(i+1)+".png");
        for (int i=0; i<standAnim.length; i++) runAnim[i] = new GreenfootImage("Run_0"+(i+1)+".png");
        for (int i=0; i<standAnim.length; i++) runleftAnim[i] = new GreenfootImage("RunLeft_0"+(i+1)+".png");
    }
    
    
    
    
    private int animCount; // counter for animations
    private int animDelay = 6; // initially set for standing animation (frame rate field)
 
    
    private void setAnim(GreenfootImage[] anim, int frameRate)
    {
        animSet = anim;
        animCount = -1; // prepares to set first image when incremented
        animDelay = frameRate;
        animate(); // calls a method to set a frame of this newly set animation
    }
    
    
    
    private GreenfootImage[] animSet = standAnim;
    
    
    
    
    /**
     * Here you can tell your actor what he has to do.
     */
    public void act() {
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        animate();
        
        
        
        moveVertically();
        horizontalMovement();
        
    }
    
    
   

    
    
    
    
    
    
    
    
    public void moveVertically()
    {
         boolean onGround = false; // assume in air
       vSpeed += acceleration; // apply gravity
       setLocation(getX(), getY()+vSpeed); // fall
       Actor actor = getOneIntersectingObject(Collider.class);
       if (actor != null)
       { // colliding with another actor
           int vDir = (int)Math.signum(vSpeed); // vertical direction of movement
           vSpeed = 0; // kill vertical speed
           if (vDir > 0) onGround = true; // landing and not bopping head
           setLocation(getX(), actor.getY()-vDir*(actor.getImage().getHeight()+getImage().getHeight())/2); // assigning stop location
        }
        if (onGround && Greenfoot.isKeyDown("space")) vSpeed = -20; // initiate a jump
    }
        
    public void horizontalMovement()
    {
        int boost = Greenfoot.isKeyDown("s") ? 9 : 0;
        int dir = 0;
        if (Greenfoot.isKeyDown("left")) dir--;
        if (Greenfoot.isKeyDown("right")) dir++;    
        
        setLocation(getX(), getY()+6+boost*dir);
        Actor actor = getOneIntersectingObject(Actor.class);
        if (actor != null) setLocation(actor.getX(), getY()-dir*(actor.getImage().getWidth()+getImage().getWidth())/2);
       
        if (dir == -1 && animSet != leftAnim) setAnim(leftAnim, 4);
        else if (dir == 1 && animSet != rightAnim) setAnim(rightAnim, 4);
        else if (dir == 0 && animSet != standleftAnim && animSet != standAnim) setAnim(animSet == leftAnim ? standleftAnim : standAnim, 4);

    }    
        
    
    
    
    
   
    
    
        
        
    
    
    
    
    private void animate()
    {
        animCount = (animCount+1)%(animSet.length*animDelay);
        if (animCount%animDelay == 0) setImage(animSet[animCount/animDelay]);
    }
}
 
danpost danpost

2018/12/27

#
Line 122 should be:
setLocation(getX()+(6+boost)*dir, getY());
and line 124 should be:
if (actor != null) setLocation(actor.getX()-dir*(actor.getImage().getWidth()+getImage().getWidth())/2, getY());
Unlimited Unlimited

2018/12/27

#
Alright changed that, though insteed of teleporting up and down i am teleporting to the left edge of the platform when pressing right and to the right edge when pressing left now.
danpost danpost

2018/12/27

#
Unlimited wrote...
Alright changed that, though insteed of teleporting up and down i am teleporting to the left edge of the platform when pressing right and to the right edge when pressing left now.
And without your border object?
Unlimited Unlimited

2018/12/27

#
Same Problem. teleports to the top edge of the object
danpost danpost

2018/12/27

#
Unlimited wrote...
Same Problem. teleports to the top edge of the object
I think I know what is going on. Please show your moveVertically method.
There are more replies on the next page.
2
3
4
5
6
7
8