Advertisement
Guest User

Untitled

a guest
Mar 19th, 2016
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 29.88 KB | None | 0 0
  1. System.setCpuSpeed(804)
  2.  
  3. Graphics.init()
  4.  
  5. -- Patch for latest lpp-3ds commit
  6. System.currentDirectory(string.sub(System.currentDirectory(),1,-2))
  7.  
  8. local appdir = System.currentDirectory()..'/rsrc'
  9. local scrdir = System.currentDirectory()..'/screenshots'
  10. local lvldir = System.currentDirectory()..'/levels'
  11.  
  12. local c_white = Color.new(255,255,255)
  13. local c_light = Color.new(178,216,255)
  14.  
  15. -- Localize all most used functions and variables so they will be accessed faster
  16. local Screen_waitVblankStart = Screen.waitVblankStart
  17. local Graphics_drawImage = Graphics.drawImage
  18. local TOP_SCREEN = TOP_SCREEN
  19. local Screen_flip = Screen.flip
  20. local Graphics_drawPartialImage = Graphics.drawPartialImage
  21. local Graphics_drawLine = Graphics.drawLine
  22. local Graphics_initBlend = Graphics.initBlend
  23. local Graphics_termBlend = Graphics.termBlend
  24. local Controls_read = Controls.read
  25. local Controls_check = Controls.check
  26. local Controls_readTouch = Controls.readTouch
  27. local KEY_A = KEY_A
  28. local KEY_X = KEY_X
  29. local KEY_Y = KEY_Y
  30. local KEY_R = KEY_R
  31. local KEY_START = KEY_START
  32. local KEY_SELECT = KEY_SELECT
  33.  
  34. Screen_waitVblankStart()
  35. Graphics_initBlend(TOP_SCREEN)
  36. img_bg_load = Graphics.loadImage(appdir..'/bg_load.png')
  37. Graphics_drawImage(0, 0, img_bg_load)
  38. Graphics_termBlend()
  39. Screen_flip()
  40.  
  41. local i=0
  42. local load_filevariable = {}
  43. local load_filepath = {}
  44.  
  45.     i=i+1; load_filevariable[i]='img_ship01'; load_filepath[i] = '/ship01.png'
  46.     i=i+1; load_filevariable[i]='img_ship_death'; load_filepath[i] = '/ship_death.png'
  47.    
  48.     i=i+1; load_filevariable[i]='img_en_death'; load_filepath[i] = '/en_death.png'
  49.     i=i+1; load_filevariable[i]='img_boss_death'; load_filepath[i] = '/boss_death.png'
  50.     i=i+1; load_filevariable[i]='img_en01'; load_filepath[i] = '/en01.png'
  51.     i=i+1; load_filevariable[i]='img_en02'; load_filepath[i] = '/en02.png'
  52.     i=i+1; load_filevariable[i]='img_en03'; load_filepath[i] = '/en03.png'
  53.     i=i+1; load_filevariable[i]='img_en04'; load_filepath[i] = '/en04.png'
  54.     i=i+1; load_filevariable[i]='img_en05'; load_filepath[i] = '/en05.png'
  55.     i=i+1; load_filevariable[i]='img_boss01'; load_filepath[i] = '/boss01.png'
  56.     i=i+1; load_filevariable[i]='img_boss02'; load_filepath[i] = '/boss02.png'
  57.    
  58.    
  59.     i=i+1; load_filevariable[i]='img_bullet01'; load_filepath[i] = '/bullet01.png'
  60.     i=i+1; load_filevariable[i]='img_bullet02'; load_filepath[i] = '/bullet02.png'
  61.     i=i+1; load_filevariable[i]='img_bullet03'; load_filepath[i] = '/bullet03.png'
  62.     i=i+1; load_filevariable[i]='img_bullet04'; load_filepath[i] = '/bullet04.png'
  63.     i=i+1; load_filevariable[i]='img_bullet05'; load_filepath[i] = '/bullet05.png'
  64.     i=i+1; load_filevariable[i]='img_shot01'; load_filepath[i] = '/shot01.png'
  65.     i=i+1; load_filevariable[i]='img_shot02'; load_filepath[i] = '/shot02.png'
  66.     i=i+1; load_filevariable[i]='img_shot03'; load_filepath[i] = '/shot03.png'
  67.     i=i+1; load_filevariable[i]='img_shot04'; load_filepath[i] = '/shot04.png'
  68.     i=i+1; load_filevariable[i]='img_shot05'; load_filepath[i] = '/shot05.png'
  69.    
  70.     i=i+1; load_filevariable[i]='img_bg_menu'; load_filepath[i] = '/bg_menu.png'
  71.     i=i+1; load_filevariable[i]='img_bg_game'; load_filepath[i] = '/bg_game.png'
  72.    
  73.     i=i+1; load_filevariable[i]='img_menubutton_play'; load_filepath[i] = '/menubutton_play.png'
  74.     i=i+1; load_filevariable[i]='img_menubutton_diff'; load_filepath[i] = '/menubutton_diff.png'
  75.     i=i+1; load_filevariable[i]='img_menubutton_level'; load_filepath[i] = '/menubutton_level.png'
  76.     i=i+1; load_filevariable[i]='img_menubutton_option'; load_filepath[i] = '/menubutton_option.png'
  77.     i=i+1; load_filevariable[i]='img_menubutton_exit'; load_filepath[i] = '/menubutton_exit.png'
  78.    
  79.     i=i+1; load_filevariable[i]='img_diff_meter'; load_filepath[i] = '/diff_meter.png'
  80.     i=i+1; load_filevariable[i]='img_diff_meter_pip'; load_filepath[i] = '/diff_meter_pip.png'
  81.     i=i+1; load_filevariable[i]='img_menu_invalid'; load_filepath[i] = '/menu_invalid.png'
  82.     i=i+1; load_filevariable[i]='img_warning'; load_filepath[i] = '/warning.png'
  83.     i=i+1; load_filevariable[i]='img_clear'; load_filepath[i] = '/clear.png'
  84.    
  85.     i=i+1; load_filevariable[i]='img_font_numbers'; load_filepath[i] = '/font_numbers.png'
  86.    
  87. load_filecount = i+1
  88.  
  89. local i=0
  90. local c_line = c_light
  91. while i<load_filecount do --load them one by one on each frame of the loading screen
  92.     if load_filevariable[i] ~= nil then
  93.         if System.doesFileExist(appdir..load_filepath[i]) then
  94.             _G[load_filevariable[i]] = Graphics.loadImage(appdir..load_filepath[i])
  95.         else
  96.             c_line = Color.new(255,0,0)
  97.         end
  98.     end
  99.     i=i+1
  100.     Screen_waitVblankStart()
  101.     Graphics_initBlend(TOP_SCREEN)
  102.     Graphics_drawImage(0, 0, img_bg_load)
  103.     Graphics_drawLine(163, 163+math.ceil(i/load_filecount*76), 175, 175, c_line)
  104.     Graphics_termBlend()
  105.     Screen_flip()
  106. end
  107.  
  108. glyph_l = {}
  109. glyph_r = {}
  110. glyph_w = {}
  111. function g_init(char, l, r)
  112.     glyph_l[char] = l
  113.     glyph_r[char] = r
  114.     glyph_w[char] = r-l+1
  115. end
  116. g_init('0',1,8)
  117. g_init('1',9,16)
  118. g_init('2',17,25)
  119. g_init('3',25,32)
  120. g_init('4',33,40)
  121. g_init('5',41,48)
  122. g_init('6',49,56)
  123. g_init('7',57,64)
  124. g_init('8',65,72)
  125. g_init('9',73,80)
  126.  
  127. --remember to blend the gpu to what screen you want before calling this function, and termblend afterwards
  128. function gpu_drawtext(x, y, text)
  129.     local text_u = string.upper(text) --my font system is caps-only. This may be slowing down the system though, consider not having this failsafe (instead loading all strings in as uppercase by default)
  130.     local i_str=0 --the current position in the string
  131.     local i_chr='' --the current character in the string
  132.     local str_width = 0 --width in pixels of the string
  133.     local str_length = string.len(text)
  134.     local cw --character width
  135.     while i_str < str_length do
  136.         i_str = i_str + 1
  137.         i_chr = string.sub(text_u, i_str, i_str)
  138.         cw = glyph_w[i_chr]
  139.         if cw ~= nil then --as long as the character exists
  140.             Graphics_drawPartialImage(x+str_width, y, glyph_l[i_chr], 1, cw, 14, img_font_numbers)
  141.             str_width = str_width + cw + 2
  142.         end
  143.     end
  144. end
  145.  
  146. dofile(appdir..'/ds_list_init.lua')
  147. dofile(appdir..'/ds_queue_init.lua')
  148.  
  149. dofile(appdir..'/object.lua')
  150.  
  151. function loadlevel(num)
  152.     local f = io.open(lvldir.."/level"..num..".dat",FREAD)
  153.     local filesize = io.size(f)
  154.     local str = io.read(f,0,filesize)
  155.     io.close(f)
  156.    
  157.     --"|T-######|enemy|direction|px|"
  158.     local i = 0
  159.     local a = string.find(str, "|T-",1,true) --find the first new line
  160.     local v = string.sub(str, 1, 4) --obtain version
  161.     if v ~= "v001" then
  162.         a=nil
  163.         return true;
  164.     else
  165.         while a~=nil do --as long as there's more newlines
  166.             local t = tonumber(string.sub(str, a+3, a+8)) --the six characters after T- is the time
  167.             local en = string.sub(str, a+10, a+13) --enemy id
  168.             local d = string.sub(str, a+15, a+15) --direction the enemy is coming from (T, L, R)
  169.             local px = tonumber(string.sub(str, a+17, a+19))
  170.             larray.time[i] = t
  171.             larray.enid[i] = en
  172.             larray.dir[i] = d
  173.             larray.pix[i] = px
  174.             i = i+1
  175.             a = string.find(str, "|T-",a+5,true)
  176.         end
  177.     end
  178. end
  179.  
  180. function onscreen(x,y)
  181.     if x>-5 and x<405 and y>-5 and y<405 then
  182.         return true
  183.     else
  184.         return false
  185.     end
  186. end
  187.  
  188. larray = {}
  189. larray.time = {}
  190. larray.enid = {}
  191. larray.dir = {}
  192. larray.pix = {}
  193.  
  194. function menu_init()
  195.     menu = true
  196.     menu_selector = 0
  197.     invalid_level = false
  198.     if game_started == true then
  199.         while bulletlist.size>0 do ds_list_delete(bulletlist,0) end
  200.         while shotlist.size>0 do ds_list_delete(shotlist,0) end
  201.         while enemylist.size>0 do ds_list_delete(enemylist,0) end
  202.     else
  203.         difficulty = 1
  204.         level_select = 1
  205.     end
  206. end
  207.  
  208. function game_init()
  209.     if loadlevel(level_select) == true then --failed to load level because version mismatch
  210.         menu = true
  211.         invalid_level = true
  212.     else
  213.         difficulty = math.floor(difficulty)
  214.         game_started = true
  215.         beam_id = -1
  216.         weapon = 1
  217.         player_x = 200
  218.         player_y = 200
  219.         player_shot = 0
  220.         player_speed = 1
  221.         player_alive = true
  222.         player_death = 0
  223.         timer = 0
  224.         spawnindex = 0
  225.         warning_flash = 0
  226.         stage_boss = ''
  227.         stage_clear = -1
  228.     end
  229. end
  230.  
  231. function angle(x1,y1,x2,y2)
  232.     local rise = y2-y1
  233.     local run = x2-x1
  234.     local a = math.atan(run,rise)
  235.     return math.deg(a)%360
  236. end
  237.  
  238. pad = Controls_read()
  239. oldpad = pad
  240.  
  241. menu_init()
  242. while true do
  243.     Screen_waitVblankStart()
  244.     pad = Controls_read()
  245.     tx_old,ty_old = tx,ty
  246.     tx,ty = Controls_readTouch()
  247.    
  248.     if (Controls_check(pad,KEY_SELECT)) and not (Controls_check(oldpad,KEY_SELECT)) then
  249.         local i=0
  250.         while i<50 do
  251.             if System.doesFileExist(scrdir.."/screenshot"..i..".png") then
  252.                 i=i+1
  253.             else
  254.                 System.takeScreenshot(scrdir.."/screenshot"..i..".png",false)
  255.                 break;
  256.             end
  257.         end
  258.     end
  259.    
  260.     if menu == true then --MENU SCREEN \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  261.    
  262.         if (Controls_check(pad,KEY_DUP)) and not (Controls_check(oldpad,KEY_DUP)) then
  263.             menu_selector = math.max(0,menu_selector-1)
  264.         end
  265.         if (Controls_check(pad,KEY_DDOWN)) and not (Controls_check(oldpad,KEY_DDOWN)) then
  266.             menu_selector = math.min(4,menu_selector+1)
  267.         end
  268.        
  269.         Graphics_initBlend(TOP_SCREEN)
  270.        
  271.         Graphics_drawImage(0, 0, img_bg_menu) --PLAY BUTTON
  272.         if menu_selector == 0 then
  273.             Graphics_drawPartialImage(50,70, 0,16, 103,16, img_menubutton_play, c_white)
  274.             if (Controls_check(pad,KEY_A)) and not (Controls_check(oldpad,KEY_A)) then
  275.                 if System.doesFileExist(lvldir.."/level"..level_select..".dat") then
  276.                     menu = false
  277.                     game_init()
  278.                 else
  279.                     invalid_level = true
  280.                 end
  281.             end
  282.         else Graphics_drawPartialImage(50,70, 0,0, 103,16, img_menubutton_play, c_white) end
  283.        
  284.         if menu_selector == 1 then --DIFFICULTY SELECTION
  285.             if (Controls_check(pad,KEY_DLEFT)) then
  286.                 difficulty = math.max(1,difficulty-0.125)
  287.             end
  288.             if (Controls_check(pad,KEY_DRIGHT)) then
  289.                 difficulty = math.min(16,difficulty+0.125)
  290.             end
  291.             Graphics_drawPartialImage(50,95, 0,16, 103,16, img_menubutton_diff, c_white)
  292.         else Graphics_drawPartialImage(50,95, 0,0, 103,16, img_menubutton_diff, c_white) end
  293.         Graphics_drawImage(180, 95, img_diff_meter)
  294.         Graphics_drawPartialImage(180,95, 0,0, 6+(4*math.floor(difficulty)),16, img_diff_meter_pip)
  295.        
  296.         if menu_selector == 2 then --LEVEL SELECTION
  297.             if (Controls_check(pad,KEY_DLEFT)) then
  298.                 invalid_level = false
  299.                 if (Controls_check(pad,KEY_Y)) then
  300.                     level_select = math.max(0,level_select-1)
  301.                 elseif not (Controls_check(oldpad,KEY_DLEFT)) then
  302.                     level_select = math.max(0,level_select-1)
  303.                 end
  304.             end
  305.             if (Controls_check(pad,KEY_DRIGHT)) then
  306.                 invalid_level = false
  307.                 if (Controls_check(pad,KEY_Y)) then
  308.                     level_select = level_select + 1
  309.                 elseif not (Controls_check(oldpad,KEY_DRIGHT)) then
  310.                     level_select = level_select + 1
  311.                 end
  312.             end
  313.             Graphics_drawPartialImage(50,120, 0,16, 103,16, img_menubutton_level, c_white)
  314.         else Graphics_drawPartialImage(50,120, 0,0, 103,16, img_menubutton_level, c_white) end
  315.         gpu_drawtext(180,122, tostring(level_select))
  316.         if invalid_level then
  317.             Graphics_drawImage(180, 140,img_menu_invalid)
  318.         end
  319.        
  320.         --options
  321.         if menu_selector == 3 then Graphics_drawPartialImage(50,145, 0,16, 103,16, img_menubutton_option, c_white)
  322.         else Graphics_drawPartialImage(50,145, 0,0, 103,16, img_menubutton_option, c_white) end
  323.         --exit
  324.         if menu_selector == 4 then Graphics_drawPartialImage(50,170, 0,16, 103,16, img_menubutton_exit, c_white)
  325.         else Graphics_drawPartialImage(50,170, 0,0, 103,16, img_menubutton_exit, c_white) end
  326.        
  327.         Graphics_termBlend()
  328.        
  329.     else --GAMEPLAY \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  330.         --player controls
  331.         if player_alive==true then
  332.             player_speed = 4
  333.             if beam_id > 0 then player_speed = 2 end
  334.             if (Controls_check(pad,KEY_R)) then
  335.                 player_speed = player_speed/2
  336.             end
  337.             if (Controls_check(pad,KEY_DUP)) and player_alive==true then
  338.                 player_y = math.max(10,player_y - player_speed)
  339.             end
  340.             if (Controls_check(pad,KEY_DDOWN)) and player_alive==true then
  341.                 player_y = math.min(230,player_y + player_speed)
  342.             end
  343.             if (Controls_check(pad,KEY_DLEFT)) and player_alive==true then
  344.                 player_x = math.max(10,player_x - player_speed)
  345.             end
  346.             if (Controls_check(pad,KEY_DRIGHT)) and player_alive==true then
  347.                 player_x = math.min(390,player_x + player_speed)
  348.             end
  349.             if (Controls_check(pad,KEY_Y)) then --show controls on bottom screen?
  350.                 if weapon == 1 then
  351.                     if player_shot > 6 then
  352.                         player_shot = 0
  353.                         object_create(player_x, player_y, 'shot01', img_shot01, shotlist, 180) -- x-3 y-8
  354.                     end
  355.                 elseif weapon == 2 then
  356.                     if player_shot > 16 then
  357.                         player_shot = 0
  358.                         object_create(player_x, player_y, 'shot02', img_shot02, shotlist, 180)
  359.                     end
  360.                 elseif weapon == 3 then
  361.                     if player_shot > 20 then
  362.                         player_shot = 0
  363.                         object_create(player_x, player_y, 'shot03', img_shot03, shotlist, 180)
  364.                     end
  365.                 elseif weapon == 4 then
  366.                     if player_shot > 10 and player_shot < 100000 then
  367.                         player_shot = 100000
  368.                         beam_id = object_create(player_x, player_y, 'shot04', img_shot04, shotlist, 180)
  369.                     end
  370.                 elseif weapon == 5 then
  371.                     if player_shot > 18 then
  372.                         player_shot = 0
  373.                         object_create(player_x, player_y, 'shot05', img_shot05, shotlist, 180)
  374.                     end
  375.                 end
  376.             elseif Controls_check(oldpad,KEY_Y) then --Y was recently released
  377.                 if weapon == 4 and beam_id > -1 then
  378.                     player_shot = 0
  379.                     object_destroy(shotlist, beam_id)
  380.                     beam_id = -1
  381.                 end
  382.             end
  383.             if (Controls_check(pad,KEY_X)) and not (Controls_check(oldpad,KEY_X)) and beam_id < 0 then
  384.                 weapon = weapon + 1
  385.                 if weapon > 5 then weapon = 1 end
  386.             end
  387.         end
  388.         player_shot = player_shot + 1
  389.        
  390.         Graphics_initBlend(TOP_SCREEN) --\\\\\
  391.        
  392.         Graphics_drawImage(0, 0, img_bg_game)
  393.         --OBJECT EVENT LIST \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  394.         --enemy actions
  395.         local i = 0
  396.         while i<enemylist.size do
  397.             local id = ds_list_find_value(enemylist, i)
  398.             local t = obj.type[id]
  399.             local ox = obj.x[id]
  400.             local oy = obj.y[id]
  401.                
  402.             if t == 'en01' then --enemy ship 1 (targeter)
  403.                 if obj.target[id] > 0 then
  404.                     obj.y[id] = oy + (math.cos(math.rad(obj.dir[id]))*2)
  405.                     obj.x[id] = ox + (math.sin(math.rad(obj.dir[id]))*2)
  406.                     obj.target[id] = obj.target[id] - 2
  407.                 end                
  408.                 Graphics_drawImage(obj.x[id]-6, obj.y[id]-6, img_en01)
  409.                 obj.clock[id] = obj.clock[id] + 1
  410.                 if obj.clock[id] > 100 then
  411.                     obj.clock[id] = 0
  412.                     object_create(ox, oy+4, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y))
  413.                     if difficulty > 5 then
  414.                         object_create(ox, oy+4, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)+(30 - difficulty))
  415.                         object_create(ox, oy+4, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)-(30 - difficulty))
  416.                     end
  417.                     if difficulty > 10 then
  418.                         object_create(ox, oy+4, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)+2*(30 - difficulty))
  419.                         object_create(ox, oy+4, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)-2*(30 - difficulty))
  420.                     end
  421.                 end
  422.             elseif t == 'en02' then --enemy ship 2 (bomber)
  423.                 if obj.target[id] > 0 then
  424.                     obj.y[id] = oy + (math.cos(math.rad(obj.dir[id]))*2)
  425.                     obj.x[id] = ox + (math.sin(math.rad(obj.dir[id]))*2)
  426.                     obj.target[id] = obj.target[id] - 2
  427.                 end
  428.                 Graphics_drawImage(ox-6, oy-7, img_en02)
  429.                 obj.clock[id] = obj.clock[id] + 1
  430.                 if obj.clock[id] > 128 then
  431.                     obj.clock[id] = difficulty*5
  432.                     object_create(ox, oy, 'b02', img_bullet02, bulletlist, 180)
  433.                 end
  434.             elseif t == 'en03' then --enemy ship 3 (strafer)
  435.                 obj.y[id] = oy + (math.cos(math.rad(obj.dir[id]))*0.5)
  436.                 obj.x[id] = ox + (math.sin(math.rad(obj.dir[id]))*0.5)
  437.                 Graphics_drawImage(ox-10, oy-4, img_en03)
  438.                 obj.clock[id] = obj.clock[id] + 1
  439.                 if obj.clock[id] > 20 then
  440.                     obj.clock[id] = difficulty/3
  441.                     object_create(ox, oy, 'b03', img_bullet03, bulletlist, 180)
  442.                 end
  443.                 obj.target[id] = obj.target[id] - 1
  444.                 if obj.target[id] < 0 then
  445.                     if not onscreen(ox,oy) then
  446.                         object_destroy(enemylist, id)
  447.                     end
  448.                 end
  449.             elseif t == 'bo01' then --boss 01
  450.                 local bhp = obj.hp[id]
  451.                 if obj.target[id] > 0 then
  452.                     obj.y[id] = oy + 0.25
  453.                     obj.target[id] = obj.target[id] - 0.25
  454.                     if obj.target[id] < 0.25 then
  455.                         obj.hp[id] = stage_boss_hp
  456.                     end
  457.                 else
  458.                     obj.clock[id] = obj.clock[id] + 1 --clock doesn't tick if boss isn't onscreen
  459.                 end
  460.                
  461.                 Graphics_drawImage(ox-29, oy-16, img_boss01)
  462.                 if bhp > 0.66*stage_boss_hp then
  463.                     if obj.clock[id] == 35 then
  464.                         object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y))
  465.                         object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)+(25 - difficulty))
  466.                         object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)-(25 - difficulty))
  467.                         object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)+2*(25 - difficulty))
  468.                         object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)-2*(25 - difficulty))
  469.                         if difficulty > 5 then
  470.                             object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)+3*(25 - difficulty))
  471.                             object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)-3*(25 - difficulty))
  472.                         end
  473.                         if difficulty > 10 then
  474.                             object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)+4*(25 - difficulty))
  475.                             object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)-4*(25 - difficulty))
  476.                         end
  477.                     elseif obj.clock[id] == 70 then
  478.                         object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)+0.5*(25 - difficulty))
  479.                         object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)-0.5*(25 - difficulty))
  480.                         object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)+1.5*(25 - difficulty))
  481.                         object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)-1.5*(25 - difficulty))
  482.                         if difficulty > 5 then
  483.                             object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)+2.5*(25 - difficulty))
  484.                             object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)-2.5*(25 - difficulty))
  485.                         end
  486.                         if difficulty > 10 then
  487.                             object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)+3.5*(25 - difficulty))
  488.                             object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)-3.5*(25 - difficulty))
  489.                         end
  490.                     elseif obj.clock[id] > 70 then
  491.                         obj.clock[id] = 1
  492.                     end
  493.                    
  494.                 elseif bhp > 0.33*stage_boss_hp then
  495.                     if obj.clock[id] == 50 then
  496.                         local o=0 --please replace the following with a while statement and an incrementally increasing i, for the love of god
  497.                         o=object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)+6*(22 - difficulty)); obj.hp[o]=-0.5
  498.                         o=object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)+4*(22 - difficulty)); obj.hp[o]=-0.5
  499.                         o=object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)+2*(22 - difficulty)); obj.hp[o]=-0.5
  500.                         o=object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)-0*(22 - difficulty)); obj.hp[o]=-0.5
  501.                         o=object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)-2*(22 - difficulty)); obj.hp[o]=-0.5
  502.                         o=object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)-4*(22 - difficulty)); obj.hp[o]=-0.5
  503.                         o=object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)-6*(22 - difficulty)); obj.hp[o]=-0.5
  504.                         o=object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)-8*(22 - difficulty)); obj.hp[o]=-0.5
  505.                         if difficulty > 3 then
  506.                             object_create(ox-18, oy, 'b02', img_bullet02, bulletlist, 0);
  507.                         end
  508.                     elseif obj.clock[id] ==100 then
  509.                         local o=0
  510.                         o=object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)-6*(25 - difficulty)); obj.hp[o]=0.5
  511.                         o=object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)-4*(25 - difficulty)); obj.hp[o]=0.5
  512.                         o=object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)-2*(25 - difficulty)); obj.hp[o]=0.5
  513.                         o=object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)+0*(25 - difficulty)); obj.hp[o]=0.5
  514.                         o=object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)+2*(25 - difficulty)); obj.hp[o]=0.5
  515.                         o=object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)+4*(25 - difficulty)); obj.hp[o]=0.5
  516.                         o=object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)+6*(25 - difficulty)); obj.hp[o]=0.5
  517.                         o=object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)+8*(25 - difficulty)); obj.hp[o]=0.5
  518.                         if difficulty > 3 then
  519.                             object_create(ox+18, oy, 'b02', img_bullet02, bulletlist, 0);
  520.                         end
  521.                     elseif obj.clock[id] >100 then
  522.                         obj.clock[id] = 1
  523.                     end
  524.                    
  525.                 else
  526.                     local cl = obj.clock[id]
  527.                     local sw = 45+difficulty*3 --point at which the rotation direction "switches"
  528.                     local ang = 0.1+(difficulty>>7)
  529.                     if ang*cl < sw then
  530.                         if cl % (15 - math.floor(difficulty/5)) == 0 then
  531.                             object_create(ox, oy, 'b01', img_bullet01, bulletlist, ang*cl)
  532.                             object_create(ox, oy, 'b01', img_bullet01, bulletlist, ang*cl+60)
  533.                             object_create(ox, oy, 'b01', img_bullet01, bulletlist, ang*cl+120)
  534.                             object_create(ox, oy, 'b01', img_bullet01, bulletlist, ang*cl+180)
  535.                             object_create(ox, oy, 'b01', img_bullet01, bulletlist, ang*cl+240)
  536.                             object_create(ox, oy, 'b01', img_bullet01, bulletlist, ang*cl+300)
  537.                         end
  538.                     else
  539.                         if cl % (15 - math.floor(difficulty/5)) == 0 then
  540.                             object_create(ox, oy, 'b01', img_bullet01, bulletlist, 2*sw - ang*cl)
  541.                             object_create(ox, oy, 'b01', img_bullet01, bulletlist, 2*sw - ang*cl +60)
  542.                             object_create(ox, oy, 'b01', img_bullet01, bulletlist, 2*sw - ang*cl +120)
  543.                             object_create(ox, oy, 'b01', img_bullet01, bulletlist, 2*sw - ang*cl +180)
  544.                             object_create(ox, oy, 'b01', img_bullet01, bulletlist, 2*sw - ang*cl +240)
  545.                             object_create(ox, oy, 'b01', img_bullet01, bulletlist, 2*sw - ang*cl +300)
  546.                         end
  547.                         if ang*cl == 2*sw then
  548.                             obj.clock[id] = 0
  549.                         end
  550.                     end
  551.                 end
  552.                
  553.             end
  554.            
  555.             i = i+1
  556.         end
  557.        
  558.         --enemy bullets
  559.         local i = 0
  560.         while i<bulletlist.size do
  561.             local id = ds_list_find_value(bulletlist, i)
  562.             local t = obj.type[id]
  563.             local ox = obj.x[id]
  564.             local oy = obj.y[id]
  565.             if t == 'b01' then
  566.                 if not onscreen(ox,oy) then
  567.                     object_destroy(bulletlist, id)
  568.                 else
  569.                     obj.y[id] = obj.y[id] + (math.cos(math.rad(obj.dir[id]))*2)
  570.                     obj.x[id] = obj.x[id] + (math.sin(math.rad(obj.dir[id]))*2)
  571.                     Graphics_drawImage(obj.x[id]-1, obj.y[id]-1, img_bullet01)
  572.                     obj.dir[id] = obj.dir[id] + obj.hp[id] --b01 bullets can have a "spin" applied to them
  573.                     --collision check
  574.                     local px = player_x
  575.                     local py = player_y
  576.                     if ox<px+3 and ox>px-3 and oy<py+3 and oy>py-3 then
  577.                         object_destroy(bulletlist, id)
  578.                         player_alive = false
  579.                     end
  580.                 end
  581.             elseif t == 'b02' then
  582.                 if not onscreen(ox,oy) then
  583.                     object_destroy(bulletlist, id)
  584.                 else
  585.                     obj.y[id] = obj.y[id] + 1
  586.                     Graphics_drawImage(obj.x[id]-1, obj.y[id]-5, img_bullet02)
  587.                     --collision check (also, make this bullet explode into more)
  588.                     local px = player_x
  589.                     local py = player_y
  590.                     if ox<px+3 and ox>px-3 and oy<py+6 and oy>py-6 then
  591.                         object_destroy(bulletlist, id)
  592.                         player_alive = false
  593.                     end
  594.                 end
  595.             elseif t == 'b03' then
  596.                 if not onscreen(ox,oy) then
  597.                     object_destroy(bulletlist, id)
  598.                 else
  599.                     obj.y[id] = obj.y[id] +1.5+(difficulty>>3)
  600.                     Graphics_drawImage(obj.x[id]-4, obj.y[id]-3, img_bullet03)
  601.                     --collision check
  602.                     local px = player_x
  603.                     local py = player_y
  604.                     if ox<px+5 and ox>px-5 and oy<py+4 and oy>py-4 then
  605.                         object_destroy(bulletlist, id)
  606.                         player_alive = false
  607.                     end
  608.                 end
  609.             elseif t == 'b04' then
  610.                
  611.             end
  612.             i = i+1
  613.         end
  614.        
  615.         --friendly bullets
  616.         local i = 0
  617.         while i<shotlist.size do
  618.             local id = ds_list_find_value(shotlist, i)
  619.             local t = obj.type[id]
  620.             local ox = obj.x[id]
  621.             local oy = obj.y[id]
  622.             local shotw = 0
  623.             local shoth = 0
  624.             local speed = 0
  625.             local power = 0
  626.             local graph = img_shot01
  627.             if t=='shot01' then
  628.                 shotw = 9; shoth = 3; speed = 8; power = 4; graph = img_shot01
  629.             elseif t=='shot02' then
  630.                 shotw = 23; shoth = 6; speed = obj.clock[id]/8; power = 12; graph = img_shot02
  631.                 obj.clock[id]=obj.clock[id]+1
  632.             elseif t=='shot03' then
  633.                 shotw = 9; shoth = 9; speed = 4; power = 8; graph = img_shot03
  634.             elseif t=='shot04' then
  635.                 shotw = 9; shoth = 480; speed = 0; power = 0.3; graph = img_shot04
  636.                 ox = player_x
  637.                 oy = player_y - 10
  638.             elseif t=='shot05' then
  639.                 shotw = 5; shoth = 5; speed = 5; power = 3; graph = img_shot05
  640.             end
  641.            
  642.             obj.y[id] = oy + (math.cos(math.rad(obj.dir[id]))*speed)
  643.             obj.x[id] = ox + (math.sin(math.rad(obj.dir[id]))*speed)
  644.            
  645.             if not onscreen(ox,oy) then --once the ship is prevented from leaving bounds, you can remove the latter part of this check
  646.                 object_destroy(shotlist, id)
  647.             else
  648.                 --collision check
  649.                 local j=0
  650.                 local range=400; local target=-1; --tracer variables
  651.                 while j<enemylist.size do
  652.                     local idc = ds_list_find_value(enemylist, j)
  653.                     local tx=obj.x[idc]
  654.                     local ty=obj.y[idc]
  655.                     if t=='shot05' then --tracer calculations
  656.                         local nr = math.sqrt((tx-ox)^2 + (ty-oy)^2)
  657.                         if range > nr then
  658.                             range = nr
  659.                             target = idc
  660.                         end
  661.                     end
  662.                     if ox<tx+8+(shotw/2) and ox>tx-8-(shotw/2) and oy<ty+8+(shoth/2) and oy>ty-8-(shoth/2) then
  663.                         obj.hp[idc] = obj.hp[idc] - power
  664.                         if obj.hp[idc] < 1 then
  665.                             local dty = obj.type[idc]
  666.                             if dty == 'en01' or dty == 'en02' or dty == 'en03' then
  667.                                 object_create(tx, ty, 'end', img_en_death, fxlist)
  668.                             elseif dty == 'bo01' then
  669.                                 object_create(tx, ty, 'bod', img_boss_death, fxlist)
  670.                             end
  671.                             object_destroy(enemylist, idc)
  672.                         end
  673.                         if t~='shot04' then --beam continues to hit, so we don't delete it yet unlike other bullets
  674.                             object_destroy(shotlist, id)
  675.                             target = -1
  676.                             j=enemylist.size
  677.                         end
  678.                     end
  679.                     j=j+1
  680.                 end
  681.                 if target>0 then --turning to face a close target
  682.                     local ang = angle(ox,oy, obj.x[target], obj.y[target])
  683.                     local fac = obj.dir[id]
  684.                     local off = ((ang-fac+180)%360)-180
  685.                     obj.dir[id]=obj.dir[id] + (off / math.abs(off))
  686.                 end
  687.                    
  688.                 Graphics_drawImage(math.floor(ox-shotw/2), math.floor(oy-shoth/2), graph)
  689.                 --end collision check
  690.             end
  691.             i = i+1
  692.         end
  693.         --effects handling
  694.         local i = 0
  695.         while i<fxlist.size do
  696.             local id = ds_list_find_value(fxlist, i)
  697.             local g = obj.graphic[id]
  698.             local t = obj.type[id]
  699.             local ox = obj.x[id]
  700.             local oy = obj.y[id]
  701.             local cl = obj.clock[id]
  702.             local fxw = 0
  703.             local fyh = 0
  704.             if t== 'end' then fxw = 11; fyh = 11;
  705.             elseif t=='bod' then fxw=49; fyh= 19; end
  706.            
  707.             Graphics_drawPartialImage(math.floor(ox-fxw/2), math.floor(oy-fyh/2), math.floor(cl)*fxw, 0, fxw,fyh, g)
  708.             if cl>6 then
  709.                 object_destroy(fxlist, id)
  710.             else
  711.                 obj.clock[id] = cl + 0.125
  712.             end
  713.             i=i+1
  714.         end
  715.        
  716.         --reading data from level array
  717.         local morespawn = true
  718.         while morespawn == true do
  719.             if larray.time[spawnindex] == nil then
  720.                 morespawn = false
  721.                 stage_clear = 0
  722.             elseif (larray.time[spawnindex] < timer) then
  723.                 local ty = larray.enid[spawnindex]
  724.                 local D = larray.dir[spawnindex]
  725.                 local P = larray.pix[spawnindex]
  726.                
  727.                 local nx =0
  728.                 local ny =0
  729.                 local dmov=0
  730.                
  731.                 if D == "T" then
  732.                     nx = P
  733.                     ny = -30
  734.                     dmov = 0
  735.                 else
  736.                     ny = P
  737.                     if D == "L" then
  738.                         nx = -30
  739.                         dmov = 90
  740.                     else
  741.                         nx = 430
  742.                         dmov = 270
  743.                     end
  744.                 end
  745.                
  746.                 local img_ = -1
  747.                 local hp_ = -1
  748.                 local targ_ = -1
  749.                 local spawn_ = -1
  750.                
  751.                 if ty == 'en01' then
  752.                     img_ = img_en01
  753.                     hp_ = 6
  754.                     targ_ = 60
  755.                     spawn_ = 1
  756.                 elseif ty == 'en02' then
  757.                     img_ = img_en02
  758.                     hp_ = 14
  759.                     targ_ = 60
  760.                     spawn_ = 1
  761.                 elseif ty == 'en03' then
  762.                     img_ = img_en03
  763.                     hp_ = 10
  764.                     targ_ = 60
  765.                     spawn_ = 1
  766.                 elseif ty == 'bo01' then
  767.                     stage_boss = ty
  768.                     stage_boss_hp = 300
  769.                     warning_flash = 1
  770.                 end
  771.                
  772.                 if spawn_ == 1 then
  773.                     local o = object_create(nx, ny, ty, img_, enemylist, dmov)
  774.                     obj.hp[o] = hp_
  775.                     obj.target[o] = targ_
  776.                 end
  777.                
  778.                 spawnindex = spawnindex + 1
  779.             else
  780.                 morespawn = false
  781.             end
  782.         end
  783.        
  784.         --player sprite and death animation
  785.         if player_alive == true then
  786.             Graphics_drawImage(math.floor(player_x-11.5), math.floor(player_y-9), img_ship01)
  787.         elseif player_death < 4 then
  788.             Graphics_drawPartialImage(math.floor(player_x-16.5), math.floor(player_y-16.5), math.floor(player_death)*33, 0, 33,33, img_ship_death)
  789.             player_death = player_death + 0.125
  790.         end
  791.        
  792.         if warning_flash > 0 then
  793.             warning_flash = warning_flash + 1
  794.             if warning_flash % 30 > 8 then
  795.                 Graphics_drawImage(174, 115, img_warning)
  796.             end
  797.             if warning_flash > 120 then
  798.                 warning_flash = 0
  799.                 local o = object_create(200, -100, 'bo01', img_boss01, enemylist, 0)
  800.                 obj.hp[o] = 9999
  801.                 obj.target[o] = 150
  802.             end
  803.         end
  804.        
  805.         if stage_clear == 0 then
  806.             if enemylist.size < 1 then
  807.                 stage_clear = 1
  808.             end
  809.         elseif stage_clear == 1 then
  810.             Graphics_drawImage(161, 112, img_clear)
  811.         end
  812.        
  813.         timer = timer + 1
  814.         Graphics_termBlend()
  815.        
  816.         if (Controls_check(pad,KEY_START)) and not (Controls_check(oldpad,KEY_START)) then
  817.             menu_init()
  818.         end
  819.     end
  820.    
  821.     Screen_flip()
  822.     oldpad = pad
  823. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement