atm959

PSP Coin Shooter script.lua

Feb 17th, 2017
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.33 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. coins = ini.read(saveFile, "SinglePlayer", "Coins", 0)
  76. bu = ini.read(saveFile, "SinglePlayer", "BulletUpgrades", 1)
  77. pu = ini.read(saveFile, "SinglePlayer", "PlayerUpgrades", 1)
  78. pressed = {}
  79. for i = 0, 3 do
  80.     pressed[i] = false
  81. end
  82. saved = false
  83. saveTimer = 0
  84.  
  85. while true do
  86.     controls.read()
  87.     if controls.up() then
  88.         y = y - pu
  89.     end
  90.     if controls.down() then
  91.         y = y + pu
  92.     end
  93.     if controls.left() then
  94.         x = x - pu
  95.     end
  96.     if controls.right() then
  97.         x = x + pu
  98.     end
  99.     if controls.cross() then
  100.         if not bulletShot then
  101.             sound.play(shoot)
  102.             bulletShot = true
  103.             if ca == 0 then
  104.                 bx = x
  105.                 by = y - 32
  106.             elseif ca == 90 then
  107.                 bx = x + 32
  108.                 by = y
  109.             elseif ca == 180 then
  110.                 bx = x
  111.                 by = y + 32
  112.             elseif ca == 270 then
  113.                 bx = x - 32
  114.                 by = y
  115.             end
  116.         end
  117.     end
  118.     if controls.l() then
  119.         if not pressed[0] then
  120.             if not bulletShot then
  121.                 if ca == 0 then
  122.                     ca = 270
  123.                 else
  124.                     ca = ca - 90
  125.                 end
  126.             end
  127.             pressed[0] = true
  128.         end
  129.     else
  130.         pressed[0] = false
  131.     end
  132.     if controls.r() then
  133.         if not pressed[1] then
  134.             if not bulletShot then
  135.                 if ca == 270 then
  136.                     ca = 0
  137.                 else
  138.                     ca = ca + 90
  139.                 end
  140.             end
  141.             pressed[1] = true
  142.         end
  143.     else
  144.         pressed[1] = false
  145.     end
  146.     if controls.select() then
  147.         break
  148.     end
  149.     if controls.start() then
  150.         if not saved then
  151.             sound.play(gameSave)
  152.             ini.write(saveFile, "SinglePlayer", "Coins", coins)
  153.             ini.write(saveFile, "SinglePlayer", "BulletUpgrades", bu)
  154.             ini.write(saveFile, "SinglePlayer", "PlayerUpgrades", pu)
  155.             saved = true
  156.         end
  157.     end
  158.     if controls.square() then
  159.         if not pressed[2] then
  160.             pressed[2] = true
  161.             if tonumber(coins) >= 10 then
  162.                 sound.play(upgradeGet)
  163.                 coins = coins - 10
  164.                 bu = bu + 1
  165.             else
  166.                 sound.play(noUpgradeGet)
  167.             end
  168.         end
  169.     else
  170.         pressed[2] = false
  171.     end
  172.     if controls.triangle() then
  173.         if not pressed[3] then
  174.             pressed[3] = true
  175.             if tonumber(coins) >= 10 then
  176.                 sound.play(upgradeGet)
  177.                 coins = coins - 10
  178.                 pu = pu + 1
  179.             else
  180.                 sound.play(noUpgradeGet)
  181.             end
  182.         end
  183.     else
  184.         pressed[3] = false
  185.     end
  186.     if bulletShot then
  187.         if ca == 0 then
  188.             by = by - bu
  189.         elseif ca == 90 then
  190.             bx = bx + bu
  191.         elseif ca == 180 then
  192.             by = by + bu
  193.         elseif ca == 270 then
  194.             bx = bx - bu
  195.         end
  196.         if (math.abs(by - cy) + math.abs(bx - cx)) < 32 then
  197.             coins = coins + 1
  198.             cx = math.random(0, 480 - 32)
  199.             cy = math.random(0, 272 - 64)
  200.             sound.play(coinGet)
  201.         end
  202.         if ca == 0 then
  203.             if by < -32 then
  204.                 bulletShot = false
  205.                 bx = -32
  206.                 by = -32
  207.             end
  208.         elseif ca == 90 then
  209.             if bx > 480 then
  210.                 bulletShot = false
  211.                 bx = -32
  212.                 by = -32
  213.             end
  214.         elseif ca == 180 then
  215.             if by > 272 then
  216.                 bulletShot = false
  217.                 bx = -32
  218.                 by = -32
  219.             end
  220.         elseif ca == 270 then
  221.             if bx < -32 then
  222.                 bulletShot = false
  223.                 bx = -32
  224.                 by = -32
  225.             end
  226.         end
  227.     end
  228.     if x < 0 then
  229.         x = 0
  230.     end
  231.     if y < 0 then
  232.         y = 0
  233.     end
  234.     if x > 480 - 32 then
  235.         x = 480 - 32
  236.     end
  237.     if y > 272 - 32 then
  238.         y = 272 - 32
  239.     end
  240.     image.blit(bg, 0, 0)
  241.     image.rotate(char, 8, 8, ca)
  242.     image.blit(char, x + 16, y + 16)
  243.     frameTimer = frameTimer + 1
  244.     if not frameDir then
  245.         if frameTimer == 9 then
  246.             frameTimer = 0
  247.             if frame == 3 then
  248.                 frameDir = 1
  249.             else
  250.                 frame = frame + 1
  251.             end
  252.         end
  253.     else
  254.         if frameTimer == 9 then
  255.             frameTimer = 0
  256.             if frame == 0 then
  257.                 frameDir = 0
  258.             else
  259.                 frame = frame - 1
  260.             end
  261.         end
  262.     end
  263.     image.blit(coin, cx, cy, frame * 32, 0, 32, 32)
  264.     image.rotate(bullet, 8, 8, ca)
  265.     image.blit(bullet, bx + 16, by + 16)
  266.     screen.print(0, 5, "Coins: " .. coins, color.new(0, 0, 0))
  267.     screen.print(0, 25, "Bullet Speed Upgrades: " .. bu, color.new(0, 0, 0))
  268.     screen.print(0, 45, "Player Speed Upgrades: " .. pu, color.new(0, 0, 0))
  269.     screen.print(100, 100, "Frame: " .. frame, color.new(0, 0, 0))
  270.     screen.print(100, 116, "FrameTimer: " .. frameTimer, color.new(0, 0, 0))
  271.     screen.print(100, 132, "FrameDir: " .. frameDir, color.new(0, 0, 0))
  272.     if saved then
  273.         saveTimer = saveTimer + 1
  274.         if saveTimer == 59 then
  275.             saveTimer = 0
  276.             saved = false
  277.         end
  278.         screen.print(0, 240, "Game Saved", 1.5, color.new(0, 0, 0), color.new(0, 0, 0, 0))
  279.     end
  280.     screen.flip()
  281.     screen.waitvblankstart()
  282. end
  283.  
  284. image.free(bg)
  285. image.free(char)
  286. image.free(coin)
  287. image.free(bullet)
  288.  
  289. sound.free(shoot)
  290. sound.free(coinGet)
  291. sound.free(upgradeGet)
  292. sound.free(noUpgradeGet)
Add Comment
Please, Sign In to add comment