# Need Some Help

6 replies to this topic

### #1 scranner

scranner

GMC Member

• New Member
• 6 posts
• Version:GM8

Posted 03 March 2012 - 10:34 PM

Currently i have to make a game with game maker 8 for my GCSE coursework in school and i have chosen to do a simple breakout game shown here to avoid any confusion (LINK). My two current issues are i first of all want the ball to move left and right with the paddle at the beginning of the game but once the space bar is pressed the ball will be projected out and the game will begin, the same will happen when a life is lost. The issue is i don't know how to, first check if the space bar has been pressed to see if the ball is already moving and thus this would change the direction of the ball and secondly have the ball move with the bat till the space is pressed. i apologise for my horrible explaining as i tend to squabble on a lot. Any help is very much appreciated!

I am using Game Maker 8.1 Lite

Edited by scranner, 03 March 2012 - 10:38 PM.

• 0

### #2 Noele

Noele

GMC Mentor

• GMC Member
• 4252 posts
• Version:GM:Studio

Posted 03 March 2012 - 11:18 PM

A Breakout type game is fairly simple - it is just a matter of getting the math right so there are no gaps when you place the blocks. Blocks of a uniform size when hit by "something" get destroyed and score awarded.

The space bar firing is not a problem.
Key Event for Space Pressed
Check Instance Number
<select ball object>
Value: 0
<select Equal to>

Add the fire ball action here

In essence it means, when the space key is pressed a check is made to see how many balls exist (we only need one) and only if it equals zero do we need to fire one, otherwise we do nothing and pressing space would have had no effect.

The boundary of the game (where the ball cannot go) you fill with wall objects. When the ball collides with these it is bounced off (not precisely so it bounces at angles)

Does that give you enough to get started?
• 0

### #3 scranner

scranner

GMC Member

• New Member
• 6 posts
• Version:GM8

Posted 03 March 2012 - 11:27 PM

A Breakout type game is fairly simple - it is just a matter of getting the math right so there are no gaps when you place the blocks. Blocks of a uniform size when hit by "something" get destroyed and score awarded.

The space bar firing is not a problem.
Key Event for Space Pressed
Check Instance Number
<select ball object>
Value: 0
<select Equal to>

Add the fire ball action here

In essence it means, when the space key is pressed a check is made to see how many balls exist (we only need one) and only if it equals zero do we need to fire one, otherwise we do nothing and pressing space would have had no effect.

The boundary of the game (where the ball cannot go) you fill with wall objects. When the ball collides with these it is bounced off (not precisely so it bounces at angles)

Does that give you enough to get started?

i think you have misunderstood me with is my fault. the ball will already exist at the beginning. i want the player to be able to to move left or right and the ball to move with the pad then when the spacebar is pressed the ball to fly off and the game to begin

Edited by scranner, 03 March 2012 - 11:28 PM.

• 0

### #4 Nocturne

Nocturne

Nocturne Games

• 25708 posts
• Version:GM:Studio

Posted 03 March 2012 - 11:36 PM

Give the ball a variable and then in the space event set it to false. Now, while it is true, have a step event that says "if variable is true then x=bat.x and y=bat.y-sprite_height"... or something similar. If you need more precise instructions then let me know!
• 0

### #5 scranner

scranner

GMC Member

• New Member
• 6 posts
• Version:GM8

Posted 04 March 2012 - 12:58 AM

on button press
```if (keyboard_check(vk_space))
{
if (obj_ball_normal.speed == 0)
{
motion_set(80,12);
}
}
else if (keyboard_check(vk_left))
{
if (obj_ball_normal.speed == 0)
{
obj_ball_normal x -= 1;
}
}
else if (keyboard_check(vk_right))
{
if (obj_ball_normal.speed == 0)
{
obj_ball_normal x += 1;
}
}
```

on button release
```if (keyboard_check(vk_space))
{
if (obj_ball_normal.speed != 0)  motion_set(0,0);
}

```
this is the code i am trying at the moment any ideas to why it dosent work. currently the ball just continues to go left to right and so on

Edited by scranner, 04 March 2012 - 01:22 AM.

• 0

### #6 scranner

scranner

GMC Member

• New Member
• 6 posts
• Version:GM8

Posted 04 March 2012 - 01:28 AM

Give the ball a variable and then in the space event set it to false. Now, while it is true, have a step event that says "if variable is true then x=bat.x and y=bat.y-sprite_height"... or something similar. If you need more precise instructions then let me know!

yes could you give me a little more detail please?
• 0

### #7 Nocturne

Nocturne

Nocturne Games

• 25708 posts
• Version:GM:Studio

Posted 04 March 2012 - 01:46 AM

Okay! In the ball object -

```//CREATE EVENT
go=false;

//STEP EVENT
if !go
{
x=bat.x; //change "bat" to the name of your bat object
y=bat.y-sprite_height; //Change sprite_height to the value that makes the ball look correctly positioned on the bat
}
else
{
//normal codes here
}```

Next, the bat object -

```//KEYBOARD SPACE PRESSED EVENT
with (ball)
{
//Lets make the ball start to move!
if !go
{
go=true; //Set go
speed=6; //Set speed
direction=135-random(90);//Set direction
}
}```

Something like that should work for you.
• 0