First game:Balloon pop

From ENIGMA

Revision as of 00:05, 7 February 2013 by IsmAvatar (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

If your new to Enigma and haven't used Game Maker before, or just want some help getting used to LateralGM's UI, or Enigma's C++ way of doing things, Here is a tutorial.

This tutorial was made during r816 and may be outdated.

First of all, Install Enigma if you haven't already. Like seriously. Its kinda hard to do this tutorial without it.

Also, download this zip archive and extract it, as it contains some sprites and sounds for us to play around with.

Open up Enigma/LGM (ENIGMA.exe on Windows. lgmb16b4.jar on Linux and whatnot). A little window titled 'Enigma Progress Console' should open along with LateralGM's UI. If any errors appear during startup in the Enigma Progress Console, please tell us via IRC.

Contents

Creating the resources

After opening up LGM, look around. There are three sections, the toolbar/menus up the top, a Resource tree hierarchy on the side and a workspace in the middle. The tree on the side is actually the resource explorer, and it allows us to manage resources. Resources are things like images, music, code, levels, and objects. To get started, create a Sprite. There are numerous ways of doing this, for now lets just right-click on the folder with the label 'Sprites' and select 'Create resource'. A window should appear. Click load (Next to the green tick) and navigate to wherever you extracted the firsttut.zip, and choose ball.png. Leave all the settings as they are, and press the green tick.

Shows sample DND code in the LateralGM object pane.

Now, we need an Object. An Object is anything in your game that can move. Right click on objects, and click 'Create resource'. You'll be greeted with a window that has four sections. On the left-most section, you'll see properties like its name, sprite and parent. In the textfield next to name, type in obj_ball. This isn't necessary, but in large projects it can become hard to remember which object is which, so it better to name them. Putting obj_ in front makes sure it doesn't get mixed up with any other resources types, like a sprite. Click on the Pacman icon within the Sprite group, and select spr_0 (Or whatever you named your sprite. should be the only option). The next panel is Events. This panel is linked to the one right of it, Actions:, or the actions list. On the far right is a panel with a bunch of Action tiles that you can choose from. If you mouse over them, you will see a tooltip telling you what it does. With Create selected in Events, drag the first Action tile (The one with 8 red arrows on it, titled "Start moving in one of the selected directions") onto the actions panel. Click on the down arrow button, type 3 into the speed box, and click save. Just for now, click on the green tick save button at the bottom of the settings panel (in the future it may be moved to the top-left). We'll do some more work on it later.

Now, we're going to make a Room to test out our object. A room is another term for level. As with before, right-click on Rooms and select 'New room'. You should be greeted with a nice grid, a properties panel with five tabs, and a bar along the top with zoom and grid size and stuff. In the properties, click on the blue ball next to the <no object> text (click on the top one. Not the one towards the bottom in Edit Instance). Select your obj_ball. Now, left-click anywhere near the top. A blue ball should appear. Press the green tick (Save), and then run your game (Go to Enigma in the top menu, and select Run). A window should open, and a blue ball will appear wherever you placed it an slowly move down the screen. Close your window, and give yourself a pat on the back. You just gained 15 Exp. You just went up a level. You are now level 2. Hahaha, Aren't I the funniest? No? D:<

Creating more resources

Well, you just successfully made your first 'Game'. However, I know it may be hard to comprehend, but you can make even better games (I know, its hard to believe). So, first of all, lets make more bubbles appear. Also, I thought the bubbles moved too slowly, so lets change that. First, we'll make something that creates more. Add a new object, you should know how by now. Name it obj_emitter. As implied by the title, this object will create balls. We want to create a continuous 'stream' of balls, rather than just a burst of balls at the beginning. To do this, we'll use the Normal Step event instead of the Create Event this time. Go to the Control tab on the very the right (beyond the Actions panel - this will change the Action icons offered) and drag on the random chance (Dice icon) action. For Sides, enter 50 (Big dice, I know).

So, want some explanation as to why thats so big? And how these events work? Enigma well check for when certain stuff happens, which will trigger an Event. The event then calls the actions in the actions panel belonging to that event when that happens. 'Normal step' is called every 'Step' or frame, recurring. As such, it can be a good place to execute game logic. There are usually about 30 steps in a second, so our Normal Step event gets called about 30 times per second (note, the 30 is specified in the Room settings, as Room Speed. However, ENIGMA sometimes has trouble honoring this number and can oftentimes run a fair bit faster than that. Hey, it's hard to hold back this speed!). Now imagine rolling a 50 sided dice 30 times a second. On average, it will roll your number every ~0.8 seconds!

Next, put in a Create Instance action (Found in the Main1 tab) below the Chance action. In the pop-up window, select obj_ball as the object, and in x put random(640). Leave Y as 0. What is this random(640)? And what is X and Y? Random returns a random number between 0 and it argument (The thing in brackets). In this case, it returns a random number between 0 and 640. What is X and Y? X and Y are Cartesian co-ordinates, used to describe where something is on a 2D plane. In this case, where describing where on the window to create the ball. X is horizontal, Y is vertical. In the top left corner, X and Y are zero. For every pixel, X and Y go up one. The default room/level/window size is 640 by 480, which is why I used a random number less then 640.

Now, lets add our emitter to the room. Open up the room (Double click on rm_0) and select obj_emitter and place it in the level, the same way you placed the ball. You won't see it, but in the side you'll see a row saying 'obj_emitter <long number here>'. Press run, and you'll see more balls appearing. So, now lets speed up (Or slow down) those balls. Open obj_ball (Double click on it in the resource tree), and double click on the 'Start moving in a direction' action. Change speed to whatever you want, I'm going to use 5.

Input

Okay, so this may be pretty amazing and overwhelming, but by definition, games usually require some form of input from the player. I'm sure you agree with me that the game is already worthy of the title 'Game', but to fill these requirements, I guess we'll have to have some input from the player. So, my idea was we add in a triangle, that pops the bubbles. So, first we add a new object and sprite. For the sprite, load the triangle.png image from the .zip. Name the object obj_triangle, and select the triangle sprite. In 'Normal step', drag in a 'Jump to position' in the pop-up window, enter mouse_x for x, and mouse_y for y. This makes the object follow the cursor. Put a triangle object into the room, and test. You'll notice the offset is kinda dodgy, and the balls don't pop D:

So, first lets fix the offset issue. Open up the triangle's sprite, and where it says 'Origin' enter 8 for the X, and 16 for the Y. This offset is where the sprite thinks point X=0,Y=0 is. Since we set the object's X and Y to the cursors X and Y, and the sprite draws itself wherever object is, this sprite now appears where we want it :D You may want it somewhere else, so play around with that if you want :).

Now, to make the balls pop. Open up obj_ball. What we need to do is add a collision event, which can be done by pressing the button with a calendar (I think its a calendar) and selecting collision. On the side, under 'Collision Object' choose obj_triangle. Now double click on Collision in the list, and you'll see a new event titled obj_triangle has appeared. With this new event selected, drag a destroy the instance action in (main1 tab, recycle bin icon). Press save on the pop-up window and then try out the game.

Also, a small issue with the game is the balls won't destroy themselves when the exit the room. After excessive playing, the game will start to lag. To fix this, open up obj_ball and add a outside of room event (found within the other folder). Then, add in another instance destroy action (Same thing you put in collision). As you can probably tell, calling this causes the ball to destroy itself.

Audio

Now our balls be popping, but they be silent! Oh noes! We better fix this! Fist, right click on Sounds and click 'Create Resource' as per usual. Next, click the load button next to the green tick, and browse to Pop.wav. You can listen to the sound with the play button, but be warned the button is still in early beta and may eat you and/or your firstborn child. Now open up your obj_ball, and in collision with obj_triangle,before 'Destroy the instance', place a 'Play sound', and choose the sound you just made in the popup window. Make sure to set looping to false unless you want to hear the sound hundreds of times! :D

Adding a score and increasing difficulty

Shows how game should look when finished.

Well, the game is currently quite easy. And there's no score, so you don't know how many balls you've popped. To rectify this, drag a 'Set the score' (First block on the score tab) block above the Destroy the Instance block in obj_ball (Doesn't matter if its above or below the Play sound), and in 'new score' enter one, and tick relative. Relative means that, instead of setting the score to this value, it'll add this value to the score. Save out of those. Open up obj_emitter, and add a draw event if you don't see one already. With the draw event selected, drag in a 'Draw the score' (Third on on score page). Leave the settings as they are, and press save. run the game again. Our score is shown in the top left corner, and increases every time we pop a ball. Now, lets make the games difficulty increase as your score increases. Easiest way to do this is to open up obj_emitter, go into the normal step event, open up the Chance block, and set sides to 50-(score/10). Thats sets the chance to be fifty minus (The score divided by ten). This means, when your score reaches 40, the chance is 1 out of 56. When you reach 500, its one out of one.

Personal tools
Namespaces
Variants
Actions
Navigation
ENIGMA
Other
Toolbox