Skip to content
Snippets Groups Projects
Commit db8b33e0 authored by dg's avatar dg
Browse files

balls stop at walls

git-svn-id: http://svn.net-core.org/repos/t-engine4@59 51575b47-30f0-44d4-a5cc-537603b46e54
parent 1dbf6d21
No related branches found
No related tags found
No related merge requests found
......@@ -339,3 +339,9 @@ function _M:getTileToScreen(tx, ty)
local y = (ty - self.my) * self.tile_h + self.display_y
return x, y
end
--- Checks the given coords to see if they are in bound
function _M:isBound(x, y)
if x < 0 or x >= self.w or y < 0 or y >= self.h then return false end
return true
end
require "engine.class"
local Map = require "engine.Map"
--- handles targetting
module(..., package.seeall, class.make)
......@@ -44,18 +45,24 @@ function _M:display()
local s = self.sb
local l = line.new(self.source_actor.x, self.source_actor.y, self.target.x, self.target.y)
local lx, ly = l()
local stopx, stopy = self.source_actor.x, self.source_actor.y
while lx and ly do
if not game.level.map.seens(lx, ly) then s = self.sr end
if self.target_type.stop_block and game.level.map:checkAllEntities(lx, ly, "block_move") then s = self.sr end
if self.target_type.stop_block and game.level.map:checkAllEntities(lx, ly, "block_move") then s = self.sr
elseif game.level.map:checkEntity(lx, ly, Map.TERRAIN, "block_move") then s = self.sr end
if self.target_type.range and math.sqrt((self.source_actor.x-lx)^2 + (self.source_actor.y-ly)^2) > self.target_type.range then s = self.sr end
if s == self.sb then stopx, stopy = lx, ly end
s:toScreen(self.display_x + (lx - game.level.map.mx) * self.tile_w, self.display_y + (ly - game.level.map.my) * self.tile_h)
lx, ly = l()
end
self.cursor:toScreen(self.display_x + (self.target.x - game.level.map.mx) * self.tile_w, self.display_y + (self.target.y - game.level.map.my) * self.tile_h)
if self.target_type.ball and s == self.sb then
core.fov.calc_circle(self.target.x, self.target.y, self.target_type.ball, function(self, lx, ly)
if s == self.b then stopx, stopy = self.target.x, self.target.y end
if self.target_type.ball then
core.fov.calc_circle(stopx, stopy, self.target_type.ball, function(self, lx, ly)
self.sg:toScreen(self.display_x + (lx - game.level.map.mx) * self.tile_w, self.display_y + (ly - game.level.map.my) * self.tile_h)
if game.level.map:checkEntity(lx, ly, Map.TERRAIN, "block_move") then return true end
end, function()end, self)
end
end
......
......@@ -61,7 +61,8 @@ function _M:useAbility(id)
if not self:postUseAbility(ab, ret) then return end
end)
coroutine.resume(co)
local ok, err = coroutine.resume(co)
if not ok and err then error(err) end
end
end
......
require "engine.class"
local Map = require "engine.Map"
local Target = require "engine.Target"
local DamageType = require "engine.DamageType"
--- Handles actors life and death
module(..., package.seeall, class.make)
......@@ -38,7 +41,7 @@ function _M:attack(target)
end
--- Project damage to a distance
-- @param t a type table describing the attack, as returned by engine.Target:getType()
-- @param t a type table describing the attack, passed to engine.Target:getType() for interpretation
-- @param x target coords
-- @param y target coords
-- @param damtype a damage type ID from the DamageType class
......@@ -74,6 +77,7 @@ function _M:project(t, x, y, damtype, dam)
core.fov.calc_circle(lx, ly, typ.ball, function(self, px, py)
-- Deam damage: ball
addGrid(px, py)
if game.level.map:checkEntity(px, py, Map.TERRAIN, "block_move") then return true end
end, function()end, self)
addGrid(lx, ly)
elseif typ.cone then
......
......@@ -35,6 +35,23 @@ function _M:move(x, y, force)
return moved
end
function _M:teleportRandom(dist)
local poss = {}
for i = self.x - dist, self.x + dist do
for j = self.y - dist, self.y + dist do
if game.level.map:isBound(i, j) and
core.fov.distance(self.x, self.y, i, j) <= dist and
not game.level.map:checkAllEntities(i, j, "block_move") then
poss[#poss+1] = {i,j}
end
end
end
local pos = poss[rng.range(1, #poss)]
return self:move(pos[1], pos[2], true)
end
function _M:tooltip()
return ("%s\n#00ffff#Level: %d\nExp: %d/%d\n#ff0000#HP: %d"):format(self.name, self.level, self.exp, self:getExpChart(self.level+1) or "---", self.life)
end
......
......@@ -237,6 +237,9 @@ function _M:setupCommands()
_a = function()
self.player:useAbility(ActorAbilities.AB_FIREFLASH)
end,
_z = function()
self.player:useAbility(ActorAbilities.AB_PHASE_DOOR)
end,
_LEFT = function() self.player:move(self.player.x - 1, self.player.y ) end,
_RIGHT = function() self.player:move(self.player.x + 1, self.player.y ) end,
......
......@@ -35,7 +35,7 @@ newAbility{
ATTACKAREA = 10,
},
action = function(self)
local t = {type="ball", range=15, radius=math.min(6, 2 + self:getMag(6))}
local t = {type="ball", range=15, radius=math.min(6, 3 + self:getMag(6))}
local x, y = self:getTarget(t)
if not x or not y then return nil end
self:project(t, x, y, DamageType.FIRE, 8 + self:getMag(70))
......@@ -44,7 +44,7 @@ newAbility{
require = { stat = { mag=16 }, },
info = function(self)
return ([[Conjures up a flash of fire doing %0.2f fire damage in a radius of %d",
The damage will increase with the Magic stat]]):format(8 + self:getMag(70), math.min(6, 2 + self:getMag(6)))
The damage will increase with the Magic stat]]):format(8 + self:getMag(70), math.min(6, 3 + self:getMag(6)))
end,
}
......@@ -57,15 +57,12 @@ newAbility{
ESCAPE = 4,
},
action = function(self)
local t = {type="ball", range=15, radius=math.min(6, 2 + self:getMag(6))}
local x, y = self:getTarget(t)
if not x or not y then return nil end
self:project(t, x, y, DamageType.FIRE, 8 + self:getMag(70))
self:teleportRandom(10 + self:getMag(10))
return true
end,
require = { stat = { mag=16 }, },
info = function(self)
return ([[Teleports you randomly on a small scale range",
The damage will increase with the Magic stat]]):format(8 + self:getMag(70), math.min(6, 2 + self:getMag(6)))
return ([[Teleports you randomly on a small scale range (%d)",
The range will increase with the Magic stat]]):format(10 + self:getMag(10))
end,
}
......@@ -158,9 +158,21 @@ static int lua_fov_calc_beam(lua_State *L)
return 0;
}
static int lua_distance(lua_State *L)
{
double x1 = luaL_checknumber(L, 1);
double y1 = luaL_checknumber(L, 2);
double x2 = luaL_checknumber(L, 3);
double y2 = luaL_checknumber(L, 4);
lua_pushnumber(L, sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)));
return 1;
}
static const struct luaL_reg fovlib[] =
{
{"new", lua_new_fov},
{"distance", lua_distance},
{"calc_circle", lua_fov_calc_circle},
{"calc_beam", lua_fov_calc_beam},
{NULL, NULL},
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment