Uploaded March 2020 | Updated November 2026, 2 hours ago
Lets take a look at building an abstraction over a character controller in our 2D platforming game. The goal of this refactoring and abstraction pattern is to improve the testability and modularity of the character controller. Hopefully by introducing this model we'll have a character controller that we can test and extend easily without introducing to much additional complexity into the project.
My abstraction design has two new components; `States` and `Actions`:
States are data providers that expose different properties to Actions. An example State might store the current controller Input's that our player is receiving. Each State is intended to store a discrete composable part of the total controller state, this is done so that individual state objects may be swapped out to support different features or tests. For example a Keyboard and Mouse State could be swapped for a Controller State to account for different input capabilities.
Actions consume the objects state and perform different State modifications of the current objects state or the game. For example an Action may consume our Input state and use that to move the player in the world. Actions do not directly interact with one another but communicate through state modifications instead. Because each Action describes a single behavior this allows us to introduce temporary new behaviors to simulate in game effects.
We can use a combination of these States and Actions over time to build out the complete capabilities of our character controller and hopefully provide a concrete testing surface for us to use.
I talk a bit about Dependency Injection, some notes on that: I've avoided Zenject in this implementation and might for the entire project. While dependency injection and inversion of control can introduce gains for testing it can also cause a significant increase in the complexity of your code. Part of the goal with the implementation here was to minimize that impact as much as possible while still benefiting from the testability of these abstractions. I'd encourage the same thoughts when reviewing abstractions for your own designs - introducing too much complexity can make the maintainability of your project significantly more difficult.
Infallible Code has a fantastic series on Zenject that covers a variety of topics around Dependency Injection and its uses inside Unity, if you want to go that route with your own project I recommend giving it a look: youtube.com/watch?v=IS2YUIb_w_M&list=PLKERDLXpXl_jNJPY2czQcfPXW4BJaGZc_
I've also put together a video covering the Dictionary constructor in C#, more info here: youtu.be/lFsgmxzw7IU
Join the World of Zero Discord Server: discord.gg/hU5Kq2u
Lets take a look at building an abstraction over a character controller in our 2D platforming game. The goal of this refactoring and abstraction pattern is to improve the testability and modularity of the character controller. Hopefully by introducing this model we'll have a character controller that we can test and extend easily without introducing to much additional complexity into the project.
My abstraction design has two new components; `States` and `Actions`:
States are data providers that expose different properties to Actions. An example State might store the current controller Input's that our player is receiving. Each State is intended to store a discrete composable part of the total controller state, this is done so that individual state objects may be swapped out to support different features or tests. For example a Keyboard and Mouse State could be swapped for a Controller State to account for different input capabilities.
Actions consume the objects state and perform different State modifications of the current objects state or the game. For example an Action may consume our Input state and use that to move the player in the world. Actions do not directly interact with one another but communicate through state modifications instead. Because each Action describes a single behavior this allows us to introduce temporary new behaviors to simulate in game effects.
We can use a combination of these States and Actions over time to build out the complete capabilities of our character controller and hopefully provide a concrete testing surface for us to use.
I talk a bit about Dependency Injection, some notes on that: I've avoided Zenject in this implementation and might for the entire project. While dependency injection and inversion of control can introduce gains for testing it can also cause a significant increase in the complexity of your code. Part of the goal with the implementation here was to minimize that impact as much as possible while still benefiting from the testability of these abstractions. I'd encourage the same thoughts when reviewing abstractions for your own designs - introducing too much complexity can make the maintainability of your project significantly more difficult.
Infallible Code has a fantastic series on Zenject that covers a variety of topics around Dependency Injection and its uses inside Unity, if you want to go that route with your own project I recommend giving it a look: youtube.com/watch?v=IS2YUIb_w_M&list=PLKERDLXpXl_jNJPY2czQcfPXW4BJaGZc_
I've also put together a video covering the Dictionary constructor in C#, more info here: youtu.be/lFsgmxzw7IU
Join the World of Zero Discord Server: discord.gg/hU5Kq2u
![Getting Started Building Pong in my Terminal - Pong in Bash - Part 1
Ive been exploring a few of the fun ways you can write text to a terminal. One of the more interesting commands available for this is `tput`. The `tput` command provides a variety of options for updating or checking the state of your terminal. This includes things like making text **bold**, *italics* or underlined. You can leverage `tput` to change the color of the foreground and background of your terminal. For us though were going to use it to position the cursor. This will allow us to simulate moving an object in the terminal like the ball in pong by updating the cursor position we draw at.
For this video well be looking to explore that capability by starting work on building pong in our shell. Our initial goal is to build a simple ball that bounces left and right horizontally across our screen (vertical movement and paddles will come later). This will involve creating a basic REPL (read-execute-print-loop) script in bash that can track the velocity and position of the ball, print the ball at its current position and test if the ball has collided with either side of the terminal.
* `tput cup [row] [column]` updates the cursor position to the provided row and column (zero indexed).
* `tput cols` returns the number of columns in the current terminal window.
* `tput rows` returns the number of rows in the current terminal window.
Our basic script looks like this after implementing this:
```sh
#!/bin/bash
width=$(tput cols)
echo width = ${width}
ball_x=$((width / 2))
echo ball pos = ${ball_x}
ball_vel_x=$((1))
trap tput cnorm; exit SIGINT
tput civis
while true; do
ball_x=$((ball_x + ball_vel_x))
# Hit the right hand wall
if [ $ball_x -gt $width ]; then
ball_vel_x=$((-1))
fi
if [ $ball_x -lt 1 ]; then
ball_vel_x=$((1))
fi
clear
tput cup 0 $ball_x
echo o
done
```
Note: not mentioned in the video, but Ive included a `trap` to restore the cursor to its normal visibility when you exit the script (more on this in a future video).
If youre looking for a deeper dive into tput linuxcommand.org has put together a great resource with a number of examples demonstrating many of the features of tput: http://www.linuxcommand.org/lc3_adv_tput.php
Ive been live streaming development and some games on Twitch at: https://www.twitch.tv/worldofzerodev
Join the World of Zero Discord Server: https://discord.gg/hU5Kq2u Getting Started Building Pong in my Terminal - Pong in Bash - Part 1](https://i.ytimg.com/vi/fEtcGFEiuQM/mqdefault.jpg)



![Adding an Accent to our Contrast Shader - Lets Make a Side Scrolling Shooter - Part 4
Lets spice up our our contrasting transition shader with an accent color that more clearly marks the border between one color and the next.
Part 1 of building this contrasting shader is here: https://www.youtube.com/watch?v=jJcSbixSy5c
Most of the magic of this shader happens in these lines which select the color we want to draw:
```
float maskPrimary = (_Transition + barrierSize [LESS THAN] maskStrength);
float maskSecondary = (_Transition - barrierSize [GREATER THAN] maskStrength);
float maskAccent = !(maskPrimary || maskSecondary);
o.Albedo = maskPrimary * _PrimaryColor
+ maskSecondary * _SecondaryColor
+ maskAccent * _AccentColor;
```
Come join the World of Zero Discord channel to talk software, game development and more: https://discord.gg/hU5Kq2u Adding an Accent to our Contrast Shader - Lets Make a Side Scrolling Shooter - Part 4](https://i.ytimg.com/vi/gu_bFoI2fIg/mqdefault.jpg)


Join the World of Zero Discord Server: https://discord.gg/hU5Kq2u Implementing Scene Switching - An Elevator Between Scenes - Part 2](https://i.ytimg.com/vi/hr6ox4bg3Ow/mqdefault.jpg)


 we built previously.
Our shader is based off of this formula.
```
weight * colorA + (1 - weight) * colorB;
```
This formula uses a weight to balance between two colors. We can modify this by using a boolean value for the weight which will make it 1 when the boolean is true or 0 when the boolean is false. This will make it possible to turn our gradient between two colors into a hard transition instead.
We can modify our material in C# using code like this in order to animate it from code:
```csharp
material.SetFloat(_Transition, currentTransitionState);
```
Join the World of Zero Discord server: https://discord.gg/hU5Kq2u Color Contrast Shader - Lets Make a Side Scrolling Shooter - Part 3](https://i.ytimg.com/vi/jJcSbixSy5c/mqdefault.jpg)

- [`AnimFloat`](https://docs.unity3d.com/ScriptReference/AnimatedValues.AnimFloat.html)
- [`AnimQuaternion`](https://docs.unity3d.com/ScriptReference/AnimatedValues.AnimQuaternion.html)
- [`AnimVector3`](https://docs.unity3d.com/ScriptReference/AnimatedValues.AnimVector3.html)
Join the World of Zero Discord Server: https://discord.gg/hU5Kq2u Using AnimatedValues in Custom Unity Editors](https://i.ytimg.com/vi/jfhCaijXm6M/mqdefault.jpg)