Try to add damage for ammo collisions

This commit is contained in:
Mikko Ahlroth 2014-10-19 03:08:25 +03:00
parent c152700a6a
commit 1399759a0e
2 changed files with 29 additions and 3 deletions

View file

@ -6,6 +6,7 @@ require 'entities/chaingunpowerup'
require 'entities/plane'
require 'chaingunmode'
require 'entities/plane'
require 'machinegun'
level_state = {}
@ -147,6 +148,29 @@ function begin_contact(a, b, coll)
if bObj:isinstance(Plane) and (aObj:getOwner() == nil or aObj:getOwner().id ~= bObj.id) then
bObj:receiveDamage(1000);
end
local plane = nil
local other = nil
if aObj:isinstance(Plane) then
plane = aObj
other = bObj
elseif bObj:isinstance(Plane) then
plane = bObj
other = aObj
end
if plane then
if other:getOwner() == nil then
-- Collision with ground or other plane
plane:receiveDamage(1000)
elseif other:getOwner().id ~= plane.id then
for key, gun in pairs(GUNS) do
if other:isinstance(gun['projectile']) then
plane:receiveDamage(gun['damage'])
end
end
end
end
end
end
end

View file

@ -4,18 +4,19 @@ Class = require 'hump/class'
require 'entities/vickers77'
require 'entities/tinyshot'
GUNS = {
chaingun = {
interval = 0.01,
force = 150000,
projectile = TinyShot
projectile = TinyShot,
damage = 1
},
vickers77 = {
interval = 0.1,
force = 300000,
projectile = Vickers77
projectile = Vickers77,
damage = 10
}
}
@ -41,6 +42,7 @@ MachineGun = Class{
end;
setType = function(self, type)
print(GUNS['vickers77'])
self.gun = GUNS[type]
self.since_last_shot = 0
end;