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 3691 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(fontname, fontsize)
self.font = core.display.newFont(fontname or "/data/font/Vera.ttf", fontsize or 12)
self.bigfont = core.display.newFont(fontname or "/data/font/VeraBd.ttf", fontsize or 18)
self.font_h = self.font:lineSkip()
self.flyers = {}
end
function _M:add(x, y, duration, xvel, yvel, str, color, bigfont)
assert(x, "no x flyer")
assert(y, "no y flyer")
assert(str, "no str flyer")
color = color or {255,255,255}
local s = core.display.drawStringBlendedNewSurface(bigfont and self.bigfont or self.font, str, color[1], color[2], color[3])
if not s then return end
local f = {
x=x,
y=y,
duration=duration or 10,
xvel = xvel or 0,
yvel = yvel or 0,
s = s
}
self.flyers[f] = true
return f
end
function _M:empty()
self.flyers = {}
end
function _M:display()
if not next(self.flyers) then return end
local dels = {}
for fl, _ in pairs(self.flyers) do
fl.s:toScreen(fl.x, fl.y)
fl.x = fl.x + fl.xvel
fl.y = fl.y + fl.yvel
fl.duration = fl.duration - 1
-- Delete the flyer
if fl.duration == 0 then
dels[#dels+1] = fl
end
end
for i, fl in ipairs(dels) do self.flyers[fl] = nil 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"
require "engine.Mouse"
require "engine.DebugConsole"
--- Represent a game
-- A module should subclass it and initialize anything it needs to play inside
module(..., package.seeall, class.make)
--- Constructor
-- Sets up the default keyhandler.
-- Also requests the display size and stores it in "w" and "h" properties
function _M:init(keyhandler)
self.key = keyhandler
self.level = nil
self.log = function() end
self.logSeen = function() end
self.w, self.h = core.display.size()
self.dialogs = {}
self.save_name = "player"
self.player_name = "player"
self.mouse = engine.Mouse.new()
self.mouse:setCurrent()
self.uniques = {}
end
function _M:loaded()
self.w, self.h = core.display.size()
self.dialogs = {}
self.key = engine.Key.current
self.mouse = engine.Mouse.new()
self.mouse:setCurrent()
end
--- Defines the default fields to be saved by the savefile code
function _M:defaultSavedFields(t)
local def = {
w=true, h=true, zone=true, player=true, level=true, entities=true,
energy_to_act=true, energy_per_tick=true, turn=true, paused=true, save_name=true,
always_target=true, gfxmode=true, uniques=true, object_known_types=true,
current_music=true, memory_levels=true, achievement_data=true, factions=true,
}
table.merge(def, t)
return def
end
--- Sets the player name
function _M:setPlayerName(name)
self.save_name = name
self.player_name = name
end
--- Starts the game
-- Modules should reimplement it to do whatever their game needs
function _M:run()
end
--- Sets the current level
-- @param level an engine.Level (or subclass) object
function _M:setLevel(level)
self.level = level
end
--- Tells the game engine to play this game
function _M:setCurrent()
core.game.set_current_game(self)
_M.current = self
end
--- Displays the screen
-- Called by the engine core to redraw the screen every frame
function _M:display()
for i, d in ipairs(self.dialogs) do
d:display()
d:toScreen(d.display_x, d.display_y)
end
if self.flyers then
self.flyers:display()
end
end
--- Returns the player
-- Reimplement it in your module, this can just return nil if you dont want/need
-- the engine adjusting stuff to the player or if you have many players or whatever
function _M:getPlayer()
return nil
end
--- This is the "main game loop", do something here
function _M:tick()
end
--- Called when a zone leaves a level
-- Going from "old_lev" to "lev", leaving level "level"
function _M:leaveLevel(level, lev, old_lev)
end
--- Called by the engine when the user tries to close the window
function _M:onQuit()
end
--- Sets up a text flyers
function _M:setFlyingText(fl)
self.flyers = fl
end
--- Registers a dialog to display
function _M:registerDialog(d)
table.insert(self.dialogs, d)
self.dialogs[d] = #self.dialogs
if d.key then d.key:setCurrent() end
if d.mouse then d.mouse:setCurrent() end
if d.on_register then d:on_register() end
end
--- Undisplay a dialog, removing its own keyhandler if needed
function _M:unregisterDialog(d)
if not self.dialogs[d] then return end
table.remove(self.dialogs, self.dialogs[d])
self.dialogs[d] = nil
d:unload()
-- Update positions
for i, id in ipairs(self.dialogs) do self.dialogs[id] = i end
local last = self.dialogs[#self.dialogs] or self
if last.key then last.key:setCurrent() end
if last.mouse then last.mouse:setCurrent() end
if last.on_recover_focus then last:on_recover_focus() end
end
--- The C core gives us command line arguments
function _M:commandLineArgs(args)
for i, a in ipairs(args) do
print("Command line: ", a)
end
end
--- Called by savefile code to describe the current game
function _M:getSaveDescription()
return {
name = "player",
description = [[Busy adventuring!]],
}
end
--- Save a settings file
function _M:saveSettings(file, data)
local restore = fs.getWritePath()
fs.setWritePath(engine.homepath)
local f = fs.open("/settings/"..file..".cfg", "w")
f:write(data)
f:close()
if restore then fs.setWritePath(restore) end
end
available_resolutions =
{
["800x600"] = {800, 600, false},
["1024x768"] = {1024, 768, false},
["1200x1024"] = {1200, 1024, false},
["1600x1200"] = {1600, 1200, false},
["800x600 Fullscreen"] = {800, 600, true},
["1024x768 Fullscreen"] = {1024, 768, true},
["1200x1024 Fullscreen"] = {1200, 1024, true},
["1600x1200 Fullscreen"] = {1600, 1200, true},
}
--- Change screen resolution
function _M:setResolution(res)
if not available_resolutions[res] then return false, "unknown resolution" end
local old_w, old_h = self.w, self.h
core.display.setWindowSize(available_resolutions[res][1], available_resolutions[res][2], available_resolutions[res][3])
self.w, self.h = core.display.size()
if self.w ~= old_w or self.h ~= old_h then
self:onResolutionChange()
self:saveSettings("resolution", ("window.size = %q\n"):format(res))
end
end
--- Called when screen resolution changes
function _M:onResolutionChange()
self.w, self.h = core.display.size()
end
--- Requests the game to save
function _M:saveGame()
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"
require "engine.Game"
--- A game type that gives each entities energy
-- When an entity reaches an energy level it is allowed to act (it calls the entity"s "act" method)
-- @inherit engine.Game
module(..., package.seeall, class.inherit(engine.Game))
--- Setup the game
-- @param keyhandler the default keyhandler for this game
-- @energy_to_act how much energy does an entity need to act
-- @energy_per_tick how much energy does an entity recieves per game tick. This is multiplied by the entity energy.mod property
function _M:init(keyhandler, energy_to_act, energy_per_tick)
self.energy_to_act, self.energy_per_tick = energy_to_act or 1000, energy_per_tick or 100
engine.Game.init(self, keyhandler)
self.entities = {}
self:loaded()
end
function _M:loaded()
engine.Game.loaded(self)
-- Loading the game has defined new uids for entities, yet we hard referenced the old ones
-- So we fix it
local nes = {}
for uid, e in pairs(self.entities) do
nes[e.uid] = e
end
self.entities = nes
-- Setup the entities repository as a weak value table, when the entities are no more used anywhere else they disappear from there too
setmetatable(self.entities, {__mode="v"})
end
--- Gives energy and act if needed
function _M:tick()
engine.Game.tick(self)
-- Give some energy to entities
if self.level then
local i, e
local arr = self.level.e_array
for i = 1, #arr do
e = arr[i]
if e and e.act and e.energy then
-- print("<ENERGY", e.name, e.uid, "::", e.energy.value, game.paused, "::", e.player)
if e.energy.value < self.energy_to_act then
e.energy.value = (e.energy.value or 0) + self.energy_per_tick * (e.energy.mod or 1)
end
if e.energy.value >= self.energy_to_act then
e.energy.used = false
e:act(self)
end
-- print(">ENERGY", e.name, e.uid, "::", e.energy.value, game.paused, "::", e.player)
end
end
end
local arr = self.entities
for i, e in pairs(arr) do
e = arr[i]
if e and e.act and e.energy then
if e.energy.value < self.energy_to_act then
e.energy.value = (e.energy.value or 0) + self.energy_per_tick * (e.energy.mod or 1)
end
if e.energy.value >= self.energy_to_act then
e.energy.used = false
e:act(self)
end
end
end
end
--- Adds an entity to the game
-- This differs from Level:addEntity in that it's not specific to actors and the entities are not bound to
-- the current level. Also they are stored in a *WEAK* table, so this wont hold them from garbage
-- collecting if they are not
function _M:addEntity(e)
if not e.canAct or not e:canAct() then return end
if self.entities[e.uid] and self.entities[e.uid] ~= e then error("Entity "..e.uid.." already present in the game and not the same") end
self.entities[e.uid] = e
end
--- Removes an entity from the game
function _M:removeEntity(e)
if not e.canAct or not e:canAct() then return end
if not self.entities[e.uid] then error("Entity "..e.uid.." not present in the game") end
self.entities[e.uid] = nil
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.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.