Commit f50676ae authored by Daffa Mudia Athifah's avatar Daffa Mudia Athifah
Browse files

upload

parent b88c7672
No related merge requests found
Showing with 361 additions and 0 deletions
+361 -0
File added
#BlueJ class context
comment0.target=Bee
comment0.text=\r\n\ Write\ a\ description\ of\ class\ Bee\ here.\r\n\ \r\n\ @author\ (Daffa\ Mudia\ Athifah)\ \r\n\ NIM\ (V3420022)\r\n\ @version\ (a\ version\ number\ or\ a\ date)\r\n
comment1.params=
comment1.target=Bee()
comment2.params=
comment2.target=void\ animate()
comment3.params=
comment3.target=void\ act()
comment4.params=
comment4.target=void\ handleMovement()
comment5.params=
comment5.target=void\ eatFly()
comment6.params=
comment6.target=void\ atTepi()
comment7.params=
comment7.target=void\ caughtBySpider()
comment8.params=
comment8.target=void\ tampilkanLives()
numComments=9
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Bee here.
*
* @author (Daffa Mudia Athifah)
* NIM (V3420022)
* @version (a version number or a date)
*/
public class Bee extends Actor
{
/**
* Act - do whatever the Bee wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
int Score = 0;
int Lives = 3;
int animateImage = 0;
int count;
private GreenfootImage image1;
private GreenfootImage image2;
public Bee()
{
image1 = new GreenfootImage("bee0.png");
image2 = new GreenfootImage("bee1.png");
setImage(image1);
}
public void animate()
{
if (count % 4 == 0)
{
setImage("bee" + animateImage +".png");
animateImage++;
if(animateImage == 2)
{
animateImage = 0;
}
}
}
public void act()
{
// Add your action code here.
handleMovement();
eatFly();
atTepi();
caughtBySpider();
tampilkanLives();
animate();
}
public void handleMovement()
{ move(4);
if(Greenfoot.isKeyDown("right"))
{
turn(2);
}
if (Greenfoot.isKeyDown("left"))
{
turn(-2);
}
}
public void eatFly()
{
Actor getFly =getOneIntersectingObject(Fly.class);
if(getFly !=null)
{
getWorld().removeObject(getFly);
Greenfoot.playSound("slurp.wav");
getWorld().addObject(new Fly(Greenfoot.getRandomNumber(4)+1),Greenfoot.getRandomNumber(690)+0,Greenfoot.getRandomNumber(490)+0);
BeeWorld myworld= (BeeWorld)getWorld();
myworld.updateScore();
}
}
public void atTepi()
{
if(getX() <= 10)
{
setLocation(getWorld().getWidth()-10, getY());
}
else if(getX() >= 690)
{
setLocation(10, getY());
}
else if(getY() <= 10)
{
setLocation(getX(), getWorld().getHeight()-10);
}
else if(getY() >= 490)
{
setLocation(getX(), 10);
}
}
public void caughtBySpider()
{
if(isTouching(Spider.class))
{
setLocation(30,30);
Lives--;
if(Lives <= 0)
{
Greenfoot.stop();
getWorld().showText("GAME OVER", getWorld().getWidth()/2, getWorld().getHeight()/2);
}
}
}
public void tampilkanLives()
{
getWorld().showText("Lives : " + Lives, 650, 80);
}
}
File added
#BlueJ class context
comment0.target=BeeWorld
comment0.text=\r\n\ Write\ a\ description\ of\ class\ MyWorld\ here.\r\n\ \r\n\ @author\ (Daffa\ Mudia\ Athifah)\ \r\n\ NIM\ (V3420022)\r\n\ @version\ (a\ version\ number\ or\ a\ date)\r\n
comment1.params=
comment1.target=BeeWorld()
comment2.params=
comment2.target=void\ prepare()
comment2.text=\r\n\ Prepare\ the\ world\ for\ the\ start\ of\ the\ program.\r\n\ That\ is\:\ create\ the\ initial\ objects\ and\ add\ them\ to\ the\ world.\r\n
comment3.params=
comment3.target=void\ updateScore()
comment4.params=
comment4.target=void\ updateTimer()
comment5.params=
comment5.target=void\ act()
numComments=6
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class MyWorld here.
*
* @author (Daffa Mudia Athifah)
* NIM (V3420022)
* @version (a version number or a date)
*/
public class BeeWorld extends World
{
public Bee mainBee = new Bee();
/**
* Constructor for objects of class MyWorld.
*/
private int Score = 0;
private Bee bee = new Bee();
public BeeWorld()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(700, 500, 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()
{
addObject(mainBee,30,30);
for (int i = 0 ; i < 10 ; i++)
{
int xCoord = Greenfoot.getRandomNumber(getWidth());
int yCoord = Greenfoot.getRandomNumber(getHeight());
addObject(new Fly(4), xCoord, yCoord);
}
for (int i = 0 ; i < 1 ; i++)
{
int xCoord = Greenfoot.getRandomNumber(getWidth());
int yCoord = Greenfoot.getRandomNumber(getHeight());
addObject(new Spider(mainBee), xCoord, yCoord);
}
}
int score = 0;
public void updateScore()
{
Score++;
showText("Score : " + Score, 650, 30);
if(score > 50)
{
Greenfoot.stop();
showText("Selamat Anda Menang", 350, 250);
}
}
private int timer = 1000;
public void updateTimer()
{
timer--;
showText("timer="+ timer, 450, 450);
if(timer <= 0){
Greenfoot.stop();
showText("Anda Gagal", 350,250);
}
}
public void act()
{
updateTimer();
}
}
File added
#BlueJ class context
comment0.target=Fly
comment0.text=\r\n\ Write\ a\ description\ of\ class\ Fly\ here.\r\n\ \r\n\ @author\ (Daffa\ Mudia\ Athifah)\ \r\n\ NIM\ (V3420022)\r\n\ @version\ (a\ version\ number\ or\ a\ date)\r\n
comment1.params=
comment1.target=void\ act()
comment2.params=maxSpeed
comment2.target=Fly(int)
numComments=3
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Fly here.
*
* @author (Daffa Mudia Athifah)
* NIM (V3420022)
* @version (a version number or a date)
*/
public class Fly extends Movement
{
/**
* Act - do whatever the Fly wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
private int speed;
public void act()
{
// Add your action code here
gerak(2);
handleTepi();
}
public Fly(int maxSpeed)
{
speed = Greenfoot.getRandomNumber(maxSpeed)+1;
}
}
File added
#BlueJ class context
comment0.target=Movement
comment0.text=\r\n\ Write\ a\ description\ of\ class\ Movement\ here.\r\n\ \r\n\ @author\ (Daffa\ Mudia\ Athifah)\r\n\ NIM\ (V3420022)\r\n\ @version\ (a\ version\ number\ or\ a\ date)\r\n
comment1.params=
comment1.target=void\ act()
comment1.text=\r\n\ Act\ -\ do\ whatever\ the\ Movement\ wants\ to\ do.\ This\ method\ is\ called\ whenever\r\n\ the\ 'Act'\ or\ 'Run'\ button\ gets\ pressed\ in\ the\ environment.\r\n
comment2.params=speed
comment2.target=void\ gerak(int)
comment3.params=
comment3.target=void\ handleTepi()
numComments=4
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Movement here.
*
* @author (Daffa Mudia Athifah)
* NIM (V3420022)
* @version (a version number or a date)
*/
public class Movement extends Actor
{
/**
* Act - do whatever the Movement 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.
}
public void gerak(int speed)
{
move(speed);
if (Greenfoot.getRandomNumber(100)<50)
{
turn(Greenfoot.getRandomNumber(20)-10);
}
}
public void handleTepi()
{
if (isAtEdge())
{
turn(180);
}
}
}
------------------------------------------------------------------------
This is the project README file. Here, you should describe your project.
Tell the reader (someone who does not know anything about this project)
all he/she needs to know. The comments should usually include at least:
------------------------------------------------------------------------
PROJECT TITLE:
PURPOSE OF PROJECT:
VERSION or DATE:
HOW TO START THIS PROJECT:
AUTHORS:
USER INSTRUCTIONS:
File added
#BlueJ class context
comment0.target=Spider
comment0.text=\r\n\ Write\ a\ description\ of\ class\ Spider\ here.\r\n\ \r\n\ @author\ (Daffa\ Mudia\ Athifah)\ \r\n\ NIM\ (V3420022)\r\n\ @version\ (a\ version\ number\ or\ a\ date)\r\n
comment1.params=
comment1.target=void\ act()
comment2.params=mainBee
comment2.target=Spider(Bee)
comment3.params=
comment3.target=void\ smartMove()
comment3.text=\r\n\ smartMove\ -\ Method\ untuk\ membuat\ kelas\ Spider\ selalu\ mengikuti\ kelas\ Bee\r\n
numComments=4
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Spider here.
*
* @author (Daffa Mudia Athifah)
* NIM (V3420022)
* @version (a version number or a date)
*/
public class Spider extends Movement
{
/**
* Act - do whatever the Spider wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
private int speed = 2;
Bee bee;
public void act()
{
// Add your action code here.
handleTepi();
smartMove();
gerak(speed);
}
public Spider(Bee mainBee)
{
bee = mainBee;
}
/**
* smartMove - Method untuk membuat kelas Spider selalu mengikuti kelas Bee
*/
public void smartMove()
{
turnTowards(bee.getX(), bee.getY());
}
}
images/bee.png

1.73 KB

images/bee0.png

1.73 KB

images/bee1.png

4.75 KB

images/fly.png

1.97 KB

Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment