Categories
development infernusrpg

Applying game programming patterns to infernusRPG

Continued with development of infernusRPG https://github.com/blockcha1n444/infernusrpg

This time i have begin to apply the game programming pattern Type Object http://gameprogrammingpatterns.com/type-object.html my goal it’s having a reusing file library of JSON enemies types.

Like this:

var types = {"enemies":[{	
	"name": "Bat",
	"hp": 10,
	"speed": 90,
	"strength": 1,
	"dexterity": 6,	
	"attack":"The Bat bites you"}
	,{
	"name": "Ghost",
	"hp": 25,
	"speed": 25,
	"strength": 4,
	"dexterity": 4,	
	"attack":"The Ghost hits you"	}
	,{
	"name": "Zombie",
	"hp": 50,
	"speed": 79,
	"strength": 5,
	"dexterity": 1,	
	"attack":"The Zombie bites you"	}
	,{
	"name": "Troll",
	"hp": 60,
	"speed": 40,
	"strength": 7,
	"dexterity": 4,	
	"attack":"The Troll throws a strong hit"	}
	]
}

This is a dictionary in gdscript that has the same sintax that JSON

Categories
development infernusrpg

New item manager in infernusrpg

I continued adding features to infernusrpg, this time i have added a item manager. I have added a new item group and a single item stats as well as a single item scene with its itemscript attached.

In PCMove.gd i have added new part in the try_move() func

	#collect items
		var item = _ref_DungeonBoard.get_sprite(_new_GroupName.ITEM, x, y)
		if item!=null:
			_ref_ItemManager.collect(_pc,item,_new_GroupName.ITEM,x,y)	
			print("item collected")
		

The item manager calls the item instance method collected_by()

func collect(_pc:Sprite,item:Sprite,_group:String ,_x:int,_y:int) -> void:
	item.collected_by(_pc) 
	_ref_RemoveObject.remove(_group,_x,_y)

And the item script pick up the call:

func collected_by(_pc:Sprite) -> void:
	_pc = _pc as PC
	_pc.hp += _new_ChickenStats.RECOVERY_HP
	
	#set the maximum hp
	if _pc.hp>_new_PCStats.HP:
		_pc.hp=_new_PCStats.HP

So every item have their own call to collected_by() then it can increase hp, decrease hp or whatever it wants.

github repository

Categories
development infernusrpg

Adding combat system to infernusrpg

The design of the classes for the combat system is as follows:

-library/Stats.gd: stores the constants of the strength,dexterity,hp and speed for each enemy or for the player.

const SPEED: int = 100
const STRENGTH: int = 1
const DEXTERITY: int = 3
const HP: int = 10

-library/Combat.gd: make the calculations for the attack and for roll a dice

func roll(number:int ,type:int  )->int:           
	var acc=0
	for x in range(0,number):                    
		acc += _rng.randi_range(1,type)                 
	return acc

-sprites/Script.gd: it serves to store some instance variables of each sprite

var ar:int
var dr:int
var hp:int

func _init():
	ar=_new_PCStats.STRENGTH/4
	dr=_new_PCStats.DEXTERITY*4
	
	hp=_new_PCStats.HP

-scenes/main/PCAttack and scenes/main/EnemyAttack make the calls to the combat system

_new_Combat.attack(_pc,enemy)

infernusrpg is a rpg turn-based demo game or prototype made in godot. you can download the source code at https://github.com/blockcha1n444/infernusrpg

screenshoot
screenshoot