Monday, 4 March 2013

Programming time!

I have been using a program called Greenfoot to make small games and animations, I would love to show you my ideas and explain them to you. :)

I have made a game where you are the crab and you have to eat the worms, but there is also a randomly moving crab, this has been used from the greenfoot website but I have tweaked it a bit.

Let me tell you a bit about Greenfoot:
The code should be compiled after it is written, this checks all of the data entered is relevant to the language you are writing in (in this case Java)

Once the compiling has finished it will say one of two things; either no-syntax errors, which means there are no errors in your work, which is great! Or it could say not a statement and highlight the error for you to change.

There are also three buttons at the bottom of the screen; act, run and reset:
  • Act - This means the system will do 'one lot' of the code that you have written and demonstrate the movement.
  • Run - This means the system will run the code over and over again to make the simulation/game work and for you to test.
  •  Reset - This means it will reset the characters and background to the original format. 
I have explained two basic practices for you:
Enjoy!

1. Basic movement 
 This script tells the computer how to move the current character (or actor in greenfoot terms) around the screen.  In this example the crab (the actor I'm using) will move continuously and only turn when the user tells it to. As you can see it says

if (Greenfoot.isKeyDown("left"))
{
    turn(-3);
 }  


This means when the left arrow is pressed the actor turns anti clockwise, the number ( in this case 3) tells the computer how fast to move around. This script is the same for the right arrow and uses + 3 to turn the actor clockwise.

2. Random enemies
This script tells the computer how to move the current enemy selected so it moves randomly around the screen. As you can see it says:
if (Greenfoot.getrandomNumber(100) <10)
{
turn(Greenfoot.get randomNumber(90| - 95);
}

This tells the computer how to move the enemy around randomly and if touching the player, it should vanish.

If you want to have a go yourself, follow this link to the website to download it for FREE!
http://www.greenfoot.org/download



No comments:

Post a Comment