The Curious Case of Mr Snugglekins and the Giant Sack of Catnip

by Max Foster: L6 Age ~17

Introduction

This game in its original form came fourth in the 2011 mini-competition organised by PascalGameDevelopment.com. The games were restricted to input by keyboard only using eight or fewer buttons, with generous bonus points for each unused button. Only one month was allowed for game development. You can see here the judges' feedback on the program. Later, Max annotated the code for you and has given you the option of using the mouse in addition to the keyboard. He has also created a unit to allow you to create your own maps to suit your level of expertise.

Max has provided clear instructions for use at the start of the main program (MrSnugglekins). Read these instructions to appreciate the complexity of the game. For example, there are four types of gun, three types of enemy, a euphoria meter, a health pack, a euphoria pack, a shop and upgradable turrets that can be hacked. In the introduction to the code of the main program we provide links to exciting developments to allow you to make 3D games more easily.

The following examples of code comments illustrate many nice touches and a remarkable attention to detail.
  • Increment the frame of the cat and drones so they dance to the exact tempo of the music.
  • A shader for drawing a 3D model with lighting and a colour tint, while using another texture to generate a worn look, or if the 'severeWear' uniform equals 1, to create holes in the model to give a truly battered look.
  • A shader for drawing a 3D model with lighting and a colour tint that allows switching between two different textures. This shader is used in the shop to make it look like the shopkeeper is talking by switching two different face textures.
  • Update floating text for when a price floats up from the till.
  • Highlight the button, calling a procedure if a procedure pointer was passed to the button on create.
  • Loads up OpenGL Shading Language shaders, while compensating for older hardware.
  • Draw a translucent black background to give the menu a faded look.
  • Have a dissolve effect that forms the cat.
  • If we're in Euphoria mode, draw the cat with a yellow tint, a bit like Super Sonic from Sonic the Hedgehog ;-)
  • We just want the spambot to look a bit beat up, not completely trashed.
  • Show some wear and puff smoke if the health is low.
  • Make each letter of GAME_OVER_TEXT fall from the top of the screen, and fade out to black.
  • Set the speed in each axis for each particle from the direction vectors. For large explosions, each particle needs to travel quicker. The smaller the particle in an explosion, the quicker it moves.
  • If the shopkeeper has not exceeded the time he needs to say a phrase, make the mouth open and close.
  • Have a fading in and out effect by having the texture alpha vary by time.
  • Increase the chance of a Spambot spawning by decreasing the range of values that the random function can pick from depending on the score.
  • The library automatically compensates for framerate issues. Set maxFramerate to 0 to go at full pelt!
  • Set the 'ideal' framerate. This is the speed that the game will simulate, independently of what framerate the game is actually at. This means that people with slower computers will not have the gameplay slowed down, and people with faster computers will not have the gameplay sped up. This can also be useful for slow motion effects!
  • Fade out the music within a time period.

In this introduction we include six screenshots kindly provided by Max, with his brief description following each image.

Menu

Menu

This is the title screen, with the characters dancing to the music.

Shooting at Spambots

Shooting at Spambots

The player is shooting the enemy Spambots, with the help of a nearby turret bought from the shop.

Hacking

Hacking

The turret is being hacked by a Hacker Spambot! Shoot down the Hacker and reclaim the turret by hacking it back.

Intro Animation

Intro Animation

Destroy enough Spambots to go into Euphoria mode, which doubles your firepower and speed. This is the intro animation.

Rocket Launcher

Rocket Launcher

Use the Anti-Mech (a rocket launcher) to destroy Mech Spambots quickly.

Upgrade

Upgrade

Upgrade your turrets to improve their firepower, range, and health.

Max apologises for the vertical sync issues, which "aren't an issue while playing, and can be fixed by enabling 'vertical sync' or 'v-sync' in graphics card driver software".

Requirements

The source code and required assets folder (with subfolders) is in MrSnugglekins.zip. The folder submitted for the competition includes these libraries (some or all of which may be already on your system if you have been experimenting with SDL): SDL.dll, SDL_gfx.dll, SDL_mixer.dll, SDL_ttf.dll, SDL_image.dll, libpng12-0.dll and libfreetype-6.dll. You may also need zlib1.dll. You can put these files in the program folder or with thousands of other libraries in your system folder if they are not already in your system. See the introduction to SpaceShooter for individual download details and/or download several at once in a zip file of libraries that are required by the Elysian Pascal game development framework. See Getting Started with SDL for download details of SDL.pas) and other Pascal header files.

Although the program compiles without problems, it has a minimum graphics specification of OpenGL 2.1 with GLSL version 1.1. (Unfortunately, the OpenGL Extensions Viewer for this computer indicated an inadequate specification).

Presentation of Code

Follow the first link below to the main program. The program units follow in the order they are listed in the units section of the main program. After these, see the SuperMaximo GameLibrary introduction in unit SMSDL and then the other game library units in the order they are listed in the main program. Despite the pressure to meet the game deadline, Max used meaningful, sometimes long identifiers. We have found the code to be truly awesome, but it is not for beginners or the faint-hearted! It includes many advanced language features, deep nesting of constructs, and routines with many parameters of several types, so do not expect to understand much of it if you are not familiar with the material in our tutorials. For many of the units you do not need to understand OpenGL.

We have prefaced some of the units with declarations of some procedures and functions called by code in the unit. The declarations show you the names and types of the parameters. We have not included these declarations if they are in the calling unit or if the arguments are fairly obvious. It is useful to remember that in some of the create constructors, the rotation follows the x, y, and z coordinates. In the case of OpenGL procedure calls, many of the definitions themselves would require further study. If you are keen enough to understand these you should browse the program from within Lazarus and refer to OpenGL documentation for clarification. We think that the code in unit GraphicalAssetClasses is particularly challenging and we would expect to take some time to understand it fully.

Remarks

Can you modify the code in any way and predict the effects of your changes? Have you been able to create your own map using it? Could you use it to help you to develop your own program using OpenGL?

Programming - a skill for life!

NetworkChat, PascalPokemon and MrSnugglekins by Max Foster