Weird Question

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
lilfinn
Prole
Posts: 10
Joined: Thu Jul 18, 2013 5:58 am

Weird Question

Post by lilfinn » Sun Nov 16, 2014 7:39 am

I have a bit of code that check if the players and enemies are colliding, if they are it subtracts the player attack from the enemy health and the enemy attack from the player health. It does this ones every 20 ticks. if i make both the player and enemy attack the same and make their health the same, then they should kill each other evenly right? They don't.

if i have this

Code: Select all

for i,v in ipairs(enemies) do
          for ii,vv in ipairs(players) do...
The players always win.

if i have this

Code: Select all

for i,v in ipairs(players) do
          for ii,vv in ipairs(enemies) do...
The enemies always win.

If i spawn less than 5 at a time, they kill each other like they should. Anything over 5 and the above problem happens.

The reason might be obvious but i'm not seeing it.
Thanks in advance

Right click to spawn Enemies
Left click to spawn Players
Attachments
Post.love
(25.14 KiB) Downloaded 64 times

User avatar
ivan
Party member
Posts: 1548
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Weird Question

Post by ivan » Sun Nov 16, 2014 8:56 am

Given the example you have provided, I think you could just resolve the battles in 1 step.
As soon as a collision occurs, just subtract the health points of the two units.
If you want to resolve the battles over time you could use floating point numbers to represent the health of the units.
So for example each unit could lose 25.33 health points per second.
But when you draw the unit, just round the number so that it looks like an integer.

User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Weird Question

Post by s-ol » Sun Nov 16, 2014 1:17 pm

The problem is just that the player kills the enemy first, and then the enemy can't hurt the player anymore I think.

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end

lachlaan
Prole
Posts: 30
Joined: Sun Jun 30, 2013 7:23 pm

Re: Weird Question

Post by lachlaan » Sun Nov 16, 2014 2:57 pm

It's as S0|||0s says. I had the same issue when tinkering around with a gravity simulator, where I needed to check each pair's interaction only once, but it was a case of the game not discriminating between "players" and "enemies". So you probably just need to check if both take damage at the same time.

Post Reply

Who is online

Users browsing this forum: No registered users and 104 guests