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.

1
2
3
4
5
6
danpost danpost

2018/12/27

#
Unlimited wrote...
are there other ways to work around the problem with the plattforms? As you could probably asume im trying to create a game like megaman x or gunvolt.
You could have all possible collision actor classes extend one class (named Collider, maybe) and have non-collision actors not extend that class. Then change Actor in line 111 (in your last code post) to the name of the class the collision classes extend. The top part of platforms, ramps, etc will not be considered colliding objects then.
Unlimited Unlimited

2018/12/27

#
Uh how do i do that?
Unlimited Unlimited

2018/12/27

#
I mean like how do i code that. what would i have to write for that to work?
danpost danpost

2018/12/27

#
Unlimited wrote...
Uh how do i do that?
Create a subclass of Actor and name it Collider. Then go to all actor classes that you want the Azure actor to collide with and change 'extends Actor' to 'extends Collider'. Then change 'Actor' in line 111 in your last code post to 'Collider'.
Unlimited Unlimited

2018/12/27

#
Wait nvm i just try it. I think there isnt much coding in that i was just a big dumb dumb.
Unlimited Unlimited

2018/12/27

#
Though how exactly will that cause ramps to work?
danpost danpost

2018/12/27

#
Unlimited wrote...
Wait nvm i just try it. I think there isnt much coding in that i was just a big dumb dumb.
STOP. There is a better way to proceed. I will edit this with what to do.
Unlimited Unlimited

2018/12/27

#
Alright.
danpost danpost

2018/12/27

#
Unlimited wrote...
Though how exactly will that cause ramps to work?
I can think of several ways to proceed from here; but, the introduction of ramps seems to spoil them. Not sure how to proceed from here. I did write a Line Following Demo which has an actor moves at an angle up a line. Maybe that will add some insight into how to proceed.
Unlimited Unlimited

2018/12/27

#
Ive looked through a couple of previous post and one person wrote this:
1
2
3
4
5
6
7
8
9
10
11
12
13
/**
     * This will return an object at offset (x,y) if its image is colored at the offset
    */
    public Actor getAnObjectAtOffset(int x, int y, Class clss){
        GreenfootImage img=getImage();
        Actor actor = getOneObjectAtOffset(x,y,clss);
        if(actor!=null) {
            int imgx=getX()+x-(actor.getX()-actor.getImage().getWidth()/2);
            int imgy=getY()+y-(actor.getY()-actor.getImage().getHeight()/2);
            if (actor.getImage().getColorAt(imgx,imgy).getAlpha()<=0)actor=null;
        }
        return actor;
    }
Is that something that works? Uh also ive made a Border that my character cannot walk through and now he can. I asume cause we removed the lines that check for walls. It would be nice to have ramps but if thats not possible thats fine too i just want to finish this and get the animations working.
danpost danpost

2018/12/27

#
Unlimited wrote...
Ive looked through a couple of previous post and one person wrote this: << Code Omitted >> Is that something that works?
Possibly; but I would prefer to avoid that type of code, if possible. It tends to produce lagging.
ive made a Border that my character cannot walk through and now he can. I asume cause we removed the lines that check for walls.
Yes. However you had horizontal movement coded in two different places and something had to be removed.
It would be nice to have ramps but if thats not possible thats fine too i just want to finish this and get the animations working.
I have high expectations that the ramps will eventually be handled. For now, animating your actor is in order, which, by the way will involve your horizontal movement. Let us start with which way the keys are directing the actor:
1
2
3
4
5
public void horizontalMovement()
{
    int dir = 0;
    if (Greenfoot.isKeyDown("left")) dir--;
    if (Greenfoot.isKeyDown("right")) dir++;
Note that there is no longer any need to check the keys as the value of dir will indicate what state they are in ("both up or down" (0), or "which was down" (1 or -1).
1
2
3
4
5
6
7
8
9
    setLocation(getX()+xSpeed*dir);
    // collision
    Actor.actor = getOneIntersectingObject(Actor.class);
    if (actor != null) setLocation(actor.getX()-dir*(actor.getImage().getWidth()+getImage().getWidth())/2);
    // image
    if (dir == -1 && animSet != leftAnim) setAnim(leftAnim, 6);
    else if (dir == 0 && animSet != standAnim) setAnim(standAnim, 2);
    else if (dir == 1 && animSet != rightAnim) setAnim(rightAnim, 6);
}
Call this method from act method.
Unlimited Unlimited

2018/12/27

#
Im getting two errors, one at xSpeed (i asume you meant vSpeed?) and one at Set location.
Unlimited Unlimited

2018/12/27

#
Also since here are also isKeyDown forms do i have to remove that ones in my move() method?
Unlimited Unlimited

2018/12/27

#
Ah also i maybe shouldve said that sooner but the code i removed from act the press s and direction was my running. That is also something i want to do in the future if possible.
danpost danpost

2018/12/27

#
Unlimited wrote...
Also since here are also isKeyDown forms do i have to remove that ones in my move() method?
Remove the move method entirely. (sorry for not saying so before)
There are more replies on the next page.
1
2
3
4
5
6