21 Commits 27d730013a ... 8d480f8835

Author SHA1 Message Date
  Pedro Gimeno 8d480f8835 Add compatibility with 0.9.0 2 years ago
  Pedro Gimeno 4940eac90a dkjson: Disable lpeg 4 years ago
  Pedro Gimeno eb864f6ccb Update ns.lua with missing namespaces, update usage comment 5 years ago
  Pedro Gimeno 173d9643c9 Change timing strategy so that it's 1/50s constant 6 years ago
  Pedro Gimeno 44481963eb Add scoring and score indicator 6 years ago
  Pedro Gimeno c689e77314 Get rid of the volume knob altogether 6 years ago
  Pedro Gimeno 7a7f8e6884 Change strategy for drawing the volume knob, to a canvas 6 years ago
  Pedro Gimeno 6b9b8cec3a Pause thrust sound in pause mode, change handling to avoid clicks 6 years ago
  Pedro Gimeno d9a09b9420 Add escape key handling to more screens 6 years ago
  Pedro Gimeno 7eaa777b52 Fix close window problem when run from love2d 0.2.1 6 years ago
  Pedro Gimeno ba82beacf0 Sort out the version check mess 6 years ago
  Pedro Gimeno c24ad69799 Make Escape return to main menu while in game (COMPLETED) 6 years ago
  Pedro Gimeno 4bc855ed32 WIP: Make Escape return to main menu while in game 6 years ago
  Pedro Gimeno a5cb1c8631 Bump copyright year 6 years ago
  Pedro Gimeno 2434bb04e9 Change global-based lovespaces.lua to local-based ns.lua 6 years ago
  Pedro Gimeno 9e7da359cb Change ww/2 to wcx and wh/2 to wcy in more places 6 years ago
  Pedro Gimeno f9b8968a06 Revamp version check so that it works with all versions back to 0.1.1a 6 years ago
  Pedro Gimeno 0836aa9a18 Bump version requirement to 11.1 6 years ago
  Pedro Gimeno 5e96aee4c8 Add 11.0 compatibility 6 years ago
  Pedro Gimeno 886897eada Display number of remaining enemies of the type of the current agent 6 years ago
  Pedro Gimeno 7f69e7d383 Don't create a function just for the pcall. 6 years ago
10 changed files with 116 additions and 78 deletions
  1. 1 1
      3rdparty/dkjson.lua
  2. 1 1
      AUTHORS.txt
  3. 9 7
      conf.lua
  4. 48 30
      game.lua
  5. 20 3
      gameover.lua
  6. 11 5
      gamewon.lua
  7. 22 5
      getready.lua
  8. 4 2
      layout.lua
  9. 0 24
      lovespaces.lua
  10. 0 0
      main.lua

+ 1 - 1
3rdparty/dkjson.lua

@@ -1,5 +1,5 @@
 -- Module options:
-local always_try_using_lpeg = true
+local always_try_using_lpeg = false
 local register_global_module_table = false
 local global_module_name = 'json'
 

+ 1 - 1
AUTHORS.txt

@@ -2,7 +2,7 @@ Original game:
   Copyright © 1986 Andrew Rogers.
 
 Code for this version:
-  Copyright © 2015-2017 Pedro Gimeno Fortea. License: Expat.
+  Copyright © 2015-2018 Pedro Gimeno Fortea. License: Expat.
   Each individual file includes the full license text.
 
 Third party libraries:

+ 9 - 7
conf.lua

@@ -2,7 +2,7 @@
 
 LÖVE Configuration file for Thrust II Reloaded.
 
-Copyright © 2015-2017 Pedro Gimeno Fortea
+Copyright © 2015-2018 Pedro Gimeno Fortea
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
@@ -25,16 +25,18 @@ SOFTWARE.
 --]========================================================================]--
 
 function love.conf(t)
+  if love._version_major == 0 and love._version_minor == 10 then
+    t.version = '0.10.0'
+  elseif love._version_major == 0 and love._version_minor == 9 then
+    t.version = '0.9.0'
+  else
+    t.version = '11.1'
+  end
+
   t.identity = "ThrustIIreloaded"
   t.modules.joystick = false
   t.modules.physics = false
 
   -- We configure the window in main.
   t.window = nil
-
-  if love._version_major == 0 and love._version_minor == 9 then
-    t.version = '0.9.1'
-  else
-    t.version = '0.10.0'
-  end
 end

+ 48 - 30
game.lua

@@ -2,7 +2,7 @@
 
 Game logic for Thrust II Reloaded.
 
-Copyright © 2015-2017 Pedro Gimeno Fortea
+Copyright © 2015-2018 Pedro Gimeno Fortea
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
@@ -26,7 +26,8 @@ SOFTWARE.
 
 local game = {}
 
-local json = require "3rdparty.dkjson"
+local la,le,lfs,lf,lg,li,lj,lk,lm,lmo,lp,ls,lsys,lth,lt,lw = require'ns'()
+local json = require '3rdparty.dkjson'
 
 local garbagetimer = 0
 local collision_canvas, no_collision
@@ -63,6 +64,7 @@ local total_shoot_time = 4
 local latchsnd, orbdangersnd, crashsnd, cablesnd, enemykillsnd
 local getagentsnd, shootsnd, orbpickupsnd, orbdropsnd, thrustsnd, music
 
+local DIV = love_version >= 11000000 and 255 or 1
 
 function game.load()
   -- Game viewport
@@ -107,7 +109,7 @@ function game.load()
   -- in the next rows until completing that height is empty.
   -- E.g. if X is 32x32 (1x1 cells) and Y is 64x64 (2x2 cells):
   --       X YY YY X X    correct
-  --         YY YY    
+  --         YY YY
   --
   --       X YY YY X X    incorrect - don't reuse the empty spaces
   --       X YY YY        (our algorithm isn't that clever)
@@ -183,9 +185,13 @@ function game.load()
   -- Crash sound
   crashsnd = la.newSource("snd/Grenade-SoundBible.com-1777900486.ogg", "static")
   -- Enemy killed
-  enemykillsnd = la.newSource("snd/supertank_plazma_fireball_22khz.mp3")
-  -- Make it a table so we can play two at the same time
-  enemykillsnd = { enemykillsnd, enemykillsnd:clone() }
+  enemykillsnd = la.newSource("snd/supertank_plazma_fireball_22khz.mp3", "static")
+  -- Make a duplicate so we can ply two at the same time
+  -- Only 0.9.1+ has Source:clone(); 0.9.0 needs to load a new instance.
+  local enemykillsnd2 = enemykillsnd.clone and enemykillsnd:clone()
+      or la.newSource("snd/supertank_plazma_fireball_22khz.mp3", "static")
+  -- Turn it into a table
+  enemykillsnd = { enemykillsnd, enemykillsnd2 }
   -- Cable extend/retract sound
   cablesnd = la.newSource("snd/Cable_Sound.wav", "static")
   -- Music
@@ -209,6 +215,8 @@ function game.activate()
     music:play()
   end
   thrustvol = 0
+  thrustsnd:setVolume(0)
+  thrustsnd:play()
 end
 
 function game.deactivate()
@@ -221,6 +229,8 @@ function game.pause(pause)
   if pause then
     orbdangersnd:stop()
     music:pause()
+    thrustsnd:setVolume(0)
+    thrustvol = 0
   else
     if cable.m ~= 0 then
       orbdangersnd:play()
@@ -228,6 +238,11 @@ function game.pause(pause)
     if main.music then
       music:play()
     end
+    thrusting = lk.isDown(keys.thrust)
+    if thrusting then
+      thrustsnd:setVolume(1)
+      thrustvol = 1
+    end
   end
 end
 
@@ -235,7 +250,7 @@ end
 local function new_or_load_game(load)
   -- restore saved game or start new game
 
-  if load and lfs.isFile("saved.txt") then
+  if load and main.isFile("saved.txt") then
     local f, s = lfs.read("saved.txt")
     local tmp, err
     game.state, tmp, err = json.decode(f, 1, json.null, nil)
@@ -372,11 +387,6 @@ local function update_ship(dt)
   local was_thrusting = thrusting
   thrusting = lk.isDown(keys.thrust)
   if thrusting then
-    if not was_thrusting then
-      thrustsnd:seek(love.math.random()*15, "seconds")
-    end
-    thrustsnd:setVolume(0.5)
-    thrustsnd:play()
     thrustsnd:setVolume(1)
     thrustvol = 1
     shipforcex = shipforcex + math.sin(fineangle*math.pi/16) * thrust
@@ -535,13 +545,13 @@ local function collided()
     end
 
     -- Draw ship/orb in multiplicative mode
-    if love._version_major == 0 and love._version_minor < 10 then
+    if love_version < 0010000 then
       lg.setBlendMode("multiplicative")
     else
-      lg.setBlendMode("multiply")
+      lg.setBlendMode("multiply", "premultiplied")
     end
     lg.draw(spritecoll, spritequads[i == 0 and ship.angle+1 or orb_sprite], 0, i)
-    lg.setBlendMode("alpha") -- return blend mode to normal
+    lg.setBlendMode("alpha", "alphamultiply") -- return blend mode to normal
   end
 
   lg.setScissor()
@@ -747,6 +757,7 @@ function game.update(dt)
          and cable.y >= tgt.y*32 and cable.y < tgt.y*32+32
       then
         orbdropsnd:play()
+        counters.score = counters.score + counters.orbtimer * 10
         cable.m = 0
         map[tgt.y*128+tgt.x+1] = tgt.tile
         tgt_index = tgt_index - 1
@@ -854,6 +865,7 @@ function game.update(dt)
           y1 = y1*y1
           if x1 + y1 < radius2 then
             -- Killed enemy
+            counters.score = counters.score + counters.agenttime * 10
             enemies[k].f = 1 -- explosion frame
             enemies[k].t = 0 -- timer to advance frame
             game.state.dyingenemies[#game.state.dyingenemies + 1] = enemies[k]
@@ -1087,11 +1099,11 @@ function game.draw()
       local freq = .01/(1.01-orbtime*0.0032)
       if freq > 10 then freq = 10 end
       local amp = (1-math.cos(freq*orbtime))*freq*0.5
-      lg.setColor(255,255,255, amp^0.7*255)
+      lg.setColor(255/DIV,255/DIV,255/DIV, amp^0.7*(255/DIV))
       orbdangersnd:setVolume(amp^2)
       lg.draw(spriteset, spritequads[orb_sprite+1], orbx, orby)
-      lg.setColor(255,255,255,255)
-      lg.setBlendMode("alpha")
+      lg.setColor(255/DIV,255/DIV,255/DIV,255/DIV)
+      lg.setBlendMode("alpha", "alphamultiply")
     end
   end
 
@@ -1106,13 +1118,13 @@ function game.draw()
 
   -- HACK: draw target in multiplicative mode (colorizes other sprites)
   if tgt then
-    if love._version_major == 0 and love._version_minor < 10 then
+    if love_version < 0010000 then
       lg.setBlendMode("multiplicative")
     else
-      lg.setBlendMode("multiply")
+      lg.setBlendMode("multiply", "premultiplied")
     end
     lg.draw(tileset, tilequads[tgt_tile_current], tgt.x*32-vpx, tgt.y*32-vpy)
-    lg.setBlendMode("alpha")
+    lg.setBlendMode("alpha", "alphamultiply")
   end
 
   -- draw shooting explosion
@@ -1124,12 +1136,12 @@ function game.draw()
     red = 255
     green = 255*t^1.5
     blue = 255*t^6
-    lg.setColor(red, green, blue, 255*(counters.shoot_timer/total_shoot_time))
+    lg.setColor(red/DIV, green/DIV, blue/DIV, 255/DIV*(counters.shoot_timer/total_shoot_time))
     local drawx = counters.shoot_x - vpx
     if drawx < -2048 then drawx = drawx + 4096 end
     if drawx > 2048 then drawx = drawx - 4096 end
     lg.draw(shotimg, drawx, counters.shoot_y-vpy, 0, shoot_radius/256, shoot_radius/256, 256, 256)
-    lg.setColor(255, 255, 255, 255)
+    lg.setColor(255/DIV, 255/DIV, 255/DIV, 255/DIV)
   end
 
   -- FIXME: draw current agent
@@ -1138,6 +1150,13 @@ function game.draw()
       if v == counters.agent then
         lg.draw(tileset, tilequads[k], 0, main.wh-32)
         lg.print(counters.agenttime, 35, main.wh-24)
+        local num = 0
+        for i = 1, #game.state.enemies do
+          if game.state.enemies[i].type == counters.agent then
+            num = num + 1
+          end
+        end
+        lg.print(num, 10, main.wh-48)
       end
     end
   end
@@ -1148,6 +1167,7 @@ function game.draw()
   if counters.orbtimer then
     lg.print(string.format("%03d", counters.orbtimer), 144, main.wh-24)
   end
+  lg.print(string.format("%8d", counters.score), 160, main.wh - 24)
 
   lg.setScissor()
 
@@ -1155,25 +1175,23 @@ function game.draw()
   --[[ debug
   lg.print(game.DEBUG, 0, 0)
   -- draw collision canvas
-  lg.setColor(100,100,100)
+  lg.setColor(100/DIV,100/DIV,100/DIV)
   lg.rectangle("fill", 100, 100, 32, 64)
-  lg.setColor(255,255,255)
+  lg.setColor(255/DIV,255/DIV,255/DIV)
   lg.draw(collision_canvas, 100, 100)
   ]]
 end
 
 function game.keypressed(k, r)
   if r then return end
-  if k == "pause" and (lk.isDown("lctrl") or lk.isDown("rctrl") or lk.isDown("ctrl")) then
-    main.activate(screens.menu)
-    return
+  if k == "escape" then
+    return main.dialog("EXIT TO MENU?", main.tomenu)
   end
   if k == "f10" then game.savegame() end
   if k == "f3" then
     new_or_load_game(true)
     screens.getready.fromstart = false
-    main.activate(screens.getready)
-    return
+    return main.activate(screens.getready)
   end
 end
 

+ 20 - 3
gameover.lua

@@ -2,7 +2,7 @@
 
 End of game screen for Thrust II Reloaded.
 
-Copyright © 2015-2017 Pedro Gimeno Fortea
+Copyright © 2015-2018 Pedro Gimeno Fortea
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
@@ -26,7 +26,10 @@ SOFTWARE.
 
 local gameover = {}
 
+local la,le,lfs,lf,lg,li,lj,lk,lm,lmo,lp,ls,lsys,lth,lt,lw = require'ns'()
+
 local snd
+local sndstate = "stopped"
 
 function gameover.load()
   snd = la.newSource("snd/EndGame.ogg", "stream")
@@ -35,23 +38,33 @@ end
 function gameover.activate()
   gameover.timer = 0
   snd:play()
+  sndstate = "playing"
 end
 
 function gameover.deactivate()
   snd:stop()
+  sndstate = "stopped"
 end
 
 
 function gameover.pause(paused)
   if paused then
-    if snd:isPlaying() then
+    if sndstate == "playing" then
       snd:pause()
+      sndstate = "paused"
     end
-  elseif snd:isPaused() then
+  elseif sndstate == "paused" then
     snd:play()
+    sndstate = "playing"
   end
 end
 
+function gameover.keypressed(k, r)
+  if r then return end
+  if k == "escape" then
+    return main.dialog("EXIT TO MENU?", main.tomenu)
+  end
+end
 
 function gameover.update(dt)
   gameover.timer = gameover.timer + dt
@@ -59,6 +72,10 @@ function gameover.update(dt)
     main.activate(screens.splash)
     return
   end
+  -- sound is not looped - update sndstate
+  if sndstate == "playing" and not snd:isPlaying() then
+    sndstate = "stopped"
+  end
 end
 
 function gameover.draw()

+ 11 - 5
gamewon.lua

@@ -2,7 +2,7 @@
 
 Game Won screen for Thrust II Reloaded.
 
-Copyright © 2015-2017 Pedro Gimeno Fortea
+Copyright © 2015-2018 Pedro Gimeno Fortea
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
@@ -26,17 +26,19 @@ SOFTWARE.
 
 local gamewon = {}
 
+local la,le,lfs,lf,lg,li,lj,lk,lm,lmo,lp,ls,lsys,lth,lt,lw = require'ns'()
+
 local timer
 local rays
 local gdt
 local rayspeed = 1000
 
 local function newray()
-  local amplitude = 1,2
-  local rnd = 2*amplitude*lma.random() - amplitude
+  local amplitude = 1
+  local rnd = 2*amplitude*lm.random() - amplitude
   local angle = math.abs(rnd)^3
   if rnd < 0 then angle = -angle end
-  local spdrnd = lma.random()*0.7+1
+  local spdrnd = lm.random()*0.7+1
   local vx = math.sin(angle)*spdrnd
   local vy = -math.cos(angle)*spdrnd
   return { x = screens.game.vw/2 + screens.game.vx, y = 255,
@@ -100,7 +102,11 @@ function gamewon.draw()
   end
 end
 
-function gamewon.keypressed(k, v)
+function gamewon.keypressed(k, r)
+  if r then return end
+  if k == "escape" then
+    return main.dialog("EXIT TO MENU?", main.tomenu)
+  end
   -- DEBUG
   if k == "f3" then
     gamewon.activate()

+ 22 - 5
getready.lua

@@ -2,7 +2,7 @@
 
 Get Ready screen for Thrust II Reloaded.
 
-Copyright © 2015-2017 Pedro Gimeno Fortea
+Copyright © 2015-2018 Pedro Gimeno Fortea
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
@@ -26,11 +26,15 @@ SOFTWARE.
 
 local getready = {}
 
+local la,le,lfs,lf,lg,li,lj,lk,lm,lmo,lp,ls,lsys,lth,lt,lw = require'ns'()
+
 local timer
 local wait_time = 1.2
 local scroll_in_time = 1.2
 local quad, prev_x, canvas
 
+local DIV = love_version >= 11000000 and 255 or 1
+
 function getready.load()
   quad = lg.newQuad(0, 0, 1, 1, main.ww, main.wh)
   canvas = lg.newCanvas(main.ww, main.wh) -- for scrolling
@@ -45,6 +49,19 @@ function getready.activate()
   prev_x = main.ww + 8
 end
 
+function getready.keypressed(k, r)
+  if r then return end
+  if k == "escape" then
+    return main.dialog("EXIT TO MENU?", main.tomenu)
+  end
+  if k == "f3" then
+    main.restore = true
+    screens.game.newgame()
+    getready.fromstart = true
+    getready.activate()
+  end
+end
+
 function getready.update(dt)
   timer = timer + dt
   if timer >= scroll_in_time then
@@ -63,9 +80,9 @@ function getready.draw()
   end
 
   if getready.fromstart and timer < 0 then
-    lg.setColor(0,0,0,255)
+    lg.setColor(0/DIV,0/DIV,0/DIV,255/DIV)
     lg.rectangle("fill", game.vx, game.vy, game.vw, game.vh)
-    lg.setColor(255,255,255,255)
+    lg.setColor(255/DIV,255/DIV,255/DIV,255/DIV)
     main.centertext("GET READY", game.vx+game.vw/2, game.vy+game.vh/2)
   end
 
@@ -92,9 +109,9 @@ function getready.draw()
 
       lg.setScissor(game.vx, game.vy, game.vw, game.vh)
     end
-    lg.setColor(120,150,150,255)
+    lg.setColor(120/DIV,150/DIV,150/DIV,255/DIV)
     lg.rectangle("fill", x-8, 0, 8, main.wh)
-    lg.setColor(255,255,255,255)
+    lg.setColor(255/DIV,255/DIV,255/DIV,255/DIV)
 
     -- Draw back to the main canvas
     lg.setCanvas(main.canvas)

+ 4 - 2
layout.lua

@@ -2,7 +2,7 @@
 
 Map and ancillary data for Thrust II Reloaded.
 
-Copyright © 2015-2017 Pedro Gimeno Fortea
+Copyright © 2015-2018 Pedro Gimeno Fortea
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
@@ -26,10 +26,12 @@ SOFTWARE.
 
 local map = {}
 
+local la,le,lfs,lf,lg,li,lj,lk,lm,lmo,lp,ls,lsys,lth,lt,lw = require'ns'()
+
 do
   local found = false
   local i = 0
-  for line in love.filesystem.lines('tilesets/ThrustIIgen4.tmx') do
+  for line in lfs.lines('tilesets/ThrustIIgen4.tmx') do
     if found then
       if line == '</data>' then
         break

+ 0 - 24
lovespaces.lua

@@ -1,24 +0,0 @@
---[========================================================================[--
-
-LÖVE namespace abbreviations
-
-Written by Pedro Gimeno Fortea, donated to the public domain.
-
---]========================================================================]--
-
-la = love.audio
-le = love.event
-lfs = love.filesystem
-lfo = love.font
-lg = love.graphics
-li = love.image
-lj = love.joystick
-lk = love.keyboard
-lma = love.math
-lmo = love.mouse
-lp = love.physics
-lso = love.sound
-lsy = love.system
-lth = love.thread
-lti = love.timer
-lw = love.window

+ 0 - 0
main.lua


Some files were not shown because too many files changed in this diff