Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- controls.homepopup(0) --Turn off the dialog that shows up when the home/PS button is pressed
- menuBg = image.load("res/images/bg/menubg.png")
- triButton = image.load("res/images/buttons/triButton.png")
- squButton = image.load("res/images/buttons/squButton.png")
- startButton = image.load("res/images/buttons/startButton.png")
- croButton = image.load("res/images/buttons/croButton.png")
- lButton = image.load("res/images/buttons/lButton.png")
- image.resize(menuBg, 480, 272)
- image.resize(triButton, 32, 32)
- image.resize(squButton, 32, 32)
- image.resize(startButton, 64, 32)
- image.resize(croButton, 32, 32)
- image.resize(lButton, 64, 32)
- loadingImage = image.load("res/images/bg/loading.png")
- image.resize(loadingImage, 480, 272)
- titleOpen = true
- while titleOpen do
- controls.read()
- image.blit(menuBg, 0, 0)
- image.blit(triButton, 0, 0)
- image.blit(squButton, 0, 32)
- image.blit(startButton, 0, 64)
- image.blit(croButton, 0, 96)
- image.blit(lButton, 0, 128)
- if controls.cross() then
- titleOpen = false
- image.blit(loadingImage, 0, 0)
- end
- screen.flip()
- screen.waitvblankstart()
- end
- image.free(menuBg)
- image.free(triButton)
- image.free(squButton)
- image.free(startButton)
- image.free(croButton)
- image.free(lButton)
- image.free(loadingImage)
- bg = image.load("res/images/bg/bg.png")
- char = image.load("res/images/character.png")
- coin = image.load("res/images/coin.png")
- bullet = image.load("res/images/bullet.png")
- image.resize(bg, 480, 272)
- image.resize(char, 32, 32)
- image.resize(coin, 128, 32)
- image.resize(bullet, 32, 32)
- shoot = sound.load("res/sfx/shoot.wav")
- coinGet = sound.load("res/sfx/coin.wav")
- gameSave = sound.load("res/sfx/gamesave.wav")
- upgradeGet = sound.load("res/sfx/upgradeget.wav")
- noUpgradeGet = sound.load("res/sfx/noupgradeget.wav")
- sound.loop("res/bgm/bgMusic.wav")
- x = 0
- y = 0
- cx = 100
- cy = 100
- bulletShot = false
- bx = -32
- by = -32
- ca = 0
- frame = 0
- frameDir = 0
- frameTimer = 0
- saveFile = ini.load("savedata.ini", true)
- ini.write(saveFile, "Debug", "Enabled", 1)
- coins = ini.read(saveFile, "SinglePlayer", "Coins", 0)
- bu = ini.read(saveFile, "SinglePlayer", "BulletUpgrades", 1)
- pu = ini.read(saveFile, "SinglePlayer", "PlayerUpgrades", 1)
- --debug = ini.read(saveFile, "Debug", "Enabled", 0)
- pressed = {}
- for i = 0, 3 do
- pressed[i] = false
- end
- saved = false
- saveTimer = 0
- while true do
- controls.read()
- if controls.up() then
- y = y - pu
- end
- if controls.down() then
- y = y + pu
- end
- if controls.left() then
- x = x - pu
- end
- if controls.right() then
- x = x + pu
- end
- if controls.cross() then
- if not bulletShot then
- sound.play(shoot)
- bulletShot = true
- if ca == 0 then
- bx = x
- by = y - 32
- elseif ca == 90 then
- bx = x + 32
- by = y
- elseif ca == 180 then
- bx = x
- by = y + 32
- elseif ca == 270 then
- bx = x - 32
- by = y
- end
- end
- end
- if controls.l() then
- if not pressed[0] then
- if not bulletShot then
- if ca == 0 then
- ca = 270
- else
- ca = ca - 90
- end
- end
- pressed[0] = true
- end
- else
- pressed[0] = false
- end
- if controls.r() then
- if not pressed[1] then
- if not bulletShot then
- if ca == 270 then
- ca = 0
- else
- ca = ca + 90
- end
- end
- pressed[1] = true
- end
- else
- pressed[1] = false
- end
- if controls.select() then
- break
- end
- if controls.start() then
- if not saved then
- sound.play(gameSave)
- ini.write(saveFile, "SinglePlayer", "Coins", coins)
- ini.write(saveFile, "SinglePlayer", "BulletUpgrades", bu)
- ini.write(saveFile, "SinglePlayer", "PlayerUpgrades", pu)
- saved = true
- end
- end
- if controls.square() then
- if not pressed[2] then
- pressed[2] = true
- if tonumber(coins) >= 10 then
- sound.play(upgradeGet)
- coins = coins - 10
- bu = bu + 1
- else
- sound.play(noUpgradeGet)
- end
- end
- else
- pressed[2] = false
- end
- if controls.triangle() then
- if not pressed[3] then
- pressed[3] = true
- if tonumber(coins) >= 10 then
- sound.play(upgradeGet)
- coins = coins - 10
- pu = pu + 1
- else
- sound.play(noUpgradeGet)
- end
- end
- else
- pressed[3] = false
- end
- if bulletShot then
- if ca == 0 then
- by = by - bu
- elseif ca == 90 then
- bx = bx + bu
- elseif ca == 180 then
- by = by + bu
- elseif ca == 270 then
- bx = bx - bu
- end
- if (math.abs(by - cy) + math.abs(bx - cx)) < 32 then
- coins = coins + 1
- cx = math.random(0, 480 - 32)
- cy = math.random(0, 272 - 64)
- sound.play(coinGet)
- end
- if ca == 0 then
- if by < -32 then
- bulletShot = false
- bx = -32
- by = -32
- end
- elseif ca == 90 then
- if bx > 480 then
- bulletShot = false
- bx = -32
- by = -32
- end
- elseif ca == 180 then
- if by > 272 then
- bulletShot = false
- bx = -32
- by = -32
- end
- elseif ca == 270 then
- if bx < -32 then
- bulletShot = false
- bx = -32
- by = -32
- end
- end
- end
- if x < 0 then
- x = 0
- end
- if y < 0 then
- y = 0
- end
- if x > 480 - 32 then
- x = 480 - 32
- end
- if y > 272 - 32 then
- y = 272 - 32
- end
- image.blit(bg, 0, 0)
- image.rotate(char, 8, 8, ca)
- image.blit(char, x + 16, y + 16)
- frameTimer = frameTimer + 1
- if frameDir == 0 then
- if frameTimer > 9 then
- frameTimer = 0
- if frame == 3 then
- frameDir = 1
- frame = 2
- else
- frame = frame + 1
- end
- end
- else
- if frameTimer > 9 then
- frameTimer = 0
- if frame == 0 then
- frameDir = 0
- frame = 1
- else
- frame = frame - 1
- end
- end
- end
- image.blit(coin, cx, cy, frame * 32, 0, 32, 32)
- image.rotate(bullet, 8, 8, ca)
- image.blit(bullet, bx + 16, by + 16)
- screen.print(0, 5, "Coins: " .. coins, color.new(0, 0, 0))
- screen.print(0, 25, "Bullet Speed Upgrades: " .. bu, color.new(0, 0, 0))
- screen.print(0, 45, "Player Speed Upgrades: " .. pu, color.new(0, 0, 0))
- if debug == 1 then
- screen.print(100, 100, "Frame: " .. frame, color.new(0, 0, 0))
- screen.print(100, 116, "FrameTimer: " .. frameTimer, color.new(0, 0, 0))
- screen.print(100, 132, "FrameDir: " .. frameDir, color.new(0, 0, 0))
- end
- if saved then
- saveTimer = saveTimer + 1
- if saveTimer == 59 then
- saveTimer = 0
- saved = false
- end
- screen.print(0, 240, "Game Saved", 1.5, color.new(0, 0, 0), color.new(0, 0, 0, 0))
- end
- screen.flip()
- screen.waitvblankstart()
- end
- image.free(bg)
- image.free(char)
- image.free(coin)
- image.free(bullet)
- sound.free(shoot)
- sound.free(coinGet)
- sound.free(upgradeGet)
- sound.free(noUpgradeGet)
Add Comment
Please, Sign In to add comment