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 19Colors = { 20 green ={124,164,26}, 21 dk_green = {120,115,19}, 22 red = {164,26,33}, 23 black = {33,18,5}, 24 orange = {206,111,33}, 25 dk_red = {120,19,24}, 26 lt_red = {183,29,39}, 27 dark_black = {0,0,0}, 28 lt_blue = {26,122,160}, 29 yellow = {207,198,33}, 30} 31 32function Colors.init() 33 Colors.background = Colors.orange 34 Colors.foreground = Colors.dk_red 35 36 love.graphics.setBackgroundColor(Colors.background) 37 love.graphics.setColor(Colors.foreground) 38 love.graphics.setPoint(1,"rough") 39end 40 41Graphics = {} 42 43Graphics.walk_framedelay = 0.030 44Graphics.jump_framedelay = 0.045 45Graphics.death_framedelay = 0.060 46Graphics.shadow_mode = false 47Graphics.show_shoot_dir = true 48Graphics.show_personalprogressbar=true 49 50function Graphics.imageSection( filename, xfraction, yfraction, wfraction, hfraction ) 51 local image = love.graphics.newImage(filename) 52 local x = math.floor(xfraction * image:getWidth()) 53 local y = math.floor(yfraction * image:getHeight()) 54 local w = math.floor(wfraction * image:getWidth()) 55 local h = math.floor(hfraction * image:getHeight()) 56 57 local frameBuffer = love.graphics.newFramebuffer( w, h ) 58 love.graphics.setRenderTarget( frameBuffer ) 59 love.graphics.clear() 60 love.graphics.draw( image, -x, -y) 61 62 63 local img = love.graphics.newImage( frameBuffer:getImageData() ) 64 love.graphics.setRenderTarget() 65 return img 66end 67 68Graphics.images = { 69 70 title = love.graphics.newImage("images/title.png"), 71 72 guy_standing = love.graphics.newImage("images/guy.png"), 73 guy_walk_right = love.graphics.newImage("images/guy_walk_right.png"), 74 guy_walk_up = love.graphics.newImage("images/guy_walk_up.png"), 75 guy_jumping_right = love.graphics.newImage("images/guy_jumping_right.png"), 76 guy_jumping_up = love.graphics.newImage("images/guy_jumping_up.png"), 77 guys_gun_right = Graphics.imageSection("images/guys_gun.png", 0, 0, 1/2, 1), 78 guys_gun_left = Graphics.imageSection("images/guys_gun.png", 1/2, 0, 1/2, 1), 79 guy_dying_right = love.graphics.newImage("images/guy_die_right.png"), 80 81 blue_bandit_standing = love.graphics.newImage("images/blue_bandit.png"), 82 blue_bandit_walk_right = love.graphics.newImage("images/blue_bandit_walk_right.png"), 83 blue_bandit_walk_up = love.graphics.newImage("images/blue_bandit_walk_up.png"), 84 blue_bandit_gun_right= Graphics.imageSection("images/blue_gun.png", 0, 0, 1/2, 1), 85 blue_bandit_gun_left =Graphics.imageSection("images/blue_gun.png", 1/2, 0, 1/2, 1), 86 blue_bandit_dying_right = love.graphics.newImage("images/blue_bandit_die_right.png"), 87 88 red_bandit_standing = love.graphics.newImage("images/red_bandit.png"), 89 red_bandit_walk_right = love.graphics.newImage("images/red_bandit_walk_right.png"), 90 red_bandit_walk_up = love.graphics.newImage("images/red_bandit_walk_up.png"), 91 red_bandit_gun_right= Graphics.imageSection("images/red_gun.png", 0, 0, 1/2, 1), 92 red_bandit_gun_left =Graphics.imageSection("images/red_gun.png", 1/2, 0, 1/2, 1), 93 red_bandit_dying_right = love.graphics.newImage("images/red_bandit_die_right.png"), 94 95 green_bandit_standing = love.graphics.newImage("images/green_bandit.png"), 96 green_bandit_walk_right = love.graphics.newImage("images/green_bandit_walk_right.png"), 97 green_bandit_walk_up = love.graphics.newImage("images/green_bandit_walk_up.png"), 98 green_bandit_gun_right= Graphics.imageSection("images/green_gun.png", 0, 0, 1/2, 1), 99 green_bandit_gun_left =Graphics.imageSection("images/green_gun.png", 1/2, 0, 1/2, 1), 100 green_bandit_dying_right = love.graphics.newImage("images/green_bandit_die_right.png"), 101 102 yellow_bandit_standing = love.graphics.newImage("images/yellow_bandit.png"), 103 yellow_bandit_walk_right = love.graphics.newImage("images/yellow_bandit_walk_right.png"), 104 yellow_bandit_walk_up = love.graphics.newImage("images/yellow_bandit_walk_up.png"), 105 yellow_bandit_gun_right= Graphics.imageSection("images/yellow_gun.png", 0, 0, 1/2, 1), 106 yellow_bandit_gun_left =Graphics.imageSection("images/yellow_gun.png", 1/2, 0, 1/2, 1), 107 yellow_bandit_dying_right = love.graphics.newImage("images/yellow_bandit_die_right.png"), 108 109 ninja_bandit_standing = love.graphics.newImage("images/ninja_bandit.png"), 110 ninja_bandit_walk_right = love.graphics.newImage("images/ninja_bandit_walk_right.png"), 111 ninja_bandit_walk_up = love.graphics.newImage("images/ninja_bandit_walk_up.png"), 112 ninja_bandit_walk_dn = love.graphics.newImage("images/ninja_bandit_walk_dn.png"), 113 ninja_bandit_blue_gun_right= Graphics.imageSection("images/ninja_bandit_blue_gun.png", 0, 0, 1/2, 1), 114 ninja_bandit_blue_gun_left =Graphics.imageSection("images/ninja_bandit_blue_gun.png", 1/2, 0, 1/2, 1), 115 ninja_bandit_red_gun_right= Graphics.imageSection("images/ninja_bandit_red_gun.png", 0, 0, 1/2, 1), 116 ninja_bandit_red_gun_left =Graphics.imageSection("images/ninja_bandit_red_gun.png", 1/2, 0, 1/2, 1), 117 ninja_bandit_green_gun_right= Graphics.imageSection("images/ninja_bandit_green_gun.png", 0, 0, 1/2, 1), 118 ninja_bandit_green_gun_left =Graphics.imageSection("images/ninja_bandit_green_gun.png", 1/2, 0, 1/2, 1), 119 ninja_bandit_yellow_gun_right= Graphics.imageSection("images/ninja_bandit_yellow_gun.png", 0, 0, 1/2, 1), 120 ninja_bandit_yellow_gun_left =Graphics.imageSection("images/ninja_bandit_yellow_gun.png", 1/2, 0, 1/2, 1), 121 ninja_bandit_dying_right = love.graphics.newImage("images/ninja_bandit_die_right.png"), 122 123 bullet = love.graphics.newImage("images/bullet.png"), 124 bullet_marker = love.graphics.newImage("images/bullet_huge.png"), 125 126 cactus = love.graphics.newImage("images/cactus.png"), 127 barrel = love.graphics.newImage("images/barrel.png"), 128 saloon = love.graphics.newImage("images/saloon.png"), 129 sheriff_box = love.graphics.newImage("images/sheriff.png"), 130 church = love.graphics.newImage("images/church.png"), 131 bank = love.graphics.newImage("images/bank.png"), 132 mansion = love.graphics.newImage("images/mansion.png"), 133 house = love.graphics.newImage("images/house.png"), 134 warehouse = love.graphics.newImage("images/warehouse.png"), 135 barrier_horiz = love.graphics.newImage("images/barrier_horiz.png"), 136 barrier_vert = love.graphics.newImage("images/barrier_vert.png"), 137 dead_branch = love.graphics.newImage("images/dead_branch.png"), 138 dead_tree = love.graphics.newImage("images/dead_tree.png"), 139 fence_horiz = love.graphics.newImage("images/fence_horiz.png"), 140 fence_vert = love.graphics.newImage("images/fence_vert.png"), 141 herb = love.graphics.newImage("images/herb.png"), 142 mill = love.graphics.newImage("images/mill.png"), 143 bush = love.graphics.newImage("images/bush.png"), 144 barber = love.graphics.newImage("images/barber.png"), 145 crate = love.graphics.newImage("images/crate.png"), 146 generic_house = love.graphics.newImage("images/generic_house.png"), 147 smith = love.graphics.newImage("images/smith.png"), 148 stable = love.graphics.newImage("images/stable.png"), 149 tiny_house = love.graphics.newImage("images/tiny_house.png"), 150 pile = love.graphics.newImage("images/pile.png"), 151 well = love.graphics.newImage("images/well.png"), 152 153 154 commands = love.graphics.newImage("images/functions.png"), 155 f1help = love.graphics.newImage("images/f1help.png"), 156 f2save = love.graphics.newImage("images/f2save.png"), 157 f3load = love.graphics.newImage("images/f3load.png"), 158 f4move = love.graphics.newImage("images/f4move.png"), 159 f5add = love.graphics.newImage("images/f5add.png"), 160 f6test = love.graphics.newImage("images/f6test.png"), 161 f7reset = love.graphics.newImage("images/f7reset.png"), 162 f8opts = love.graphics.newImage("images/f8opts.png"), 163 f10wipe = love.graphics.newImage("images/f10wipe.png"), 164 165} 166 167function Graphics.initAnim( _strip, _w, _h, _frametime ) 168 local frames = {} 169 local i 170 local data ={ 171 frame_w = _w, 172 frame_h = _h, 173 frame_count = math.floor(_strip:getWidth() / _w), 174 frame_ndx = 0, 175 frame_delay = _frametime, 176 frame_timer = _frametime 177 } 178 179 local frameBuffer = love.graphics.newFramebuffer( data.frame_w, data.frame_h ) 180 love.graphics.setRenderTarget( frameBuffer ) 181 for i=0,data.frame_count-1 do 182 love.graphics.clear() 183 love.graphics.draw( _strip, -data.frame_w * i, 0) 184 frames[i] = love.graphics.newImage( frameBuffer:getImageData() ) 185 end 186 data.strip = frames 187 love.graphics.setRenderTarget() 188 return data 189end 190 191 192function Graphics.resetAnim( anim ) 193 anim.frame_timer = anim.frame_delay 194 anim.frame_ndx = 0 195end 196 197function Graphics.updateAnim( anim, dt ) 198 anim.frame_timer = anim.frame_timer - dt 199 while (anim.frame_timer <= 0) do 200 anim.frame_timer = anim.frame_timer + anim.frame_delay 201 anim.frame_ndx = anim.frame_ndx + 1 202 if (anim.frame_ndx == anim.frame_count) then 203 anim.frame_ndx = 0 204 end 205 end 206end 207 208function Graphics.drawCurrentFrame( anim, x, y, reverse ) 209 local x0 = (x - anim.frame_w/2) 210 local y0 = (y-anim.frame_h/2) 211 212 if not reverse then 213 love.graphics.draw(anim.strip[anim.frame_ndx], x, y, 0, 1, 1, math.floor(anim.frame_w/2), math.floor(anim.frame_h/2)) 214 else 215 love.graphics.draw(anim.strip[anim.frame_ndx], x, y, 0, -1, 1, math.floor(anim.frame_w/2), math.floor(anim.frame_h/2)) 216 end 217end 218 219Graphics.animations = { 220 guy_walk_right = Graphics.initAnim(Graphics.images.guy_walk_right, 18, 22, Graphics.walk_framedelay), 221 guy_walk_up = Graphics.initAnim(Graphics.images.guy_walk_up, 18, 22, Graphics.walk_framedelay), 222 guy_jumping_right = Graphics.initAnim(Graphics.images.guy_jumping_right, 18, 22, Graphics.jump_framedelay), 223 guy_jumping_up = Graphics.initAnim(Graphics.images.guy_jumping_up, 18, 22, Graphics.jump_framedelay), 224 guy_dying_right = Graphics.initAnim(Graphics.images.guy_dying_right, 18, 22, Graphics.death_framedelay), 225} 226 227function Graphics.animations.new_blue_bandit_walk_right() 228 return Graphics.initAnim(Graphics.images.blue_bandit_walk_right, 18, 24, Graphics.walk_framedelay) 229end 230 231function Graphics.animations.new_blue_bandit_walk_up() 232 return Graphics.initAnim(Graphics.images.blue_bandit_walk_up, 18, 24, Graphics.walk_framedelay) 233end 234function Graphics.animations.new_blue_bandit_dying_right() 235 return Graphics.initAnim(Graphics.images.blue_bandit_dying_right, 18, 22, Graphics.death_framedelay) 236end 237 238function Graphics.animations.new_red_bandit_walk_right() 239 return Graphics.initAnim(Graphics.images.red_bandit_walk_right, 18, 22, Graphics.walk_framedelay) 240end 241function Graphics.animations.new_red_bandit_walk_up() 242 return Graphics.initAnim(Graphics.images.red_bandit_walk_up, 18, 22, Graphics.walk_framedelay) 243end 244function Graphics.animations.new_red_bandit_dying_right() 245 return Graphics.initAnim(Graphics.images.red_bandit_dying_right, 18, 22, Graphics.death_framedelay) 246end 247 248function Graphics.animations.new_green_bandit_walk_right() 249 return Graphics.initAnim(Graphics.images.green_bandit_walk_right, 18, 24, Graphics.walk_framedelay) 250end 251function Graphics.animations.new_green_bandit_walk_up() 252 return Graphics.initAnim(Graphics.images.green_bandit_walk_up, 18, 24, Graphics.walk_framedelay) 253end 254function Graphics.animations.new_green_bandit_dying_right() 255 return Graphics.initAnim(Graphics.images.green_bandit_dying_right, 18, 22, Graphics.death_framedelay) 256end 257 258function Graphics.animations.new_yellow_bandit_walk_right() 259 return Graphics.initAnim(Graphics.images.yellow_bandit_walk_right, 18, 22, Graphics.walk_framedelay) 260end 261function Graphics.animations.new_yellow_bandit_walk_up() 262 return Graphics.initAnim(Graphics.images.yellow_bandit_walk_up, 18, 22, Graphics.walk_framedelay) 263end 264function Graphics.animations.new_yellow_bandit_dying_right() 265 return Graphics.initAnim(Graphics.images.yellow_bandit_dying_right, 18, 22, Graphics.death_framedelay) 266end 267 268function Graphics.animations.new_ninja_bandit_walk_right() 269 return Graphics.initAnim(Graphics.images.ninja_bandit_walk_right, 18, 22, Graphics.walk_framedelay) 270end 271function Graphics.animations.new_ninja_bandit_walk_up() 272 return Graphics.initAnim(Graphics.images.ninja_bandit_walk_up, 18, 22, Graphics.walk_framedelay) 273end 274function Graphics.animations.new_ninja_bandit_walk_dn() 275 return Graphics.initAnim(Graphics.images.ninja_bandit_walk_dn, 18, 22, Graphics.walk_framedelay) 276end 277function Graphics.animations.new_ninja_bandit_dying_right() 278 return Graphics.initAnim(Graphics.images.ninja_bandit_dying_right, 18, 22, Graphics.death_framedelay) 279end 280 281function Graphics.get_jumptime( ) 282 return Graphics.jump_framedelay * Graphics.animations.guy_jumping_up.frame_count 283end 284 285function Graphics.get_deathtime( ) 286 return Graphics.death_framedelay * Graphics.animations.guy_dying_right.frame_count - Graphics.death_framedelay/2 287end 288 289function Graphics.reset_jump() 290 Graphics.resetAnim( Graphics.animations.guy_jumping_right ) 291 Graphics.resetAnim( Graphics.animations.guy_jumping_up ) 292end 293 294function Graphics.reset_death() 295 Graphics.resetAnim( Graphics.animations.guy_dying_right ) 296end 297 298function Graphics.update_player(delta) 299 Graphics.updateAnim( Graphics.animations.guy_walk_right, delta) 300 Graphics.updateAnim( Graphics.animations.guy_walk_up, delta) 301 Graphics.updateAnim( Graphics.animations.guy_jumping_right, delta) 302 Graphics.updateAnim( Graphics.animations.guy_jumping_up, delta) 303 Graphics.updateAnim( Graphics.animations.guy_dying_right, delta) 304end 305 306function Graphics.update_enemies(delta) 307 if Level.ninjamode and not (Editor.enabled and Editor.mode ~= 6) and Level.currentlevel > 0 then 308 Graphics.update_ninja_enemies( delta ) 309 return 310 end 311 312 for i,enemy in ipairs(Level.enemies) do 313 if enemy.dir ~= {0,0} then 314 if math.abs(enemy.dir[1]) > math.abs(enemy.dir[2]) then 315 Graphics.updateAnim( enemy.sprite_walking_right, delta) 316 else 317 if enemy.dir[2]<0 then 318 Graphics.updateAnim( enemy.sprite_walking_up, delta) 319 else 320 Graphics.updateAnim( enemy.sprite_walking_dn, delta) 321 end 322 end 323 end 324 325 if enemy.state == 0 then 326 Graphics.updateAnim( enemy.sprite_dying, delta) 327 end 328 329 end 330 331end 332 333function Graphics.update_ninja_enemies(delta) 334 for i,enemy in ipairs(Level.enemies) do 335 if enemy.dir ~= {0,0} then 336 if math.abs(enemy.dir[1]) > math.abs(enemy.dir[2]) then 337 Graphics.updateAnim( enemy.sprite_ninja_walking_right, delta) 338 else 339 if enemy.dir[2]<0 then 340 Graphics.updateAnim( enemy.sprite_ninja_walking_up, delta) 341 else 342 Graphics.updateAnim( enemy.sprite_ninja_walking_dn, delta) 343 end 344 end 345 end 346 347 if enemy.state == 0 then 348 Graphics.updateAnim( enemy.sprite_ninja_dying, delta) 349 end 350 351 end 352 353end 354 355-- ============== modes ================== 356-- viewmodes= 1-fullscreen, 2-windowed 357Graphics.viewmode = 2 358function Graphics.toggleMode() 359 if Graphics.viewmode == 1 then 360 return Graphics.setWindowed() 361 else 362 return Graphics.setFullscreen() 363 end 364end 365 366function Graphics.setWindowed() 367 local success = love.graphics.setMode( screensize[1], screensize[2], false, true, 0 ) 368 Graphics.viewmode = 2 369 return success 370end 371 372function Graphics.setFullscreen() 373 local success = love.graphics.setMode( screensize[1], screensize[2], true, true, 0 ) 374 Graphics.viewmode = 1 375 return success 376end 377 378function Graphics.drawtext(text, x, y) 379 love.graphics.setColorMode("modulate") 380 love.graphics.setColor(Colors.dark_black) 381 love.graphics.print(text,x,y) 382 love.graphics.setColorMode("replace") 383end 384 385function Graphics.drawCentered( image, x, y, reversed ) 386 if not reversed then 387 love.graphics.draw(image, x, y, 0, 1, 1, math.floor(image:getWidth()/2), math.floor(image:getHeight()/2) ) 388 else 389 love.graphics.draw(image, x , y, 0, -1, 1, math.floor(image:getWidth()/2), math.floor(image:getHeight()/2)) 390 end 391end 392 393function Graphics.prepareBackground() 394 local frameBuffer = love.graphics.newFramebuffer( screensize[1], screensize[2] ) 395 love.graphics.setRenderTarget( frameBuffer ) 396 love.graphics.clear() 397 398 if Level.buildings then 399 for i,building in ipairs(Level.buildings) do 400 if building.solid == 5 then 401 Graphics.draw_building( building ) 402 end 403 end 404 end 405 406 Graphics.backgroundImage = love.graphics.newImage( frameBuffer:getImageData() ) 407 love.graphics.setRenderTarget() 408end 409 410function Graphics.prepareTopLayer() 411 local frameBuffer = love.graphics.newFramebuffer( screensize[1], screensize[2] ) 412 love.graphics.setRenderTarget( frameBuffer ) 413 love.graphics.clear() 414 415 if Level.buildings then 416 for i,building in ipairs(Level.buildings) do 417 if building.solid ~= 5 then 418 Graphics.draw_building( building ) 419 end 420 end 421 end 422 423 Graphics.topImage = love.graphics.newImage( frameBuffer:getImageData() ) 424 love.graphics.setRenderTarget() 425end 426 427function Graphics.init() 428 -- initialize empty ones 429 Graphics.prepareTopLayer() 430 Graphics.prepareBackground() 431end 432-- ============== DRAW FUNCTION ============== 433function Graphics.drawTitleScreen() 434 435 Graphics.drawCentered(Graphics.images.title,320,60) 436-- Graphics.drawCentered(Level.menutext, 150, 130) 437 Graphics.drawtext(Level.menutext_U, 150, 95) 438 Graphics.drawtext("F1 - Instructions\n\nF2 - Start in normal mode\n\nF3 - Start in hard mode\n\nF4 - Play user level\n\nF5 - Level editor\n\nESC - Exit", 200,160) 439end 440 441function Graphics.drawEndScreen() 442 Graphics.drawtext(Level.endtext, 130, 130) 443 if Game.gamemode == 2 then 444 Graphics.drawtext(Level.hardtext, 130,70) 445 end 446end 447 448function Graphics.showinstructions() 449 Graphics.drawtext(Level.menutext_L, 150, 30) 450 Graphics.drawtext(Level.menutext_R, 370, 30) 451end 452-- in graphics! 453function Graphics.draw() 454 455 if Game.paused then 456 love.graphics.setColor(Colors.dark_black) 457 Graphics.drawtext("Game Paused",280,240) 458 return 459 end 460 461 if Game.helpmode then 462 Graphics.showinstructions() 463 return 464 end 465 466 if not Editor.enabled then 467 if Level.currentlevel == 0 then 468 Graphics.drawTitleScreen() 469 470 --~ return 471 elseif Level.currentlevel == 11 then 472 Graphics.drawEndScreen() 473 -- return 474 end 475 end 476 477 478 --Graphics.drawCentered("WANTED\nDead or Alive\nJoseph <Joe> Smith\nWilliam <Happy Trigger> Gordon\nAbraham <Gramps> Derrick\nRobert <Crazy Horse> Morris\n6000$",10,10) 479 480 love.graphics.draw(Graphics.backgroundImage, 0, 0) 481 482 Graphics.draw_player() 483 484 List.apply(Bullets, Graphics.draw_bullet) 485 486 for i,enemy in ipairs(Level.enemies) do 487 Graphics.draw_enemy(enemy) 488 end 489 490 love.graphics.draw( Graphics.topImage, 0, 0 ) 491 492 -- bullettime progressbar 493 if BulletTime.showprogress and ((Editor.enabled and Editor.showprogress) or not Editor.enabled) then 494 if Graphics.show_personalprogressbar then 495 Graphics.draw_personalprogressbar() 496 else 497 Graphics.draw_progressbar(550, 10) 498 end 499 end 500 501end 502 503function Graphics.draw_player( ) 504 local lplayerpos = { math.floor( Player.pos[1] ), math.floor( Player.pos[2]) } 505 if Player.alive then 506 507 if Player.jumping then 508 -- jumping animation 509 if Player.spinning_dir[1] > 0 then 510 Graphics.drawCurrentFrame(Graphics.animations.guy_jumping_right, lplayerpos[1], lplayerpos[2]) 511 elseif Player.spinning_dir[1] < 0 then 512 Graphics.drawCurrentFrame(Graphics.animations.guy_jumping_right, lplayerpos[1], lplayerpos[2], true) 513 elseif Player.spinning_dir[2] < 0 then 514 Graphics.drawCurrentFrame(Graphics.animations.guy_jumping_up, lplayerpos[1], lplayerpos[2]) 515 elseif Player.spinning_dir[2] > 0 then 516 Graphics.drawCurrentFrame(Graphics.animations.guy_jumping_up, lplayerpos[1], lplayerpos[2], true) 517 else 518 Player.jumping = false 519 end 520 else 521 -- normal walk 522 if Player.dir[1] > 0 then 523 Graphics.drawCurrentFrame(Graphics.animations.guy_walk_right, lplayerpos[1], lplayerpos[2]) 524 elseif Player.dir[1] < 0 then 525 Graphics.drawCurrentFrame(Graphics.animations.guy_walk_right, lplayerpos[1], lplayerpos[2], true) 526 elseif Player.dir[2] ~= 0 then 527 Graphics.drawCurrentFrame(Graphics.animations.guy_walk_up, lplayerpos[1], lplayerpos[2]) 528 else 529 Graphics.drawCentered(Graphics.images.guy_standing, lplayerpos[1], lplayerpos[2]) 530 end 531 532 -- render gun 533 if Player.firing_timer > 0 then 534 if love.mouse.getX() > lplayerpos[1] then 535 love.graphics.draw(Graphics.images.guys_gun_right, math.floor(lplayerpos[1]), math.floor(lplayerpos[2]), 0, 1, 1, 536 Player.spritesize[1]/2, Player.spritesize[2]/2) 537 else 538 love.graphics.draw(Graphics.images.guys_gun_left, math.floor(lplayerpos[1]), math.floor(lplayerpos[2]), 0, 1, 1, 539 Player.spritesize[1]/2, Player.spritesize[2]/2) 540 end 541 end 542 end 543 else 544 if Player.death_timer > 0 then 545 if Player.dir[1]>=0 then 546 Graphics.drawCurrentFrame(Graphics.animations.guy_dying_right, lplayerpos[1], lplayerpos[2]) 547 else 548 Graphics.drawCurrentFrame(Graphics.animations.guy_dying_right, lplayerpos[1], lplayerpos[2], true) 549 end 550 end 551 end 552end 553 554function Graphics.draw_bullet( bullet ) 555 Graphics.drawCentered(Graphics.images.bullet, bullet.pos[1], bullet.pos[2]) 556end 557 558function Graphics.draw_enemy( enemy ) 559 560 if Level.ninjamode and not (Editor.enabled and Editor.mode ~= 6) and Level.currentlevel > 0 then 561 Graphics.draw_ninja_enemy( enemy ) 562 return 563 end 564 565 local px, py = math.floor(enemy.pos[1]), math.floor(enemy.pos[2]) 566 567 -- if it's dead, don't draw 568 if enemy.state == 0 then 569 if enemy.death_timer > 0 then 570 if enemy.dir[1]>=0 then 571 Graphics.drawCurrentFrame(enemy.sprite_dying, px, py) 572 else 573 Graphics.drawCurrentFrame(enemy.sprite_dying, px, py, true) 574 end 575 end 576 return 577 end 578 579 580 581 if enemy.blocked or (enemy.dir[1] == 0 and enemy.dir[2] == 0) then 582 Graphics.drawCentered(enemy.sprite_standing, px, py) 583 else 584 -- moving! 585 if math.abs(enemy.dir[1]) > math.abs(enemy.dir[2]) then 586 -- horizontal movement 587 if enemy.dir[1]>0 then 588 -- moving right 589 Graphics.drawCurrentFrame(enemy.sprite_walking_right, px, py) 590 else 591 -- moving left 592 Graphics.drawCurrentFrame(enemy.sprite_walking_right, px, py, true ) 593 end 594 else 595 -- vertical movement 596 if enemy.dir[2]<0 then 597 Graphics.drawCurrentFrame(enemy.sprite_walking_up, px, py) 598 else 599 Graphics.drawCurrentFrame(enemy.sprite_walking_dn, px, py) 600 end 601 end 602 end 603 604 -- if he is shooting, draw the gun 605 if enemy.shooting_timer > 0 then 606 local lx, ly = enemy.sprite_gun_left:getWidth()/2, enemy.sprite_gun_left:getHeight() 607 if enemy.shoot_dir[1]>enemy.accuracy*2 then 608 enemy.side = 1 609 end 610 if enemy.shoot_dir[1]<-enemy.accuracy*2 then 611 enemy.side = 2 612 end 613 if enemy.side==1 then 614 Graphics.drawCentered(enemy.sprite_gun_right, px, py) 615 else 616 Graphics.drawCentered(enemy.sprite_gun_left, px, py) 617 end 618 619 end 620 621 -- show the shooting direction pointer 622 if Graphics.show_shoot_dir then 623 love.graphics.setColor(Colors.black) 624 love.graphics.point(enemy.pos[1]+enemy.shoot_dir[1]*15,enemy.pos[2]+enemy.shoot_dir[2]*15) 625 love.graphics.point(enemy.pos[1]+enemy.shoot_dir[1]*16,enemy.pos[2]+enemy.shoot_dir[2]*16) 626 end 627end 628 629function Graphics.draw_ninja_enemy( enemy ) 630 631 local px, py = math.floor(enemy.pos[1]), math.floor(enemy.pos[2]) 632 633 -- if it's dead, don't draw 634 if enemy.state == 0 then 635 if enemy.death_timer > 0 then 636 if enemy.dir[1]>=0 then 637 Graphics.drawCurrentFrame(enemy.sprite_ninja_dying, px, py) 638 else 639 Graphics.drawCurrentFrame(enemy.sprite_ninja_dying, px, py, true) 640 end 641 end 642 return 643 end 644 645 if not EnemyAI.ninja_see_player_short( enemy ) then 646 return 647 end 648 649 650 if enemy.blocked or (enemy.dir[1] == 0 and enemy.dir[2] == 0) then 651 Graphics.drawCentered(enemy.sprite_ninja_standing, px, py) 652 else 653 -- moving! 654 if math.abs(enemy.dir[1]) > math.abs(enemy.dir[2]) then 655 -- horizontal movement 656 if enemy.dir[1]>0 then 657 -- moving right 658 Graphics.drawCurrentFrame(enemy.sprite_ninja_walking_right, px, py) 659 else 660 -- moving left 661 Graphics.drawCurrentFrame(enemy.sprite_ninja_walking_right, px, py, true ) 662 end 663 else 664 -- vertical movement 665 if enemy.dir[2]<0 then 666 Graphics.drawCurrentFrame(enemy.sprite_ninja_walking_up, px, py) 667 else 668 Graphics.drawCurrentFrame(enemy.sprite_ninja_walking_dn, px, py) 669 end 670 end 671 end 672 673 -- if he is shooting, draw the gun 674 if enemy.shooting_timer > 0 then 675 local lx, ly = enemy.sprite_ninja_gun_left:getWidth()/2, enemy.sprite_ninja_gun_left:getHeight() 676 if enemy.shoot_dir[1]>enemy.accuracy*2 then 677 enemy.side = 1 678 end 679 if enemy.shoot_dir[1]<-enemy.accuracy*2 then 680 enemy.side = 2 681 end 682 if enemy.side==1 then 683 Graphics.drawCentered(enemy.sprite_ninja_gun_right, px, py) 684 else 685 Graphics.drawCentered(enemy.sprite_ninja_gun_left, px, py) 686 end 687 688 end 689 690 -- show the shooting direction pointer 691 if Graphics.show_shoot_dir then 692 love.graphics.setColor(enemy.color) 693 love.graphics.point(enemy.pos[1]+enemy.shoot_dir[1]*15,enemy.pos[2]+enemy.shoot_dir[2]*15) 694 love.graphics.point(enemy.pos[1]+enemy.shoot_dir[1]*16,enemy.pos[2]+enemy.shoot_dir[2]*16) 695 end 696end 697 698function Graphics.draw_building( building ) 699 if building.sprite then 700 if building.len then 701 -- several 702 -- len[1] tells the direction: 1 horiz, 2 vert 703 -- len[2] tells the number of repetitions 704 -- len[3] tells the size of a single element 705 if building.len[1] == 1 then 706 for j=1,building.len[2] do 707 Graphics.drawCentered(building.sprite, 708 math.floor(building.pos[1]+(j-1-(building.len[2]-1)/2)*building.len[3]), 709 math.floor(building.pos[2])) 710 end 711 elseif building.len[1] == 2 then 712 for j=1,building.len[2] do 713 Graphics.drawCentered(building.sprite, 714 math.floor(building.pos[1]), 715 math.floor(building.pos[2]+(j-1-(building.len[2]-1)/2)*building.len[3])) 716 717 end 718 719 end 720 else 721 -- just one 722 Graphics.drawCentered(building.sprite, math.floor(building.pos[1]), math.floor(building.pos[2])) 723 end 724 end 725end 726 727function Graphics.draw_progressbar(px, py) 728 729 local fraction 730 local bar_len = 100 731 732 -- enclosing box 733 love.graphics.setColor(Colors.black) 734 love.graphics.setLine(12,love.line_rough) 735 love.graphics.line( px- bar_len/2 -3, py, px + bar_len/2 + 3, py ) 736 737 -- bar 738 739 -- charging or discharging? 740 if BulletTime.charged then 741 love.graphics.setColor(Colors.dk_green) 742 fraction = 1 743 else 744 if BulletTime.active then 745 fraction = BulletTime.timer / BulletTime.duration 746 -- green when discharging 747 love.graphics.setColor(Colors.dk_green) 748 else 749 fraction = BulletTime.charge_timer/BulletTime.charge_duration 750 -- red when charging 751 love.graphics.setColor(Colors.red) 752 end 753 end 754 755 love.graphics.setLine(6,love.line_rough ) -- big dots! 756 love.graphics.line( px- bar_len/2 , py, px- bar_len/2 + math.floor(fraction*bar_len) , py) 757 758 -- rest 759 love.graphics.setColor(Colors.background) 760 love.graphics.line( px- bar_len/2 + math.floor(fraction*bar_len) , py , px + bar_len/2, py) 761 762 -- bullet pocket 763 for i=1,Player.bullet_pocket do 764 Graphics.drawCentered(Graphics.images.bullet_marker,i*10, 8) 765 end 766 767 -- return to foreground color 768 love.graphics.setColor(Colors.foreground) 769 770 771 772end 773 774function Graphics.draw_personalprogressbar() 775 776 local fraction 777 local bar_len = 18 778 local px,py = Player.pos[1],math.floor(Player.pos[2] - 13) 779 780 -- bar 781 782 -- charging or discharging? 783 if BulletTime.charged then 784 love.graphics.setColor(Colors.dk_green) 785 fraction = 1 786 else 787 if BulletTime.active then 788 fraction = BulletTime.timer / BulletTime.duration 789 -- green when discharging 790 love.graphics.setColor(Colors.dk_green) 791 else 792 fraction = BulletTime.charge_timer/BulletTime.charge_duration 793 -- red when charging 794 love.graphics.setColor(Colors.red) 795 end 796 end 797 798 love.graphics.setLine(1,"rough" ) -- small dots! 799 love.graphics.line( px- bar_len/2 , py, px- bar_len/2 + math.floor(fraction*bar_len) , py) 800 801 -- bullet pocket 802 love.graphics.setColor(Colors.dark_black) 803 804 for i=1,Player.bullet_pocket do 805 love.graphics.point(math.floor(px-bar_len/2) + i*3 - 2, py-1) 806 love.graphics.point(math.floor(px-bar_len/2) + i*3 - 2, py-2) 807 end 808 809 -- return to foreground color 810 love.graphics.setColor(Colors.foreground) 811 812end 813 814-- ============== END DRAW FUNCTION ============== 815 816