Category Archives: Programming

MAD: Game DevLog #2

Hello everyone! Time for devlog number #2!

In the last week, we’ve implemented transparent walls and the player animation state machine. Max continued designing sprites for the game and Andrei implemented the bomb animations and it is working on some enemies. The next week I will try to implement and finish the UpgradeManager, a Singleton class that shall handle the dispatch player powerups.

The transparent walls were implemented using Raycasts the wall will cast a ray in the up direction and if it detects the Player collider it will reduce it’s alpha value to 50%, when the ray doesn’t collide with anything the alpha values goes up to 100%. In the following picture the raycast is drawn with a red line:

When I first attempted to do the player animation state machine I got lost very quickly and I quickly abandoned the idea. I tried implementing it with a blending tree, hoping that it would work that way but it didn’t.

Blend Trees are used to blend multiple animations smoothly, when you have a walking/running animation in 2D you’d like to play the “WalkLeft” animation when X is -1 and Y is Don’tCare. To achieve this Unity gives us blend trees:

The problem with this approach is that it doesn’t work when you have idleLeft and runLeft, because the blend tree doesn’t know what idle to pick when both X and Y are 0. After taking a break the solution just popped into my head: Use a state machine instead of a blend tree. From any state you can go into the RunX state but after you’re done with the RunX state you’ll transition to IdleX.

This works as expected but with a tradeoff, you can’t move in diagonals. Each transition has a rule for AnimationX or AnimationY attached to it, and if you change both X and Y at the same time you randomly jump to RunX and RunY animations, making it look like a glitch.

In Unity X and Y are custom parameters for the state machine, it doesn’t necessarily need to be the X and Y position of the game object. You can tweak your movement handling code to set AnimationX and AnimationY to prefer the max of those two and set the other to 0.

To work collaboratively on this project we use Github for code and Google Drive for assets sharing.

If you want to use Github for your Unity project I’ll recommend that you generate a proper .gitignore file.

Thanks for reading!

In case you’re wondering from where the title MAD comes it just comes from our names: Maxi, Andrei and Denis. Since this is our first game and out first attempt in doing something together I had no idea what name to chose.

If you wanna start developing your first game with Unity, we’ve found the following video lectures to be quite motivational and helpful: https://learn.unity.com/tutorial/your-first-game

Advertisements

MAD Game DevLog #1

Hello Everyone!

In this devlog I’ll try to keep you updated with the latest state of our game. Since we all have full-time jobs, we’ve been working on this game only on our free time.

I’ve been implementing the world generation code and since I hadn’t any Sprites for the walls available, I’ve made my own ones in Aseprite.

Using the Sprite from above I’ve created two prefabs in Unity and I’ve changed the colour of one prefab to brown, the generated world looks like this:

The player sprite is also my doing.

A few days later I’ve received the wall sprites from Max and I imported them in Unity.

The reason the sprites look so small is that Max designed them so they can overlap but we’re not exactly sure how we’re going to do that, since this game is based on a matrix grid adding overlapping sprites to it might make it a bit confusing.

Here are some pictures on how the game would look like with overlapping.

Andrei took the heaviest task to get the bombs working. He was struggling with Raycasting, Coroutines and the 2D Physics system from Unity. After some time he managed to get it working. The bombs are placed and explosions are spawned, it still needs a bit of polish.

Thanks for reading and have a nice day!

Adding PostgreSQL support to your ASP.Net Core application via Docker

I’ve been playing recently with ASP.Net Core and I’m developing a small Web API project in order to teach myself the framework.

In still article I’ll explain how to use a Postgres database with Docker, in order to make your development experience much more enjoyable.

Before moving on, please make sure that you’ve installed:

First, create the docker-compose.yml file in your root directory of the project, the file should contain:


version: '3.4'
services:
  postgres:
    image: postgres
    environment:
      - POSTGRES_USER=app
      - POSTGRES_PASSWORD=app
      - POSTGRES_DB=mydbname
    volumes:
      - ./volumes/data/db:/var/lib/postgresql/data
    ports:
       - 5432:5432

This specific postgres configuration passes some self-explanatory environments variables to the postgres database, it binds the ./volumes/data directory to the postgres’ data volume and it exposes the port 5432. We bind the volume so we can achieve data persistency and explore the files generated by the postgres database.

Next, add the following packages to your ASP.Net Core application:

  dotnet add package Npgsql.EntityFrameworkCore.PostgreSQL
  dotnet add package Npgsql.EntityFrameworkCore.PostgreSQL.Design

Add your database connection configuration to the appsettings.Development.json file, note that they match the strings from the docker-compose.yml file. When running in production you should deploy each service in a separate container and configure them with environment variables. Never hardcode sensitive information in your files!

{
"DatabaseConfig": {
    "PostgresSQL": "Server=localhost;Port=5432;Database=mydbname;User Id=app;Password=app;"
  },
...
}

Now in the Startup.cs file, when configuring the application context, specify that you want to use PostgresSQL.

services.AddDbContext<ApplicationContext>(options =>
{
    options.UseNpgsql(Configuration.GetSection("DatabaseConfig")["PostgresSQL"]);
});

This is it! Make sure that your application is not running and start the database with docker-compose up. After the database has started open a new terminal and add the migrations:

dotnet ef migrations add InitialMigration
dotnet ef database update

If you’d like to stop the database you can run docker ps and docker stop <hash> where <hash> is the hash of your database container. Following the steps from above gives you an isolated development database that you can use alongside your ASP.Net Core application, if you need to add ElasticSearch, Redis or another service all you need to do is change the docker-compose.yml file to include them and voilà.

Thank you for reading, have a nice day!