Trying to create colour detection in order to make accurate collision detection with the floor. My character code is here:
I'm getting an error here "if(img.getColorAt(getX(), getY() + 24).cLevel.getRGB().equals("FF00FF00"))", with the error saying cannot find variable cLevel
P.S. I'm working in version 3.0.4
P.P.S I'm very new here so just tell me if anything is wrong please
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 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)import java.awt.Color;/** * Write a description of class Character here. * * @author (your name) * @version (a version number or a date) */public class Character extends Actor{ private int Speed = 0; private int acceleration = 1; private boolean jumping; private int jumpStrength = 11; private int speed = 2; /** * Act - do whatever the Character wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { Movement(); checkFall(); } public void Movement() { if (Greenfoot.isKeyDown("d")) { move(3); } if (Greenfoot.isKeyDown("a")) { move(-3); } if (Greenfoot.isKeyDown("w") && jumping == false) { Jump(); } } public void Jump() { Speed = Speed - jumpStrength; jumping = true; Fall(); } public void Fall() { setLocation(getX(), getY() + Speed); if (Speed <= 9) { Speed = Speed + acceleration; } jumping = true; } public void checkFall() { Level1 level1 = getWorldOfType(Level1.class); GreenfootImage img = level1.getBackground(); java.awt.Color cLevel = img.getColorAt(getX(), getY()); if(img.getColorAt(getX(), getY() + 24).cLevel.getRGB().equals("FF00FF00")) { Speed = 0; jumping = false; } else { Fall(); } }} |
