Skip to content

Instantly share code, notes, and snippets.

@MrEnder0
Last active June 16, 2023 20:32
Show Gist options
  • Save MrEnder0/401f6ee1039263a8b72ee2cd0a4b58cb to your computer and use it in GitHub Desktop.
Save MrEnder0/401f6ee1039263a8b72ee2cd0a4b58cb to your computer and use it in GitHub Desktop.
A simple game made in retro gadgets
---@diagnostic disable: undefined-global
-- Retro Gadgets
local spriteFont = gdt.ROM.System.SpriteSheets["StandardFont"]
local sine : AudioSample = gdt.ROM.User.AudioSamples["sine.wav"]
local death : AudioSample = gdt.ROM.User.AudioSamples["death.wav"]
local win : AudioSample = gdt.ROM.User.AudioSamples["win.wav"]
local ticksPerSpawn = 45
local ticks = 0
local enemies = {}
local difficulty = 0.3
local difficultyCurve = 0.0002
local gameState = true
local score = 0
function update()
if gameState == true then
gdt.VideoChip0.Clear(gdt.VideoChip0, color.black)
ticks += 1
if ticks > ticksPerSpawn then
ticks = 0
local x = math.random(3.5, 13.5)
table.insert(enemies, {x=x, y=-1})
end
for i, enemy in ipairs(enemies) do
difficulty += difficultyCurve
enemy.y += difficulty
gdt.VideoChip0:DrawCircle(vec2(enemy.x, enemy.y), 2, color.red)
end
local rot = (((gdt.Knob0.Value+100)/2)/10)+3.5
gdt.VideoChip0:DrawCircle(vec2(rot,45),2,color.green)
for i, enemy in ipairs(enemies) do
if enemy.x > rot-3 and enemy.x < rot+3 and enemy.y > 41.5 and enemy.y < 48.5 then
gdt.AudioChip0:Play(death, 1)
gameState = false
end
if enemy.y > 52 then
table.remove(enemies, i)
gdt.AudioChip0:Play(sine, 1)
score += 1
end
if score > 999 then
gdt.AudioChip0:Play(win, 1)
gameState = false
end
end
elseif gameState == false then
gdt.VideoChip0.Clear(gdt.VideoChip0, color.black)
if score > 999 then
gdt.VideoChip0:DrawText(vec2(0, 20),spriteFont,"WIN",color.white,color.black)
elseif score > 99 then
gdt.VideoChip0:DrawText(vec2(0, 20),spriteFont,tostring(score),color.white,color.black)
elseif score > 9 then
gdt.VideoChip0:DrawText(vec2(3, 20),spriteFont,tostring(score),color.white,color.black)
else
gdt.VideoChip0:DrawText(vec2(5, 20),spriteFont,tostring(score),color.white,color.black)
end
if gdt.LedButton0.ButtonState == true then
gameState = true
enemies = {}
ticks = 0
difficulty = 0.3
score = 0
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment