New challenges for nameless game number 2

shipplayer

I’ve just started to write some code for game number two. The end product will have exciting levels and different game states. There will be a (to start with) main menu, intro screen and the actual game level (a couple of diffent game play levels). These seem to have very little in common, but to structure the code I’ve tried to make a Statemachine which returns a game state. Each state will have implementations for the routines listen, update, render.

The enum lists all the different types of states. The GameState contains a static state id, which keeps track on which state that is in use.
Note: This code will be rewritten to make use of unique_ptrs instead the shared_ptrs.

Dependencies

The game state relies on a number of dependencies, such as pointers to the SDL_Renderer and the SDL_Window. I encapsulated these dependencies in a class called manager. In SDL2 almost everything that deals with graphics needs a reference to the renderer, together with the resource handlers AnimationLibrary and SoundLibrary.

Camera, action!

The observant, can see there is a reference to a camera in the gamestate. I’ve been experimenting with scrolling the level horizontal and also vertical. The camera is not a real cameraobject (as you would use in 3D. Each object on the level/stage will be tied with the camera, so instead that the camera is panning or tilting, it actually moves the objects through the “viewport”, except the player. The player object is responsible for pushing the camera up, down, left or right.

When updating the objects position, I’ll set speed the object will move, this gives it a sense of  depth. For example the background image will scroll slower than the foreground (all the sprites). The camera function is still very experimental and I’ll try to make more features like focusing and maybe zooming into different objects

Level builder

I’ve been thinking a lot on how to make it easy to build all the levels. First I had an idea of creating a small png image. Where each pixel represents a tile and the color value the type of the tile. However I feel this is a fairly un-flexible solution, and I would need to define a whole range of color codes.

I’ve been doing some research and I found out that there are some good free to use tile editors like Tiled. It can also export to JSON, which should hopefully make it easy to parse with jsoncpp. And another plus, it looks like someone already written a parser for the Tiled format here.

Game design

Lately I’ve been playing with the idea to make a more larger game. With a story line and a world outside the ship, to make a more of a RPG experience. This largely increases the game complexity and development time.

The need for a simple script language

What I can see already now, is that I need to create some simple scripting language to stage the game. Like the following:

      • FOCUS on PLAYER
      • AUTOSCROLL CAMERA *The player is cruising
      • PLAYER DIALOG (“MESSAGE TO ENEMY”, 4) *The player starts a conversation to someone
      • WAITFORKEY(10) *Waits for the player to press a key or automatically continues after 10 sec.
      • FOCUS ON ENEMY(“BOSS32”) *The camera pans over to the enemy tagged (“BOSS32”)
      • ENEMY DIALOG(“MESSAGE TO PLAYER”)  *The enemy spurts out some text.
      • START GAME *The game state begins.

This is in particualar very useful when making cut-scenes in the game. I will read up more on game scripting, and what I could use. Because writing all the cutscenes in c++.

Posted in Game programming, Libraries, Programming Tagged with:

Leave a Reply

Your email address will not be published. Required fields are marked *

*