Sei sulla pagina 1di 26

SOURCE CODE GAME GREENFOOT BALAPAN

Script World rumput :


import greenfoot.*;

/**
* Write a description of class rumput here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class rumput extends World
{
public static GreenfootSound abc;
/**
* Constructor for objects of class rumput.
*
*/
public rumput()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(600, 400, 1);
setPaintOrder(crash.class,bangunan1.class,bangunan2.class,bangunan3.clas
s,bangunan4.class,lampu1.class,pohon1.class,mobil1.class,mobil2.class,koin.
class,aspal.class,point.class,tombol.class);
prepare();

}
int i=1000;
public void act()
{
i++;
if (i%840==0)
{
abc = new GreenfootSound("awal.wav");
abc.play();
}

}
private void prepare()
{

bangunan1 bangunan1 = new bangunan1();


addObject(bangunan1, 75, 83);
bangunan2 bangunan2 = new bangunan2();
addObject(bangunan2, 88, 324);
bangunan3 bangunan3 = new bangunan3();
addObject(bangunan3, 524, 92);
bangunan4 bangunan4 = new bangunan4();
addObject(bangunan4, 71, 333);
bangunan4.setLocation(71, 195);
bangunan2.setLocation(528, 319);

bangunan4.setLocation(75, 312);
pohon1 pohon1 = new pohon1();
addObject(pohon1, 595, 106);
bangunan2.setLocation(527, 339);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);

pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
lampu1 lampu1 = new lampu1();
addObject(lampu1, 164, 172);
bangunan1.setLocation(72, 111);
lampu1.setLocation(153, 134);
bangunan4.setLocation(81, 301);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);

pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);
pohon1.setLocation(595, 106);

removeObject(pohon1);
bangunan3.setLocation(67, 286);
bangunan4.setLocation(522, 71);
bangunan3.setLocation(67, 303);
bangunan1.setLocation(73, 97);
removeObject(bangunan4);
bangunan4 bangunan42 = new bangunan4();
addObject(bangunan42, 97, 325);
bangunan42.setLocation(102, 341);
bangunan42.setLocation(507, 75);
bangunan3.setLocation(553, 107);
bangunan42.setLocation(91, 309);
bangunan3.setLocation(517, 87);
removeObject(bangunan3);
bangunan3 bangunan32 = new bangunan3();
addObject(bangunan32, 519, 96);
removeObject(bangunan2);
pohon1 pohon12 = new pohon1();
pohon1 pohon13 = new pohon1();
addObject(pohon13, 594, 94);
lampu1.setLocation(153, 184);
bangunan1.setLocation(71, 79);
pohon13.setLocation(598, 92);
bangunan2 bangunan22 = new bangunan2();
addObject(bangunan22, 493, 88);

bangunan22.setLocation(416, 85);
bangunan32.setLocation(528, 61);
bangunan22.setLocation(515, 327);
bangunan32.setLocation(513, 62);
pohon1 pohon14 = new pohon1();
addObject(pohon14, 595, 63);
lampu1.setLocation(155, 100);
bangunan1.setLocation(62, 95);
lampu1.setLocation(155, 113);
bangunan42.setLocation(91, 296);
removeObject(bangunan1);
lampu1.setLocation(159, 127);
bangunan22.setLocation(75, 77);
lampu1.setLocation(157, 129);
bangunan2 bangunan23 = new bangunan2();
addObject(bangunan23, 511, 69);
removeObject(bangunan23);
bangunan2 bangunan24 = new bangunan2();
addObject(bangunan24, 85, 80);
lampu1.setLocation(161, 137);
bangunan24.setLocation(77, 80);
bangunan3 bangunan33 = new bangunan3();
addObject(bangunan33, 521, 72);
bangunan4 bangunan43 = new bangunan4();
addObject(bangunan43, 99, 293);

bangunan43.setLocation(83, 280);
lampu1.setLocation(160, 156);
removeObject(bangunan43);
bangunan4 bangunan44 = new bangunan4();
addObject(bangunan44, 114, 304);
removeObject(bangunan44);
removeObject(bangunan24);
removeObject(bangunan33);
bangunan42.setLocation(527, 331);
removeObject(pohon13);
pohon12.setLocation(599, 71);
pohon12.setLocation(599, 71);
bangunan42.setLocation(527, 319);
addObject(bangunan1, 94, 304);
bangunan22.setLocation(74, 84);
lampu1.setLocation(160, 150);
bangunan1.setLocation(89, 275);
pohon12.setLocation(599, 58);
mobil1 mobil1 = new mobil1();
addObject(mobil1, 266, 361);
mobil2 mobil2 = new mobil2();
addObject(mobil2, 324, 52);
point point = new point();
addObject(point, 520, 23);

}
}
Script World menu
import greenfoot.*;

/**
* Write a description of class main_menu here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class menu extends World

{
public static GreenfootSound titleSound;
/**
* Constructor for objects of class main_menu.
*
*/

public menu()
{
super(600, 400, 1);
if (this.getClass().getName().equalsIgnoreCase("this"))

prepare();
titleSound = new GreenfootSound("background.mp3");
titleSound.stop();
titleSound.setVolume(30);
titleSound.playLoop();
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()
{
tombol tombol = new tombol();
addObject(tombol, 554, 374);
tombol.setLocation(554, 362);
tombol.setLocation(554, 367);
tombolstart tombolstart = new tombolstart();
addObject(tombolstart, 565, 375);
tombolstart.setLocation(564, 365);
}
}
Script Actor desain pada lampu1 :

import greenfoot.*;

/**
* Write a description of class lampu1 here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class lampu1 extends desain
{
/**
* Act - do whatever the lampu1 wants to do. This method is called
whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
setLocation(getX(),getY()+4);
if(isAtEdge()){
setLocation(getX(),0);
}
}
}
Script Actor desain pada pohon1 :
import greenfoot.*;

/**
* Write a description of class pohon1 here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class pohon1 extends desain
{
/**
* Act - do whatever the pohon1 wants to do. This method is called
whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
setLocation(getX(),getY()+4);
if(isAtEdge()){
setLocation(getX(),0);
}
}
}
Script Actor desain pada bangunan1 :
import greenfoot.*;

/**
* Write a description of class bangunan1 here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class bangunan1 extends desain
{
/**
* Act - do whatever the bangunan1 wants to do. This method is called
whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
setLocation(getX(),getY()+4);
if(isAtEdge()){
setLocation(getX(),0);
}
}
}
Script Actor desain pada bangunan2 :
import greenfoot.*;

/**

* Write a description of class bangunan1 here.


*
* @author (your name)
* @version (a version number or a date)
*/
public class bangunan1 extends desain
{
/**
* Act - do whatever the bangunan1 wants to do. This method is called
whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
setLocation(getX(),getY()+4);
if(isAtEdge()){
setLocation(getX(),0);
}
}
}
Script Actor desain pada bangunan3 :
import greenfoot.*;

/**
* Write a description of class bangunan1 here.

*
* @author (your name)
* @version (a version number or a date)
*/
public class bangunan1 extends desain
{
/**
* Act - do whatever the bangunan1 wants to do. This method is called
whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
setLocation(getX(),getY()+4);
if(isAtEdge()){
setLocation(getX(),0);
}
}
}
Script Actor desain pada bangunan4 :
import greenfoot.*;

/**
* Write a description of class bangunan1 here.
*

* @author (your name)


* @version (a version number or a date)
*/
public class bangunan1 extends desain
{
/**
* Act - do whatever the bangunan1 wants to do. This method is called
whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
setLocation(getX(),getY()+4);
if(isAtEdge()){
setLocation(getX(),0);
}
}
}
Script Actor tombol pada tombolstart :
import greenfoot.*;
/**
* Write a description of class btn_start here.
*
* @author (your name)
* @version (a version number or a date)

*/

public class tombolstart extends tombol

{
/**
* Act - do whatever the btn_start wants to do. This method is called
whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
// Add your action code here.
super.act(this.getClass().getName());
}
}
Script Actor jalanan pada koin :
import greenfoot.*;

/**
* Write a description of class koin here.
*
* @author (your name)
* @version (a version number or a date)
*/

public class koin extends jalanan


{
/**
* Act - do whatever the koin wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
World koin;
public void act()
{
setLocation(getX(),getY()+4);
koin = getWorld();
if (isAtEdge()) {
koin.removeObject(this);
}
}
}
Script Actor jalanan pada aspal :
import greenfoot.*;

/**
* Write a description of class aspal here.
*
* @author (your name)
* @version (a version number or a date)
*/

public class aspal extends jalanan


{
/**
* Act - do whatever the aspal wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
setLocation(getX(),getY()+4);
if(isAtEdge()){
setLocation(getX(),0);
}
}
}
Script Actor jalanan pada point :
import greenfoot.*;
import java.awt.Color;
import java.util.List;
/**
* Write a description of class point here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class point extends jalanan

{
/**
* Act - do whatever the point wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
// Add your action code here.
}
}
Script Actor jalanan pada mobil1 :
import greenfoot.*;
import java.awt.Color;

/**
* Write a description of class mobil1 here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class mobil1 extends jalanan
{
/**
* Act - do whatever the mobil1 wants to do. This method is called
whenever

* the 'Act' or 'Run' button gets pressed in the environment.


*/
public static GreenfootSound abc;
int count=0;
int score=0;
public void act()
{
if (count==80) {
getWorld().addObject(new
mobil2(),Greenfoot.getRandomNumber(180)+200,0);
getWorld().addObject(new
koin(),Greenfoot.getRandomNumber(180)+200,0);
count=0;

}
else {
count++;
}

if (isTouching(mobil2.class)) {
Greenfoot.stop();
getWorld().addObject(new crash(),300,200);
Greenfoot.playSound("crash.wav");
}
if (isTouching(koin.class)) {
getWorld().removeObjects(getWorld().getObjects(koin.class));

score++;
String scorestring=""+score;
GreenfootImage g = new GreenfootImage("Score : "+scorestring, 40,
Color.red, null);
point a = (point) getWorld().getObjects(point.class).get(0);
a.setImage(g);
Greenfoot.playSound("koin.wav");
}
else {
if (getX()>=200 && getX()<=380) {
if (Greenfoot.isKeyDown("left")) {
move(-3);
abc = new GreenfootSound("mobil1.mp3");
abc.play();
}
if (Greenfoot.isKeyDown("right")) {
move(3);
abc = new GreenfootSound("mobil1.mp3");
abc.play();
}
if (Greenfoot.isKeyDown("up")) {
setLocation(getX(),getY()-1);
abc = new GreenfootSound("mobil1.mp3");
abc.play();
}

if (Greenfoot.isKeyDown("down")) {
setLocation(getX(),getY()+1);
abc = new GreenfootSound("mobil1.mp3");
abc.play();
}
}
else if (getX()<200){
if (Greenfoot.isKeyDown("right")) {
move(3);
}
if (Greenfoot.isKeyDown("up")) {
setLocation(getX(),getY()-1);
}
if (Greenfoot.isKeyDown("down")) {
setLocation(getX(),getY()+1);
}
}
else {
if (Greenfoot.isKeyDown("left")) {
move(-3);
}
if (Greenfoot.isKeyDown("up")) {
setLocation(getX(),getY()-1);
}
if (Greenfoot.isKeyDown("down")) {

setLocation(getX(),getY()+1);
}
}
}

}
}
Script Actor jalanan pada mobil2 :
import greenfoot.*;

/**
* Write a description of class mobil2 here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class mobil2 extends jalanan
{
/**
* Act - do whatever the mobil2 wants to do. This method is called
whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
private int count=0;
World mobil2;

public void act()


{
setLocation(getX(),getY()+2);
mobil2 = getWorld();
if (isAtEdge()) {
mobil2.removeObject(this);
}
}
}
Script Actor crash :
import greenfoot.*;

/**
* Write a description of class crash here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class crash extends Actor
{
/**
* Act - do whatever the crash wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()

{
// Add your action code here.
}
}

Potrebbero piacerti anche