atm959

script.lua

Feb 13th, 2019
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.48 KB | None | 0 0
  1. controls.homepopup(0) --Turn off the dialog that shows up when the home/PS button is pressed
  2.  
  3. menuBg = image.load("res/images/bg/menubg.png")
  4. triButton = image.load("res/images/buttons/triButton.png")
  5. squButton = image.load("res/images/buttons/squButton.png")
  6. startButton = image.load("res/images/buttons/startButton.png")
  7. croButton = image.load("res/images/buttons/croButton.png")
  8. lButton = image.load("res/images/buttons/lButton.png")
  9. image.resize(menuBg, 480, 272)
  10. image.resize(triButton, 32, 32)
  11. image.resize(squButton, 32, 32)
  12. image.resize(startButton, 64, 32)
  13. image.resize(croButton, 32, 32)
  14. image.resize(lButton, 64, 32)
  15.  
  16. loadingImage = image.load("res/images/bg/loading.png")
  17. image.resize(loadingImage, 480, 272)
  18.  
  19. titleOpen = true
  20.  
  21. while titleOpen do
  22.     controls.read()
  23.     image.blit(menuBg, 0, 0)
  24.     image.blit(triButton, 0, 0)
  25.     image.blit(squButton, 0, 32)
  26.     image.blit(startButton, 0, 64)
  27.     image.blit(croButton, 0, 96)
  28.     image.blit(lButton, 0, 128)
  29.     if controls.cross() then
  30.         titleOpen = false
  31.         image.blit(loadingImage, 0, 0)
  32.     end
  33.     screen.flip()
  34.     screen.waitvblankstart()
  35. end
  36.  
  37. image.free(menuBg)
  38. image.free(triButton)
  39. image.free(squButton)
  40. image.free(startButton)
  41. image.free(croButton)
  42. image.free(lButton)
  43. image.free(loadingImage)
  44.  
  45.  
  46. bg = image.load("res/images/bg/bg.png")
  47. char = image.load("res/images/character.png")
  48. coin = image.load("res/images/coin.png")
  49. bullet = image.load("res/images/bullet.png")
  50. image.resize(bg, 480, 272)
  51. image.resize(char, 32, 32)
  52. image.resize(coin, 128, 32)
  53. image.resize(bullet, 32, 32)
  54.  
  55. shoot = sound.load("res/sfx/shoot.wav")
  56. coinGet = sound.load("res/sfx/coin.wav")
  57. gameSave = sound.load("res/sfx/gamesave.wav")
  58. upgradeGet = sound.load("res/sfx/upgradeget.wav")
  59. noUpgradeGet = sound.load("res/sfx/noupgradeget.wav")
  60.  
  61. sound.loop("res/bgm/bgMusic.wav")
  62.  
  63. x = 0
  64. y = 0
  65. cx = 100
  66. cy = 100
  67. bulletShot = false
  68. bx = -32
  69. by = -32
  70. ca = 0
  71. frame = 0
  72. frameDir = 0
  73. frameTimer = 0
  74. saveFile = ini.load("savedata.ini", true)
  75. ini.write(saveFile, "Debug", "Enabled", 1)
  76. coins = ini.read(saveFile, "SinglePlayer", "Coins", 0)
  77. bu = ini.read(saveFile, "SinglePlayer", "BulletUpgrades", 1)
  78. pu = ini.read(saveFile, "SinglePlayer", "PlayerUpgrades", 1)
  79. --debug = ini.read(saveFile, "Debug", "Enabled", 0)
  80. pressed = {}
  81. for i = 0, 3 do
  82.     pressed[i] = false
  83. end
  84. saved = false
  85. saveTimer = 0
  86.  
  87. while true do
  88.     controls.read()
  89.     if controls.up() then
  90.         y = y - pu
  91.     end
  92.     if controls.down() then
  93.         y = y + pu
  94.     end
  95.     if controls.left() then
  96.         x = x - pu
  97.     end
  98.     if controls.right() then
  99.         x = x + pu
  100.     end
  101.     if controls.cross() then
  102.         if not bulletShot then
  103.             sound.play(shoot)
  104.             bulletShot = true
  105.             if ca == 0 then
  106.                 bx = x
  107.                 by = y - 32
  108.             elseif ca == 90 then
  109.                 bx = x + 32
  110.                 by = y
  111.             elseif ca == 180 then
  112.                 bx = x
  113.                 by = y + 32
  114.             elseif ca == 270 then
  115.                 bx = x - 32
  116.                 by = y
  117.             end
  118.         end
  119.     end
  120.     if controls.l() then
  121.         if not pressed[0] then
  122.             if not bulletShot then
  123.                 if ca == 0 then
  124.                     ca = 270
  125.                 else
  126.                     ca = ca - 90
  127.                 end
  128.             end
  129.             pressed[0] = true
  130.         end
  131.     else
  132.         pressed[0] = false
  133.     end
  134.     if controls.r() then
  135.         if not pressed[1] then
  136.             if not bulletShot then
  137.                 if ca == 270 then
  138.                     ca = 0
  139.                 else
  140.                     ca = ca + 90
  141.                 end
  142.             end
  143.             pressed[1] = true
  144.         end
  145.     else
  146.         pressed[1] = false
  147.     end
  148.     if controls.select() then
  149.         break
  150.     end
  151.     if controls.start() then
  152.         if not saved then
  153.             sound.play(gameSave)
  154.             ini.write(saveFile, "SinglePlayer", "Coins", coins)
  155.             ini.write(saveFile, "SinglePlayer", "BulletUpgrades", bu)
  156.             ini.write(saveFile, "SinglePlayer", "PlayerUpgrades", pu)
  157.             saved = true
  158.         end
  159.     end
  160.     if controls.square() then
  161.         if not pressed[2] then
  162.             pressed[2] = true
  163.             if tonumber(coins) >= 10 then
  164.                 sound.play(upgradeGet)
  165.                 coins = coins - 10
  166.                 bu = bu + 1
  167.             else
  168.                 sound.play(noUpgradeGet)
  169.             end
  170.         end
  171.     else
  172.         pressed[2] = false
  173.     end
  174.     if controls.triangle() then
  175.         if not pressed[3] then
  176.             pressed[3] = true
  177.             if tonumber(coins) >= 10 then
  178.                 sound.play(upgradeGet)
  179.                 coins = coins - 10
  180.                 pu = pu + 1
  181.             else
  182.                 sound.play(noUpgradeGet)
  183.             end
  184.         end
  185.     else
  186.         pressed[3] = false
  187.     end
  188.     if bulletShot then
  189.         if ca == 0 then
  190.             by = by - bu
  191.         elseif ca == 90 then
  192.             bx = bx + bu
  193.         elseif ca == 180 then
  194.             by = by + bu
  195.         elseif ca == 270 then
  196.             bx = bx - bu
  197.         end
  198.         if (math.abs(by - cy) + math.abs(bx - cx)) < 32 then
  199.             coins = coins + 1
  200.             cx = math.random(0, 480 - 32)
  201.             cy = math.random(0, 272 - 64)
  202.             sound.play(coinGet)
  203.         end
  204.         if ca == 0 then
  205.             if by < -32 then
  206.                 bulletShot = false
  207.                 bx = -32
  208.                 by = -32
  209.             end
  210.         elseif ca == 90 then
  211.             if bx > 480 then
  212.                 bulletShot = false
  213.                 bx = -32
  214.                 by = -32
  215.             end
  216.         elseif ca == 180 then
  217.             if by > 272 then
  218.                 bulletShot = false
  219.                 bx = -32
  220.                 by = -32
  221.             end
  222.         elseif ca == 270 then
  223.             if bx < -32 then
  224.                 bulletShot = false
  225.                 bx = -32
  226.                 by = -32
  227.             end
  228.         end
  229.     end
  230.     if x < 0 then
  231.         x = 0
  232.     end
  233.     if y < 0 then
  234.         y = 0
  235.     end
  236.     if x > 480 - 32 then
  237.         x = 480 - 32
  238.     end
  239.     if y > 272 - 32 then
  240.         y = 272 - 32
  241.     end
  242.     image.blit(bg, 0, 0)
  243.     image.rotate(char, 8, 8, ca)
  244.     image.blit(char, x + 16, y + 16)
  245.     frameTimer = frameTimer + 1
  246.     if frameDir == 0 then
  247.         if frameTimer > 9 then
  248.             frameTimer = 0
  249.             if frame == 3 then
  250.                 frameDir = 1
  251.                 frame = 2
  252.             else
  253.                 frame = frame + 1
  254.             end
  255.         end
  256.     else
  257.         if frameTimer > 9 then
  258.             frameTimer = 0
  259.             if frame == 0 then
  260.                 frameDir = 0
  261.                 frame = 1
  262.             else
  263.                 frame = frame - 1
  264.             end
  265.         end
  266.     end
  267.     image.blit(coin, cx, cy, frame * 32, 0, 32, 32)
  268.     image.rotate(bullet, 8, 8, ca)
  269.     image.blit(bullet, bx + 16, by + 16)
  270.     screen.print(0, 5, "Coins: " .. coins, color.new(0, 0, 0))
  271.     screen.print(0, 25, "Bullet Speed Upgrades: " .. bu, color.new(0, 0, 0))
  272.     screen.print(0, 45, "Player Speed Upgrades: " .. pu, color.new(0, 0, 0))
  273.     if debug == 1 then
  274.         screen.print(100, 100, "Frame: " .. frame, color.new(0, 0, 0))
  275.         screen.print(100, 116, "FrameTimer: " .. frameTimer, color.new(0, 0, 0))
  276.         screen.print(100, 132, "FrameDir: " .. frameDir, color.new(0, 0, 0))
  277.     end
  278.     if saved then
  279.         saveTimer = saveTimer + 1
  280.         if saveTimer == 59 then
  281.             saveTimer = 0
  282.             saved = false
  283.         end
  284.         screen.print(0, 240, "Game Saved", 1.5, color.new(0, 0, 0), color.new(0, 0, 0, 0))
  285.     end
  286.     screen.flip()
  287.     screen.waitvblankstart()
  288. end
  289.  
  290. image.free(bg)
  291. image.free(char)
  292. image.free(coin)
  293. image.free(bullet)
  294.  
  295. sound.free(shoot)
  296. sound.free(coinGet)
  297. sound.free(upgradeGet)
  298. sound.free(noUpgradeGet)
Add Comment
Please, Sign In to add comment