Browse Source

adding one hand

pixelbath 2 years ago
parent
commit
ae5bce1aff
5 changed files with 312 additions and 0 deletions
  1. 17 0
      einhander/editor.py
  2. BIN
      einhander/einhander.aseprite
  3. 291 0
      einhander/einhander.lua
  4. BIN
      einhander/einhander.png
  5. 4 0
      einhander/start.bat

+ 17 - 0
einhander/editor.py

@@ -0,0 +1,17 @@
+import pyglet
+from pyglet.gl import *
+from pyglet.window import key
+
+class EditorWindow(pyglet.window.Window):
+    def __init__(self):
+        super(EditorWindow, self).__init__()
+
+        self.label = pyglet.text.Label('Hi!')
+    
+    def on_draw(self):
+        self.clear()
+        self.label.draw()
+
+if __name__ == '__main__':
+    window = EditorWindow()
+    pyglet.app.run()

BIN
einhander/einhander.aseprite


+ 291 - 0
einhander/einhander.lua

@@ -0,0 +1,291 @@
+-- title:  einhander
+-- author: pixelbath
+-- desc:   one-handed
+-- script: lua
+
+seed=12345
+player={
+	x=20, y=50,
+    inv=0,
+    show=1,
+	fire=0,
+	gun_down=0,
+    gun_anim=0,
+    gun_held=0,
+}
+gunsprites={
+    292, -- vulcan
+    294, -- cannon
+    296, -- spreader
+    298, -- wasp
+    300, -- grenade
+    302, -- hedgehog
+}
+gunnames={
+    {324, "V", "ULCAN"},
+    {325, "C", "ANNON"},
+    {326, "S", "PREADER"},
+    {327, "W", "ASP"},
+    {328, "G", "RENADE"},
+    {329, "H", "EDGEHOG"},
+}
+vulcanMuzzleSprites={
+    264, 266, 280
+}
+shellParticles={}
+-- particles are just white pixels by default
+for i=1,15 do
+    table.insert(shellParticles, {x=0,y=0,vx=0,vy=0,age=0,dieAt=0,color=12,idx=0,isPixel=true})
+end
+particlePointer=1 -- points at the next particle to be spawned
+
+weaponBgSize=16--12
+weaponBgTimer=0
+weaponAmmo=3000
+
+p_bullets = {}
+p_big_bullets = {}
+multiplier = 12
+multiplier_sub = 0
+multiplier_tick = 0
+score = 25000
+
+t=0
+math.randomseed(seed)
+
+function drawParallelogram(x, y, w, h, skewpx, color)
+    tri(x+skewpx, y, x+w, y+h, x, y+h, color)
+    tri(x+skewpx, y, x+w, y+h, x+w+skewpx, y, color)
+end
+
+function spawnPixelParticle(x, y, vx, vy, age, dieAt, color)
+    local p = shellParticles[particlePointer]
+    p.x = x
+    p.y = y
+    p.vx = vx
+    p.vy = vy
+    p.age = age
+    p.dieAt = dieAt
+    p.color = color
+    p.isPixel = true
+    particlePointer = particlePointer + 1
+    if particlePointer > 15 then particlePointer = 1 end
+end
+function spawnSpriteParticle(x, y, vx, vy, age, dieAt, index)
+    local p = shellParticles[particlePointer]
+    p.x = x
+    p.y = y
+    p.vx = vx
+    p.vy = vy
+    p.age = age
+    p.dieAt = dieAt
+    p.idx = index
+    p.isPixel = false
+    particlePointer = particlePointer + 1
+    if particlePointer > 15 then particlePointer = 1 end
+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)
+        else
+            spr(260, player.x+12, player.y-2, 0, 1, 2, 0, 2, 1)
+        end
+
+        -- ship
+        spr(256, player.x, player.y, 0, 1, 0, 0, 4, 2)
+    end
+    -- draw regular bullets
+    for key,val in ipairs(p_bullets) do
+        spr(262, val.x, val.y, 0)
+    end
+
+    -- custom routines depending on gun held
+    if player.gun_held > 0 then
+        local gunsprite = gunsprites[player.gun_held]
+        local gunpos = player.y - 2
+        if player.gun_down then
+            gunsprite = gunsprite + 16
+            gunpos = gunpos + 14
+        end
+        spr(gunsprite, player.x+12, gunpos, 0, 1, 0, 0, 2, 1)
+        
+        -- vulcan
+        if player.gun_held == 1 then
+            local flipfire = 0
+            local muzzleIdx = math.random(0,3)
+            if math.random(1, 2) == 2 then
+                flipfire = 2
+            end
+            if player.fire == 0 then
+                player.fire = 2
+            else
+                player.fire = player.fire - 1
+            end
+            -- 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)
+                end
+
+                -- shells
+                spawnPixelParticle(player.x+14, player.y+spawnOffsetY, -0.2, -0.6 + (randFactor / 100), 0, 50, 15)
+            end
+            -- update shells with light gravity
+            for i=1,#shellParticles do
+                local p = shellParticles[i]
+                p.vy = p.vy + 0.1
+            end
+        end
+    end
+
+    for i=1,#shellParticles do
+        local p = shellParticles[i]
+        if p.age < p.dieAt then
+            if p.isPixel then
+                pix(p.x, p.y, p.color)
+            else
+                spr(p.idx, p.x, p.y)
+            end
+        end
+    end
+end
+
+function drawUI()
+    -- weapon bg
+    -- spr(322, 4, 114, 0, 1, 0, 0, 1, 2)
+    -- rect(12, 114, 8, 16, 6)
+    -- spr(323, 20, 114, 0, 1, 0, 0, 1, 2)
+    drawParallelogram(6, 115, weaponBgSize, 12, 6, 6)
+
+    -- selected weapon
+    if player.gun_held > 0 then
+        local lettersprite = gunnames[player.gun_held][1]
+        local guntext = gunnames[player.gun_held][3]
+        spr(lettersprite, 14, 118, 0, 1)
+        print(guntext, 24, 122, 12, true, 1, true)
+        print(weaponAmmo, 12, 129, 12, true, 1, true)
+    end
+
+    -- multiplier
+    -- TODO: need to do multipliers over 10, so the X needs to move left when that happens
+    spr(340, 164, 114, 0)
+    --spr(340 + multiplier, 172, 113, 0)
+    spr(330, 180, 114, 0, 1, 0, 0, 4, 1)
+    spr(331, 212, 114, 0, 1, 0, 0, 3, 1)
+    spr(334, 236, 114, 0, 1)
+    if multiplier_sub > 0 then
+        for i = 1, multiplier_sub do
+            spr(335, 177 + (i * 6), 114, 0)
+        end
+    end
+    
+    -- score
+    local scorestring = tostring(score)
+    for i = 1, #scorestring do
+        local char = scorestring:sub(i, i)
+        local numsprite = 340 + tonumber(char)
+        -- this is a hack because I ordered the numbers weirdly
+        if char == "0" then numsprite = 350 end
+        spr(numsprite, (230 - (8 * #scorestring)) + (i * 8), 123, 0)
+    end
+end
+
+-- 1xxxxxxxxxxx
+-- 0xxxxxxxxxxx
+-- 0xxxxxxxxxxx
+-- 1xxxxxxxxxxx
+function drawWater(waterHeight)
+    for i=0,waterHeight-1 do
+        local row = (135 - i - waterHeight) * 120
+        local rowDest = (135 + i - waterHeight + 1) * 120
+        memcpy(rowDest, row, 120)
+    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)
+end
+
+function update()
+    if btn(0) then
+        if player.y > 0 then
+            player.y=player.y-2
+        end
+	end
+    if btn(1) then
+        if player.y < 120 then
+            player.y=player.y+2
+        end
+	end
+    if btn(2) then
+        if player.x > 1 then
+            player.x=player.x-2
+        end
+	end
+	if btn(3) then
+        if player.x < 216 then
+            player.x=player.x+2
+        end
+    end
+    if btnp(4) then
+        player.gun_held = 1
+        player.gun_down = not player.gun_down
+    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})
+            else
+                player.fire = player.fire - 1
+            end
+        --end
+    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 i=1,#shellParticles do
+        local p = shellParticles[i]
+        p.x = p.x + p.vx
+        p.y = p.y + p.vy
+        p.age = p.age + 1
+    end
+
+    t=t+1
+end
+
+function TIC()
+    update()
+    cls(0)
+    drawPlayer()
+    -- drawWater(10)
+    drawUI()
+    drawDebug()
+end

BIN
einhander/einhander.png


+ 4 - 0
einhander/start.bat

@@ -0,0 +1,4 @@
+"%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
+%USERPROFILE%\Desktop\tic80.exe --skip --cmd "load einhander.tic & import code einhander.lua & import sprites einhander.png & save & run"