sets speed and direction variables of an instance in one line
instance_place(x, y, object)
function
exactly like place_meeting except this function returns the 'specific instance identifier' which means we can do stuff with the instance we have collided with.
returns the direction from one point (x1,y1) to another point (x2, y2). Helpful for setting course for a specific direction. We will use it in this example for a 'controlled bounce' (as opposed to a 'natural bounce').
Sprite
Images
sprBall
sprBrick
sprPaddle
sprTargetBlock
Set the mask and origin of ball for spot on bouncing:
Next, set the origin of paddle for controlled bouncing a short distance below the middle-centre of the paddle surface:
The reason for this is explained in this diagram:
Object
Sprite
Properties
objBall
sprBall
Visible
objBrick
sprBrick
Visible
objPaddle
sprPaddle
Visible
objTargetBlock
sprTargetBlock
Visible
objBall Create event:
randomize();
motion_set(irandom_range(225,305),7)
objBall Step event:
if place_meeting(x + hspeed, y + vspeed, all){
//after we bounce, if there is a target block,
//we will have to remove the target block:
targetBlock = instance_place(x + hspeed, y + vspeed, objTargetBlock);
//for the paddle (only)...:
if place_meeting(x + hspeed, y + vspeed, objPaddle){
//...give the user some control as to where they are aiming,
//which means an 'unnatural' bounce:
direction = point_direction(objPaddle.x, objPaddle.y, x, y)
}
else{
//...otherwise use a regular (natural) bounce:
move_bounce_all(true);
}
if (targetBlock != noone) {
with (targetBlock) {
instance_destroy();
}
}
}
objPaddle Step event:
switch (keyboard_key) {
case vk_left: x = x - 7; break;
case vk_right: x = x + 7; break;
}
Adjust speed of paddle, ball, and layout of level, to make game more playable
Make ball speed up +1 with every touch
Come back and improve this game with score, lives and end-game once you develop more skill in GMS2