Jump to content


Photo

Need Some Help


  • Please log in to reply
6 replies to this topic

#1 scranner

scranner

    GMC Member

  • New Member
  • 6 posts
  • Version:GM8

Posted 03 March 2012 - 10:20 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:24 PM.

  • 0

#2 Noele

Noele

    GMC Mentor

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

Posted 03 March 2012 - 11:04 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
:GM057: Check Instance Number
<select ball object>
Value: 0
<select Equal to>
:GM063:
Add the fire ball action here
:GM066:

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) :GM016:

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:13 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
:GM057: Check Instance Number
<select ball object>
Value: 0
<select Equal to>
:GM063:
Add the fire ball action here
:GM066:

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) :GM016:

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:14 PM.

  • 0

#4 Nocturne

Nocturne

    Nocturne Games

  • Administrators
  • 20908 posts
  • Version:GM:Studio

Posted 03 March 2012 - 11:22 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:44 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:08 AM.

  • 0

#6 scranner

scranner

    GMC Member

  • New Member
  • 6 posts
  • Version:GM8

Posted 04 March 2012 - 01:14 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

  • Administrators
  • 20908 posts
  • Version:GM:Studio

Posted 04 March 2012 - 01:32 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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users