Hello, i need some help with my platform class.
I got 1 platform moving from left to right.. but i want another moving on the Y axis.
However i've tried several approaches including DanPost's Method:
"
}"
Which he helped someone else with earlier.
The platform moves up, but when reaching the point given in the method it just stops.
it seems to be moving up and down at the same time!
heres my full code of the class:
1 2 3 4 5 6 7 | public void moveplatformupdown( int Ya, int Yb){ Actor flyer2 = (Actor) getWorld().getObjects(flyingplatform. class ).get( 1 ); Actor player = (Actor) getWorld().getObjects(Player. class ).get( 0 ); minimumY = Ya; maximumY = Yb; direction = 1 ; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class flyingplatform here. * * @author (your name) * @version (a version number or a date) */ public class flyingplatform extends Platform { private GreenfootImage platformleft = new GreenfootImage( "platform.png" ); private GreenfootImage platformright = new GreenfootImage( "platformright.png" ); private int minimumY; private int maximumY; private int direction; boolean gelijk = false ; boolean moveUp = true ; /** * Act - do whatever the flyingplatform wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { moveplayerleftright(); moveplatformleftright(); moveplatformupdown( 300 , 400 ); } public void moveplayerleftright() { Actor player = (Actor) getWorld().getObjects(Player. class ).get( 0 ); Actor flyer1 = (Actor) getWorld().getObjects(flyingplatform. class ).get( 0 ); if ((player.getX() == flyer1.getX() - 10 && player.getY() < 545 ) || (player.getX() == flyer1.getX() + 10 && player.getY() < 545 )) { gelijk = true ; } if (gelijk) { player.setLocation(flyer1.getX(), flyer1.getY() - 25 ); } if (Greenfoot.isKeyDown( "left" ) || Greenfoot.isKeyDown( "right" ) || Greenfoot.isKeyDown( "z" )) { gelijk = false ; } } public void moveplatformleftright(){ Actor flyer1a = (Actor) getWorld().getObjects(flyingplatform. class ).get( 0 ); if (flyer1a.getX() >= 320 ) { flyer1a.move(- 1 ); } else if (flyer1a.getX() <= 320 ){ flyer1a.setRotation( 180 ); flyer1a.move(- 1 ); flyer1a.setImage(platformright); } if (flyer1a.getX() >= 460 && flyer1a.getX() <= 466 ) { flyer1a.setRotation( 0 ); flyer1a.move(- 1 ); flyer1a.setImage(platformleft); } } public void moveplayerupdown() { Actor player = (Actor) getWorld().getObjects(Player. class ).get( 0 ); Actor flyer2 = (Actor) getWorld().getObjects(flyingplatform. class ).get( 1 ); if ((player.getX() == flyer2.getX() - 10 && player.getY() < 545 ) || (player.getX() == flyer2.getX() + 10 && player.getY() < 545 )) { gelijk = true ; } if (gelijk) { player.setLocation(flyer2.getX(), flyer2.getY() - 25 ); } if (Greenfoot.isKeyDown( "left" ) || Greenfoot.isKeyDown( "right" ) || Greenfoot.isKeyDown( "z" )) { gelijk = false ; } } public void moveplatformupdown( int Ya, int Yb){ Actor flyer2 = (Actor) getWorld().getObjects(flyingplatform. class ).get( 1 ); Actor player = (Actor) getWorld().getObjects(Player. class ).get( 0 ); minimumY = Ya; maximumY = Yb; direction = 1 ; if (flyer2.getY() <= minimumY) direction = 1 ; if (flyer2.getY() >= maximumY) direction = - 1 ; setLocation(flyer2.getX(), flyer2.getY() + direction); } } |