This site requires JavaScript, please enable it in your browser!
Greenfoot back
jason.sahli@gmail.com
jason.sahli@gmail.com wrote ...

2012/9/17

RE Here is the code I have been having trouble with-Davmac.

import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class ball here. * * @author (your name) * @version (a version number or a date) */ public class ball extends Actor { /** * Act - do whatever the ball wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { move(4); if (atWorldEdge()){ turn(153); } } /** * Test if we are close to one of the edges of the world. Return true is we are. */ public boolean atWorldEdge() { if(getX() < 10 || getX() > getWorld().getWidth() - 10) return true; if(getY() < 10 || getY() > getWorld().getHeight() - 10) return true; else return false; } }
davmac davmac

2012/9/17

#
There's nothing wrong with this code. The best bet is to upload the whole scenario. Use the 'Share' button in the main Greenfoot window.
You need to login to post a reply.