Jump to content


Photo

Breakout-like Game


  • Please log in to reply
5 replies to this topic

#1 borgisme5

borgisme5

    GMC Member

  • New Member
  • 10 posts

Posted 10 February 2009 - 03:38 PM

I am fairly new to Game Maker. I am using the Lite version of Game Maker 7, but I have access to the Pro version if needed. I've picked up the Drag and Drop mechanics pretty fast, but I have yet to really use GML that much, but eager to learn, as I know you can do so much more with it. Looking for some help, which is why I am here!

I have ran into a few problems with the powerups in my game.



1.) The multiball powerup
The way I have it set up, when the game start, I have the ball spawn right above the paddle (object_ball), with a move free action where the direction is " random(30)+90 ". That way, when it spawns, it will always go up. Because of this, however, I needed to create another ball object for the multiball where the direction is " random(360) " (object_ball_random), since I don't want the new balls to always go up. object_ball_random is a child of object_ball.

However, because of this, this causes problems with other power ups.

When there are multiple balls in the playing field, only one of them will spawn more balls. I want it so that all balls in play will spawn two more.

I have the multiball powerup set up to where it creates two moving instances of object_ball_random, and the x and y coordinates are those of object_ball. I am guessing the game just picks ones of the object_ball instances in play and spawns the moving instance at that on. These balls always will spawn at the one that is there when the level starts, if that one is gone, one of the child's will get chosen.




2.) The speed up and speed down power ups

I have one power up that will set the speed of the ball(s) to 15 for 10 seconds.
I have another power up that will set the speed of the ball(s) to 5 for 10 seconds.
(What they should do)

I want them the affect all balls on the field, regardless if they were there before or after when the power up was picked up. This one has been a head ache for me because I just can't make much progress. I can get them to speed up/speed down and to override one another, but I can't ever get them to return the default speed. Then, of course, if I hit a multiball, the new ones will be at the default speed until I hit another powerup. I also am trying to get it so that in addition to the 10 second delay, any additional speed power ups will reset it. IE. if I pick up a speed boost power up and 7 seconds go by and I pick up another one, the speed boost will last for an addition 10 seconds, and if a speed slower is picked up, the speed becomes slower and it will last for 10 seconds, with the old powerup null.



3.) Multiple powerups would spawn when there were multiple balls in play. ~fixed

This script actually fixed it as I was using create random instance for the first four of my powerups, then an " else ", followed by a second create random instance. I did do this code for a random chance that a brick may or may not spawn a powerup, and then when it does, it picks a random power up to spawn.

if round(random(5))>4
{
{
instance_create(other.x, other.y, choose( object_powerup_speed_up, ..., ..., ...));
}
}

4.) Paddle gets stuck in wall with paddle extender powerup

If I pick up a paddle extender powerup when next to a wall, it will make the paddle go into the wall, and thus become stuck. I use a Change Instance from the regular paddle to the large paddle to do this. I know this has to do with collision and solid objects, but I don't know how to fix this one at all.

I've also ran into problems of the paddles not changing into the right instance. IE, going from a small to a large paddle instead of the default paddle when a paddle extender powerup is picked up. I am pretty sure this is because I am doing this far from right. I check the number of instances of the regular paddle, and if it = 1, change instance to big paddle, else, small paddle.



~~~

I basically looking for a way to make so that when a multiball power up is activated, two new balls will be created at that location, and they will go in a random direction. If a speed powerup is picked up, all the balls in play will be affected, and any new ones will be as well. If another speed powerup is picked up, it will over ride the previous one. After a time delay, they return to their start speed of 10. I also need to find out to keep an extending paddle to not get stuck in the wall and to get the right paddle to appear for the appropriate powerup.

!~Thank you for any and all help~!

Edited by borgisme5, 10 February 2009 - 04:14 PM.

  • 0

#2 Nocturne

Nocturne

    Nocturne Games

  • Administrators
  • 16792 posts
  • Version:GM:Studio

Posted 10 February 2009 - 05:00 PM

1.) In the multiball power up collision event put this...

with (obj_ball) //Selects all ball objects to perform the following code...
{
var nnn; //A temp variable only for this code...
repeat (2); //repeat the following code twice...
	{
	nnn=instance_create(x,y,obj_ball_random); //Create random ball object...
	nnn.direction=random(360); //Set random ball objects direction to random...
	nnn.speed=10; //Set the random ball objects speed...
	nnn.oldspeed=10; //See further down...
	if instance_exists(obj_Speed_Control) speed+=obj_Speed_Control.spd; //See further down...
	}
}

2.) This is a bit more tricky... You need to add a variable into the ball objects create event to hold the starting speed (I use "oldspeed" in the following code).eg...
speed=10;
oldspeed=speed;

Then you should make a controller object (obj_Speed_Control for example) and in the collision event with the power ups and the paddle create it like this...

//For the speed-up power up
if !instance_exists(obj_Speed_Control) //Checks to see if the controller exists...
{
var nnn;
nnn=instance_create(0,0,obj_Speed_Control); //If not, create it...
nnn.spd=5; //Sets the spd variable to 5...
with (obj_ball)
	{
	oldspeed=speed; //Stores the obj_ball current speed.
	}
}
else
{
with (obj_Speed_Control) //If it does exists, select it...
	{
	alarm[1]=room_speed*10; //Resets the alarm another 10 seconds...
	spd+=5; //Add more speed to the variable... See the further down for more info...
	if spd>20 spd=20; //This is a check to make sure that the balls don´t go over a max speed (20 here)...
	}
}

