A new version of this scenario was uploaded on Sun Oct 07 21:54:14 UTC 2012
You are the blue ball.
Shoot the Yellow balls to get points.
Normal red balls are neutral and will knock you about, don't shoot them or you will lose points.
Red flaming balls will give you more points, but they are dangerous, look out!
Ghost balls can only knock you about
Controls:
Turn left - Left arrow
Turn right - Right arrow
Shoot - Space or Down arrow
Pause - P
A new version of this scenario was uploaded on Mon Oct 08 18:53:29 UTC 2012
SOUND!
MUSIC!
Warning:Very loud put your sound level down before pressing play!
bugs:Balls might get stuck in walls and play an annoying loop of sound
import greenfoot.*; // (CrabWorld, ScoreBoard)
import java.awt.Color;
import java.util.List;
/**
* An actor class that can display a scoreboard, using Greenfoot's
* UserInfo class.
*
* You typically use this by including some code into the world for when your game ends:
*
* <pre>
* addObject(new ScoreBoard(800, 600), getWidth() / 2, getHeight() / 2);
* </pre>
*
* Where 800 by 600 should be replaced by the desired size of the score board.
*
* @author Neil Brown
* @version 1.0
*/
public class ScoreBoard extends Actor
{
// The vertical gap between user images in the scoreboard:
private static final int GAP = 10;
// The height of the "All Players"/"Near Me" text at the top:
private static final int HEADER_TEXT_HEIGHT = 25;
// The main text color:
private static final Color MAIN_COLOR = new Color(0x60, 0x60, 0x60); // dark grey
// The score color:
private static final Color SCORE_COLOR = new Color(0xB0, 0x40, 0x40); // orange-y
// The background colors:
private static final Color BACKGROUND_COLOR = new Color(0xFF, 0xFF, 0xFF, 0xB0);
private static final Color BACKGROUND_HIGHLIGHT_COLOR = new Color(180, 230, 255, 0xB0);
/**
* Constructor for objects of class ScoreBoard.
* <p>
* You can specify the width and height that the score board should be, but
* a minimum width of 600 will be enforced.
*/
public ScoreBoard(int width, int height)
{
setImage(new GreenfootImage(Math.max(600, width), height));
drawScores();
}
private void drawString(String text, int x, int y, Color color, int height)
{
getImage().drawImage(new GreenfootImage(text, height, color, new Color (0, true)), x, y);
}
private void drawScores()
{
// 50 pixels is the max height of the user image
final int pixelsPerUser = 50 + 2*GAP;
// Calculate how many users we have room for:
final int numUsers = ((getImage().getHeight() - (HEADER_TEXT_HEIGHT + 10)) / pixelsPerUser);
final int topSpace = getImage().getHeight() - (numUsers * pixelsPerUser) - GAP;
getImage().setColor(BACKGROUND_COLOR);
getImage().fill();
drawString("All Players", 100, topSpace - HEADER_TEXT_HEIGHT - 5, MAIN_COLOR, HEADER_TEXT_HEIGHT);
drawString("Near You", 100 + getImage().getWidth() / 2, topSpace - HEADER_TEXT_HEIGHT - 5, MAIN_COLOR, HEADER_TEXT_HEIGHT);
drawUserPanel(GAP, topSpace, (getImage().getWidth() / 2) - GAP, topSpace + numUsers * pixelsPerUser, UserInfo.getTop(numUsers));
drawUserPanel(GAP + getImage().getWidth() / 2, topSpace, getImage().getWidth() - GAP, topSpace + numUsers * pixelsPerUser, UserInfo.getNearby(numUsers));
}
private void drawUserPanel(int left, int top, int right, int bottom, List users)
{
getImage().setColor(MAIN_COLOR);
getImage().drawRect(left, top, right - left, bottom - top);
if (users == null)
return;
UserInfo me = UserInfo.getMyInfo();
int y = top + GAP;
for (Object obj : users)
{
UserInfo playerData = (UserInfo)obj;
Color c;
if (me != null && playerData.getUserName().equals(me.getUserName()))
{
// Highlight our row in a sky blue colour:
c = BACKGROUND_HIGHLIGHT_COLOR;
}
else
{
c = BACKGROUND_COLOR;
}
getImage().setColor(c);
getImage().fillRect(left + 5, y - GAP + 1, right - left - 10, 50 + 2*GAP - 1);
int x = left + 10;
drawString("#" + Integer.toString(playerData.getRank()), x, y+18, MAIN_COLOR, 14);
x += 50;
drawString(Integer.toString(playerData.getScore()), x, y+18, SCORE_COLOR, 14);
x += 80;
getImage().drawImage(playerData.getUserImage(), x, y);
x += 55;
drawString(playerData.getUserName(), x, y + 18, MAIN_COLOR, 14);
y += 50 + 2*GAP;
}
}
}
heres my whole scoreboard
import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot)
import java.awt.Color;
import java.awt.Font;
import java.util.Calendar;
/**
* The ScoreBoard is used to display results on the screen. It can display some
* text and several numbers.
*
* @author M Kolling
* @version 1.0
*/
public class GameOver extends Actor
{
public static final float FONT_SIZE = 48.0f;
public static final int WIDTH = 400;
public static final int HEIGHT = 300;
int SCORE=0;
/**
* Create a score board with dummy result for testing.
*/
public GameOver()
{
this(100);
}
/**
* Create a score board for the final result.
*/
public GameOver(int score)
{
makeImage("Game Over", "Score: ", "Press enter", score);
SCORE=score;
}
/**
* Make the score board image.
*/
private void makeImage(String title, String prefix, String prefix2, int score)
{
GreenfootImage image = new GreenfootImage(WIDTH, HEIGHT);
image.setColor(new Color(255,255,255, 128));
image.fillRect(0, 0, WIDTH, HEIGHT);
image.setColor(new Color(0, 0, 0, 128));
image.fillRect(5, 5, WIDTH-10, HEIGHT-10);
Font font = image.getFont();
font = font.deriveFont(FONT_SIZE);
image.setFont(font);
image.setColor(Color.WHITE);
image.drawString(title, 60, 100);
image.drawString(prefix + score, 60, 200);
image.drawString(prefix2, 60, 250);
setImage(image);
}
public void act()
{
if(Greenfoot.isKeyDown("enter")){
Worldy worldy = (Worldy) getWorld();
worldy.scoreboard(SCORE);
getWorld().removeObject(this);
}
if(Greenfoot.isKeyDown("e")){
Worldy worldy = (Worldy) getWorld();
worldy.scoreboard(SCORE);
getWorld().removeObject(this);
}
}
}
the game over
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class Crab extends Actor
{
private int points= 0;
private Counter counter;
public Crab(Counter pointCounter)
{
counter = pointCounter; //Saves the reference to Counter.class in the variable counter
}
/**
* Act - do whatever the Crab wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
move(4);
if (Greenfoot.isKeyDown("left"))
{
turn (-3);
}
if (Greenfoot.isKeyDown("right"))
{
turn(3);
}
{Actor worm;
worm = getOneObjectAtOffset(0 ,0, worm.class);
if (worm != null)
{
World world;
world = getWorld();
world.removeObject(worm);
if (getWorld().getObjects(worm.class).isEmpty())
{
//levelup();
}
counter.add(5);
}
}
}
public void gameOver()
{
CrabWorld crabworld = (CrabWorld) getWorld();
getWorld().addObject(new GameOver(points),450, 375);
}
}
the crab
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class CrabWorld here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class CrabWorld extends World
{
/**
* Constructor for objects of class CrabWorld.
*
*/
public CrabWorld()
{
super(560, 560, 1);
prepare();
}
/**
* Prepare the world for the start of the program. That is: create the initial
* objects and add them to the world.
*/
private void prepare()
{
Counter counter = new Counter();
addObject(counter, 84, 44);
worm worm = new worm();
addObject(worm, 166, 62);
worm worm2 = new worm();
addObject(worm2, 363, 174);
worm worm3 = new worm();
addObject(worm3, 409, 287);
worm worm4 = new worm();
addObject(worm4, 131, 57);
worm worm5 = new worm();
addObject(worm5, 104, 42);
worm worm6 = new worm();
addObject(worm6, 81, 39);
worm worm7 = new worm();
addObject(worm7, 59, 50);
worm worm8 = new worm();
addObject(worm8, 26, 37);
worm worm9 = new worm();
addObject(worm9, 421, 324);
worm.setLocation(278, 397);
worm4.setLocation(109, 432);
worm5.setLocation(504, 80);
worm7.setLocation(20, 238);
worm8.setLocation(208, 264);
worm6.setLocation(231, 64);
worm9.setLocation(473, 453);
lobster lobster = new lobster();
addObject(lobster, 433, 97);
lobster.setLocation(81, 302);
Crab crab = new Crab(counter);
addObject(crab, 102, 310);
crab.setLocation(515, 153);
crab.setLocation(493, 305);
counter.setLocation(84, 44);
counter.setLocation(84, 44);
counter.setLocation(84, 44);
counter.setLocation(84, 44);
counter.setLocation(84, 44);
counter.setLocation(84, 44);
counter.setLocation(84, 44);
counter.setLocation(84, 44);
counter.setLocation(84, 44);
counter.setLocation(84, 44);
counter.setLocation(84, 44);
counter.setLocation(84, 44);
counter.setLocation(84, 44);
counter.setLocation(84, 44);
counter.setLocation(84, 44);
counter.setLocation(84, 44);
counter.setLocation(84, 44);
counter.setLocation(84, 44);
counter.setLocation(37, 7);
counter.setLocation(42, 14);
worm worm10 = new worm();
addObject(worm10, 70, 143);
}
public void scoreboard(int SCORE)
{
addObject(new ScoreBoard(600, 600), getWidth() / 2, getHeight() / 2);
if (UserInfo.isStorageAvailable()) {//test to see if your data is avalable(logged in)
UserInfo myInfo = UserInfo.getMyInfo();// set myInfo to UserInfo
if (SCORE> myInfo.getScore()) //test to see if your score is better than your last
{
myInfo.setScore(SCORE);//set the score to your info
myInfo.store();// store the info
}
}
Score=SCORE;
}
}
the crabworld
2012/10/7
2012/10/8
2012/10/8
2012/10/8
2012/10/16
2012/10/16
2012/10/18
2012/10/18
2012/10/18
2012/10/19
2012/10/19
2012/10/19
2012/10/19
2012/10/19
2012/10/19
2012/10/19
2012/10/19
2012/10/19
2012/10/19
2012/10/19
2012/10/19
2012/10/19
2012/10/19
2012/10/19
2012/10/19
2012/10/19
2012/10/19
2012/10/19
2012/10/19
2012/10/19
2012/10/19
2012/10/19
2012/10/19
2012/10/19
2012/10/19
2012/10/20
2012/11/3