Page 1 of 1

Break me out

PostPosted: Sat Mar 07, 2015 3:06 am
by LadyCam
Hello, can someone help me about the game break out
Help me about the codes :

When I click the space bar I would go to the left or right side wall, here's my code I would like to be random Please I really need Help

Click Actor (Ball)
Click keydown (space)
Script editor

yvelocity = -6;
xvelocity = 6;
bola = 1;



How to be like the game of break out. Please Help me ASAP

Re: Break Out game

PostPosted: Sat Mar 07, 2015 10:41 am
by DjVan
Welcome to the forum! :D

if you want the ball(actor) direction to be random, you have to make a variable then give it a random number
every time you press space bar with the function rand(x)
first creat a variable on global code, Name it dir

so on actor ball, Key Down (space)
Script Editor :
Code: Select all
dir = rand(2);      // this will creat a random number (0 OR 1)
if(dir == 0){
   xvelocity = -6;    // go to the left
}
else
xvelocity = 6         // go to the right
bola = 1;             // no idea..


btw, sometimes the function rand() can be really unfair, it might force you to go right 5 times in a row
in that case you have to find a way to stop the ball-actor from leaving the view.

GoodLuck

Re: Break me out

PostPosted: Sun May 03, 2015 11:53 am
by bat78
rand() does not return a "random" value but a pseudo-arbitrary one.
A pseudo-arbitrary value can be reversed, because it has been created with mathematical formula that uses the local time as a seed.
Completely random values are hard to get in real life. It must be from a source, that has no logic.

Therefore, the use of rand() makes you a terrible C/C++ programmer.
Not only it is easy-to-reverse (with correlation for instance) but it is also a heavy function.
If you are willing to subdue a High-Quality game you will use a system to base the "randomness" from.

Example:
Code: Select all
stTime time = getTime();
int prime_diffusion = !(real_fps % 2);
textNumber = prime_diffusion && !(time.sec % prime_diffusion);