Lua - Reddit – Telegram
Lua - Reddit
31 subscribers
281 photos
31 videos
4.27K links
News and discussion for the Lua programming language.

Subreddit: https://www.reddit.com/r/lua

Powered by : @r_channels & @reddit2telegram
Download Telegram
Code issues (LUA 5.1)

Using an old macro program in WoW. Having issues with this code, and i'm not a coder. It seems to be complaining about the random() and randomseed() commands. Plus it doesn;t like building indicies. I didn't write this, I pared down someone else's free macro code just to get something working to learn from.

I am limited to LUA 5.1 unfortunately. I'm guessing this code is much newer.

Any help would be appreciated. Thanks!

-- Initialize random seed for Lua 5.1
math.randomseed(os.time())

mountListGround = {
"Black War Bear",
"Purple Hawkstrider",
"Black War Wolf",
"Summon Charger",
"Traveler's Tundra Mammoth"
}

mountListFlying = {
"Green Proto-Drake",
"Blue Wind Rider",
"Albino Drake"
}

-- First run after reloading - getting indices
if not builtIndices then

mountListGroundIndices = {}
mountListFlyingIndices = {}
mountListWintergraspIndices = {}

for i = 1, GetNumCompanions("MOUNT") do
local id, name = GetCompanionInfo("MOUNT", i)
if tContains(mountListGround, name) then
tinsert(mountListGroundIndices, i)
if name ~= "Purple Hawkstrider" then
tinsert(mountListWintergraspIndices, i)
end
end
if tContains(mountListFlying, name) then
tinsert(mountListFlyingIndices, i)
end
if name == "Traveler's Tundra Mammoth" then
tundraIndex = i
end
end
builtIndices = true
end

-- Random CallCompanion alias
function callMount(indexTable)
CallCompanion("MOUNT", indexTablemath.random(#indexTable))
end

-- Dismounter
if not IsFlying() and IsMounted() then
Dismount()
end

-- Main function
if not InCombatLockdown() then
cancelShapeshifts()
if IsAltKeyDown() then
CallCompanion("MOUNT", tundraIndex)
else
if not IsFlyableArea() then
callMount(mountListGroundIndices)
else
if not IsFlying() then
if IsShiftKeyDown() then
callMount(mountListGroundIndices)
else
if GetZoneText() == "Wintergrasp" and not GetWintergraspWaitTime() then
callMount(mountListWintergraspIndices)
else
callMount(mountListFlyingIndices)
end
end
end
end
end
end

https://redd.it/1g7l88u
@r_lua
What's the best way to learn Lua?

I'm new to Lua and I'd like to learn it. I have almost no experience with coding except for a bit that I learned from Roblox coding tutorials on Lua. I'd like to learn Lua 5.3, since I heard that Lua 5.4 has some drawbacks that are not good. I'd like to know the best way to learn Lua. I want to learn Lua, to where I can use it professionally and have the deepest understanding of it. I'm thinking after I'm done; I want to build games. I would appreciate any help with this. I'm thinking of learning it from YouTube tutorials like this one: (55) Crash Courses - YouTube, but I'd like to know what would work the best.

https://redd.it/1g7oc7f
@r_lua
my first coding language to learn

Is lua a good starting language to learn and will it help in learning other languages or should i start learning another one

does roblox engine need an expert in lua or just a good knowledge



https://redd.it/1g8uuv6
@r_lua
My new project: LuAssembly

I want to make machine code writing accessible and enjoyable for everyone. My idea is to create a "language" based on Lua's syntax, which will then be converted into an assembly (.asm) file using C++. Afterward, the NASM assembler will turn it into a binary (.bin) file. Does this sound like a good idea?

https://redd.it/1g95yt7
@r_lua
YMT FILES

Hello,

I'm seeking help with modifying .ymt files in Red Dead Redemption 2, specifically for RedM compatibility. Below is a portion of the binary code from a functional .ymt file that works in both story mode and RedM:

PSIN..RP.................".".............c+¡....................ëÁ᛬#.Ú................?€......................?€......ÿÿ................................

I successfully modified the player_three.ymt file, and while it works perfectly in story mode, the character becomes invisible in RedM. I suspect the file is likely becoming corrupted because it's not encrypted as RedM requires. Even OpenIV cannot open the corrupted version, flagging it as a corrupted file.

Any help or insight on how to properly encrypt .ymt files or make them compatible with RedM would be greatly appreciated.

https://redd.it/1g9h7ed
@r_lua
Updates about my project: LuAssembly

I started making the lexer and the parser (On python, because I felt more comfortable to do it with), and I thought and realized that the language wasn't as "Lua-Like" as I initially intended. So I decided to rebrand i'ts name. Unfortunately, because of the subreddit rules, I won't be able to keep updating everyone here. The new name is... .FAST (Fast Assembly Source Translator). I'll post the Github link soon to keep everyone updated.

https://redd.it/1g9xv2t
@r_lua
Is Lua stil used for ML

As a data scientist I knew at the back of my head that one of the most popular Python libraries in ML, PyTorch, started as a Lua package named Torch. It seems that since then the field left Lua completely and turned to Python, a bit of Julia and R, maybe Matlab and C/C++ for embedded stuff.

I came to Lua via Neovim a year ago. Using it, and enjoying it, made me wonder - are there any ML/DS people using Lua these days?

https://redd.it/1ga62t3
@r_lua
Where can I learn how to make a text based game?

I noscript in Roblox Studio, and I want to try to make a text based RPG in a Lua IDE, problem is that the only Lua stuff I know is purely from Roblox Studio, and thus I have no idea what to do.

https://redd.it/1gb4czi
@r_lua
JSON library for Reddit?

I'm experimenting with API on Reddit and used dkjson, but I got parsing errors. I don't get any errors with Go's native equivalent, so I assume that the very long/complex Reddit response might trigger a bug in dkjson. What alternative do you recommend? (luarocks has tons of them)

https://redd.it/1gbncz7
@r_lua
How to deobfuscate an MLO mod from FiveM?

I recently purchased an MLO mod and tried to make it work in GTA V singleplayer (it is a house mod) And after doing research, found out that it is being obfuscated and encrypted.

these are the contents of the folder:

fxmanifest.lua

.fxap

-tream

From my research, i would want to decrypt the manifest.lua? But when i open it with notepad or visual code, it just says this:

fx\_version 'cerulean'

game "gta5"

author 'brofx'

denoscription 'brofx\_mansion\_20'

version '1.1.2'

this\_is\_a\_map "yes"

dependency '/assetpacks'

Visual code will open the .fxap into this:

# FXAP �����6����� ڝA� ��6ӵ Q^Iq� �B)�� �<���8U�~�T�œ}X���U%1��A ,�    n_�S���|w�k�U52 �~��.���v [0�C�3��C� �� �mO _� ��׌'�?��ӽ���Y٫ �4

# M�� � l\�T ��Qs�"�����{󓧵ߤn<



any way i can decrypt this to work in singleplayer?

i really want to play this in singleplayer and it cost a lot so i would be bummed out that i would not be able to get this to work. thank you all.



UPDATE: I found out that in order to decrypt, i must decrypt the .YDR files, im not certain where i would start or how different it would be to decrypt these .YDR files.

https://redd.it/1gbohar
@r_lua
Need advice for Windows + Busted + GitHub workflows

I'm trying to setup a test matrix for Windows + Linux + MacOS for lua unitests, using busted

My best attempt so far is viewable here, I got lua + luarocks installed, I'm installing the test dependencies from my .rockspec file. But it fails to build. The only error I see in the log is Error: test suite failed. The line is in the middle of a bunch of logs and the noscript keeps running but ultimately fails with exit code 1.

I have some questions about this

1. Which dependency failed to run the test suite? From the log it looks like it's a package called say. Just want to make sure I'm reading this correctly.
2. Is an error like that generally ignorable? I could completely silence the error because I could silence something important later.
3. If you know of a working "(Windows + Linux + MacOS) * Busted * GitHub" I would love to see a link to it!

https://redd.it/1gceyzj
@r_lua
Recursive directory watching

Hi guys, I'm looking for a Lua library that can watch directory recursively as luv doesn't support that feature in Linux. Thank you so much!

https://redd.it/1gch7x0
@r_lua
I can't get this program to work

https://github.com/veethree/KDP this is a keyboard only pixel art editor that i have been trying to use but no matter what i do with Lua nothing happens, i installed Lua for windows with this: https://github.com/rjpcomputing/luaforwindows/releases/tag/v5.1.5-52 but no matter what i do i can't use any lua files in the folder, double clicking does nothing, using cmd, powershell, and the lua thing it gave me on the desktop does nothing, i don't know what to do

https://redd.it/1gctr31
@r_lua
I made a version of the YCTP from Baldi's basics in Lua

https://preview.redd.it/1yebx16308xd1.png?width=1920&format=png&auto=webp&s=bb38973f01f9a21970bcbba11df637b6d269e4e3

print("Problem One, 7+2=?")
Answer = io.read("n")
if Answer == 9 then
print("Great job!")
print("Problem two, 2+3=?")
end
Answertwo = io.read("n")
if Answertwo == 5 then
print("You might be smarter than me!")
print("Problem two, 4-1=?")
end
Answerthree = io.read("n")
if Answerthree == 3 then
print("Wow, you exsist")
end

https://redd.it/1gd2cs6
@r_lua
finding better syntax

>< ideal >
if mission_temp.reward[index_mission\] == (nil or 0)

>< real >
if mission_temp.reward[index_mission\] == nil or mission_temp.reward[index_mission\] == 0

how can you deal with?

https://redd.it/1gdjpbu
@r_lua
What is the best way to learn how to use the lua
https://redd.it/1gdqfqx
@r_lua
PLEASE HELP MEEEEEEEEEEEEEE

function love.load()
math.randomseed(os.time())
love.window.setFullscreen(true)

bullets = {}

player = {}
player.width = 25
player.height = 25
player.x = love.graphics.getWidth() / 2 - player.width / 2
player.y = love.graphics.getHeight() / 2 - player.height / 2
player.speed = 350

gun = {}
gun.width = 15
gun.height = 10
gun.x = player.x + player.width
gun.y = player.y + player.height / 2 - gun.height / 2
gun.speed = player.speed

count = 0
fireRateCount = 0
fireRateTimer = 1
bulletdirection = "right"
gun
direction = "right"

wave = 0
enemies = {}
kills = 0
gameOver = false
pierceshot = false
upgrades = {"piercing","bulletspeed","playerspeed","bulletdamage"}
upgrade = 0
bullet
speed = 500
bulletdamage = 1
wave
update()
end



function love.update(dt)
if #enemies == 0 and wave > 0 then
    upgradeSelect()
    waveupdate()
end

count = count + dt
fireRateCount = fireRateCount + dt



if fireRateCount >= fireRateTimer then
    createBullet()
    fireRateCount = 0
end

--enemy movement
for i, v in ipairs(enemies) do
    if v.x >= player.x - 10 and v.x <= player.x + 10 then
        v.x = v.x + v.close
horspeed * dt
    elseif v.x < player.x then
        v.x = v.x + v.hor
speed dt
    elseif v.x > player.x then
        v.x = v.x - v.hor_speed
dt
    end
    if v.y >= player.y - 10 and v.y <= player.y + 10 then
        v.y = v.y + v.closevertspeed dt
    elseif v.y < player.y then
        v.y = v.y + v.vert_speed
dt
    elseif v.y > player.y then
        v.y = v.y - v.vertspeed * dt
    end
end
for i in ipairs(enemies) do
    if checkCollision(player,enemies[i]) == true then
        gameOver = true
    end
end

for e =
#enemies, 1, -1 do
    for i =
#bullets, 1, -1 do
        if checkCollision(bullets[i],enemies[e]) == true  and enemies[e].hit == false then
                enemies[e].health = enemies[e].health - bullets[i].damage
                enemies[e].hit = true
        elseif not checkCollision(bullets[i],enemies[e]) then
            enemies[e].hit = false
        end

        if enemies[e].health <= 0 then
            table.remove(enemies,e)
            kills = kills + 1
        end

        if pierce
shot == false then
            table.remove(bullets,i)
        elseif checkCollision(bulletsi,enemiese) == false then
            enemiese.istouching = false
            bullets[i].is
touching = false
        end
        break
    end
end

for i = #bullets, 1, -1 do
    if bulletsi.y <= 0 then
        table.remove(bullets,i)
    elseif bulletsi.x <= 0 then
        table.remove(bullets,i)
    elseif bulletsi.y >= love.graphics.getHeight() - bulletsi.height then
        table.remove(bullets,i)
    elseif bulletsi.x >= love.graphics.getWidth() - bulletsi.width then
        table.remove(bullets,i)
    end
end
--player movement
if love.keyboard.isDown("w") then
    player.y = player.y - player.speed dt
    gun.y = gun.y - gun.speed
dt
end
if love.keyboard.isDown("s") then
    player.y = player.y + player.speed dt
    gun.y = gun.y + gun.speed
dt
end
if love.keyboard.isDown("a") then
    player.x = player.x - player.speed dt
    gun.x = gun.x - gun.speed
dt
end
if love.keyboard.isDown("d") then
    player.x = player.x + player.speed dt
    gun.x = gun.x + gun.speed
dt
end

love.keypressed(key)

for i, v in ipairs(bullets) do
    if v.direction == "up" then
        v.y = v.y - v.speed dt
    elseif v.direction == "right" then
        v.x = v.x + v.speed
dt
    elseif v.direction == "down" then
        v.y = v.y + v.speed dt
    elseif v.direction == "left" then
        v.x = v.x - v.speed
dt
    end

end

if player.x < 0 then
    player.x = 0
    if gundirection == "left" then
        gun.x = 0 - gun.width
    elseif gun
direction == "right" then
        gun.x = 0 + player.width
    elseif gundirection == "down" then
        gun.x = player.x + player.width / 2 - gun.width / 2
    elseif gun
direction == "up" then
        gun.x = player.x + player.width / 2 - gun.width / 2
    end
elseif player.x + player.width > love.graphics.getWidth() then
    player.x = love.graphics.getWidth() - player.width
    if gundirection == "right" then
        gun.x = love.graphics.getWidth()
    elseif gun
direction == "left" then
        gun.x = love.graphics.getWidth() - player.width - gun.width
    elseif gundirection == "down" then
        gun.x = player.x + player.width / 2 - gun.width / 2
    elseif gun
direction == "up" then
        gun.x = player.x + player.width / 2 - gun.width / 2
    end
end

if player.y < 0 then
    player.y = 0
    if gundirection == "up" then
        gun.y = 0 - gun.height
    elseif gun
direction == "down" then
        gun.y = 0 + player.height
    elseif gundirection == "right" then
        gun.y = player.y + player.height / 2 - gun.height / 2
    elseif gun
direction == "left" then
        gun.y = player.y + player.height / 2 - gun.height / 2
    end
elseif player.y + player.height > love.graphics.getHeight() then
    player.y = love.graphics.getHeight() - player.height
    if gundirection == "down" then
        gun.y = love.graphics.getHeight()
    elseif gun
direction == "up" then
        gun.y = love.graphics.getHeight() - player.height - gun.height
    elseif gundirection == "right" then
        gun.y = player.y + player.height / 2 - gun.height / 2
    elseif gun
direction == "left" then
        gun.y = player.y + player.height / 2 - gun.height / 2
    end
end



end

function love.draw()
love.graphics.setColor(1,1,1)
love.graphics.print("Kills: "..kills,love.graphics.getWidth() / 2, 100)
love.graphics.print("Bullet speed:"..bulletspeed, 0, 20)
love.graphics.print("Player speed:"..player.speed, 0, 40)
love.graphics.print("Bullet damage:"..bullet
damage, 0, 60)
if pierceshot == true then
    love.graphics.print("Piercing shot: active", 0, 80)
elseif pierce
shot == false then
    love.graphics.print("Piercing shot: inactive", 0, 80)
end
if gameOver == false then
    love.graphics.rectangle("fill", player.x, player.y, player.width, player.height)
    love.graphics.rectangle("fill", gun.x, gun.y, gun.width, gun.height)
    for i, v in ipairs(bullets) do
        love.graphics.rectangle("fill", v.x - v.xorigin, v.y - v.yorigin, v.width, v.height)
    end
    for i, v in ipairs(enemies) do
        love.graphics.setColor(1,0,0)
        love.graphics.rectangle("fill",v.x,v.y,v.width,v.height)
        love.graphics.setColor(0,0,0)
        love.graphics.print(v.health,v.x,v.y)
    end
elseif gameOver == true then
    love.graphics.print("Game Over!", love.graphics.getWidth() / 2,love.graphics.getHeight() / 2)
end

end

function love.keypressed(key)
    local turntimer = 0.1
    if key == "down" and count >= turn
timer then
        count = 0
        gun.width = 10
        gun.height = 15
        gun.x = player.x + player.width / 2 - gun.width / 2
        gun.y = player.y + player.height
        bulletdirection = "down"
        gun
direction = bulletdirection
    elseif key == "right" and count >= turn
timer then
        count = 0
        gun.width = 15
        gun.height = 10
        gun.x = player.x + player.width
        gun.y = player.y + player.height / 2 - gun.height / 2
 
PLEASE HELP MEEEEEEEEEEEEEE

function love.load()
math.randomseed(os.time())
love.window.setFullscreen(true)

bullets = {}

player = {}
player.width = 25
player.height = 25
player.x = love.graphics.getWidth() / 2 - player.width / 2
player.y = love.graphics.getHeight() / 2 - player.height / 2
player.speed = 350

gun = {}
gun.width = 15
gun.height = 10
gun.x = player.x + player.width
gun.y = player.y + player.height / 2 - gun.height / 2
gun.speed = player.speed

count = 0
fireRateCount = 0
fireRateTimer = 1
bullet_direction = "right"
gun_direction = "right"

wave = 0
enemies = {}
kills = 0
gameOver = false
pierce_shot = false
upgrades = {"piercing","bulletspeed","playerspeed","bulletdamage"}
upgrade = 0
bullet_speed = 500
bullet_damage = 1
wave_update()
end



function love.update(dt)
if #enemies == 0 and wave > 0 then
    upgradeSelect()
    wave_update()
end

count = count + dt
fireRateCount = fireRateCount + dt



if fireRateCount >= fireRateTimer then
    createBullet()
    fireRateCount = 0
end

--enemy movement
for i, v in ipairs(enemies) do
    if v.x >= player.x - 10 and v.x <= player.x + 10 then
        v.x = v.x + v.close_hor_speed * dt
    elseif v.x < player.x then
        v.x = v.x + v.hor_speed * dt
    elseif v.x > player.x then
        v.x = v.x - v.hor_speed * dt
    end
    if v.y >= player.y - 10 and v.y <= player.y + 10 then
        v.y = v.y + v.close_vert_speed * dt
    elseif v.y < player.y then
        v.y = v.y + v.vert_speed * dt
    elseif v.y > player.y then
        v.y = v.y - v.vert_speed * dt
    end
end
for i in ipairs(enemies) do
    if checkCollision(player,enemies[i]) == true then
        gameOver = true
    end
end

for e = #enemies, 1, -1 do
    for i = #bullets, 1, -1 do
        if checkCollision(bullets[i],enemies[e]) == true  and enemies[e].hit == false then
                enemies[e].health = enemies[e].health - bullets[i].damage
                enemies[e].hit = true
        elseif not checkCollision(bullets[i],enemies[e]) then
            enemies[e].hit = false
        end

        if enemies[e].health <= 0 then
            table.remove(enemies,e)
            kills = kills + 1
        end

        if pierce_shot == false then
            table.remove(bullets,i)
        elseif checkCollision(bullets[i],enemies[e]) == false then
            enemies[e].is_touching = false
            bullets[i].is_touching = false
        end
        break
    end
end

for i = #bullets, 1, -1 do
    if bullets[i].y <= 0 then
        table.remove(bullets,i)
    elseif bullets[i].x <= 0 then
        table.remove(bullets,i)
    elseif bullets[i].y >= love.graphics.getHeight() - bullets[i].height then
        table.remove(bullets,i)
    elseif bullets[i].x >= love.graphics.getWidth() - bullets[i].width then
        table.remove(bullets,i)
    end
end
--player movement
if love.keyboard.isDown("w") then
    player.y = player.y - player.speed * dt
    gun.y = gun.y - gun.speed * dt
end
if love.keyboard.isDown("s") then
    player.y = player.y + player.speed * dt
    gun.y = gun.y + gun.speed * dt
end
if love.keyboard.isDown("a") then
    player.x = player.x - player.speed * dt
    gun.x = gun.x - gun.speed * dt
end
if love.keyboard.isDown("d") then
    player.x = player.x + player.speed * dt
    gun.x = gun.x + gun.speed * dt
end

love.keypressed(key)

for i, v in ipairs(bullets) do
    if v.direction == "up" then
        v.y = v.y - v.speed * dt
    elseif v.direction == "right" then
        v.x = v.x + v.speed * dt
    elseif v.direction == "down" then
        v.y = v.y + v.speed * dt
    elseif v.direction == "left" then
        v.x = v.x - v.speed * dt
    end

end

if player.x < 0 then
    player.x = 0
    if gun_direction == "left" then
        gun.x = 0 - gun.width
    elseif gun_direction == "right" then
        gun.x = 0 + player.width
    elseif gun_direction == "down" then
        gun.x = player.x + player.width / 2 - gun.width / 2
    elseif gun_direction == "up" then
        gun.x = player.x + player.width / 2 - gun.width / 2
    end
elseif player.x + player.width > love.graphics.getWidth() then
    player.x = love.graphics.getWidth() - player.width
    if gun_direction == "right" then
        gun.x = love.graphics.getWidth()
    elseif gun_direction == "left" then
        gun.x = love.graphics.getWidth() - player.width - gun.width
    elseif gun_direction == "down" then
        gun.x = player.x + player.width / 2 - gun.width / 2
    elseif gun_direction == "up" then
        gun.x = player.x + player.width / 2 - gun.width / 2
    end
end

if player.y < 0 then
    player.y = 0
    if gun_direction == "up" then
        gun.y = 0 - gun.height
    elseif gun_direction == "down" then
        gun.y = 0 + player.height
    elseif gun_direction == "right" then
        gun.y = player.y + player.height / 2 - gun.height / 2
    elseif gun_direction == "left" then
        gun.y = player.y + player.height / 2 - gun.height / 2
    end
elseif player.y + player.height > love.graphics.getHeight() then
    player.y = love.graphics.getHeight() - player.height
    if gun_direction == "down" then
        gun.y = love.graphics.getHeight()
    elseif gun_direction == "up" then
        gun.y = love.graphics.getHeight() - player.height - gun.height
    elseif gun_direction == "right" then
        gun.y = player.y + player.height / 2 - gun.height / 2
    elseif gun_direction == "left" then
        gun.y = player.y + player.height / 2 - gun.height / 2
    end
end



end

function love.draw()
love.graphics.setColor(1,1,1)
love.graphics.print("Kills: "..kills,love.graphics.getWidth() / 2, 100)
love.graphics.print("Bullet speed:"..bullet_speed, 0, 20)
love.graphics.print("Player speed:"..player.speed, 0, 40)
love.graphics.print("Bullet damage:"..bullet_damage, 0, 60)
if pierce_shot == true then
    love.graphics.print("Piercing shot: active", 0, 80)
elseif pierce_shot == false then
    love.graphics.print("Piercing shot: inactive", 0, 80)
end
if gameOver == false then
    love.graphics.rectangle("fill", player.x, player.y, player.width, player.height)
    love.graphics.rectangle("fill", gun.x, gun.y, gun.width, gun.height)
    for i, v in ipairs(bullets) do
        love.graphics.rectangle("fill", v.x - v.x_origin, v.y - v.y_origin, v.width, v.height)
    end
    for i, v in ipairs(enemies) do
        love.graphics.setColor(1,0,0)
        love.graphics.rectangle("fill",v.x,v.y,v.width,v.height)
        love.graphics.setColor(0,0,0)
        love.graphics.print(v.health,v.x,v.y)
    end
elseif gameOver == true then
    love.graphics.print("Game Over!", love.graphics.getWidth() / 2,love.graphics.getHeight() / 2)
end

end

function love.keypressed(key)
    local turn_timer = 0.1
    if key == "down" and count >= turn_timer then
        count = 0
        gun.width = 10
        gun.height = 15
        gun.x = player.x + player.width / 2 - gun.width / 2
        gun.y = player.y + player.height
        bullet_direction = "down"
        gun_direction = bullet_direction
    elseif key == "right" and count >= turn_timer then
        count = 0
        gun.width = 15
        gun.height = 10
        gun.x = player.x + player.width
        gun.y = player.y + player.height / 2 - gun.height / 2
 
      bullet_direction = "right"
        gun_direction = bullet_direction
    elseif key == "up" and count >= turn_timer then
        count = 0
        gun.width = 10
        gun.height = 15
        gun.x = player.x + player.width / 2 - gun.width / 2
        gun.y = player.y - gun.height
        bullet_direction = "up"
        gun_direction = bullet_direction
    elseif key == "left" and count >= turn_timer then
        count = 0
        gun.width = 15
        gun.height = 10
        gun.x = player.x - gun.width
        gun.y = player.y + player.height / 2 - gun.height / 2
        bullet_direction = "left"
        gun_direction = bullet_direction
    end
end

function createBullet()
    bullet = {}
    bullet.x = gun.x + gun.width / 2
    bullet.y = gun.y + gun.height / 2
    bullet.width = 5
    bullet.height = 5
    bullet.speed =  bullet_speed or 500
    bullet.speedOfBullet = bullet.speed
    bullet.direction = bullet_direction
    bullet.x_origin = bullet.width / 2
    bullet.y_origin = bullet.height / 2
    bullet.damage = bullet_damage or 1
    table.insert(bullets,bullet)
end


function createEnemy()
local x_min = -300
local x_max = love.graphics.getWidth() + 300
local y_min = -300
local y_max = love.graphics.getHeight() + 300
local deciding_x = math.random(0,1)
local deciding_y = math.random(0,1)
enemy = {}
enemy.width = math.random(20,50)
enemy.height = enemy.width
enemy.area = enemy.height * enemy.width
enemy.close_vert_speed = 0
enemy.close_hor_speed = 0
if pierce_shot == true then
    enemy.hit = false
end

if deciding_x == 0 then
    enemy.x = math.random(x_min,0)
elseif deciding_x == 1 then
    enemy.x = math.random(love.graphics.getWidth(),x_max)
end
if deciding_y == 0 then
    enemy.y = math.random(y_min,0)
elseif deciding_y == 1 then
    enemy.y = math.random(love.graphics.getHeight(),y_max)
end
if enemy.area >= 2500 then
    enemy.vert_speed = 50
    enemy.hor_speed = 50
    enemy.health = 7
elseif enemy.area >= 2025 then
    enemy.vert_speed = 100
    enemy.hor_speed = 100
    enemy.health = 6
elseif enemy.area >= 1600 then
    enemy.vert_speed = 150
    enemy.hor_speed = 150
    enemy.health = 5
elseif enemy.area >= 1225 then
    enemy.vert_speed = 200
    enemy.hor_speed = 200
    enemy.health = 4
elseif enemy.area >= 900 then
    enemy.vert_speed = 250
    enemy.hor_speed = 250
    enemy.health = 3
elseif enemy.area >= 625 then
    enemy.vert_speed = 300
    enemy.hor_speed = 300
    enemy.health = 2
elseif enemy.area >= 400 then
    enemy.vert_speed = 350
    enemy.hor_speed = 350
    enemy.health = 1
end
table.insert(enemies,enemy)
end

function wave_update()
    wave = wave + 1
    for i = 1,wave do
        createEnemy()
    end
end

function checkCollision(a,b)
    local a_left = a.x
    local a_right = a.x + a.width
    local a_top = a.y
    local a_bottom = a.y + a.height

    local b_left = b.x
    local b_right = b.x + b.width
    local b_top = b.y
    local b_bottom = b.y + b.height

    return  a_right > b_left
    and a_left < b_right
    and a_bottom > b_top
    and a_top < b_bottom
end


function upgradeSelect()
upgrade = math.random(1,#upgrades)
player_speed = 350
bullet_speed = 500
bullet_damage = 1
if upgrades[upgrade] == "piercing" then
    pierce_shot = true
    table.remove(upgrades,i)
elseif upgrades[upgrade] == "bulletspeed" then
    bullet_speed = bullet.speedOfBullet + 100
elseif upgrades[upgrade] == "playerspeed" then
    player_speed = player.speed + 50
    player.speed = player_speed
    gun.speed = player_speed
elseif upgrades[upgrade] ==