About the author:

All posts by Terence:

Creating a Farming RPG (like Harvest Moon) in Unity — Part 35: Festival System (Part 1)

This article is a part of the series:
Creating a Farming RPG (like Harvest Moon) in Unity

Ever wanted to create a game like Harvest Moon in Unity? Check out Part 35 of our guide here, where we fix a few bugs and implement a new Festival system for our game. You can also find Part 34 of our guide here, where we created our storage system.

To view this content, you must be a member of Terresquall Patreon at $5 or more
Already a qualifying Patreon member? Refresh to access this content.
Using GitHub Desktop for Unity - Part 4: Branching

GitHub Desktop for Unity — Part 4: Branching

This article is a part of the series:
Using GitHub Desktop for Unity collaboration

In the 4th part of this series, we dive into one of Git’s most powerful features—branching. 

When working on projects, it’s common to accidentally overwrite someone else’s work or struggle with testing new ideas without affecting the main project. Branches act as a safe workspace, letting you build new features without worrying about breaking your existing game build.

In this article, we’ll explore what branches are, how to create and manage them, and how you can use them for your own development workflow.

Continue reading
Creating a Rogue-like (like Vampire Survivors) - Part 1

Creating a Rogue-like Shoot ‘Em Up (like Vampire Survivors) — Part 1: Movement and Camera

This article is a part of the series:
Creating a Rogue-like Shoot 'Em Up (like Vampire Survivors) in Unity

Ever wanted to create a rogue-like shoot ’em up game like Vampire Survivors? In Part 1 of our guide, we will go through how to create movement, animations and a camera for our player character.

A link to a package containing the project files up to Part 1 of this tutorial series can also be found at the end of this article.

Continue reading
Why is calling setters in Java constructors discouraged?

Why is calling setters from constructors discouraged in Java?

In Java, coders are discouraged from calling setter functions in class constructors. Even though doing so can sometimes reduce the amount of repeated code.

Consider the following class:

Unit.java

public class Unit {
	protected int health;

	public Unit(int hp) {
		// Prevents health for being set to 0 or less.
		if(hp <= 0)
			throw new IllegalArgumentException("Health must be more than 0.");
		health = hp;
	}

	public void setHealth(int hp) {
		// Prevents health for being set to 0 or less.
		// Repeat of the code in the constructor.
		if(hp <= 0)
			throw new IllegalArgumentException("Health must be more than 0.");

		health = hp;
	}

}

Instead of doing the check twice across 2 functions to ensure the incoming hp value is correct, it might occur to some coders that we can call the setter within the constructor instead, to reduce the amount of repeated code:

Unit.java

public class Unit {
	protected int health;

	public Unit(int hp) {
		// Prevents health for being set to 0 or less.
		if(hp <= 0)
			throw new IllegalArgumentException("Health must be more than 0.");
		health = hp;
		setHealth(hp);
	}

	public void setHealth(int hp) {
		// Prevents health for being set to 0 or less.
		// Repeat of the code in the constructor.
		if(hp <= 0)
			throw new IllegalArgumentException("Health must be more than 0.");

		health = hp;
	}
}

This, however, is discouraged, because (according to textbooks) setters like setHealth() can be overriden by child classes, creating unexpected or buggy behaviour in these child classes.

Continue reading