|
DX_Ball 2
#342063
09/23/10 05:28
09/23/10 05:28
|
Joined: Jul 2010
Posts: 32
EID
OP
Newbie
|
OP
Newbie
Joined: Jul 2010
Posts: 32
|
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.
Last edited by EID; 09/23/10 06:19.
|
|
|
Re: DX_Ball 2
[Re: Liamissimo]
#342122
09/23/10 17:47
09/23/10 17:47
|
Joined: Jul 2010
Posts: 32
EID
OP
Newbie
|
OP
Newbie
Joined: Jul 2010
Posts: 32
|
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
Last edited by EID; 09/23/10 17:48.
|
|
|
Re: DX_Ball 2
[Re: EID]
#342147
09/24/10 07:07
09/24/10 07:07
|
Joined: Sep 2007
Posts: 62 Germany
bodden
Junior Member
|
Junior Member
Joined: Sep 2007
Posts: 62
Germany
|
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
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);
}
}
Last edited by bodden; 09/24/10 07:10.
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|