Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • amagad/t-engine4
  • HirumaKai/t-engine4
  • Hogulus/t-engine4
  • Inkie/t-engine4
  • Liberty/t-engine4
  • Lokean/t-engine4
  • Mawootad/t-engine4
  • Michelle/t-engine4
  • MrFrog/t-engine4
  • Nagyhal/t-engine4
  • Recaiden/t-engine4
  • RootOfAllThings/t-engine4
  • Sebsebeleb/t-engine4
  • Sheila/t-engine4
  • Shibari/t-engine4
  • Stof/t-engine4
  • Umbral/t-engine4
  • tome/t-engine4
  • 0player/t-engine4
  • BreezyIdiot/t-engine4
  • Bunny/t-engine4
  • Effigy/t-engine4
  • Hachem_Muche/t-engine4
  • razakai/t-engine4
  • Zireael/t-engine4
  • cinornu/t-engine4
  • edge2054/t-engine4
  • gordaxx727/t-engine4
  • grayswandir/t-engine4
  • helminthauge/t-engine4
  • housepet/t-engine4
  • minqmay/t-engine4
  • nsrr/t-engine4
  • orange/t-engine4
  • otowakotori/t-engine4
  • purequestion/t-engine4
  • rexorcorum/t-engine4
  • rgeens/t-engine4
  • sageacrin/t-engine4
  • stuntofthelitter/t-engine4
  • tiger_eye/t-engine4
  • xelivous/t-engine4
  • yutio888/t-engine4
43 results
Show changes
Showing
with 0 additions and 3574 deletions
-- 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"
module(..., package.seeall, class.make)
function _M:init(zone, map, level)
self.zone = zone
self.map = map
self.level = level
-- Setup the map's room-map
if not map.room_map then
map.room_map = {}
for i = 0, map.w - 1 do
map.room_map[i] = {}
for j = 0, map.h - 1 do
map.room_map[i][j] = {}
end
end
end
end
function _M:generate()
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 Entity = require "engine.Entity"
module(..., package.seeall, class.inherit(Entity))
function _M:init(t, no_default)
t = t or {}
self.name = t.name
Entity.init(self, t, no_default)
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"
--- Heightmap fractal generator
-- This can be used to create rooms, levels, world maps, whatever
module(..., package.seeall, class.make)
_M.max = 100000
_M.min = 0
--- Creates the fractal generator for the specified heightmap size
function _M:init(w, h, roughness, start)
self.w = w
self.h = h
self.roughness = roughness or 1.2
self.hmap = {}
self.start = start or {}
print("Making heightmap", w, h)
-- Init the hmap to 0
for i = 1, w do
self.hmap[i] = {}
for j = 1, h do
self.hmap[i][j] = 0
end
end
end
--- Actually creates the heightmap
function _M:generate()
local rects = {}
-- Init the four corners
self.hmap[1][1] = self.start.up_left or rng.range(self.min, self.max)
self.hmap[1][self.h] = self.start.down_left or rng.range(self.min, self.max)
self.hmap[self.w][1] = self.start.up_right or rng.range(self.min, self.max)
self.hmap[self.w][self.h] = self.start.down_right or rng.range(self.min, self.max)
rects[#rects+1] = {1, 1, self.w, self.h, force_middle=self.start.middle}
-- While we have subzones to handle, handle them
while #rects > 0 do
local r = table.remove(rects, 1)
-- print("Doing rect", r[1], r[2], "::", r[3], r[3])
local w = r[3] - r[1]
local h = r[4] - r[2]
if w > 1 or h > 1 then
local nw = math.floor(w / 2)
local nh = math.floor(h / 2)
-- Compute "displacement" random value
local d = (w + h) / (self.w + self.h) * self.roughness
d = (rng.range(0, self.max) - self.max / 2) * d
-- Compute middles
self.hmap[r[1] + nw][r[2]] = (self.hmap[r[1]][r[2]] + self.hmap[r[3]][r[2]]) / 2
self.hmap[r[1] + nw][r[4]] = (self.hmap[r[1]][r[4]] + self.hmap[r[3]][r[4]]) / 2
self.hmap[r[1]][r[2] + nh] = (self.hmap[r[1]][r[2]] + self.hmap[r[1]][r[4]]) / 2
self.hmap[r[3]][r[2] + nh] = (self.hmap[r[3]][r[2]] + self.hmap[r[3]][r[4]]) / 2
if r.force_middle then
self.hmap[r[1] + nw][r[2] + nh] = r.force_middle
else
self.hmap[r[1] + nw][r[2] + nh] = (self.hmap[r[1]][r[2]] + self.hmap[r[1]][r[4]] + self.hmap[r[3]][r[2]] + self.hmap[r[3]][r[4]]) / 4 + d
end
-- Assign new rects
if nw > 1 or nh > 1 then rects[#rects+1] = {r[1], r[2], r[1] + nw, r[2] + nh} end
if r[3] - r[1] - nw > 1 or nh > 1 then rects[#rects+1] = {r[1] + nw, r[2], r[3], r[2] + nh} end
if nw > 1 or r[4] - r[2] - nh > 1 then rects[#rects+1] = {r[1], r[2] + nh, r[1] + nw, r[4]} end
if r[3] - r[1] - nw > 1 or r[4] - r[2] - nh > 1 then rects[#rects+1] = {r[1] + nw, r[2] + nh, r[3], r[4]} end
end
end
return self.hmap
end
function _M:displayDebug(symbs)
symbs = symbs or "abcdefghijklmnopqrstwxyzABCDEFGHIJKLMNOPQRSTWXYZ"
print("Dispalying heightmap", self.w, self.h)
for j = 1, self.h do
local str = ""
for i = 1, self.w do
local c = util.bound((math.floor(self.hmap[i][j] / self.max * symbs:len()) + 1), 1, symbs:len())
str = str..symbs:sub(c, c)
end
print(str)
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"
module(..., package.seeall, class.make)
function _M:init(actor, x, y, w, h, bgcolor)
self.actor = actor
self.bgcolor = bgcolor
self.font = core.display.newFont("/data/font/VeraMono.ttf", 10)
self.font_h = self.font:lineSkip()
self.clics = {}
self:resize(x, y, w, h)
end
--- Resize the display area
function _M:resize(x, y, w, h)
self.display_x, self.display_y = math.floor(x), math.floor(y)
self.w, self.h = math.floor(w), math.floor(h)
self.surface = core.display.newSurface(w, h)
if self.actor then self.actor.changed = true end
local cw, ch = self.font:size(" ")
self.font_w = cw
self.max_char_w = math.min(127, math.floor(w / self.font_w))
end
local page_to_hotkey = {"", "SECOND_", "THIRD_"}
-- Displays the hotkeys, keybinds & cooldowns
function _M:display()
local a = self.actor
if not a or not a.changed then return self.surface end
local hks = {}
for i = 1, 12 do
local j = i + (12 * (a.hotkey_page - 1))
local ks = game.key:formatKeyString(game.key:findBoundKeys("HOTKEY_"..page_to_hotkey[a.hotkey_page]..i))
if a.hotkey[j] and a.hotkey[j][1] == "talent" then
hks[#hks+1] = {a.hotkey[j][2], j, "talent", ks}
elseif a.hotkey[j] and a.hotkey[j][1] == "inventory" then
hks[#hks+1] = {a.hotkey[j][2], j, "inventory", ks}
end
end
self.surface:erase(self.bgcolor[1], self.bgcolor[2], self.bgcolor[3])
local x = 0
local y = 0
self.clics = {}
for ii, ts in ipairs(hks) do
local s
local i = ts[2]
local txt, color = "", {0,255,0}
if ts[3] == "talent" then
local tid = ts[1]
local t = a:getTalentFromId(tid)
if a:isTalentCoolingDown(t) then
txt = ("%s (%d)"):format(t.name, a:isTalentCoolingDown(t))
color = {255,0,0}
elseif a:isTalentActive(t.id) then
txt = t.name
color = {255,255,0}
else
txt = t.name
color = {0,255,0}
end
elseif ts[3] == "inventory" then
local o = a:findInAllInventories(ts[1])
local cnt = 0
if o then cnt = o:getNumber() end
txt = ("%s (%d)"):format(ts[1], cnt)
if cnt == 0 then
color = {128,128,128}
end
end
txt = ("%2d) %-"..(self.max_char_w-4-24).."s Key: %s"):format(i, txt, ts[4])
local w, h = self.font:size(txt)
if self.cur_sel and self.cur_sel == i then self.surface:erase(0, 50, 120, nil, x, y, w+4, h+4) end
self.surface:drawString(self.font, txt, x+2, y+2, color[1], color[2], color[3])
self.clics[i] = {x,y,w+4,h+4}
if y + self.font_h * 2 > self.h then
x = x + self.w / 2
y = 0
else
y = y + self.font_h
end
end
return self.surface
end
--- Call when a mouse event arrives in this zone
-- This is optional, only if you need mouse support
function _M:onMouse(button, mx, my, click)
mx, my = mx - self.display_x, my - self.display_y
for i, zone in pairs(self.clics) do
if mx >= zone[1] and mx < zone[1] + zone[3] and my >= zone[2] and my < zone[2] + zone[4] then
if button == "left" and click then
self.actor:activateHotkey(i)
else
self.actor.changed = true
self.cur_sel = i
end
return
end
end
self.cur_sel = nil
end
This diff is collapsed.
This diff is collapsed.
-- 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 "config"
require "engine.class"
require "engine.Key"
--- Receieves keypresses and acts upon them
module(..., package.seeall, class.inherit(engine.Key))
function _M:init()
engine.Key.init(self)
self.commands = {}
self.on_input = false
self.locale_convert = {}
-- Fullscreen toggle
self:addCommand(self._RETURN, {"alt"}, function() core.display.fullscreen() end)
end
--- Adds the profiler keybind (ctrl, alt, chift, p)
function _M:setupProfiler()
-- Profiler
self:addCommand(self._p, {"ctrl","alt","shift"}, function()
if not _G.profiling then
print("Starting profiler")
_G.profiling = true
profiler.start("profiler.log")
else
profiler.stop()
print("Stopped profiler")
end
end)
end
function _M:receiveKey(sym, ctrl, shift, alt, meta, unicode, isup)
self:handleStatus(sym, ctrl, shift, alt, meta, unicode, isup)
if isup then return end
-- Convert locale
sym = self.locale_convert[sym] or sym
if not self.commands[sym] and not self.commands[self.__DEFAULT] then
if self.on_input and unicode then self.on_input(unicode) end
elseif self.commands[sym] and (ctrl or shift or alt or meta) and not self.commands[sym].anymod then
local mods = {}
if alt then mods[#mods+1] = "alt" end
if ctrl then mods[#mods+1] = "ctrl" end
if meta then mods[#mods+1] = "meta" end
if shift then mods[#mods+1] = "shift" end
mods = table.concat(mods,',')
if self.commands[sym][mods] then
self.commands[sym][mods](sym, ctrl, shift, alt, meta, unicode)
end
elseif self.commands[sym] and self.commands[sym].plain then
self.commands[sym].plain(sym, ctrl, shift, alt, meta, unicode)
elseif self.commands[self.__DEFAULT] and self.commands[self.__DEFAULT].plain then
self.commands[self.__DEFAULT].plain(sym, ctrl, shift, alt, meta, unicode)
end
if self.atLast then self.atLast(sym, ctrl, shift, alt, meta, unicode) end
end
--- Adds a key/command combinaison
-- @param sym the key to handle
-- @param mods a table with the mod keys needed, i.e: {"ctrl", "alt"}
-- @param fct the function to call when the key is pressed
function _M:addCommand(sym, mods, fct, anymod)
if type(sym) == "string" then sym = self[sym] end
if not sym then return end
if sym == self.__TEXTINPUT then return self:setTextInput(mods) end
self.commands[sym] = self.commands[sym] or {}
if not fct then
self.commands[sym].plain = mods
else
table.sort(mods)
self.commands[sym][table.concat(mods,',')] = fct
end
if anymod then self.commands[sym].anymod = true end
end
--- Adds many key/command at once
-- @usage self.key:addCommands{<br/>
-- _LEFT = function()<br/>
-- print("left")<br/>
-- end,<br/>
-- _RIGHT = function()<br/>
-- print("right")<br/>
-- end,<br/>
-- {{"x","ctrl"}] = function()<br/>
-- print("control+x")<br/>
-- end,<br/>
-- }
function _M:addCommands(t)
local aliases = {}
for k, e in pairs(t) do
if type(e) == "function" then
if type(k) == "string" then
self:addCommand(k, e)
elseif type(k) == "table" then
local sym = table.remove(k, 1)
local anymod = false
if k[1] == "anymod" then k, e, anymod = e, nil, true end
self:addCommand(sym, k, e, anymod)
end
elseif e[1] == "alias" then
aliases[#aliases+1] = {k, e[2]}
end
end
for i, alias in ipairs(aliases) do
self:addCommands{[alias[1]] = self.commands[self[alias[2]]].plain}
end
end
--- Receieves any unbound keys as UTF8 characters (if possible)
-- @param fct the function to call for each key, get a single parameter to pass the UTF8 string
function _M:setTextInput(fct)
self.on_input = fct
end
--- Loads a locale converter
-- WARNING: This only converts the "sym" key, *NOT* the unicode key
-- @param file the locale convertion file to load
function _M:loadLocaleConvertion(file)
local f, err = loadfile(file)
if not f and err then error(err) end
setfenv(f, setmetatable({
locale = config.settings.keyboard.locale,
}, {__index=engine.Key}))
conv = f() or {}
for k, e in pairs(conv) do
self.locale_convert[k] = e
end
end
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.