Staying the Course[work]

In my last post, I began working my way through the free video lessons on www.gameprogrammingcourse.com and it’s associated YouTube channel.

It’s important to note that the YouTube channel is supplementary to the website, not the other way around; as such, if you arrive at the YouTube channel first (as I did) you might find yourself scratching your head when you get to the playlists, particularly where to start

If you’re looking for Level 01, that’s on his website here. There isn’t a video for this as you’re just downloading and installing GMS, the videos begin at Level 02.

###

It’s hard to believe that it’s only been 2 days since I started these courses, and I just finished Level 04, which wasn’t a lesson series, but rather a series of challenges designed to utilize all the skills I’d acquired in Levels 02 and 03.

Random Solutions

One of the problems we’d be wrestling with is game speed and it’s effect on action timing. Suppose you plant a brick wall in front a horde of advancing peasants.

Event > Collision > Obj_Peasant > Obj_BrickWall

//subtracts 1 hitpoint from the brick wall upon collision
with other {
hp=hp-1
}

Assuming you’ve given the Obj_BrickWall an instance variable called “hp” (i.e. hitpoints) and assigned a numeric value to it (e.g. 100), it would take one peasant about 3.2 seconds or so to break it down as he’s colliding with it 30 times a second, dealing 1 damage each time.

My solution to this was simple, but lacking – give the wall more hitpoints, say 1000 for instance. This isn’t a very elegant way to handle this, but it worked, and it took a peasant about 32 seconds or so to break down the wall, which is what I was looking for.

Then I completed Level 03, and in the process of doing so, learned about irandom_range (#,#). What this does is allow you to replace any integer with randomized range of numbers. For example, you could have the peasant do a savings throw (much like a tabletop RPG) to determine whether or not he landed a successful blow. That would look something like this:

//Utilizes a random number to determine whether or not a hit is scored,
//subtracts 1 hitpoint from the brick wall upon successful roll.


savingsthrow=irandom_range(0,100)

If savingsthrow=1 {
with other {

hp=hp-1
}
}

As such, the peasant has ~30 chances a second to hit the wall, dealing 1 point of damage on every successful hit. Towards the end of Level 03, and a few times in Level 04, this method was used as a makeshift timer of sorts to throttle the speed of an event by adjusting the range (i.e. bigger range = more time, smaller range = less time).

Looking ahead toward Level 05, I suspect that this will be replaced with a far more precise way of handling timing.

Published by

Yousef

IT Manager by trade, game developer by heart.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.