//For the slow-down power up
if !instance_exists(obj_Speed_Control) //Checks to see if the controller exists...
{
var nnn;
nnn=instance_create(0,0,obj_Speed_Control); //If not, create it...
nnn.spd=-5; //Sets the spd variable to -5...
with (obj_ball)
	{
	oldspeed=speed; //Stores the obj_ball current speed.
	}
}
else
{
with (obj_Speed_Control) //If it does exists, select it...
	{
	alarm[1]=room_speed*10; //Resets the alarm another 10 seconds...
	spd-=5; //Add more speed to the variable... See the further down for more info...
	if spd<5 spd=5; //This is a check to make sure that the balls don´t go under a min speed (20 here)...
	}
}


Then in the controller do this...

//IN THE CREATE EVENT
spd=0; //This initialises the variable that the other objects change to the actual speed...
alarm[0]=1; //This will be used to add on the first spd variable to the balls...
alarm[1]=room_speed*10; //This sets a 10 second alarm...

//IN THE STEP EVENT
with (obj_ball)
{
speed=other.spd; //This sets the ball objects speed to the current controller speed variable...
}

//IN THE ALARM[0] EVENT
with (obj_ball)
{
speed=oldspeed+other.spd; //This adds the initial spd variable when first creating the controller object...
}

//IN THE ALARM[1] EVENT
with (obj_ball)
{
speed=oldspeed;
}
instance_destroy();

And as you say 3.) is fixed we´ll move on to...

4.) You have to do a check with the wall object and then adjust the position of the paddle accordingly... Like this in the create event of the new paddle...

//The following checks for a collision and stores the id of the colliding object (if there is one) in a variable...
var nnn;
nnn=collision_line(x-sprite_width,y,x+sprite_width,y,obj_wall,false,tru
e);
if nnn>0
{
move_outside_solid(point_direction(other.x,other.y,x,y),-1); //this moves the object out of any collision, but only if your walls are solid...
}

Phew! that was a lot more than I thought... I hope that I kept everything clear and that you follow it all! Check the functions you don´t know in the manual and post back with problems/questions...

Oh, and it´s your first post, so welcome to the GMC!
All the best,

Mark

Edited by Mark13673, 10 February 2009 - 05:23 PM.

  • 0

#3 borgisme5

borgisme5

    GMC Member

  • New Member
  • 10 posts

Posted 10 February 2009 - 06:45 PM

Ignore what was in here before

When I run the game, the ball does not move. It will start to move a few seconds after the game starts.
The speed up will actually slow down the ball.
Also, if I pick up a slow down power up it's direction changes and goes back from where it came from.

The multiball powerup gives me this error:

~~
ERROR in
action number 3
of Collision Event with object object_paddle
for object object_powerup_multiball:

Error in code at line 4:
repeat (2); //repeat the following code twice...

at position 12: Statement expected.
~~
I ended up removing the ; after the (2), and it worked like a charm!

And thank you again! You're a godsend, I wish I had you to help me in my java and C++ classes. Programming just makes my mind implode, but so does complex level editing for some people, so I don't feel too bad =p

Edited by borgisme5, 10 February 2009 - 09:09 PM.

  • 0

#4 Nocturne

Nocturne

    Nocturne Games

  • Administrators
  • 16792 posts
  • Version:GM:Studio

Posted 10 February 2009 - 11:25 PM

Sorry about the ";" extra... I do that with my own code too! It´s very frustrating... Anyway, after posting I started to realise that some of what I´d said would cause errors, and so I set about making a wee demo with the things you asked about and the code nice and clean and fixed...

Posted Image

I haven´t commented everything as you seem to have a working knowledge of GML, but it´s all pretty obvious and straightforward...

All the best!

Mark
  • 0

#5 borgisme5

borgisme5

    GMC Member

  • New Member
  • 10 posts

Posted 10 February 2009 - 11:34 PM

I am flattered.
I have 0 experience with GML. There was an error message for that line. I figured that there was 50/50 chance that it needed a ; at the end of it, heh. I have some minor Java and C++ experience, but it's so minor it doesn't matter. Almost failed 'em. Never found a way that programming could be taught to me that would make it stick in.

At school tomorrow I will be sure to check out everything you did and try to implement it into my own. Hopefully all goes well and I will post here to let you know how it went.

Edited by borgisme5, 10 February 2009 - 11:35 PM.

  • 0

#6 borgisme5

borgisme5

    GMC Member

  • New Member
  • 10 posts

Posted 12 February 2009 - 12:10 AM

Thanks a lot~!

I've been able to hybrid your code into mine. Well, I actually replace a lot of what I had since the code is much more efficient that what I had going before.

What I am trying to do now is to set up the power ups that enlarge and shrink the paddle. I have two separate powerups, one for each, as I want the player to be able to rush to get the big one and avoid the shrinker. I've been trying to set it so that when each paddle hits different power up happens, but it doesn't work. It doesn't seem that change instance is working either, I am assuming this is related to the Control object for the paddle interfering. The speed up, speed down and multiball powerups are all working like a charm, however, so thanks much!

http://www.megaupload.com/?d=D7OTNJ5M

That should be a download to what I have going on more or less. Gotta wait like a bit before you can download it, however. I deleted much of what I added since it wasn't working, so those powerups don't do anything at the moment. There is an object for 1000 points, but I haven't done that one yet, so don't worry about it~! (
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users