In the last segment on movement in Game Maker, you built a small, simple little object that moved around an empty space. It was pretty neat, sure, but only the starting point. After all, what's a game without walls!
A blog with a focus on critical analysis of video games, and other general discussion on the topic.
Showing posts with label Game Making With Game Maker. Show all posts
Showing posts with label Game Making With Game Maker. Show all posts
Wednesday, January 22, 2014
Monday, October 28, 2013
Intro to GML Part 3: A Simple Hit Points System
Ok, now that I've shown you variables and the if statement, we can build something useful with them. Once again, this stuff is specific to Game Maker, so it may or may not be helpful if you're using something else.
Here's some general things you would do to create a hit points system for one of your objects. First, you'd need to set a maximum the object can have, then fill it up.
So, in the object's create event you'd want:
Woo! Now your object has hit points that do nothing!
The system we're going to use is pretty simple and will only work with games that use collision as being hit. You know, like Mario games.
How does that work? Well, you'll need to put this in the player's collision with enemy event:
As is, this system won't work all that great. Why? Since collision will be checked every step, the enemy will reduce your HP really quickly. To fix this, you'll have to add a time after being hit that the player can't be damaged. There are lots of ways to do this, but this solution will use a "hurt" variable and an alarm.
Add hurt=0 to the create event like this:
We're just using "hurt" as a sort of switch. If it's 1, the player can't be hit.
We'll need our friend the if statement in the collision event now. Basically, "if the player has been hit, don't hit the player again."
That's all you need from the player's side. You'll need an enemy object, and a damage variable in it to have a workable damage system.
Here's some general things you would do to create a hit points system for one of your objects. First, you'd need to set a maximum the object can have, then fill it up.
So, in the object's create event you'd want:
//In Create Event
maxHP = 100; //Could be any number, change it depending on your needs
HP = maxHP; //Fills up HP to the max
Woo! Now your object has hit points that do nothing!
The system we're going to use is pretty simple and will only work with games that use collision as being hit. You know, like Mario games.
How does that work? Well, you'll need to put this in the player's collision with enemy event:
//In Collision with Enemy
HP -= other.damage; //Player's HP is reduced by the enemy's damage
As is, this system won't work all that great. Why? Since collision will be checked every step, the enemy will reduce your HP really quickly. To fix this, you'll have to add a time after being hit that the player can't be damaged. There are lots of ways to do this, but this solution will use a "hurt" variable and an alarm.
Add hurt=0 to the create event like this:
//In Create Event
maxHP = 100; //Could be any number, change it depending on your needs
HP = maxHP; //Fills up HP to the max
hurt = 0; // Player can only be hit when this variable is 0
We're just using "hurt" as a sort of switch. If it's 1, the player can't be hit.
We'll need our friend the if statement in the collision event now. Basically, "if the player has been hit, don't hit the player again."
//In Collision with Enemy
if (hurt != 0) exit; //Nothing after this gets done if the player has been hurt
HP -= other.damage; //Player's HP is reduced by the enemy's damage
hurt = 1;
alarm[0] = 90; //Amount of time you want the player to be "invincible" after a hit
In the alarm[0] event, we tell the player it can be hit again:
//Alarm[0]
hurt = 0;
That's all you need from the player's side. You'll need an enemy object, and a damage variable in it to have a workable damage system.
Thursday, April 11, 2013
GML: 8 Direction Movement Tutorial
Update: Part 2 can be found here.
Now that you have a few basics down, let's actually DO something with them. Older style top down games allow players to move in eight different directions (ok, sometimes four, shut up, this is MY tutorial). Now, how do you accomplish that in Game Maker?
Well, first you have to create an object and a room. You can name them whatever you like. Oh, you'll need a sprite as well. It can be a picture of a goldfish.
Place one instance of your object in that room you created. It doesn't really matter where, but you should probably put it at exactly (249,156). Once that's done, we can get to coding a bit.
You can build a movement engine like this in a lot of ways, and I'm just going to present one possibility here. Let's create an empty skeleton for all our code.
Obviously, you're going to want to check your keyboard. I'm going to use the arrow keys. This all goes in the step event of your player object:
Now run your game. You should be able to run around a blank empty space.
Edit and use to your heart's content.
Update: Part 2 can be found here.
Now that you have a few basics down, let's actually DO something with them. Older style top down games allow players to move in eight different directions (ok, sometimes four, shut up, this is MY tutorial). Now, how do you accomplish that in Game Maker?
Well, first you have to create an object and a room. You can name them whatever you like. Oh, you'll need a sprite as well. It can be a picture of a goldfish.
Place one instance of your object in that room you created. It doesn't really matter where, but you should probably put it at exactly (249,156). Once that's done, we can get to coding a bit.
You can build a movement engine like this in a lot of ways, and I'm just going to present one possibility here. Let's create an empty skeleton for all our code.
Obviously, you're going to want to check your keyboard. I'm going to use the arrow keys. This all goes in the step event of your player object:
if (keyboard_check(vk_left)){
x-=3;
}
if (keyboard_check(vk_right)){
x+=3;
}
if (keyboard_check(vk_up)){
y-=3;
}
if (keyboard_check(vk_down)){
y+=3;
}
Now run your game. You should be able to run around a blank empty space.
Edit and use to your heart's content.
Update: Part 2 can be found here.
Sunday, April 7, 2013
Intro to GML Part 2: The if Statement
Now that you've learned a bit about what variables are, let's use them to do stuff. Probably the most basic statement you will run across in GML (and most other programming languages) is the
Here it is in the most basic form:
That might look scary if you haven't done much work in code, but the idea is really simple. Whenever your script gets to this part, it evaluates the "condition." It can be any number of things, but usually it's a comparison between two values. If the condition is true, it does the stuff.
Now, let's use it together with some variables, shall we? Let's make a variable called condition, and set it to one.
Ok, now make another variable, and set it to 2:
We can use the if statement to compare these two things, like this:
So, do you think we will reach the "Do Stuff" part? Nope, not in this case. The if statement asks, "is condition equal to anotherVariable"? The answer is no, of course 1 isn't equal to 2, so the stuff inside gets skipped over.
Basically, it works like this:
The
if statement. It helps control the flow execution in your code.Here it is in the most basic form:
if (condition){
//Do Stuff
}
That might look scary if you haven't done much work in code, but the idea is really simple. Whenever your script gets to this part, it evaluates the "condition." It can be any number of things, but usually it's a comparison between two values. If the condition is true, it does the stuff.
Now, let's use it together with some variables, shall we? Let's make a variable called condition, and set it to one.
condition = 1;
Ok, now make another variable, and set it to 2:
anotherVariable = 2;
We can use the if statement to compare these two things, like this:
if (condition == anotherVariable){
//Do Stuff
}
So, do you think we will reach the "Do Stuff" part? Nope, not in this case. The if statement asks, "is condition equal to anotherVariable"? The answer is no, of course 1 isn't equal to 2, so the stuff inside gets skipped over.
Basically, it works like this:
if (true){
//Do stuff
}
if (false){
//Don't do stuff
}
The
if statement has a wide range of uses, so it's pretty important to know. In future posts, I'll show you how to put it to work in your games.
Thursday, April 4, 2013
Intro to GML Part 1: Variables
Here's part 1 of a multiple (as yet undetermined) part series on GML (Game Maker Language). I've seen a few posts of people having virtually no idea about using GML, and hopefully this series will solve that.
A variable is used to store information in GML. They can store a lot of things, ranging from numbers to strings. You can then manipulate them to achieve a number of purposes.
Well, you have to declare them and identify them. Usually this is done in one step, like this:
This sets a variable named aNumber equal to 1. You can then use this variable to perform different operations. Let's say you wanted to add 1 to aNumber:
You'd get 2 as the return value.
GML has a bunch of built-in variables that you can use. You don't even need to declare them. Here's a short rundown of a few common built-in variables:
x
The horizontal position of something in the coordinate system
y
The vertical position of something in the coordinate system
hspeed
The pixels per step and object is moving horizontally
vspeed
The pixels per step and object is moving vertically
You use these variables to move objects around, and find out where things are in your game. Of course, GML has many more built in variables than this, but it's best to take things in small bits at a time.
Ok, hopefully this gives you some idea about how variables work in GML, I'd be happy to anwer any questions in the comments.
What Are Variables?
A variable is used to store information in GML. They can store a lot of things, ranging from numbers to strings. You can then manipulate them to achieve a number of purposes.
So, how do you use variables in GML?
Well, you have to declare them and identify them. Usually this is done in one step, like this:
aNumber = 1;This sets a variable named aNumber equal to 1. You can then use this variable to perform different operations. Let's say you wanted to add 1 to aNumber:
return aNumber + 1;You'd get 2 as the return value.
Built-In Variables
GML has a bunch of built-in variables that you can use. You don't even need to declare them. Here's a short rundown of a few common built-in variables:
x
The horizontal position of something in the coordinate system
y
The vertical position of something in the coordinate system
hspeed
The pixels per step and object is moving horizontally
vspeed
The pixels per step and object is moving vertically
You use these variables to move objects around, and find out where things are in your game. Of course, GML has many more built in variables than this, but it's best to take things in small bits at a time.
Ok, hopefully this gives you some idea about how variables work in GML, I'd be happy to anwer any questions in the comments.
Friday, March 23, 2012
Subscribe to:
Posts (Atom)