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.

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; } |
1 2 3 4 5 | public void horizontalMovement() { int dir = 0 ; if (Greenfoot.isKeyDown( "left" )) dir--; if (Greenfoot.isKeyDown( "right" )) dir++; |
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 ); } |