So I am making a 2D fighter game and I want to have my players run down and up hills falls into holes etc. I only have one world right now but there is a big hole in the center where you drop. The problem is my gravity uses if Touching and if it is touching then it falls if it doesn't then it stays up. But the problem is it detects transparency. So it is just floating in mid air. I have found Pixel Pefectiong but I don't know how to include that in my code. Here is my code as of now:
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 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Shooter here. * * @author (your name) * @version (a version number or a date) */ public class Fighter extends Actor { /** * Act - do whatever the Shooter wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public int damage; public int level; private boolean facingLeft; private int waitCycle; private boolean gravityOn = true ; private GreenfootImage image1 = new GreenfootImage( "step1Right.png" ); private GreenfootImage image2 = new GreenfootImage( "step2Right.png" ); private GreenfootImage image3 = new GreenfootImage( "step1Left.png" ); private GreenfootImage image4 = new GreenfootImage( "step2Left.png" ); public void act() { checkKeys(); gravity(); } public void checkKeys() { if (Greenfoot.isKeyDown( "d" ) && !Greenfoot.isKeyDown( "a" )){ facingLeft = false ; moveRight(); } if (Greenfoot.isKeyDown( "a" ) && !Greenfoot.isKeyDown( "d" )){ facingLeft = true ; moveLeft(); } if (Greenfoot.isKeyDown( "space" )){ } } public void moveRight() { waitCycle++; if (waitCycle== 30 ) waitCycle= 0 ; move( 5 ); if (waitCycle== 0 ) setImage(image1); if (waitCycle== 15 ) setImage(image2); } public void moveLeft() { waitCycle++; if (waitCycle== 30 ) waitCycle= 0 ; move(- 5 ); if (waitCycle== 0 ) setImage(image3); if (waitCycle== 15 ) setImage(image4); } public void animateRight() { if (getImage().equals(image1)){ setImage(image2); } if (getImage().equals(image2)){ setImage(image1); } } public void gravity() { if (gravityOn = true ){ if (getIntersectingObjects(Tunnel. class ).isEmpty()) this .setLocation(getX(), getY() + 1 ); } } public void attack() { if (level == 0 ){ damage = 5 ; } if (level == 1 ){ damage = 6 ; } if (level == 2 ){ damage = 7 ; } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Tunnel here. * * @author (your name) * @version (a version number or a date) */ public class Tunnel extends Actor { /** * Act - do whatever the Tunnel wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { // Add your action code here. } } |