Hello,
I have this computer science project in high school. I am a beginner, and am in grade 11. Here is my Greenfoot programs:
I want to make my character stop when it collides with the wall. The wall is a background image, in black, and the path is white. Can I do this?
If I cant, how do I make an object, like a wall. I'm making a maze, and want to control the character through it. This game is in 2d.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.awt.Color; /** * Write a description of class You here. * * @author (your name) * @version (a version number or a date) */ public class You extends Actor { /** * Act - do whatever the You wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { checkKeys(); } /** * Check whether there are any key pressed and react to them. */ private void checkKeys() { if (Greenfoot.isKeyDown("up") && canMove()) { move(1); } if(Greenfoot.isKeyDown("left") ) { setRotation(getRotation() - 5); } if(Greenfoot.isKeyDown("right")) { setRotation(getRotation() + 5); } } private boolean canMove() { if (getColor() !== Black)) { return true; } else { return false; } } }