breakout | gml
| Type | Desc | |
|---|---|---|
| motion_set(direction, speed) | function | 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. |
| point_direction(originX, originY, targetX, targetY) | function | 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 |
objPaddle Step
switch (keyboard_key) {
case vk_left: x = x - 7; break;
case vk_right: x = x + 7; break;
}
objBall Create
randomize(); motion_set(irandom_range(225,305),7)
objBall Step
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();
}
}
}
- 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




