• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

I made asteroids to try and learn Game Maker

T

tomster785

Guest
So I've always wanted to make games, and have always been stopped by the hurdling of actually learning how to program. I can make art, sound and music to varying degrees of success, I also watch channels on youtube like extra credits and stuff to learn about design too, but my biggest hurdle is programming.

Anyway, I decided to finally make amends to that and begin by loosely following tutorials and making my own versions of old arcade and early console classics. I'm gonna work my way up, so I started with asteroids. For no other reason than Shaun Spalding did a tutorial on it that was text and not a video and I much prefer text.

Anyway, I would like some critique on my code in order to improve it in anyway and to correct any bad habits I may be already learning. I already know a little bit of code, as I've attempted this several times and have made various versions of pong, breakout, pacman, etc on this or unity. So I have a rough understanding of what I'm doing. But not nearly as tight a grasp as I would like.

I intend on polishing this too, make a menu, fix bugs and all that sort of stuff. I assume that's important to learn from the get go. I learnt from making music that finishing something is much harder than starting it. But I want to make sure there's nothing I need to iron out first.

The code I used to generate new asteroids when you destroy all the ones on screen is probably terrible and I don't like how close they can spawn to the player sometimes. You just die from an unlucky spawn at times. Also I don't think the player moves and rotates fast enough. But I'd like opinions on these matters and anything else that comes to mind.

Here's the demo:

http://www.mediafire.com/file/74nnhvwpn2f85d7/Asteroids.gmx.7z

And here's a screenshot:



There's not really much to show to be honest, it's asteroids, but the rules said I had to post a screenshot aha.


Thank you in advance if anybody actually sifts through my 💩💩💩💩ty code.
 

Toque

Member
Remaking atari classics is a great way to learn. (They are fun games too!)

I am just starting on GM myself. Thats a great idea
Thanks





 
M

Matt Hawkins

Guest
Your code seems pretty legit. I'd say if you've written it yourself and not copy pasted it you have some good computer nerd abilities.
Your code does have some mistakes though. I noticed you are using instance_destroy incorrectly -
Code:
if place_meeting(x,y,oBullet){
    bullet = place_meeting(x,y,oBullet);
    asteroid1 = instance_create(x,y,oAsteroid2)
    asteroid2 = instance_create(x,y,oAsteroid2)
    asteroid1.direction = direction + (bullet.image_angle + 90);
    asteroid2.direction = direction + (bullet.image_angle - 90);
    instance_destroy(bullet);
    score += 100
    instance_destroy();
}
That is wrong and has a mistake, you should be nerding like this -
Code:
if place_meeting(x,y,oBullet){
    bullet = place_meeting(x,y,oBullet);
    asteroid1 = instance_create(x,y,oAsteroid2)
    asteroid2 = instance_create(x,y,oAsteroid2)
    asteroid1.direction = direction + (bullet.image_angle + 90);
    asteroid2.direction = direction + (bullet.image_angle - 90);
    with bullet
        {
        instance_destroy()
        }
    score += 100
    instance_destroy();
}
 

Ladi_Pix3l

Member
Your code seems pretty legit. I'd say if you've written it yourself and not copy pasted it you have some good computer nerd abilities.
Your code does have some mistakes though. I noticed you are using instance_destroy incorrectly -
Code:
if place_meeting(x,y,oBullet){
    bullet = place_meeting(x,y,oBullet);
    asteroid1 = instance_create(x,y,oAsteroid2)
    asteroid2 = instance_create(x,y,oAsteroid2)
    asteroid1.direction = direction + (bullet.image_angle + 90);
    asteroid2.direction = direction + (bullet.image_angle - 90);
    instance_destroy(bullet);
    score += 100
    instance_destroy();
}
That is wrong and has a mistake, you should be nerding like this -
Code:
if place_meeting(x,y,oBullet){
    bullet = place_meeting(x,y,oBullet);
    asteroid1 = instance_create(x,y,oAsteroid2)
    asteroid2 = instance_create(x,y,oAsteroid2)
    asteroid1.direction = direction + (bullet.image_angle + 90);
    asteroid2.direction = direction + (bullet.image_angle - 90);
    with bullet
        {
        instance_destroy()
        }
    score += 100
    instance_destroy();
}
Pretty Much what he said. Heck you don't even need the brackets at that point.
Just
Code:
with (bullet) instance_destroy();
Shabooie
 
