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

2012/6/2

Two Questions PLEASE HELP As soon as possibly..

Sidstar Sidstar

2012/6/2

#
Question 1: Hi I making a game I have worked out the shooting process and that sort of stuff but I would like to Know how to add and actor in your game after a certain amount of time or something like that. Question 2: As I said up above I have finished the shooting so I would like to make it so when I shooting my actor I will disappear or blow up etc. Thanks SOOOO much!
Sidstar Sidstar

2012/6/2

#
Also if you could make a video on it that would help soooooooooo much.. I am just started using greenfoot. Thanks
MatheMagician MatheMagician

2012/6/2

#
Question 1: right after
public class whatever extends World()
{
define this variable:
Date now = new Date();
long t = now.getTime();
Then, in the act cycle of your world put:
Date now = new Date();
long t2 = now.getTime();// time since January 1978 in milliseconds

if((t2*1000-t*1000)>40) //gets the difference between times
{
       addObject(new Actor(), 100, 100);
       t = t2;
}
This code should work, though I have not tested it. Now, to explain: when defining the variables at the beginning, we set a variable telling the time in milliseconds since I believe January 1978 (that date is not important). Then, in the act cycle, it figures out what time it is currently. The if statement converts the times into seconds and finds the difference between them. This way it knows how many seconds it has been since the variable t was defined. If the time is greater than a certain amount, in this case 40 seconds, it will add an actor into the world and then reset t to the current time. I will try to answer the second question in a later post.
MatheMagician MatheMagician

2012/6/2

#
Question 2: put this in your act cycle of the thing which is being shot at:
if(getOneIntersectingObject(Bullet.class) != null)
{
       Actor bullet = getOneIntersectingObject(Bullet.class) ;
       getWorld().removeObject(bullet);
       getWorld().removeObject(this);
       return;
}
nadouda nadouda

2012/6/2

#
where do we get the date class? i'm facing almost the same problem, i put the first code it gives me cannot find symbol!
danpost danpost

2012/6/2

#
You do not have to use the 'Date' class at all. Declare: Long beginTime = System.currentTimeMillis(); In act: if ((System.currentTimesMillis() - beginTime) / 1000 >= 40)
nadouda nadouda

2012/6/2

#
Tahnk you it worked there is no more syntax errors but no new actors are added to the game, how can i add random number of actors each time?
MatheMagician MatheMagician

2012/6/2

#
Sorry, I puled the code from one of my games so I forgot to tell you to add this:
import java.util.Date;
Sidstar Sidstar

2012/6/2

#
Could anybody make a video on this that would help sooo much
danpost danpost

2012/6/3

#
It is not a video, but it will probably help. Code similar to what you want in given in another discussion. You can find it here.
Sidstar Sidstar

2012/6/3

#
MatheMagician wrote...
Question 1: right after
public class whatever extends World()
{
define this variable:
Date now = new Date();
long t = now.getTime();
Then, in the act cycle of your world put: HEy Thanks do you have to put "define this variable" in your cade? Also Where do you put
Date now = new Date();
long t2 = now.getTime();// time since January 1978 in milliseconds

if((t2*1000-t*1000)>40) //gets the difference between times
{
       addObject(new Actor(), 100, 100);
       t = t2;
}
This code should work, though I have not tested it. Now, to explain: when defining the variables at the beginning, we set a variable telling the time in milliseconds since I believe January 1978 (that date is not important). Then, in the act cycle, it figures out what time it is currently. The if statement converts the times into seconds and finds the difference between them. This way it knows how many seconds it has been since the variable t was defined. If the time is greater than a certain amount, in this case 40 seconds, it will add an actor into the world and then reset t to the current time. I will try to answer the second question in a later post.
Sidstar Sidstar

2012/6/3

#
MatheMagician wrote...
Question 1: right after
public class whatever extends World()
{
define this variable:
Date now = new Date();
long t = now.getTime();
Then, in the act cycle of your world put: HEy Thanks do you have to put "define this variable" in your cade? Also Where do you put
Date now = new Date();
long t2 = now.getTime();// time since January 1978 in milliseconds

if((t2*1000-t*1000)>40) //gets the difference between times
{
       addObject(new Actor(), 100, 100);
       t = t2;
}
This code should work, though I have not tested it. Now, to explain: when defining the variables at the beginning, we set a variable telling the time in milliseconds since I believe January 1978 (that date is not important). Then, in the act cycle, it figures out what time it is currently. The if statement converts the times into seconds and finds the difference between them. This way it knows how many seconds it has been since the variable t was defined. If the time is greater than a certain amount, in this case 40 seconds, it will add an actor into the world and then reset t to the current time. I will try to answer the second question in a later post.
You need to login to post a reply.