DEV Community

Cover image for CodeSim - A Game controlled by Code - DevLog - Part 2
Tom Van den Bon
Tom Van den Bon

Posted on

CodeSim - A Game controlled by Code - DevLog - Part 2

Phew, a lot has changed since my last update around my CodeSim game. It's been a wonderful learning experience getting to grips with using Unity. My little experimental game has progressed quite a lot. Here are some of the more notable updates:

Graphics

I'm not much of a 3d graphic designer so I'm mostly dependent on existing assets for my game (at least for now). I originally used an asset that had models for vehicles and a town environment. The more I worked on the game, the more I realized that it doesn't really fit well for me.

Alt Text

I did some more searching and came across another set which fits better. I overhauled everything with the new assets and it looks great! Our main programmable vehicle is nou a catapult. It sounds a bit weird, but it has the advantage of turning it into a shooting catapult...but more on that later

Actions and Sensors

Obviously just programming our code vehicle to go forward and turn around is a good start, but it really gets old quickly. I've started to add more commands for "Sensors", this essentially is a command that gives data back but doesn't directly do anything to the code vehicle movements. The sensors I've added are:

  • Location - Returns our current grid X and Y position
  • GoalLocation - Returns the goal X and Y Position
  • FrontSensor - This tells us whether there is an obstacle in front of us
  • DirectionSensor - This tells us which direction we are pointing to

All these sensors would not necessarily be available from level 1 as they can be added as the levels increase.

Another big action that I added, is the ability to shoot! This allows us to put down "Breakable" objects that needs to be destroyed to be able to let our program reach the goal.

Alt Text

The new sensors and shooting action should make the levels a lot more fun and engaging.

Speaking of levels...

Level Editor

On my bigger issues was how annoying it was to setup a level in code. It worked fine for testing and developing, but once I needed more levels it became an essential requirement.

Originally I went with one of the popular ways that unity developers use (according to a bunch of YouTube videos) is to create a graphic with different colored pixels. When the level loads, it would go through each pixel in the graphic and then build the level.

For all intents and purposes, this worked, but it wasn't really much less work than actually coding in the level.

I decided to bite the bullet and figure out a way to make a level editor in the game that allows you to place objects easily. The end result is a simple top down view of the game world and you just click wherever you want to put down a piece. Pressing space-bar allows you to cycle through the pieces. You also use it to place the player position and the goal position (its smart enough to know that if you try to place to player positions, it will just update it)

Alt Text

At the moment there is only 1 level, but with the above changes done I can start focusing on more expanding the levels and doing more game play mechanics. My little tester (8 years) also have lots of ideas to improve it, but I love how quickly he caught on with writing simple python programs to control the game.

Alt Text

It's been a fun journey considering that I started with Unity for the first time over Xmas holidays. I try to add work on it for an hour here and there in the evenings. Still have lots of ideas so stay tuned for the next update. Also should have a test release with the next update as well so that everyone can play along!

Top comments (0)