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 19Game = {} 20 21 22function Game.init() 23 Game.gamemode = 1 24 Game.paused = false 25 Game.testlevel = false 26 Game.smallcollision = true 27 Game.helpmode = false 28end 29 30function Game.titlescreen() 31 Level.init() 32 Level.currentlevel = 0 33 Level.menutext = " by Christiaan Janssen\n\nObjective - kill all bandits\nArrow keys or WASD - move\nMouse - aim\nLeft Click - shoot\nMiddle Click - bullet time\nRight Click + Direction - jump + bullet time\nSpace, R or RShift - reload gun\nF12 - toggle fullscreen\nESC - quit\n\n Press space to start" 34 Level.menutext_U = " by Christiaan Janssen" 35--~ Level.menutext_L = "Objective -\nArrow keys or WASD -\nMouse -\nLeft Click -\nMiddle Click -\nRight Click + Direction -\nSpace, R or RShift -\nP -\nF12 -\nN -\nM -\nESC -" 36--~ Level.menutext_R = "kill all bandits\nmove\naim\nshoot\nbullet time\njump + bullet time\nreload gun\npause game\ntoggle fullscreen\nsound FX on-off\nmusic on-off\nquit" 37 Level.menutext_L = "Objective: \n\n Movement:\nArrow keys or WASD -\nMouse -\nLeft Click -\nMiddle Click -\nRight Click + Direction -\nSpace, R or RShift -\n\n Other:\nP -\nN -\nM -\nF12 -\nESC -\n\n Press F1 to go back" 38 Level.menutext_R = "kill all bandits\n\n\nmove\naim\nshoot\nbullet time\njump + bullet time\nreload gun\n\n\npause game\nsound FX on-off\nmusic on-off\ntoggle fullscreen\nquit" 39 Entities.add_element(Entities.entitylist.player,{184,24}) 40 Entities.add_element(Entities.entitylist.blue_bandit,{91,393}) 41 Entities.add_element(Entities.entitylist.blue_bandit,{584,324}) 42 Entities.add_element(Entities.entitylist.cactus,{54,124}) 43 Entities.add_element(Entities.entitylist.cactus,{554,224}) 44 Entities.add_element(Entities.entitylist.cactus,{484,400}) 45 Graphics.prepareBackground() 46 Graphics.prepareTopLayer() 47 Level.reset_enemies() 48 Player.alive = false 49 Player.death_timer = 0 50 BulletTime.showprogress = false 51 Editor.enabled=false 52 53end 54 55function Game.endgame() 56 Level.init() 57 Level.currentlevel = 11 58 Level.endtext = "Victory!\n\nEveryone is dead now.\nYou are the only survivor in this ghost town.\nNo more bad people. No more people at all.\n\nYou win.\n\nESC for main menu" 59 Level.hardtext = "You've beaten the hard mode! You are a true badass!" 60 Entities.add_element(Entities.entitylist.player,{30,30}) 61 Entities.add_element(Entities.entitylist.cactus,{54,124}) 62 Entities.add_element(Entities.entitylist.cactus,{554,224}) 63 Entities.add_element(Entities.entitylist.cactus,{354,400}) 64 Graphics.prepareBackground() 65 Graphics.prepareTopLayer() 66end 67 68function Game.update(dt) 69--~ if Level.currentlevel == 0 then 70--~ return 71--~ end 72 73 if Game.paused or Game.helpmode then 74 return 75 end 76 77 if not BulletTime.active then 78 Player.update( dt ) 79 80 Movement.update_bullets( dt ) 81 82 EnemyAI.update( dt ) 83 84 Graphics.update_player( dt ) 85 Graphics.update_enemies( dt ) 86 else 87 Player.update( dt * BulletTime.slowdown_player ) 88 89 Movement.update_bullets( dt * BulletTime.slowdown_bullets ) 90 91 EnemyAI.update( dt * BulletTime.slowdown_enemies ) 92 93 Graphics.update_player( dt * BulletTime.slowdown_player ) 94 Graphics.update_enemies( dt * BulletTime.slowdown_enemies ) 95 end 96 97 BulletTime.update( dt ) 98 99 Level.update( dt ) 100end 101 102 103function Game.keypressed( key ) 104 105 106 if key == "escape" then 107 if Game.helpmode then 108 Game.helpmode = false 109 elseif Level.currentlevel == 0 and not Editor.enabled then 110 if ProfilingEnabled then 111 dumpTrace() 112 end 113 love.event.push('q') 114 else 115 Game.paused = false 116 Game.titlescreen() 117 end 118 end 119 120 if key == "p" then 121 Game.paused = not Game.paused 122 end 123 124 if key == "f1" and (not Editor.enabled) and (not Game.paused) then 125 Game.helpmode = not Game.helpmode 126 end 127 128 if Game.paused or Game.helpmode then 129 return 130 end 131 132 if key == "f7" then 133 if Editor.enabled then 134 Level.restart() 135 end 136 end 137 138 if Level.currentlevel == 0 and not Editor.enabled then 139 if key == "f2" then 140 -- start normal game 141 BulletTime.showprogress = true 142 Game.gamemode = 1 143 Level.currentlevel = 1 144 Level.load(1) 145 end 146 if key == "f3" then 147 -- start hard game 148 BulletTime.showprogress = true 149 Game.gamemode = 2 150 Level.currentlevel = 1 151 Level.load(1) 152 end 153 if key== "f5" then 154 Level.currentlevel = 1 155 Editor.init() 156 end 157 if key== "f4" then 158 Level.currentlevel = 1 159 UserLevel.init() 160 end 161 end 162 163 if Level.currentlevel > 0 and 164 (key == "r" or key == "rshift" or key == " ") then 165 Player.start_reload() 166 end 167 168end 169 170 171function Game.keyreleased(key) 172end 173 174 175function Game.mousepressed(x,y,button) 176 if Game.paused or Game.helpmode then 177 return 178 end 179 180 if Level.currentlevel == 0 and not Editor.enabled then 181 return 182 end 183 184-- Checks which button was pressed. 185 if button == "l" then 186 Player.start_firing() 187 188 elseif button == "r" then 189 Player.start_jumping() 190 BulletTime.start() 191 elseif button == "m" then 192 BulletTime.start() 193 end 194end 195 196function Game.mousereleased(x,y, button) 197 if Game.paused or Game.helpmode then 198 return 199 end 200-- Checks which button was pressed. 201 if button == "l" then 202 Player.stop_firing() 203 elseif button == "r" then 204 Player.set_jumping_done() 205 end 206end 207