T

tomster785

Guest
Thank you for the kind words. I did copy a little bit of code, most of the movement and collision stuff really. I changed stuff where I felt it was appropriate (to make it more fun or if it didn't replicate the mechanics how I wanted) and I didn't rely on events as much as the tutorial did. I like to do as much in the step event as possible because it makes me feel like I'm a real ̶b̶o̶y̶ programmer.

But the script to generate asteroids is entirely mine, adding the small asteroids was me, and anything that I did copy I didn't copy until I understood what it was doing. Like the max function is new to me for example.


But out of interest, the code I used to destroy the bullet works (the tutorial said to use drag and drop there btw, one set to self, and one set to other, so that's my code), so why is using "with" the better way to do it? Just more efficient or is there something else? Not trying to deflect, I just want to know. So I can fulfil my anime dreams of being the best programmer the world has ever seen.



If anyone's interested this is the tutorial I followed: http://gamemakertutorials.com/?p=854 http://gamemakertutorials.com/?p=882 http://gamemakertutorials.com/?p=914


Also I should have mentioned before, I'm using GM studio 1.4 and the controls are W to accelerate, A and D to rotate trajectory and Space to fire. R restarts the game so when you die you can keep playing. I wanted to edit my OP but it wont let me. I updated some stuff too: http://www.mediafire.com/file/0wfz5s5pl4cclqi/Asteroids.gmx v.02.7z

Made the controls a bit faster, added a brake/reverse (that I actually just wanted to be a brake, so if anybody could help me out with that it would be much appreciated aha) and I feel like I've improved the way the asteroids spawn so they don't immediately kill you sometimes and I slowed them down so you have to time to react if they come right towards you. It may be too easy now though. If you just stay in the middle you'll basically never be touched and if anything comes towards you, you just move out the way and deal with it and return to the centre. I'm not sure how much I really need to polish it in that respect.
 
N

NodziGames

Guest
Your code seems pretty legit. I'd say if you've written it yourself and not copy pasted it you have some good computer nerd abilities.
Your code does have some mistakes though. I noticed you are using instance_destroy incorrectly -
Code:
if place_meeting(x,y,oBullet){
    bullet = place_meeting(x,y,oBullet);
    asteroid1 = instance_create(x,y,oAsteroid2)
    asteroid2 = instance_create(x,y,oAsteroid2)
    asteroid1.direction = direction + (bullet.image_angle + 90);
    asteroid2.direction = direction + (bullet.image_angle - 90);
    instance_destroy(bullet);
    score += 100
    instance_destroy();
}
That is wrong and has a mistake, you should be nerding like this -
Code:
if place_meeting(x,y,oBullet){
    bullet = place_meeting(x,y,oBullet);
    asteroid1 = instance_create(x,y,oAsteroid2)
    asteroid2 = instance_create(x,y,oAsteroid2)
    asteroid1.direction = direction + (bullet.image_angle + 90);
    asteroid2.direction = direction + (bullet.image_angle - 90);
    with bullet
        {
        instance_destroy()
        }
    score += 100
    instance_destroy();
}
I know this thread is old, but why shouldn't he pass in the instance ID into the instance_destroy() function when that functionality exists as an overloaded method? I don't see logic in retrieving the instance and running the code from there if you can just destroy it from the currently accessed instance.
 

O.Stogden

Member
I don't believe there is any reason not to use instance_destroy(obj,flag).

However it might be the fact that the arguments were only added in GMS1.

Anyone who used GM6/7/8 would probably be used to using the "with" function to do it, as back then, instance_destroy always destroyed the instance that called it.

Now however, instance_destroy can specify what instance.
 
Top