woods
Member
been away for a while and figured id get blow the dust off with a lil game of pong.
the paddle can move up/down, left/right
simple collision works fine, however doubletapping the ball is a bit wonky still.
the issue is when the ball is moving away from the paddle and it gets bumped, it reverses direction (unwanted)
i understand i am telling the ball to change direction whenever it hits the paddle... how do i make it so the ball continues forward when hitting it from behind?
obj_ball create event
obj_ball step event
obj_paddle_1 step event
the paddle can move up/down, left/right
simple collision works fine, however doubletapping the ball is a bit wonky still.
the issue is when the ball is moving away from the paddle and it gets bumped, it reverses direction (unwanted)
i understand i am telling the ball to change direction whenever it hits the paddle... how do i make it so the ball continues forward when hitting it from behind?
obj_ball create event
Code:
/// start moving
direction = random(360);
speed = random(2);
obj_ball step event
Code:
//collision with paddle_1
//horizontal
if place_meeting(x+hspeed,y,obj_paddle_1)
{
hspeed = -hspeed;
}
//vertical
if place_meeting(x,y+vspeed,obj_paddle_1)
{
vspeed = -vspeed;
}
obj_paddle_1 step event
Code:
/// move with WASD
if keyboard_check(key_right)
{
dir = 0;
x += 8;
}
else
if keyboard_check(key_left)
{
dir = 2;
x -= 8;
}
else
if keyboard_check(key_up)
{
dir = 1;
y -= 8;
}
else
if keyboard_check(key_down)
{
dir = 3;
y += 8;
}
// keep from going off screen
x = clamp(x, 64, 256);
y = clamp(y, 96, room_height - 96);