1-- GunFu Deadlands 2-- Copyright 2009-2011 Christiaan Janssen, September 2009-October 2011 3-- 4-- This file is part of GunFu Deadlands. 5-- 6-- GunFu Deadlands is free software: you can redistribute it and/or modify 7-- it under the terms of the GNU General Public License as published by 8-- the Free Software Foundation, either version 3 of the License, or 9-- (at your option) any later version. 10-- 11-- GunFu Deadlands is distributed in the hope that it will be useful, 12-- but WITHOUT ANY WARRANTY; without even the implied warranty of 13-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14-- GNU General Public License for more details. 15-- 16-- You should have received a copy of the GNU General Public License 17-- along with GunFu Deadlands. If not, see <http://www.gnu.org/licenses/>. 18 19function loadModule( moduleName ) 20 local chunk = love.filesystem.load( moduleName ) 21 chunk() 22end 23 24function love.load() 25 -- uncomment this for profiling (will affect performance!) 26 --loadModule("profiling.lua") 27 28 -- Dependencies 29 loadModule("mymath.lua") 30 loadModule("lists.lua") 31 32 loadModule("sprites.lua") 33 loadModule("audio.lua") 34 35 loadModule("player.lua") 36 loadModule("movement.lua") 37 loadModule("enemies.lua") 38 39 loadModule("entities.lua") 40 loadModule("level.lua") 41 42 loadModule("bullettime.lua") 43 loadModule("editor.lua") 44 loadModule("editor_files.lua") 45 loadModule("userlevel.lua") 46 47 loadModule("game.lua") 48 49 50 51 -- Initialization 52 math.randomseed(os.time()) 53 54 -- Init graphics mode 55 screensize = { 640, 480 } 56 --if not love.graphics.setMode( screensize[1], screensize[2], false, true, 0 ) then 57 if not Graphics.setWindowed() then 58 love.event.push('q') 59 end 60 61 love.graphics.setColorMode("replace") 62 63 Game.init() 64 65 -- Colors 66 Colors.init() 67 Graphics.init() 68 69 -- Audio system 70 if Sounds.active then 71 love.audio.setVolume(.3) 72 end 73 74 -- Font 75 love.graphics.setFont( love.graphics.newImageFont ("images/western_font_clear.png", 76 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890($>:.,!?)'<-+\\/ ") ) 77 78 79 Editor.load() 80 UserLevel.load() 81 82 Game.titlescreen() 83 84 Music.start() 85 86 87end 88 89function love.update(dt) 90 if Editor.enabled then 91 Editor.update(dt) 92 return 93 elseif UserLevel.enabled then 94 UserLevel.update(dt) 95 return 96 end 97 98 Game.update(dt) 99 100end 101 102function love.draw() 103 if Editor.enabled then 104 Editor.draw() 105 return 106 elseif UserLevel.enabled then 107 UserLevel.draw() 108 return 109 end 110 111 Graphics.draw() 112 113end 114 115 116function love.keypressed(key) 117 -- general 118 if key == "n" then 119 Sounds.switch() 120 end 121 122 if key == "m" then 123 Music.switch() 124 end 125 126 if key == "f12" then 127 Graphics.toggleMode() 128 end 129 130 if Editor.enabled then 131 Editor.keypressed( key ) 132 return 133 elseif UserLevel.enabled then 134 UserLevel.keypressed( key ) 135 return 136 end 137 138 Game.keypressed(key) 139 140end 141 142 143function love.keyreleased(key) 144 if Editor.enabled then 145 Editor.keyreleased( key ) 146 return 147 elseif UserLevel.enabled then 148 UserLevel.keyreleased( key ) 149 return 150 end 151 152 153 Game.keyreleased(key) 154 155end 156 157 158function love.mousepressed(x, y, button) 159 if Editor.enabled then 160 Editor.mousepressed(x, y, button) 161 return 162 elseif UserLevel.enabled then 163 UserLevel.mousepressed(x, y, button) 164 return 165 end 166 167 Game.mousepressed(x,y,button) 168 169end 170 171 172 173function love.mousereleased(x, y, button) 174 if Editor.enabled then 175 Editor.mousereleased(x, y, button) 176 return 177 elseif UserLevel.enabled then 178 UserLevel.mousereleased(x, y, button) 179 return 180 end 181 182 183 Game.mousereleased(x,y, button) 184 185end 186 187 188 189