Introduction to GameMaker and Programming

30 2 0
Introduction to GameMaker and Programming

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Introduction to GameMaker and Programming Building Your First Game Before we begin, I want you to understand my philosophy on how to learn I believe that your very first time doing something, you sho.

Introduction to GameMaker and Programming: Building Your First Game! Before we begin, I want you to understand my philosophy on how to learn I believe that your very first time doing something, you should be walked all of the way through it, and then you should be let go completely and you should learn everything else on your own through researching, tinkering with stuff, asking questions, and developing It’s the way I’ve learned and I wouldn’t have it any other way I will walk you through what to with this project, and I will explain my steps in great detail, but will not explain some things that are not needed for this project I will however, explain everything you are doing to build this project in detail This guide is as long as it is primarily because of the pictures, so don’t be alarmed by its length GLHF! Install Gamemaker Studio: http://ccm.net/download/download-23641-gamemaker-studio-standard Open GameMaker Studio Select New Project Name it whatever you want and hit next Screen should look like this after closing the news updates window (You may have a bar running across the bottom Don’t worry about it You can close it if you’d like.) The left window is where everything in your game is stored I repeat, this is where literally EVERYTHING is stored Scripts, pictures, music, everything What is that stuff on the side bar???: Sprites – This is a fancy name for pictures Pictures of stuff you want in your game Sounds – This is where you just put all of your sound files This helps you stay organized Backgrounds – This is where you put your background photos Again, helps you stay organized Paths – A much more advanced idea You can create a path you want some object to follow in the game I recommend not worrying about this until you feel you need to So for now, ignore it I’ve never even used it myself Scripts – This is an optional folder that you will not use for a while In game maker you can use what is called drag and drop (D&D) or you can write code Writing code is much more powerful, however, you will find that Drag and Drop is exactly the same as programming, but is a little easier to get the hang of and still extremely powerful So, this is just where you would store code you write Fonts – For when you have text in your game, such as a “GAME OVER” appear at the end of your game, you can store fonts in these files and reference them later when you need it Time Lines – I’ve never used these, so I’m not going to define it so I don’t give you wrong information Objects – This is where the magic happens Most of your game development will be done here This is where you create game “objects” You create an object, and have to tell it everything to For example, this is where you would program the logic of an object moving, having health, responding to user input, giving it a sprite, making a sound when it hits the edge of the screen and then changing direction Things like this! Rooms – This is where your level design happens These rooms are what the person who is playing your game will see I’ve never used Included Files, Extensions, or Macros before so I am not aware of what they are The big ones to understand are sprites, objects, and rooms I only wrote these definitions for you to reference You’re not going to truly understand what these things are until you take that first step in making games Once you make a game or two, you will have a solid understanding of what all of these things are! The first few games you make, this can be extremely confusing, and that’s something you should understand about anything in the STEM field WE’VE ALL BEEN THERE Things will get frustrating and difficult to understand, however, there is no feeling more rewarding than completing a project you’ve started Not only that, but the more you it, the more you understand it Now that that’s cleared up, let’s get started! Game concept: The game will start with an object completely stopped (a red square) When the user clicks the object, they get point, the object randomly spawns to a new location and gets a little bit faster Each time, the user has seconds to click on the object If they don’t click on the object, the game is over LET’S BUILD THE GAME: Create your main object sprite a Right click on the Sprites folder in the menu to the left and click “Create Sprite” b A window should pop up Where you see the “Name:” box, put “spr_red_square” c When you make a sprite it’s best to name it “spr_descriptive_name” This is totally up to you, but it will make your project much cleaner and much more organized d Now, click the button that says “Edit Sprite” A new window should have popped up that looks like this: e Click on the icon next to the green checkmark all the way to the left If you hover over this icon, it should say: “Create a new sprite” A window should pop up like this: f Leave width and height each at 32 and hit OK This is in pixels in case you are curious g When you click okay, it should take you back to your sprite editor, which should now look like this: h Double click on image The image editor should come up that looks something like this: i j Don’t worry about what everything here does Remember that everything is here as an additional tool You could technically just use the pencil tool, select a color and everything These tools are here to help you, not confuse you! We’re just making a red square so we’re going to use the “fill” tool This is the one with the buck pouring over In the tools section, this is the one that is in the second column, fourth row Click on this, select some shade of red to the right and then just click on the checkerboard thing (it’s actually our sprite so far, just nothing has been done) to fill the entire image up with red paint k Click the green checkmark on the image editor, then click the checkmark on the sprite editor and you should return to the window with the title “Sprite Properties: spr_red_square” where you should click on the “OK” button and you’ve officially made your first sprite! Now, the same exact thing except call this one “spr_blue_wall” and make it a blue square You now have the only two sprites we’ll need for this game! Your project should now look like this: Making our Wall object a This object will simply be a wall When the red square hits it, it will cause the red square to change direction as you would expect in real life b Right click on the word Objects and select Create Object A screen should pop up like this: c DON’T QUIT! We’re going to simplify what everyhting here is You only need to understand what is necessary for this project (that’s true even in professional development by the way Only learn what you need to to accomplish your goals) d Where it says name, name your object “obj_blue_wall” e So now we have an object named obj_blue_wall, but what does it actually look like? This is where sprites come in We need to tell the obj_blue_wall to look like the sprite: spr_blue_wall f So, right under Name, there’s a box with the words “” in it Click on the box, and a little menu will appear Select “spr_blue_wall” g You’ve now told the object to take the form of spr_blue_wall h The last thing we need to is check the box that says “Solid” We only this for objects that not move as a rule of thumb This rule of thumb has never failed me I don’t recommend doing this with objects that are moving i Click OK I’m writing this as I’m making the game, and I’m 99% sure we’re now completely done with obj_blue_wall” If we come back to it later, I apologize for telling you otherwise j You’re not really going to understand these things until you actually make a few games, but here are some things that will help you understand objects: https://docs.yoyogames.com/source/dadiospice/000_using%20gamemaker/ 008_defining%20objects.html Creating our first (and only) level a Screen should currently look like this: b Right click on “Rooms” from the left menu and click “Create Room” Should look like this: c The first thing we should is ignore everything we don’t understand (I expect that to be almost everything) d This is literally what your game is going to look like, and this is where the designing happens e Let’s rename the room to “game” by simply typing “game” in the name field We’ll leave the Width, Height, and speed alone for now f Now, where you see the tabs near the top left, (backgrounds, views, physics, objects, settings, and tiles) click on objects Should look like this: g Now that you’re in the objects tab, go near the bottom of tab and click on where it says “” and select “obj_blue_wall” h We now have our object selected and ready to put into our level You can click anywhere in your room to add the objects But them around the border of your room If you hold Ctrl + Shift while holding down the left button on your mouse, you can actually drag your mouse to create multiple objects at once values that are required for a function to work - n1 and n2 and will generate a random number between n1 and n2 Because direction is measured in degrees, we want the direction to be a random value between and 360 In practice, we must set direction equal to: random_range(0,360) All this function does is give us a random value between and 360 For further clarification, if we wanted a random number between 10 and 20, we would random_range(10,20) Don’t worry about anything else we haven’t talked about that is on this screen These things will make more sense after you get a feel for how game development works Your screen should look like this: Now Click OK Your Object Properties window should look like this: 10 If all looks good, click OK to save and close the Object Properties window d Now that the square has the logic programmed into it, all we have to is add the red square object to the room Do you remember how? Your screen should look like this when you’re done: e Where exactly your red square is doesn’t matter You can start it wherever you please f Now, run the game and observe what happens Your shape should begin moving in a random direction, but your object goes right through the wall! Let’s fix this g Go back to the obj_red_square and add the step event For a description of what the step event is, see above where I described it in detail Now, still in the move tab, under the “Jump” section there is an action called “bounce” that is the second column and third row It looks like an arrow bouncing off of a wall Drag that into the actions menu You should have a screen that looks like: h You can leave everything at their defaults It’s worth noting that we want to only bounce off of other solid objects So if there were other red squares in the game they wouldn’t bounce off of each other because they aren’t solid because they are moving Click OK and OK again to save and close the object properties window If you run your game, your square should bounce off of the walls Responding to user input a In order to understand what I’m about to show you as best as possible you need to know about some built in variables every object automatically has in GameMaker Studio The ones we will be using are: x, y, speed, and direction Variables are simply values that every object has Every object has an x value, y value, speed, and direction We can change these values as much as we please In fact, we already have! Remember when you gave the object a speed and a random direction between and 360? You were setting the object’s variable b Open back up the red square object and add the event Mouse and select Left Button from the list Your screen should look like this: c Still in the move tab, under jump select “Jump to Random” which is found under the jump tab in the first row 3rd column It’s the box with an arrow pointing to the question mark Leave everything at the defaults and hit OK d Now, run your game and click on the red square It should jump to a random location when you click on it Well now the game is a little harder, but it stays moving in the same direction and the speed is always the same Let’s fix that e Go back to the object properties and go to the actions menu under Left Button This should be your screen at the moment: f The first thing we need to is set the direction to a new random value and then we need to increment the speed by The easiest way to this is to go to the “control” actions tab This screen: g All the way at the bottom, there is a section called variables Remember how I said we have built in values? This is where we’re going to set them You can see what each box actually is by hovering over them The first one says “set variable”, the second says, “test variable”, and the third says “draw variable” Well we’re trying to set direction to a random value so we should drag the first one over into the actions menu A screen like this should appear: h Where it says variable, that is what we’re going to change Case matters here! You must write exactly direction DIRECTION or Direction will not work Now, we want a random value for direction, so we’ll once again use GameMaker’s built in function random_range(n1,n2) So we should set the value at random_range(0,360) It should look like this: i Run your game a couple of times and make sure it works well If it does, then continue Now we need to set the speed to increase by some value For now, we’ll only set the speed to increase by j To this, again, drag the “Set Variable” action and type “speed” where it says variable Again, SPEED and Speed will not work Set the value to “speed + 1” The computer reads this as “set the speed to speed + 1” Run your game The red square should get faster and faster every time you click on it There’s a cleaner way to this however k Go back into the Left Button event inside of the red square object and double click on the action: Set variable speed to speed + Now, delete speed+1 and replace it with just and check the relative box at the bottom It should look like this: l Click OK and OK again and run your game You should notice that your game runs the same way it did just a minute ago The key here is that relative checkbox When you check that it automatically adds whatever value you put to the variable The first way and the second way are literally identical, it’s just another way to it In programming, there’s always more than way to something, and that’s part of the fun Creating a score system: a Go to the Left Button Even inside of obj_red_square once again The reason this is where we are doing the programming of the score is because every time the left button clicks on the square, we want the score to go up by one b There’s a tab dedicated to score you’ll notice It’s the 5th one down Right next to the control tab we just worked in Click on that tab to see the score actions c There are three sections, score, lives, and health Currently we only are setting up a score system, so we should drag the set score action into the action menu Again, we want the score to increase by every time, so we want to set the new score to and check the box that says Relative It should look like this: d Now let’s set up the score to always be drawn on the screen To this, we have to create a draw event Click on “Add Event” and click Draw then click Draw again Your screen should look like this: e So now, we have to tell the computer to draw the score Let’s that In order to draw the score, you must go to the “score” tab Once you’re there, you need to drag the action “draw score” into the draw event You should get a pop up window that looks like this: f It’s up to you what x and y coordinate you have set up If you want to draw it exactly in the middle of the screen you will have to set x to room_width/2 and y to room_height/2 These are both built-in variables and you can use them however you wish I have mine set up this way: g Now, if you run your game, the score is there, but there’s a problem! Where did the red square go?! So here’s what happened: We took control over what to draw to the screen As soon as we create a draw event, GameMaker no longer assumes you want that object drawn to the screen, so we just have to tell GameMaker to draw the red square again The way we this is in the draw event, we go to the “draw” tab and select “Draw Self” This action is represented by the icon of a person with their arms straight out It’s in the drawing section First row and first column so all the way on the top left of that section Drag that in, run your game, and everything should be good! h That’s it! The score system is set up Setting up the alarm to give you seconds to click on the square before the game ends a So the game is already challenging We have to click on the square and it gets faster and changes direction It’s very unpredictable and after a while it gets very difficult However, the game will never end, and as much as we hate to see the words Game Over, a game would be very boring if it never presented a feeling a defeat or accomplishment b We are going to learn about alarms in GameMaker to help us accomplish this We need to set up an alarm to count down from seconds, set it back to seconds in the event that the player clicks on the square Then, in the event that the alarm reaches 0, we need to end the game c Go to the red square object’s create event and set up the alarm To set up an alarm, we need to go to the tab “main2” and all the way at the top there is a section called “Timing” All the way at the top is a green clock This action is called Set Alarm Drag it into the action menu d Now leave everything as it is except “number of steps:” This might be a little confusing, but bear with me Right now if you recall, we have a room speed and the room speed is 30 You can see that here: e This value represents how many steps there will be per second So since the room speed is 30 steps for seconds, there logically would be 150 steps for seconds f Therefore, we should put 150 in the number of steps here and say OK: g But what if we forget the room speed and are too lazy to go all the way to the room and find it and the math ourselves? Well, that’s where variables come into play h The room speed is stored in a variable called room_speed Given this we can actually change the number of steps from 150 to 5*room_speed and they will be the same thing i j There’s another reason why this is better than just typing 150 Say that half way through the project, you decide you want to change your room speed to something else Well, if you had 150 steps, now that is no longer seconds, it’s something completely different However, * room_speed will always end up being seconds long, so this is the better way to go Now let’s the same thing in the Left Button event Try to set the alarm yourself It’s the same process, just in a different event Your left event actions menu should look like this now: k Great, we have an alarm that counts down from seconds, but what happens when that alarm reaches 0? Nothing yet, we have to tell the computer what happens l Click “Add Event” and then click Alarm and from the menu select Alarm Your screen should look like this: m What we want to happen when the alarm goes off? We want the game to end! n Doing this is extremely simple All we have to is go to the tab “main2” which is third from the top and under the section that says “Game” there are actions listed here The two arrows pointing in a circle are the restart action and the one to its right is the end game action You can choose either one All you is drag either one into the action menu and your game is complete! It should look like this: CONGRATULATIONS ON MAKING IT THROUGH THE GAME DEVELOPMENT PROCESS! A lot was thrown at you in this tutorial and it’s okay if you didn’t retain everything In fact, it’s expected that you didn’t I recommend you go back and go through this tutorial at least one more time I think you will find that it isn’t that hard and maybe after or times doing this tutorial you can begin to build your own games! If you have any questions, comments, concerns, or recommendations, email me at willisb5@student.morainevalley.edu I’ll be sure to be quick to respond The best way to get good at game development is to it! Your first game is by far the most confusing and awkward and you don’t feel like you belong, but that’s okay We’ve all been there I’ve been there I was you at some point following a tutorial online and ripping my hair out because something doesn’t work I hope I was able to help you gain some understanding of how to use GameMaker and maybe helped you think of some other games you want to develop I recommend that you take this game and play around with some things Change the speed, maybe create a power-up that flies across the screen that slows down the square? I don’t know What you is up to you, but you have something to play with now If you have any interest in learning how to actually type code in game maker and get a game to run that way, find a guy name Shaun Spalding on YouTube He taught me everything I know and is very detailed in his tutorials Congratulations again and happy coding! :) ... We took control over what to draw to the screen As soon as we create a draw event, GameMaker no longer assumes you want that object drawn to the screen, so we just have to tell GameMaker to draw... if you were reading (Left to Right and Top to Bottom) a Move Fixed – Allows you to define a speed and choose a direction (Left, Right, Up, Down, Up-Left, Up-Right etc…) to move your object in b... or accomplishment b We are going to learn about alarms in GameMaker to help us accomplish this We need to set up an alarm to count down from seconds, set it back to seconds in the event that the

Ngày đăng: 10/09/2022, 09:00

Tài liệu cùng người dùng

Tài liệu liên quan