Skip to content

Instantly share code, notes, and snippets.

@Frenzycore
Created January 13, 2026 13:16
Show Gist options
  • Select an option

  • Save Frenzycore/c81eb9a4f63db94c407821045dfb7696 to your computer and use it in GitHub Desktop.

Select an option

Save Frenzycore/c81eb9a4f63db94c407821045dfb7696 to your computer and use it in GitHub Desktop.
My First MicroStudio Game Project
init = function()
player = object
x = 0
y = 0
speed = 2
width = 50
height = 50
sprite = "ghost"
end
diamond = object
x = 40
y = 40
width = 30
height = 30
sprite = "diamond"
end
score = 0
timer = 100
gameover = false
end
update = function()
if timer <= 0 then
gameover = true
else
timer -= 1/60
movements()
avoidVoid()
if collision() then
audio.playSound("collect", .2)
score = score + 1
changeDiamondPosition()
end
end
end
draw = function()
screen.clear()
screen.fillRect(0, 0, screen.width, screen.height, "rgb(10, 10, 18)")
screen.drawSprite(player.sprite, player.x, player.y, player.width, player.height)
screen.drawSprite(diamond.sprite, diamond.x, diamond.y, diamond.width, diamond.height)
screen.drawText("Time: " + ceil(timer), 135, 85, 20, "rgb(130, 139, 190)")
screen.drawText("Score: " + ceil(score), -135, 85, 20, "rgb(130, 139, 190)")
if gameover then
screen.fillRect(0, 0, screen.width, screen.height, "rgb(150, 0, 0, 0.5)")
screen.drawText("GAME OVER", 0, 0, 50, "rgb(255, 255, 255)")
end
end
movements = function()
if keyboard.A or keyboard.LEFT then
player.x = player.x - 1
end
if keyboard.D or keyboard.RIGHT then
player.x = player.x + 1
end
if keyboard.W or keyboard.UP then
player.y = player.y + 1
end
if keyboard.S or keyboard.DOWN then
player.y = player.y - 1
end
end
collision = function()
x_distance = abs(player.x - diamond.x)
y_distance = abs(player.y - diamond.y)
if x_distance <= 18 and y_distance <= 18 then
return true
else
return false
end
end
changeDiamondPosition = function()
diamond.x = random.next() * 170 * positiveOrNegative()
diamond.y = random.next() * 90 * positiveOrNegative()
end
positiveOrNegative = function()
if random.next() < .5 then
return 1
else
return -1
end
end
clamp = function(value, lower_limit, upper_limit)
local val = max(value, lower_limit)
val = min(val, upper_limit)
return val
end
avoidVoid = function()
player.x = clamp(player.x, -163, 163)
player.y = clamp(player.y, -80, 83)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment