random

Talk about making games.

random

Postby barney12345 » Sun Feb 16, 2014 1:30 am

Ok, how could I have randomly placed bad guys that are between x +310 and -310 but anywhere on the y axis but without having more than 3 on screen at the same time?
Darth Vader called... he wants his cookies back
User avatar
barney12345
 
Posts: 122
Joined: Wed Nov 07, 2012 6:52 am
Location: A land down under
Score: 4 Give a positive score

Re: random

Postby CrackedP0t » Sun Feb 16, 2014 6:01 am

1. Make an Integer variable called "badguycount". In the CreateActor event of the bad guy, put this code:
Code: Select all
badguycount++;

In the DestroyActor event, put this code:
Code: Select all
badguycount--;

2. Make an actor that will place the bad guys; he should just be off the screen or not visible.
3. In his Draw Actor event, put this script:
Code: Select all
if (badguycount <= 3) {
    CreateActor("badguy", "badguyanimation", rand(310) - 620, rand(view.width) - view.width* 2, true);
}

You could replace view.width with any number; I'm just assuming that the view won't move.

That should do it; if you have questions, make sure to post them!
/人 ◕‿‿◕ 人\
Fang Pictures, my game development company:
http://fangpictures.comuf.com
User avatar
CrackedP0t
 
Posts: 157
Joined: Mon Dec 30, 2013 5:49 pm
Location: Crested Butte, CO (The US of A)
Score: 8 Give a positive score

Re: random

Postby barney12345 » Sun Feb 16, 2014 7:27 am

thanks for that, just that my view actor does move, so there is an error code. so what would the numbers be then if it was 310 to -310(not exact, but where about)
Darth Vader called... he wants his cookies back
User avatar
barney12345
 
Posts: 122
Joined: Wed Nov 07, 2012 6:52 am
Location: A land down under
Score: 4 Give a positive score

Re: random

Postby CrackedP0t » Sun Feb 16, 2014 8:10 am

What's going wrong, and what's the error?
/人 ◕‿‿◕ 人\
Fang Pictures, my game development company:
http://fangpictures.comuf.com
User avatar
CrackedP0t
 
Posts: 157
Joined: Mon Dec 30, 2013 5:49 pm
Location: Crested Butte, CO (The US of A)
Score: 8 Give a positive score

Re: random

Postby barney12345 » Sun Feb 16, 2014 8:45 am

Error line 2: Incompatable types, cannot convert from "double" to "* const char"
Darth Vader called... he wants his cookies back
User avatar
barney12345
 
Posts: 122
Joined: Wed Nov 07, 2012 6:52 am
Location: A land down under
Score: 4 Give a positive score

Re: random

Postby CrackedP0t » Sun Feb 16, 2014 4:57 pm

I'm sorry, I forgot 2 arguments in the CreateActor function... :oops:
And, actually, the view.width should be replaced with view.height if you're using the Y axis, which you are.
This is better.
Code: Select all
if (badguycount <= 3) {
    CreateActor("badguy", "badguyanimation", "(none)", "(none)", rand(310) - 620, rand(view.height) - view.height* 2, true);
}

The first "(none)" is the parent, and the second "(none)" is the path. I'm just assuming there won't be either.
/人 ◕‿‿◕ 人\
Fang Pictures, my game development company:
http://fangpictures.comuf.com
User avatar
CrackedP0t
 
Posts: 157
Joined: Mon Dec 30, 2013 5:49 pm
Location: Crested Butte, CO (The US of A)
Score: 8 Give a positive score

Re: random

Postby barney12345 » Sun Feb 16, 2014 8:05 pm

It still doesn't make any of the badguys, or am I meant to add a timer thing which will create a bad guy
Darth Vader called... he wants his cookies back
User avatar
barney12345
 
Posts: 122
Joined: Wed Nov 07, 2012 6:52 am
Location: A land down under
Score: 4 Give a positive score

Re: random

Postby CrackedP0t » Sun Feb 16, 2014 9:49 pm

Hmmm... maybe you could post the GED?
/人 ◕‿‿◕ 人\
Fang Pictures, my game development company:
http://fangpictures.comuf.com
User avatar
CrackedP0t
 
Posts: 157
Joined: Mon Dec 30, 2013 5:49 pm
Location: Crested Butte, CO (The US of A)
Score: 8 Give a positive score

Re: random

Postby barney12345 » Mon Feb 17, 2014 7:14 am

here you go, ignore the graphics and the weird control thing
Attachments
super.zip
(117.56 KiB) Downloaded 350 times
Darth Vader called... he wants his cookies back
User avatar
barney12345
 
Posts: 122
Joined: Wed Nov 07, 2012 6:52 am
Location: A land down under
Score: 4 Give a positive score

Re: random

Postby CrackedP0t » Mon Feb 17, 2014 5:52 pm

Alright, I think I fixed it.
The problem was caused by me switching the two numbers inside and outside the rand() function. You'll still want to play with them, though, as t robots have a tendency to appear on the right.
Attachments
superfixed.zip
(286.25 KiB) Downloaded 343 times
/人 ◕‿‿◕ 人\
Fang Pictures, my game development company:
http://fangpictures.comuf.com
User avatar
CrackedP0t
 
Posts: 157
Joined: Mon Dec 30, 2013 5:49 pm
Location: Crested Butte, CO (The US of A)
Score: 8 Give a positive score

Re: random

Postby barney12345 » Mon Feb 17, 2014 8:00 pm

Thanks for that, +2
Darth Vader called... he wants his cookies back
User avatar
barney12345
 
Posts: 122
Joined: Wed Nov 07, 2012 6:52 am
Location: A land down under
Score: 4 Give a positive score

Re: random

Postby barney12345 » Mon Feb 17, 2014 8:03 pm

Just one more thing sorry, is there a way to stop them being made on screen?

PS: I will definitely give u credit at the end of this game
Darth Vader called... he wants his cookies back
User avatar
barney12345
 
Posts: 122
Joined: Wed Nov 07, 2012 6:52 am
Location: A land down under
Score: 4 Give a positive score

Re: random

Postby CrackedP0t » Tue Feb 18, 2014 7:30 am

Yeah, just change the Y numbers.
Code: Select all
//Between -500 and 500:
rand(500 * 2) - 500;
//Between 0 and 500:
rand(500);
//Between 250 and 500:
rand() % 250 + 250;
//That is, rand() modulo (%) the range you want plus(+) the base
//Between -250 and -500:
(rand() % 250 + 250) * -1
//Between -250 and 500:
rand() % 750 - 250

Just substitute your numbers for the multiples of 250 in the examples.
P.S. The random numbers go in the Y argument of the CreateActor function in the actor that makes the bad guys.
/人 ◕‿‿◕ 人\
Fang Pictures, my game development company:
http://fangpictures.comuf.com
User avatar
CrackedP0t
 
Posts: 157
Joined: Mon Dec 30, 2013 5:49 pm
Location: Crested Butte, CO (The US of A)
Score: 8 Give a positive score

Re: random

Postby barney12345 » Tue Feb 18, 2014 7:54 am

Thanks, but that still doesn't stop the creation of actors on screen





Im sorry if this is getting really annoying trying to answer such dumb questions
Darth Vader called... he wants his cookies back
User avatar
barney12345
 
Posts: 122
Joined: Wed Nov 07, 2012 6:52 am
Location: A land down under
Score: 4 Give a positive score

Re: random

Postby CrackedP0t » Tue Feb 18, 2014 8:06 am

Oooohhh... OK.
Make another int variable, called badguyscanspawn or something.
Initialize it to 1.
In the bad guy maker, add
Code: Select all
if (badguyscanspawn == 1 && badguycount < 3)

to the script. When you want the bad guys to not spawn, set badguyscanspawn to 0.


If you want to destroy all the bad guys at the same time, put in their Draw Actor event:
Code: Select all
if (badguyscanspawn == 0) DestroyActor("Event Actor");

That should do it!

P.S. I don't mind in the slightest helping you! I'm just glad I can help. :D
/人 ◕‿‿◕ 人\
Fang Pictures, my game development company:
http://fangpictures.comuf.com
User avatar
CrackedP0t
 
Posts: 157
Joined: Mon Dec 30, 2013 5:49 pm
Location: Crested Butte, CO (The US of A)
Score: 8 Give a positive score

Next

Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest