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

Actor's Emote system

Mount Doom zone (not accessible yet)


git-svn-id: http://svn.net-core.org/repos/t-engine4@815 51575b47-30f0-44d4-a5cc-537603b46e54
parent dd8547f6
No related branches found
No related tags found
No related merge requests found
Showing
with 344 additions and 9 deletions
game/data/gfx/emote/1.png

266 B

game/data/gfx/emote/2.png

192 B

game/data/gfx/emote/3.png

216 B

game/data/gfx/emote/4.png

184 B

game/data/gfx/emote/6.png

185 B

game/data/gfx/emote/7.png

217 B

game/data/gfx/emote/8.png

189 B

game/data/gfx/emote/9.png

219 B

......@@ -77,6 +77,20 @@ function _M:removeParticles(ps)
end
end
--- Set the current emote
function _M:setEmote(e)
-- Remove previous
if self.__emote then
game.level.map:removeEmote(self.__emote)
end
self.__emote = e
if e and self.x and self.y and game.level and game.level.map then
e.x = self.x
e.y = self.y
game.level.map:addEmote(e)
end
end
--- Moves an actor on the map
-- *WARNING*: changing x and y properties manualy is *WRONG* and will blow up in your face. Use this method. Always.
-- @param map the map to move onto
......@@ -102,18 +116,28 @@ function _M:move(x, y, force)
end
self.old_x, self.old_y = self.x or x, self.y or y
self.x, self.y = x, y
if map(x, y, Map.ACTOR) then
print("[MOVE] WARNING erasing actor!!!")
util.show_backtrace()
end
map(x, y, Map.ACTOR, self)
-- print("[MOVE]", self.uid, x, y)
-- Update particle emitters attached to that actor
local del = {}
for e, _ in pairs(self.__particles) do
e.x = x
e.y = y
map.particles[e] = true
if e.dead then del[#del+1] = e
else
e.x = x
e.y = y
map.particles[e] = true
end
end
for i = 1, #del do self.particles[del[i]] = nil end
-- Move emote
if self.__emote then
if self.__emote.dead then self.__emote = nil
else
self.__emote.x = x
self.__emote.y = y
map.emotes[self.__emote] = true
end
end
map:checkAllEntities(x, y, "on_move", self, force)
......
......@@ -95,6 +95,7 @@ function _M:selectType(type)
local default = 1
self.list = {}
-- Make up the list
print("[BIRTHER] selecting type", type)
for i, d in ipairs(self.birth_descriptor_def[type]) do
local allowed = true
for j, od in ipairs(self.descriptors) do
......
-- TE4 - T-Engine 4
-- Copyright (C) 2009, 2010 Nicolas Casalini
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
--
-- Nicolas Casalini "DarkGod"
-- darkgod@te4.org
require "engine.class"
require "engine.Tiles"
module(..., package.seeall, class.make)
local font = core.display.newFont(fontname or "/data/font/VeraBd.ttf", 16)
local tiles = engine.Tiles.new(16, 16)
function _M:init(text, dur, color)
local w, h = font:size(text)
w = w + 10
h = h + 15
self.dur = dur or 30
color = color or {r=0, g=0, b=0}
local s = core.display.newSurface(w, h)
if not s then return end
s:erase(0, 0, 0, 255)
s:merge(tiles:get(nil, 0,0,0, 0,0,0, "emote/7.png"), 0, 0)
s:merge(tiles:get(nil, 0,0,0, 0,0,0, "emote/9.png"), w - 6, 0)
s:merge(tiles:get(nil, 0,0,0, 0,0,0, "emote/1.png"), 0, h - 10)
s:merge(tiles:get(nil, 0,0,0, 0,0,0, "emote/3.png"), w - 6, h - 10)
for i = 6, w - 6 do
s:merge(tiles:get(nil, 0,0,0, 0,0,0, "emote/8.png"), i, 0)
s:merge(tiles:get(nil, 0,0,0, 0,0,0, "emote/2.png"), i, h - 10)
end
for i = 6, h - 10 do
s:merge(tiles:get(nil, 0,0,0, 0,0,0, "emote/4.png"), 0, i)
s:merge(tiles:get(nil, 0,0,0, 0,0,0, "emote/6.png"), w - 6, i)
end
s:erase(255, 255, 255, 255, 6, 6, w - 6 - 6, h - 10 - 6)
s:erase(0, 0, 0, 0, 6, h - 4, w - 6, 4)
s:drawStringBlended(font, text, 5, 5, color.r, color.g, color.b)
self.text = text
self.w = w
self.h = h
self.surface = s
end
function _M:update()
self.dur = self.dur - 1
if self.dur < 0 then return true end
end
......@@ -196,6 +196,7 @@ function _M:init(w, h)
for i = 0, w * h - 1 do self.map[i] = {} end
self.particles = {}
self.emotes = {}
self:loaded()
end
......@@ -466,6 +467,7 @@ function _M:display()
self:displayParticles()
self:displayEffects()
self:displayEmotes()
-- If nothing changed, return the same surface as before
if not self.changed then return end
......@@ -852,9 +854,54 @@ function _M:displayParticles()
if not alive then
del[#del+1] = e
e.dead = true
end
e = next(self.particles, e)
end
for i = 1, #del do self.particles[del[i]] = nil end
end
-------------------------------------------------------------
-------------------------------------------------------------
-- Emotes
-------------------------------------------------------------
-------------------------------------------------------------
--- Adds an existing emote to the map
function _M:addEmote(e)
if self.emotes[e] then return false end
self.emotes[e] = true
print("[EMOTE] added", e.text, e.x, e.y)
return e
end
--- Removes an emote from the map
function _M:removeEmote(e)
if not self.emotes[e] then return false end
self.emotes[e] = nil
return true
end
--- Display the emotes, called by self:display()
function _M:displayEmotes()
local del = {}
local e = next(self.emotes)
while e do
-- Dont bother with obviously out of screen stuff
if e.x >= self.mx and e.x < self.mx + self.viewport.mwidth and e.y >= self.my and e.y < self.my + self.viewport.mheight and self.seens(e.x, e.y) then
e.surface:toScreen(
self.display_x + (e.x - self.mx + 0.5) * self.tile_w * self.zoom,
self.display_y + (e.y - self.my - 0.9) * self.tile_h * self.zoom
)
end
if e:update() then
del[#del+1] = e
e.dead = true
end
e = next(self.emotes, e)
end
for i = 1, #del do self.emotes[del[i]] = nil end
end
......@@ -106,6 +106,7 @@ function _M:loadMap(file)
self.map.w = m.w
self.map.h = m.h
print("[STATIC MAP] size", m.w, m.h)
end
function _M:resolve(typ, c)
......
......@@ -472,6 +472,18 @@ function rng.tableIndex(t, ignore)
return rng.table(rt)
end
function util.factorial(n)
if n == 0 then
return 1
else
return n * util.factorial(n - 1)
end
end
function rng.poissonProcess(k, turn_scale, rate)
return math.exp(-rate*turn_scale) * ((rate*turn_scale) ^ k)/ util.factorial(k)
end
function util.show_backtrace()
local level = 2
......
......@@ -32,9 +32,17 @@ newAI("target_simple", function(self)
end
end)
-- Target the player if within sense radius
newAI("target_player_radius", function(self)
if core.fov.distance(self.x, self.y, game.player.x, game.player.y) < self.ai_state.sense_radius then
self.ai_target.actor = game.player
return true
end
end)
-- Special targetting for mount doom, select a normal target, if none is found go for the player
newAI("mount_doom_target", function(self)
if self:runAI("target_simple") then return true end
self.ai_target.actor = game.player
return true
end)
......@@ -348,6 +348,10 @@ end
--- Called every game turns
-- Does nothing, you can override it
function _M:onTurn()
if self.zone then
if self.zone.on_turn then self.zone:on_turn() end
end
-- The following happens only every 10 game turns (once for every turn of 1 mod speed actors)
if self.turn % 10 ~= 0 then return end
......@@ -529,7 +533,8 @@ function _M:setupCommands()
self.key:addCommands{
[{"_d","ctrl"}] = function()
if config.settings.tome.cheat then
self:changeLevel(1, "wilderness-arda-fareast")
self.player:setEmote(require("engine.Emote").new("Hello World!", 100))
-- self:changeLevel(1, "wilderness-arda-fareast")
end
end,
}
......
-- TE4 - T-Engine 4
-- Copyright (C) 2009, 2010 Nicolas Casalini
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
--
-- Nicolas Casalini "DarkGod"
-- darkgod@te4.org
require "engine.class"
local Map = require "engine.Map"
require "engine.Generator"
module(..., package.seeall, class.inherit(engine.Generator))
function _M:init(zone, map, level, spots)
engine.Generator.init(self, zone, map, level, spots)
self.data = level.data.generator.actor
self.level = level
self.rate = self.data.rate
self.max_rate = 5
self.turn_scale = game.energy_per_tick / game.energy_to_act
end
function _M:tick()
local val = rng.float(0,1)
for i = 1,self.max_rate - 1 do
if val < rng.poissonProcess(i, self.turn_scale, self.rate) then
self:generateOne()
else
break
end
end
end
function _M:generateOne()
local m = self.zone:makeEntityByName(self.level, "actor", "URUK-HAI_ATTACK")
if m then
local x = rng.range(3, 8)
local y = 0
local tries = 0
while (not m:canMove(x, y)) and tries < 10 do
x = rng.range(3, 8)
tries = tries + 1
end
if tries < 100 then
self.zone:addEntity(self.level, m, "actor", x, y)
end
end
end
-- TE4 - T-Engine 4
-- Copyright (C) 2009, 2010 Nicolas Casalini
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
--
-- Nicolas Casalini "DarkGod"
-- darkgod@te4.org
require "engine.class"
local Map = require "engine.Map"
require "engine.Generator"
module(..., package.seeall, class.inherit(engine.Generator))
function _M:init(zone, map, level, data)
engine.Generator.init(self, zone, map, level)
self.data = data
self.grid_list = zone.grid_list
end
function _M:resolve(c)
local res = self.data[c]
if type(res) == "function" then
return res()
elseif type(res) == "table" then
return res[rng.range(1, #res)]
else
return res
end
end
function _M:generate(lev, old_lev)
for i = 0, self.map.w - 1 do for j = 0, self.map.h - 1 do
self.map(i, j, Map.TERRAIN, self.grid_list[self:resolve("#")])
end end
local ln = 0
local path = core.noise.new(1)
local widness = core.noise.new(1)
local i = self.data.start
local dir = true
for j = 0, self.map.h - 1 do
local wd = widness:fbm_perlin(20 * j / self.map.h, 4)
wd = math.ceil(((wd + 1) / 2) * 4)
for ii = i - wd, i + wd do if self.map:isBound(ii, j) then self.map(ii, j, Map.TERRAIN, self.grid_list[self:resolve(".")]) end end
if j < self.map.h - 10 then
local n = path:fbm_perlin(150 * j / self.map.h, 4)
if (ln > 0 and n < 0) or (ln < 0 and n > 0) then dir = not dir end
i = util.bound(i + (dir and -1 or 1), 0, self.map.w - 1)
ln = n
else
-- Close in on the exit
if i < self.data.stop then i = i + 1
elseif i > self.data.stop then i = i - 1
end
end
end
-- Make stairs
local spots = {}
return 1,1,1,1, spots
end
uniform sampler2D tex;
uniform float tick;
void main(void)
{
float fTime0_X = tick / 4000;
vec4 color1 = vec4(1,1,1,1);
vec4 color2 = vec4(1,0.8,1,1);
gl_FragColor = mix(color1, color2, smoothstep(0.3,0.7,abs(mod(fTime0_X,2.0)-1.0)));
gl_FragColor *= texture2D(tex, gl_TexCoord[0].xy);
}
-- ToME - Tales of Middle-Earth
-- Copyright (C) 2009, 2010 Nicolas Casalini
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
--
-- Nicolas Casalini "DarkGod"
-- darkgod@te4.org
return {
frag = "lava",
vert = nil,
args = {
},
clone = false,
}
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