Uploaded by s4tr1o.n4nd1t0

coding game sederhana

advertisement
(("IKI CODING AKTOR"))
public void act()
{
KontrolKey();
ambil();
meledak();
menang();
}
public void KontrolKey()
{
if(Greenfoot.isKeyDown("right"))
{
move(5);
}
if(Greenfoot.isKeyDown("left"))
{
move(-5);
}
}
public void ambil()
{
if(isTouching(stoberi.class))
{
removeTouching(stoberi.class);
Greenfoot.playSound("cling.wav");
langit.score.add(3);
getWorld().addObject(new stoberi(), Greenfoot.getRandomNumber(getWorld().getWidth()),0);
}
if(isTouching(pelem.class))
{
removeTouching(pelem.class);
Greenfoot.playSound("cling.wav");
langit.score.add(2);
getWorld().addObject(new pelem(), Greenfoot.getRandomNumber(getWorld().getWidth()),0);
}
if(isTouching(anggur.class))
{
removeTouching(anggur.class);
Greenfoot.playSound("cling.wav");
langit.score.add(4);
getWorld().addObject(new anggur(), Greenfoot.getRandomNumber(getWorld().getWidth()),0);
}
if(isTouching(gedang.class))
{
removeTouching(gedang.class);
Greenfoot.playSound("cling.wav");
langit.score.add(1);
getWorld().addObject(new gedang(), Greenfoot.getRandomNumber(getWorld().getWidth()),0);
}
if(isTouching(semongko.class))
{
removeTouching(semongko.class);
Greenfoot.playSound("cling.wav");
langit.score.add(5);
getWorld().addObject(new semongko(),
Greenfoot.getRandomNumber(getWorld().getWidth()),0);
}
}
public void meledak()
{
if(isTouching(bom.class))
{
removeTouching(bom.class);
getWorld().addObject(new blast(),getX(),getY());
Greenfoot.playSound("duar1.wav");
getWorld().addObject(new bom(), Greenfoot.getRandomNumber(getWorld().getWidth()),0);
}
}
}
IKI CODING BUAH
public void act()
{
// Add your action code here.
{
setLocation(getX(),getY()+4);
if(isAtEdge())
setLocation(Greenfoot.getRandomNumber(getWorld().getWidth()),0);
}
}
}
IKI CODING BOM
int x=2;
public void act()
{
// Add your action code here.
{
setLocation(getX(),getY()+4);
if(isAtEdge())
setLocation(Greenfoot.getRandomNumber(getWorld().getWidth()),0);
}
if(isTouching(aktor.class))
{
langit.nyawa.add(-1);
if(langit.nyawa.getValue()==0)
{
getWorld().addObject(new gameover(),getWorld().getWidth()/2, getWorld().getHeight()/2);
removeTouching(aktor.class);
}
}
}
}
IKI CODING LANGIT SEK SCORE KARO NYAWA
public static Counter score = new Counter("Score:");
public static Counter nyawa = new Counter("Nyawa:");
Download