Pages

Wednesday 9 December 2015

Assignment - Creating a Game (Shapeman)

Shape-Man Game Sketch
For this assignment, I have been making a game called "Shape-Man," which is a variant of Pac-Man. The aim of the game is to move around a maze like level, collect pills (to get score) and kill enemies. However, there's a slight twist. The enemies move around randomly, and they change shape randomly (they change between circle, cross, triangle, and pentagon.) The player can only kill enemies if they are the same shape. To do this, the player must touch the stationary shapes that are placed in the map, these will turn the player into that shape. There is also a timer in the middle of the map that shows the player which shape will be next, by displaying the number of sides the next shape has. The game is never-ending, which means it cannot be beaten. The player can die, however, and they have 3 lives. 

Here you can see the room for the game. In this sketch I have not included enemies, however they are scattered around the room and begin moving in random directions when the game starts. The shapes that you can see in this picture are the stationary shapes that the player has to touch to become that shape. In the middle you can see the timer that displays which shape will be next, and at the top the score and amount of lives that the player has. In terms of score, the player gets 1 whenever they pick up a pill, and 100 when they kill an enemy. There are 100 pills in total, and I have shown them in this sketch by drawing thin blue lines. 

Shape-Man Sprites
Shape man uses several different sprites, and you can see them on the left. I created these sprites myself with Game Makers built in sprite editor/creator. Some of them, such as the pill and wall, I drew with just the pen tool. To create others however I used things like the circle tool and square tool etc. Below there is also a screenshot of the sprite editor. On the left you can see the various different tools, in the middle you can edit the sprite, and on the right you can change colours. You can see my square sprite in the middle.

































Shape-Man Objects

On the right you can see a list of all my objects. Each object does has a different purpose, and to get some of them to function properly I had to use code.

Obj_Controller

Obj_controller may be last on the list but it is the most important because without it all the other code wouldn't work! This is because the controller contains a piece of code called "Variables." This code contains the global variables, which are things that all of the other objects can use. The controller also draws the score on the screen (makes the score visible for the player) and sets the colour of the score font etc.



Here you can see the global variables. You will see these in the code used for the games other objects too. I will go over some of the main ones.

Number and Countdown = 200 are involved with the game ticks and the random shape changing of the enemies.

Myshape = the players shape.

Spriteto and Spritenext = irandom(4); are for when the enemy shape changes. It makes sure that the enemy changes to any random shape out of the 4 that are available. 

idied = whether the player has died or not.



The next code is in a step event. This code is involved with the countdown. The first line "if irandom(number) > 50" makes the games enemy change countdown random. Line 8 "if countdown < 1" is saying "if the countdown is lower than 1" (it runs out) then the actions on line 10-14 should be performed. When the countdown runs out, the enemies sprite should change and it should change to a random one (spriteto = spritenext; and spritenext = irandom(4);) Lines 17 and 19 are saying that if there are no more enemies in the room (if instance_number(obj_enemy) < 1) a message should be shown that says "ran out of bad guys." This message along with any other debug messages are shown in this section of Game Maker (highlighted with red box,) which is separate from the game window itself:


Obj_fwall & Obj_cwall

Obj_fwall and cwall have the same simple function, they are walls. They stop the players from getting out of the map and they give the map it's maze-like shape (they are named slightly differently because of the sprites used. F stands for front, and c stands for continuing. This just helped me tell them apart properly and made sure I didn't mix them up.) These two objects have no code and the only thing I did to them was make them solid.

Obj_square, circle, triangle, pentagon and cross

These 5 objects are the stationary shapes placed in the room, and if the player touches them they become that shape. I have not used any code for these objects directly, however there is code related to these objects in other areas, which I will get on to later.

Obj_enemy

Obj_enemy is the enemy of the player. The enemy will bounce around the room randomly and change shape. To get the enemy to work as desired, code was needed. I will show the code below.
                    



The first line of this code sets the speed that the enemy will move at. In my game the speed is 0.6. Not all enemies will move at 0.6 however, and the +random(2) allows this. Line 2 allows the enemies to move in a random direction, and this is easy to understand because of the way it's written. It says that the direction should be random, and they objects are free to move 360 degrees. I will not show the next piece of code under the "alarm event" because it is the exact same however it does not use the line 1 code.



The next code is used when obj_enemy collides with obj_me (obj_me is the shape that the player controls.) This code controls whether the enemy is destroyed or not when the player collides with it. In terms of what this code does, let's focus on line 6-9 first. "case 0" is basically saying "if obj_enemy is a circle." We can tell it's about a circle because it uses the number 0, which is the amount of sides a circle has -1. The next line, "if spriteto == 0 then killedit = true;" is saying "if the players sprite is a circle (0) as well, then the enemy will be killed when the player collides with it." The next line "else idied = true;" is basically saying "if the player is anything other than a circle, the player will be killed." At the end of the code, (lines 29-37) it is saying that "if we kill the enemy, it's instance should be destroyed." It will also up the players score by 100 if an enemy is killed.



This next code is in a "draw event" for obj_enemy. This code is telling the enemy which case = what sprite. For example, when the enemy changes to case 0, it is changing to a circle because a 0 is the number of sides a circle has -1.


Obj_enemy is also set to bounce off solid objects e.g. the walls. This stops the enemies from leaving the game map.




Obj_me


Obj_me mainly uses drag and drop features but does include a little bit of code.









Firstly I have obj_me set to stop moving when it hits a wall. This is an easy way of using collision with the drag and drop features




I then have collision events set for when the player collides with a stationary shape. All the shapes work in the same way so for an example I will show you the square. 


Here you can see the drag and drop action that turns the players sprite into the square when the player collides with the square.



The code is quite simple and includes a global variable that tells the game what the value of the shape is. For square it is 3, and as I've said before it's the number of sides the shape has -1.



The rest of the events in obj_me are keyboard controls. Set to the arrow keys. The player moves at a speed of 2.5 when using the controls.










Obj_pill

The last object to talk about is obj_pill, which is what the player picks up to get score. The player is given one point when one pill is collected and there are 100 in total.


All that obj_pill has to do is disappear when the player collides with it, and up the players score by 1.

The Room

The room is the area in which the game takes place. Below you can see a picture of the room for Shape-Man.



Gameplay video
https://www.youtube.com/watch?v=4NCHqv1fjy8

What could be done to improve the game?

My friend Tom played Shape-Man and from his feedback I know what I could do to make the game more interesting. Firstly I could animate the sprites. By animating the sprites it makes the game look more interesting and visually appealing. Secondly, I could have used a wider range of sounds. Maybe sounds of the enemies pinging off walls, or my character exploding when I die. Thirdly, I could try harder to fix major issues with the game, for example the countdown in the middle. The countdown is an important feature and like me my friend struggled kill the enemies sometimes because he didn't know what they were going to turn into next. And even though the player can easily be told in a manual, the number of remaining lives should be displayed on the screen.

Game Manual



No comments:

Post a Comment