Tag Archives: Monogame

Deferred 2D Lights

The lighting used in the game ‘Full Bore’ is fascinating. The devs wrote a nice blog post about it. Reason enough for me to replicate the effect. In 2014 I did a succesful test (see the result on Youtube).

The code wouldn’t run in Monogame and the shader files wouldn’t compile in the native Monogame Content tool. Also the 2014 code was quite messy and other than just a proof of concept was hard to implement in a game.

So I went back to the drawingboard and rewrote everything so it can be used as a library in a game project. The result of my test project can be seen in the gif below:

I’m cleaning up the code a bit and plan to upload it to Github if there is interest. The code is now available on Github!

Gamecamera implementation

After reading the excellent article on Gamasutra: The Theory and Practice of Camera’s in 2D Sidescrollers by Itay Keren, I thought of showing the code I use in my 2D game camera.

The camera I use is of the type ‘Camera window’ with ‘LERP Smoothing’. It meams the camera follows the player, if the player pushes the boundaries of a window inside the camera viewport:

The blue area (1) is the gameworld. This area is bigger than the part shown on the player’s screen. The yellowish area (2) is the actual viewport that is rendered to the player screen. The reddish (3) part is the ‘camera window’: the player controlled character will always be inside that part. Only when the player actually pushes the boundaries of that inside section the view will move. Imagine the character moves to the right edge- the camera gets moved until the player is back inside the reddish area and will nog move again until  the player reaches the edge again.

LERP smoothing means the camera ‘lags’ a bit and moves smoothly instead of immediate.

On to some code…

Continue reading

Handling Gamestates

Every game has a few gamestates; the most simple version may be ‘Title’, ‘Gameplay’ and ‘Game Over’. In this simple version one might declare an enum like this:

This leads to a switch statement in the Update() and Draw() sections of your code. However, what if the player can access an ‘options’ screen from the title and gameplay states? Or switch between inventory or map modes? Soon you’ll be adding substates and trying to remember what the previous state was…

Let’s start with a clean slate, rid ourselves of the Gamestate enum… how can we handle this in a more elegant way? Read on …

Continue reading

Content processors in Monogame

The flatshaded models are the result of modelling the object in Wings3D then exporting it to XML (vertices and faces). I made my own tool that reads the XML and converts the model to my own VertexPositionNormalColor format. In the tool I can do various tweaks and color the model. This tool then exports the data to an XML file with the extension VPNC.

The file is quite simple really:

It defines 1 black triangle with the normal pointing up.

To handle the meshes in my game I made a simple content processor- this makes using my own models as easy as:

I may make more content processors later for the tracks or any other objects that I use external tools for.

Disclaimer: There may be easier ways to handle flatshaded models (via shaders for example) that’s another topic. This topic shows how to create a content processor, I use my flatshaded model as example.

Continue reading if you want to know how to make a content processor yourself.

Continue reading

The F1 car is complete

So today I completed the car. The wheels are spinning and the steering mechanism is working. I’ve added some simple physics to the car (springs in the pitch and roll of the car so it leans in corners and tilts when accelerating or braking. Still a lot of tuning needs to be done for the car to ‘feel’ right, but the basics are there. For more info about these ‘springs’: this article gave me the idea.

If you look carefully you’ll notice the lighting on the car changing when steering. It already moves in 3D space and the BasicEffect lighting is working.

In all a productive weekend!

F1 Modelling part 2

The result of the 3D mouse picking and modelling:

The black square is the current active color. The short clip shows what the model looks like in the flat shaded mode. I’m getting more comfortable with the 3D stuff. With the BasicEffect though so Shaders will be something I’m going to dive into later.

3D mouse picking

I have converted the 3D model of the Formula One car to my own VertexPositionNormalColor format. I want to create a few variants of the car with different colors so I needed a way to select vertices and give them a color. A simple editor would suit my needs so I started writing a tool for it. This (old) question on StackExchange helped me a lot: Get 3D mouse position.

This snippet reads the mouse and creates a Ray:

The ray is still in object space, so it needs to be rotated so it matches the 3D object I want to manipulate. This snippet rotates the ray so it matches the 3D object:

Now the ray matches the 3D object, so a triangle intersection on the faces of the mesh does the trick!

Note: the triangle-hitlocation function is not my own, I had it stored on my harddrive (I knew it would come handy some day!) Unfortunately I don’t know the author.

 

Monogame in the third dimension

Until now most of my games were made in 2D. Sprites and a bit of pseudo 3D- essentially scaling tricks to make thing appear 3D.  For my next project I will need ‘real’ 3D stuff. Time to get familiar with how 3D computer graphics work. I’m still learning so join me while I figure this out.

I will be using Monogame for this project. Why Monogame? Glad you asked. I want to use Monogame for a couple of reasons: I want to learn how things work.
I’ve tried both Unity and Unreal Engine. It worked nice for quick prototypes, but I felt I was struggling learning how these tools work instead of actually getting the result I was looking for. Perhaps my next game will be in Unity once I have a better understanding 3D concepts in general.
Another thing is familiarity: I started creating games in the XNA framework a couple of years ago and have since moved on to Monogame. Stuff like a custom Content Pipeline has become familiar to me.
Furthermore I’m not a 3D modeller. I have the basic concept of my game in my mind and I plan to generate most of the 3D content. Using this concept a familiar tool helps me to focus on what I want to learn.

So time to get familiar with Monogame and basic 3D concepts!