DX_Ball 2

Posted By: EID

DX_Ball 2 - 09/23/10 05:28

hey all.
at the last days i had reaching an code to animate the ball but now i have an thinking error the compiler out from checking the (if statement when it's apply the first statement i want it to continue checking i want to animate the ball to be in an three closed walls to impact with it and at the fourth wall the blade make it's objective to keep the ball between the three walls and the blade ..
here is the code

action bar()
{
while(1)
{
if (key_a)
{
c_move (my, vector(0, 0, -10 * time_step), nullvector, GLIDE);
}
if (key_d)
{
c_move (my, vector(0, 0, 10 * time_step), nullvector, GLIDE);
}
wait (1);
}
}

action ball()
{
var ball_speed =30;
var top_border= 100;
var Rside_border= 400;
var Lside_border= -200;
while(1)
{
c_move (my, vector(0, 0, ball_speed * time_step), nullvector, GLIDE);
c_move (my, vector(0, -ball_speed * time_step, 0), nullvector, GLIDE);


if (my.z>=top_border)
{
my.z-=3 -random(3);
my.y+=3 +random(3);

if(my.y<=Lside_border)
{
my.y-=ball_speed*time_step - random(3);
my.z+=ball_speed*time_step + random(3);
}
if (my.y>=Rside_border)
{
my.y+=ball_speed*time_step -random(3);
my.z+=ball_speed*time_step + random(3);
}
}
wait(1);
}
}

hint the actions is assigned to the models the bar and the ball. and the game is 2d game the ball and bar are models . the level consisting in an sprite as background.

Posted By: Liamissimo

Re: DX_Ball 2 - 09/23/10 10:27

Hehe, I am sorry but could you describe again what you want? I don't get it laugh
Posted By: EID

Re: DX_Ball 2 - 09/23/10 17:47

never mind my friend u can see what i want from this link at youtube (http://www.youtube.com/watch?v=YvkEtVpkGTs) .i want to make a game like this...
Thanks a lot again laugh
Posted By: TrackingKeks

Re: DX_Ball 2 - 09/23/10 18:17

And what is the problem? laugh
Posted By: EID

Re: DX_Ball 2 - 09/23/10 18:20

the problem that the compiler when he apply the first if statement it's out of it's loop i want to continue in the loop to be like this (http://www.youtube.com/watch?v=YvkEtVpkGTs)
Posted By: bodden

Re: DX_Ball 2 - 09/24/10 07:07

I think, with this code, it can't work. You never change ball_speed, so the ball can never bounce from the wall.

You don't need two c_move's, because you can put both directions (x/y) in one c_move-vector.

If you use the same value for x/y, the ball will allways fly in a 45° angle. You could use differnet vars for x and y speed. Also, you could use collision-detection and the BOUNCE-result of a collision to set the new direction of the ball. In your code, you don't change any speed, when collision with the wall.

Your brackets are not correct. In the ball-action the checks for the left and right wall are only done, when the ball hits the upper wall. I've formated your code to make it clear
Code:
action ball()
{
	var ball_speed =30;
	var top_border= 100;
	var Rside_border= 400;
	var Lside_border= -200;
	while(1)
	{
		c_move (my, vector(0, 0, ball_speed * time_step), nullvector, GLIDE);
		c_move (my, vector(0, -ball_speed * time_step, 0), nullvector, GLIDE);
		
		
		if (my.z>=top_border)
		{
			my.z-=3 -random(3); 
			my.y+=3 +random(3); 
		
			if(my.y<=Lside_border)
			{
				my.y-=ball_speed*time_step - random(3);
				my.z+=ball_speed*time_step + random(3);
			}
			if (my.y>=Rside_border)
			{
				my.y+=ball_speed*time_step -random(3);
				my.z+=ball_speed*time_step + random(3);
			}
		}
		wait(1);
	}
}


Posted By: EID

Re: DX_Ball 2 - 09/24/10 07:59

really thank you bodden i will do it now but we have another problem that the compiler exit from it's while(1) loop after applying the first If statement . i wana to be continue in the loop.

Thanks bodden.
Posted By: bodden

Re: DX_Ball 2 - 09/24/10 08:50

I can't see any reason in this code, why the while(1)-loop should be left. Do you use more than 1 ball? Could you post your main-function?
Posted By: EID

Re: DX_Ball 2 - 09/24/10 08:55

sure the while (1) loop is for the if statement . i will post the main- function

here it

function main()
{
level_load("TrySprite.wmb"); // load the level
wait (2);
while (1)
{
camera.x = 200;
camera.y = 0;
camera.z =-50;
wait (1);
}
}
Posted By: EID

Re: DX_Ball 2 - 09/24/10 08:56

in the option of the game u could use more than 1 ball
Posted By: TrackingKeks

Re: DX_Ball 2 - 09/24/10 20:23

Have you assigned the action "ball" to the ball entity? Thie is required to start the action.

Besides you don't need a loop in the main function...

function main()
{
level_load("TrySprite.wmb"); // load the level
//wait(2); You don't need this
camera.x = 200;
camera.y = 0;
camera.z =-50;
}
Posted By: EID

Re: DX_Ball 2 - 09/25/10 00:25

hello my bro . sure i am assigned the action to the ball and it's moveing but the problem i want to move like that (http://www.youtube.com/watch?v=T9ClZvzy3hI&feature=related) also i was write an action to the blade to move like in video left and right. please help me .
Appreciate your kindly reply.

Thanks a lot.
Posted By: EID

Re: DX_Ball 2 - 09/26/10 12:23

please help......
Posted By: Liamissimo

Re: DX_Ball 2 - 09/26/10 12:56

You want three walls and a paddle no?
because all those things are really confusing
Posted By: EID

Re: DX_Ball 2 - 09/26/10 13:43

yes i need three walls and a paddle to keep the ball life . just it .
hints.
1- the ball and the paddle is an entity
2- i have level consist of three walls .
3- after i animate the ball by c_move function the ball pass the wall and don't collide with the paddle .
4- the paddle move right and left by c_move function.
that's all about my project . if u want to see the project i can send it to your e-mail.
Thanks a lot.
Posted By: Liamissimo

Re: DX_Ball 2 - 09/26/10 14:01

Why do you do it in 3D? That is way more complicated? Just use the example I gave you and add 3 other walls wink

If you need mor help PM me.
© 2024 lite-C Forums