Browse Source

adding in cannon, other stuff

pixelbath 2 years ago
parent
commit
2d5d63a308
4 changed files with 123 additions and 36 deletions
  1. BIN
      einhander/einhander.aseprite
  2. 118 36
      einhander/einhander.lua
  3. BIN
      einhander/einhander.png
  4. 5 0
      einhander/start.bat

BIN
einhander/einhander.aseprite


+ 118 - 36
einhander/einhander.lua

@@ -12,6 +12,8 @@ player={
 	gun_down=0,
     gun_anim=0,
     gun_held=0,
+    is_firing=0,
+    big_gun_cooldown=0,
 }
 gunsprites={
     292, -- vulcan
@@ -50,6 +52,8 @@ multiplier_sub = 0
 multiplier_tick = 0
 score = 25000
 
+
+
 t=0
 math.randomseed(seed)
 
@@ -88,10 +92,14 @@ end
 function drawPlayer()
     if (player.show) then
         -- arm
-        if player.gun_down then
-            spr(260, player.x+12, player.y+11, 0, 1, 0, 0, 2, 1)
+        if player.gun_anim > 0 then
+            --spr(260, player.x+12, player.y+11, 0, 1, 0, 3, 2, 1)
         else
-            spr(260, player.x+12, player.y-2, 0, 1, 2, 0, 2, 1)
+            if player.gun_down then
+                spr(260, player.x+12, player.y+11, 0, 1, 0, 0, 2, 1)
+            else
+                spr(260, player.x+12, player.y-2, 0, 1, 2, 0, 2, 1)
+            end
         end
 
         -- ship
@@ -102,6 +110,14 @@ function drawPlayer()
         spr(262, val.x, val.y, 0)
     end
 
+    -- draw big bullets
+    for key,val in ipairs(p_big_bullets) do
+        local spritenum = 0
+        if val.type == 2 then spritenum = 282 end
+        if val.type == 3 then spritenum = 267 end
+        spr(spritenum, val.x, val.y, 0)
+    end
+
     -- custom routines depending on gun held
     if player.gun_held > 0 then
         local gunsprite = gunsprites[player.gun_held]
@@ -110,7 +126,11 @@ function drawPlayer()
             gunsprite = gunsprite + 16
             gunpos = gunpos + 14
         end
-        spr(gunsprite, player.x+12, gunpos, 0, 1, 0, 0, 2, 1)
+        if player.gun_anim > 0 then
+            spr(gunsprite, player.x+3, gunpos, 0, 1, 0, 3, 2, 1)
+        else
+            spr(gunsprite, player.x+12, gunpos, 0, 1, 0, 0, 2, 1)
+        end
         
         -- vulcan
         if player.gun_held == 1 then
@@ -124,41 +144,64 @@ function drawPlayer()
             else
                 player.fire = player.fire - 1
             end
+
+            -- not tracking individual bullets with vulcan
+
             -- begin dakka
-            if muzzleIdx > 0 then
-                if player.gun_down then
-                    spr(vulcanMuzzleSprites[muzzleIdx], player.x + 27, player.y + 14, 0, 1, flipfire, 0, 2, 1)
-                else
-                    spr(vulcanMuzzleSprites[muzzleIdx], player.x + 28, player.y - 2, 0, 1, flipfire, 0, 2, 1)
-                end
-            end
-            if t % 10 == 0 then
-                local randFactor = math.random(10,100)
-                local spawnOffsetY = 1
-
-                local lineStart = math.random(player.x+20, 260)
-                if player.gun_down then
-                    spawnOffsetY = 18
-                    -- vulcan tilts downward so we get to do trig! yay!
-                    lineStart = lineStart - player.x
-                    local angle = 8
-                    local radius2 = lineStart+38
-                    local c = math.cos(angle * math.pi / 180)
-                    local s = math.sin(angle * math.pi / 180)
-                    line(c * lineStart + player.x + 18, s * lineStart + player.y + 17, c * radius2 + player.x + 18, s * radius2 + player.y + 17, 14)
-                else
-                    line(lineStart, player.y+1, lineStart+40, player.y+1, 14)
+            if player.is_firing > 0 then
+                if muzzleIdx > 0 then
+                    if player.gun_down then
+                        spr(vulcanMuzzleSprites[muzzleIdx], player.x + 27, player.y + 14, 0, 1, flipfire, 0, 2, 1)
+                    else
+                        spr(vulcanMuzzleSprites[muzzleIdx], player.x + 28, player.y - 2, 0, 1, flipfire, 0, 2, 1)
+                    end
                 end
+                if t % 10 == 0 then
+                    local randFactor = math.random(10,100)
+                    local spawnOffsetY = 1
+
+                    local lineStart = math.random(player.x+20, 260)
+                    if player.gun_down then
+                        spawnOffsetY = 18
+                        -- vulcan tilts downward so we get to do trig! yay!
+                        lineStart = lineStart - player.x
+                        local angle = 8
+                        local radius2 = lineStart+38
+                        local c = math.cos(angle * math.pi / 180)
+                        local s = math.sin(angle * math.pi / 180)
+                        line(c * lineStart + player.x + 18, s * lineStart + player.y + 17, c * radius2 + player.x + 18, s * radius2 + player.y + 17, 14)
+                    else
+                        line(lineStart, player.y+1, lineStart+40, player.y+1, 14)
+                    end
 
-                -- shells
-                spawnPixelParticle(player.x+14, player.y+spawnOffsetY, -0.2, -0.6 + (randFactor / 100), 0, 50, 15)
+                    -- shells
+                    spawnPixelParticle(player.x+14, player.y+spawnOffsetY, -0.2, -0.6 + (randFactor / 100), 0, 50, 15)
+                end
             end
+
+
             -- update shells with light gravity
             for i=1,#shellParticles do
                 local p = shellParticles[i]
                 p.vy = p.vy + 0.1
             end
         end
+
+        -- cannon
+        if player.gun_held == 2 then
+            if player.fire == 0 then
+                player.fire = 30
+            else
+                player.fire = player.fire - 1
+            end
+
+            -- todo: move to update()
+            for i=1, #p_big_bullets do
+                if p_big_bullets[i].x < 250 then
+                    p_big_bullets[i].x = p_big_bullets[i].x + 10
+                end
+            end
+        end
     end
 
     for i=1,#shellParticles do
@@ -171,6 +214,8 @@ function drawPlayer()
             end
         end
     end
+
+    if player.gun_anim > 0 then player.gun_anim = player.gun_anim - 1 end
 end
 
 function drawUI()
@@ -213,11 +258,8 @@ function drawUI()
     end
 end
 
--- 1xxxxxxxxxxx
--- 0xxxxxxxxxxx
--- 0xxxxxxxxxxx
--- 1xxxxxxxxxxx
 function drawWater(waterHeight)
+    -- TODO: ripples, distortion
     for i=0,waterHeight-1 do
         local row = (135 - i - waterHeight) * 120
         local rowDest = (135 + i - waterHeight + 1) * 120
@@ -225,6 +267,13 @@ function drawWater(waterHeight)
     end
 end
 
+-- shiftValue   1, 0, -1, -2   From brightest to darkest, respectively. 0 is no change
+function filterColor(inputColor, shiftValue)
+    if shiftValue == 0 then return end
+
+
+end
+
 function drawDebug()
     -- print("p.gdown: " .. tostring(player.gun_down), 5, 5, 12, true, 1, true)
     -- print("spr: " .. tostring(vulcanMuzzleSprites[player.fire + 1]), 5, 13, 12, true, 1, true)
@@ -252,25 +301,58 @@ function update()
         end
     end
     if btnp(4) then
-        player.gun_held = 1
-        player.gun_down = not player.gun_down
+        player.gun_held = player.gun_held + 1
+        if player.gun_held > 6 then player.gun_held = 0 end
     end
     if btn(5) then
         --if player.gun_held == 0 then
             if player.fire == 0 then
                 player.fire = 5
-                table.insert(p_bullets, {x=player.x+10, y=player.y+2})
+                --table.insert(p_bullets, {x=player.x+10, y=player.y+2})
             else
                 player.fire = player.fire - 1
             end
         --end
+        if player.gun_held == 1 then
+            player.is_firing = 1
+        end
+        if player.gun_held == 2 then
+            -- controlled by cooldown (or semi-auto)
+            if player.is_firing == 1 then player.is_firing = 0 end
+
+            if player.big_gun_cooldown == 0 then
+                player.big_gun_cooldown = 30
+                player.is_firing = 1
+            else
+                player.big_gun_cooldown = player.big_gun_cooldown - 1
+                player.is_firing = 0
+            end
+
+            if player.is_firing == 1 then
+                table.insert(p_big_bullets, {x=player.x+12, y=player.y+6, type=player.gun_held})
+            end
+        end
+    else
+        player.big_gun_cooldown = 0
     end
+    if btnp(5) then
+        -- debug
+        player.gun_down = not player.gun_down
+        player.gun_anim = 1
+    end
+
     for key,val in ipairs(p_bullets) do
         p_bullets[key].x = p_bullets[key].x + 8
         if val.x > 240 then
             table.remove(p_bullets, key)
         end
     end
+    for key,val in ipairs(p_big_bullets) do
+        p_big_bullets[key].x = p_big_bullets[key].x + 8
+        if val.x > 240 then
+            table.remove(p_big_bullets, key)
+        end
+    end
     for i=1,#shellParticles do
         local p = shellParticles[i]
         p.x = p.x + p.vx

BIN
einhander/einhander.png


+ 5 - 0
einhander/start.bat

@@ -1,4 +1,9 @@
+@echo off
 "%PROGRAMFILES%\Aseprite\Aseprite.exe" -b einhander.aseprite --save-as einhander.png
 copy /Y .\einhander.lua %USERPROFILE%\AppData\Roaming\com.nesbox.tic\TIC-80\einhander.lua
 copy /Y .\einhander.png %USERPROFILE%\AppData\Roaming\com.nesbox.tic\TIC-80\einhander.png
+
+REM copy the .tic file back here because the SFX/Music editing is done there
+copy /Y %USERPROFILE%\AppData\Roaming\com.nesbox.tic\TIC-80\einhander.tic .\einhander.tic
+
 %USERPROFILE%\Desktop\tic80.exe --skip --cmd "load einhander.tic & import code einhander.lua & import sprites einhander.png & save & run"