Implementing a speed-based turn counter system in a roguelike

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Applebaps
Prole
Posts: 3
Joined: Mon Sep 05, 2016 9:23 pm

Implementing a speed-based turn counter system in a roguelike

Post by Applebaps »

Never mind, I figured it out on my own. See my 2nd post for the solution.
Last edited by Applebaps on Thu Sep 08, 2016 6:13 am, edited 3 times in total.
Zireael
Party member
Posts: 139
Joined: Fri Sep 02, 2016 10:52 am

Re: Implementing a speed-based turn counter system in a roguelike

Post by Zireael »

Are you using any libraries? 31 MB for a .love is fairly large!

Also I can't NOT recommend ROTLove if you're making a roguelike game. Their Scheduler class covers pretty much all possible scheduling variants.

EDIT: Check out my Veins of the Earth thread in games and creations :P I'm making a roguelike, too!
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Implementing a speed-based turn counter system in a roguelike

Post by raidho36 »

The idea is that when you make a move, you attach a specific amount of AP to it, so you can't move until those AP count down to 0. The turn manager counts down every occuring move's AP down, and when any of those reaches 0 it lets the entity make another move.
Applebaps
Prole
Posts: 3
Joined: Mon Sep 05, 2016 9:23 pm

Re: Implementing a speed-based turn counter system in a roguelike

Post by Applebaps »

BIG EDIT: I figured it out.

Code: Select all

-- in "Mob.lua" module
function Mob:roll_call()
		who_is_here[self.y][self.x] = self.is_monster -- puts true or false in the space
		self.turn_counter = self.turn_counter * math.random(0.9, 1.1) -- randomizes turns a little
		table.insert(allMobs, self)
end

function Mob:move(dx, dy)
   -- update "who is here"
	 who_is_here[self.y][self.x] = nil -- erases the previous grid entry
   self.x, self.y = self.x + dx, self.y + dy -- moves
   who_is_here[self.y][self.x] = self.is_monster -- puts true or false in the space (for combat)
	 self.turn_counter = 1 * self.speed -- resets turn counter inside its own table
	 for k,v in ipairs(allMobs) do
		 if v == self then -- looks for itself in allMobs
	 		v.turn_counter = self.turn_counter -- replaces its own turn_counter in the spot paired with whatever has that name with the fresh value
		 end
	 end
	 self.my_turn = false -- flags turn is over
	 turn_active = false -- flags no active turn
end

-- in "turn.lua" module
function turn.decrement_counters(dt) -- runs in Dungeon.update(dt) and subtracts from all turn_counters
	if turn_active == false then
		for k,v in ipairs(allMobs) do -- runs down each entry in allMobs table, k is the index, v is the table associated with it (the mob)
			v.turn_counter = v.turn_counter - (10 * dt) -- v is the mob
			if v.turn_counter < 0 then
				v.turn_counter = 0 -- catches negative values and scoops em up to zero
				turn_active = true -- flags that there's an active turn (halts decrementing)
				whose_turn = v -- sends the mob that's in the #1 slot to a variable for outside use
				whose_turn.my_turn = true
				return
			end
		end
	end
end
That's it, that's all it took.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Amazon [Bot], Bing [Bot], Google [Bot], rabbitboots, Semrush [Bot] and 7 guests