This site requires JavaScript, please enable it in your browser!
Greenfoot back
Anne2403
Anne2403 wrote ...

2014/12/1

HowToKill

Anne2403 Anne2403

2014/12/1

#
Hello. My game was almost done but I can't find way on how my game will be over if the Player was fired by the enemy. I can't make the enemy shot by the player. I have here a code and this code is for one of my enemy, the problem is How am I gonna kill the enemy or the player using that code so the game will be over while the Time is running.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.*;
/**
 * Write a description of class Snake here.
 *
 * @author (your name)
 * @version (a version number or a date)
 */
public class Snake extends Actor
{
  private int Speed = 3;
  private int shotLate = 5;
  public int deSync = Greenfoot.getRandomNumber(40);
  public void act()
  {
      move();
      checkEdges();
      shoot();
  }
  public void move()
  {
    move(Speed);
  }
  public void checkEdges()
  {
      if(getX() > 990)
      {
          Speed = -3;
      }
      if(getX() <= 10)
      {
          Speed = 3;
      }
    }
  public void shoot()
  {
      if(shotLate >= 25 && shotLate > deSync)
      {
      getWorld().addObject(new Fire(60), getX(), getY());
      shotLate = 5;
      }
      shotLate++;
  }
}
danpost danpost

2014/12/1

#
If it is the Fire object that kills the player and ends the game, then the Fire class code should be shown.
Anne2403 Anne2403

2014/12/2

#
here @danpost. I haven't doind anything but just this only because I don't know how..
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
 
/**
 * Write a description of class Fire here.
 *
 * @author (your name)
 * @version (a version number or a date)
 */
public class Fire extends Actor
{
    public Fire(int rotation)
    {
        setRotation(rotation);
    }
    public void act()
    {
        move(5);
    }
}
danpost danpost

2014/12/2

#
Just add a check for touching the player in the Fire act method. If touching player, set a new GameOver world active.
Anne2403 Anne2403

2014/12/2

#
ahm, sorry didn't get that.. so did you mean.. I will add "TouchingPlayer();" in the 'act' method and create "public void TouchingPlayer() and use a if statement? Like this...?
public void act() { TouchingPlayer(); } public void TouchingPlayer() { if(TouchingPlayer > 0) { getWorld().addObject(new GameOver(), 330, 500); } }
danpost danpost

2014/12/2

#
danpost wrote...
Just add a check for touching the player in the Fire act method. If touching player, set a new GameOver world active.
I was quite specific in what I said here as far as where the code should go. Also, there is already an 'isTouching' method in the Actor class. Please review its documentation here.
You need to login to post a reply.