Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- System.setCpuSpeed(804)
- Graphics.init()
- -- Patch for latest lpp-3ds commit
- System.currentDirectory(string.sub(System.currentDirectory(),1,-2))
- local appdir = System.currentDirectory()..'/rsrc'
- local scrdir = System.currentDirectory()..'/screenshots'
- local lvldir = System.currentDirectory()..'/levels'
- local c_white = Color.new(255,255,255)
- local c_light = Color.new(178,216,255)
- -- Localize all most used functions and variables so they will be accessed faster
- local Screen_waitVblankStart = Screen.waitVblankStart
- local Graphics_drawImage = Graphics.drawImage
- local TOP_SCREEN = TOP_SCREEN
- local Screen_flip = Screen.flip
- local Graphics_drawPartialImage = Graphics.drawPartialImage
- local Graphics_drawLine = Graphics.drawLine
- local Graphics_initBlend = Graphics.initBlend
- local Graphics_termBlend = Graphics.termBlend
- local Controls_read = Controls.read
- local Controls_check = Controls.check
- local Controls_readTouch = Controls.readTouch
- local KEY_A = KEY_A
- local KEY_X = KEY_X
- local KEY_Y = KEY_Y
- local KEY_R = KEY_R
- local KEY_START = KEY_START
- local KEY_SELECT = KEY_SELECT
- Screen_waitVblankStart()
- Graphics_initBlend(TOP_SCREEN)
- img_bg_load = Graphics.loadImage(appdir..'/bg_load.png')
- Graphics_drawImage(0, 0, img_bg_load)
- Graphics_termBlend()
- Screen_flip()
- local i=0
- local load_filevariable = {}
- local load_filepath = {}
- i=i+1; load_filevariable[i]='img_ship01'; load_filepath[i] = '/ship01.png'
- i=i+1; load_filevariable[i]='img_ship_death'; load_filepath[i] = '/ship_death.png'
- i=i+1; load_filevariable[i]='img_en_death'; load_filepath[i] = '/en_death.png'
- i=i+1; load_filevariable[i]='img_boss_death'; load_filepath[i] = '/boss_death.png'
- i=i+1; load_filevariable[i]='img_en01'; load_filepath[i] = '/en01.png'
- i=i+1; load_filevariable[i]='img_en02'; load_filepath[i] = '/en02.png'
- i=i+1; load_filevariable[i]='img_en03'; load_filepath[i] = '/en03.png'
- i=i+1; load_filevariable[i]='img_en04'; load_filepath[i] = '/en04.png'
- i=i+1; load_filevariable[i]='img_en05'; load_filepath[i] = '/en05.png'
- i=i+1; load_filevariable[i]='img_boss01'; load_filepath[i] = '/boss01.png'
- i=i+1; load_filevariable[i]='img_boss02'; load_filepath[i] = '/boss02.png'
- i=i+1; load_filevariable[i]='img_bullet01'; load_filepath[i] = '/bullet01.png'
- i=i+1; load_filevariable[i]='img_bullet02'; load_filepath[i] = '/bullet02.png'
- i=i+1; load_filevariable[i]='img_bullet03'; load_filepath[i] = '/bullet03.png'
- i=i+1; load_filevariable[i]='img_bullet04'; load_filepath[i] = '/bullet04.png'
- i=i+1; load_filevariable[i]='img_bullet05'; load_filepath[i] = '/bullet05.png'
- i=i+1; load_filevariable[i]='img_shot01'; load_filepath[i] = '/shot01.png'
- i=i+1; load_filevariable[i]='img_shot02'; load_filepath[i] = '/shot02.png'
- i=i+1; load_filevariable[i]='img_shot03'; load_filepath[i] = '/shot03.png'
- i=i+1; load_filevariable[i]='img_shot04'; load_filepath[i] = '/shot04.png'
- i=i+1; load_filevariable[i]='img_shot05'; load_filepath[i] = '/shot05.png'
- i=i+1; load_filevariable[i]='img_bg_menu'; load_filepath[i] = '/bg_menu.png'
- i=i+1; load_filevariable[i]='img_bg_game'; load_filepath[i] = '/bg_game.png'
- i=i+1; load_filevariable[i]='img_menubutton_play'; load_filepath[i] = '/menubutton_play.png'
- i=i+1; load_filevariable[i]='img_menubutton_diff'; load_filepath[i] = '/menubutton_diff.png'
- i=i+1; load_filevariable[i]='img_menubutton_level'; load_filepath[i] = '/menubutton_level.png'
- i=i+1; load_filevariable[i]='img_menubutton_option'; load_filepath[i] = '/menubutton_option.png'
- i=i+1; load_filevariable[i]='img_menubutton_exit'; load_filepath[i] = '/menubutton_exit.png'
- i=i+1; load_filevariable[i]='img_diff_meter'; load_filepath[i] = '/diff_meter.png'
- i=i+1; load_filevariable[i]='img_diff_meter_pip'; load_filepath[i] = '/diff_meter_pip.png'
- i=i+1; load_filevariable[i]='img_menu_invalid'; load_filepath[i] = '/menu_invalid.png'
- i=i+1; load_filevariable[i]='img_warning'; load_filepath[i] = '/warning.png'
- i=i+1; load_filevariable[i]='img_clear'; load_filepath[i] = '/clear.png'
- i=i+1; load_filevariable[i]='img_font_numbers'; load_filepath[i] = '/font_numbers.png'
- load_filecount = i+1
- local i=0
- local c_line = c_light
- while i<load_filecount do --load them one by one on each frame of the loading screen
- if load_filevariable[i] ~= nil then
- if System.doesFileExist(appdir..load_filepath[i]) then
- _G[load_filevariable[i]] = Graphics.loadImage(appdir..load_filepath[i])
- else
- c_line = Color.new(255,0,0)
- end
- end
- i=i+1
- Screen_waitVblankStart()
- Graphics_initBlend(TOP_SCREEN)
- Graphics_drawImage(0, 0, img_bg_load)
- Graphics_drawLine(163, 163+math.ceil(i/load_filecount*76), 175, 175, c_line)
- Graphics_termBlend()
- Screen_flip()
- end
- glyph_l = {}
- glyph_r = {}
- glyph_w = {}
- function g_init(char, l, r)
- glyph_l[char] = l
- glyph_r[char] = r
- glyph_w[char] = r-l+1
- end
- g_init('0',1,8)
- g_init('1',9,16)
- g_init('2',17,25)
- g_init('3',25,32)
- g_init('4',33,40)
- g_init('5',41,48)
- g_init('6',49,56)
- g_init('7',57,64)
- g_init('8',65,72)
- g_init('9',73,80)
- --remember to blend the gpu to what screen you want before calling this function, and termblend afterwards
- function gpu_drawtext(x, y, text)
- 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)
- local i_str=0 --the current position in the string
- local i_chr='' --the current character in the string
- local str_width = 0 --width in pixels of the string
- local str_length = string.len(text)
- local cw --character width
- while i_str < str_length do
- i_str = i_str + 1
- i_chr = string.sub(text_u, i_str, i_str)
- cw = glyph_w[i_chr]
- if cw ~= nil then --as long as the character exists
- Graphics_drawPartialImage(x+str_width, y, glyph_l[i_chr], 1, cw, 14, img_font_numbers)
- str_width = str_width + cw + 2
- end
- end
- end
- dofile(appdir..'/ds_list_init.lua')
- dofile(appdir..'/ds_queue_init.lua')
- dofile(appdir..'/object.lua')
- function loadlevel(num)
- local f = io.open(lvldir.."/level"..num..".dat",FREAD)
- local filesize = io.size(f)
- local str = io.read(f,0,filesize)
- io.close(f)
- --"|T-######|enemy|direction|px|"
- local i = 0
- local a = string.find(str, "|T-",1,true) --find the first new line
- local v = string.sub(str, 1, 4) --obtain version
- if v ~= "v001" then
- a=nil
- return true;
- else
- while a~=nil do --as long as there's more newlines
- local t = tonumber(string.sub(str, a+3, a+8)) --the six characters after T- is the time
- local en = string.sub(str, a+10, a+13) --enemy id
- local d = string.sub(str, a+15, a+15) --direction the enemy is coming from (T, L, R)
- local px = tonumber(string.sub(str, a+17, a+19))
- larray.time[i] = t
- larray.enid[i] = en
- larray.dir[i] = d
- larray.pix[i] = px
- i = i+1
- a = string.find(str, "|T-",a+5,true)
- end
- end
- end
- function onscreen(x,y)
- if x>-5 and x<405 and y>-5 and y<405 then
- return true
- else
- return false
- end
- end
- larray = {}
- larray.time = {}
- larray.enid = {}
- larray.dir = {}
- larray.pix = {}
- function menu_init()
- menu = true
- menu_selector = 0
- invalid_level = false
- if game_started == true then
- while bulletlist.size>0 do ds_list_delete(bulletlist,0) end
- while shotlist.size>0 do ds_list_delete(shotlist,0) end
- while enemylist.size>0 do ds_list_delete(enemylist,0) end
- else
- difficulty = 1
- level_select = 1
- end
- end
- function game_init()
- if loadlevel(level_select) == true then --failed to load level because version mismatch
- menu = true
- invalid_level = true
- else
- difficulty = math.floor(difficulty)
- game_started = true
- beam_id = -1
- weapon = 1
- player_x = 200
- player_y = 200
- player_shot = 0
- player_speed = 1
- player_alive = true
- player_death = 0
- timer = 0
- spawnindex = 0
- warning_flash = 0
- stage_boss = ''
- stage_clear = -1
- end
- end
- function angle(x1,y1,x2,y2)
- local rise = y2-y1
- local run = x2-x1
- local a = math.atan(run,rise)
- return math.deg(a)%360
- end
- pad = Controls_read()
- oldpad = pad
- menu_init()
- while true do
- Screen_waitVblankStart()
- pad = Controls_read()
- tx_old,ty_old = tx,ty
- tx,ty = Controls_readTouch()
- if (Controls_check(pad,KEY_SELECT)) and not (Controls_check(oldpad,KEY_SELECT)) then
- local i=0
- while i<50 do
- if System.doesFileExist(scrdir.."/screenshot"..i..".png") then
- i=i+1
- else
- System.takeScreenshot(scrdir.."/screenshot"..i..".png",false)
- break;
- end
- end
- end
- if menu == true then --MENU SCREEN \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
- if (Controls_check(pad,KEY_DUP)) and not (Controls_check(oldpad,KEY_DUP)) then
- menu_selector = math.max(0,menu_selector-1)
- end
- if (Controls_check(pad,KEY_DDOWN)) and not (Controls_check(oldpad,KEY_DDOWN)) then
- menu_selector = math.min(4,menu_selector+1)
- end
- Graphics_initBlend(TOP_SCREEN)
- Graphics_drawImage(0, 0, img_bg_menu) --PLAY BUTTON
- if menu_selector == 0 then
- Graphics_drawPartialImage(50,70, 0,16, 103,16, img_menubutton_play, c_white)
- if (Controls_check(pad,KEY_A)) and not (Controls_check(oldpad,KEY_A)) then
- if System.doesFileExist(lvldir.."/level"..level_select..".dat") then
- menu = false
- game_init()
- else
- invalid_level = true
- end
- end
- else Graphics_drawPartialImage(50,70, 0,0, 103,16, img_menubutton_play, c_white) end
- if menu_selector == 1 then --DIFFICULTY SELECTION
- if (Controls_check(pad,KEY_DLEFT)) then
- difficulty = math.max(1,difficulty-0.125)
- end
- if (Controls_check(pad,KEY_DRIGHT)) then
- difficulty = math.min(16,difficulty+0.125)
- end
- Graphics_drawPartialImage(50,95, 0,16, 103,16, img_menubutton_diff, c_white)
- else Graphics_drawPartialImage(50,95, 0,0, 103,16, img_menubutton_diff, c_white) end
- Graphics_drawImage(180, 95, img_diff_meter)
- Graphics_drawPartialImage(180,95, 0,0, 6+(4*math.floor(difficulty)),16, img_diff_meter_pip)
- if menu_selector == 2 then --LEVEL SELECTION
- if (Controls_check(pad,KEY_DLEFT)) then
- invalid_level = false
- if (Controls_check(pad,KEY_Y)) then
- level_select = math.max(0,level_select-1)
- elseif not (Controls_check(oldpad,KEY_DLEFT)) then
- level_select = math.max(0,level_select-1)
- end
- end
- if (Controls_check(pad,KEY_DRIGHT)) then
- invalid_level = false
- if (Controls_check(pad,KEY_Y)) then
- level_select = level_select + 1
- elseif not (Controls_check(oldpad,KEY_DRIGHT)) then
- level_select = level_select + 1
- end
- end
- Graphics_drawPartialImage(50,120, 0,16, 103,16, img_menubutton_level, c_white)
- else Graphics_drawPartialImage(50,120, 0,0, 103,16, img_menubutton_level, c_white) end
- gpu_drawtext(180,122, tostring(level_select))
- if invalid_level then
- Graphics_drawImage(180, 140,img_menu_invalid)
- end
- --options
- if menu_selector == 3 then Graphics_drawPartialImage(50,145, 0,16, 103,16, img_menubutton_option, c_white)
- else Graphics_drawPartialImage(50,145, 0,0, 103,16, img_menubutton_option, c_white) end
- --exit
- if menu_selector == 4 then Graphics_drawPartialImage(50,170, 0,16, 103,16, img_menubutton_exit, c_white)
- else Graphics_drawPartialImage(50,170, 0,0, 103,16, img_menubutton_exit, c_white) end
- Graphics_termBlend()
- else --GAMEPLAY \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
- --player controls
- if player_alive==true then
- player_speed = 4
- if beam_id > 0 then player_speed = 2 end
- if (Controls_check(pad,KEY_R)) then
- player_speed = player_speed/2
- end
- if (Controls_check(pad,KEY_DUP)) and player_alive==true then
- player_y = math.max(10,player_y - player_speed)
- end
- if (Controls_check(pad,KEY_DDOWN)) and player_alive==true then
- player_y = math.min(230,player_y + player_speed)
- end
- if (Controls_check(pad,KEY_DLEFT)) and player_alive==true then
- player_x = math.max(10,player_x - player_speed)
- end
- if (Controls_check(pad,KEY_DRIGHT)) and player_alive==true then
- player_x = math.min(390,player_x + player_speed)
- end
- if (Controls_check(pad,KEY_Y)) then --show controls on bottom screen?
- if weapon == 1 then
- if player_shot > 6 then
- player_shot = 0
- object_create(player_x, player_y, 'shot01', img_shot01, shotlist, 180) -- x-3 y-8
- end
- elseif weapon == 2 then
- if player_shot > 16 then
- player_shot = 0
- object_create(player_x, player_y, 'shot02', img_shot02, shotlist, 180)
- end
- elseif weapon == 3 then
- if player_shot > 20 then
- player_shot = 0
- object_create(player_x, player_y, 'shot03', img_shot03, shotlist, 180)
- end
- elseif weapon == 4 then
- if player_shot > 10 and player_shot < 100000 then
- player_shot = 100000
- beam_id = object_create(player_x, player_y, 'shot04', img_shot04, shotlist, 180)
- end
- elseif weapon == 5 then
- if player_shot > 18 then
- player_shot = 0
- object_create(player_x, player_y, 'shot05', img_shot05, shotlist, 180)
- end
- end
- elseif Controls_check(oldpad,KEY_Y) then --Y was recently released
- if weapon == 4 and beam_id > -1 then
- player_shot = 0
- object_destroy(shotlist, beam_id)
- beam_id = -1
- end
- end
- if (Controls_check(pad,KEY_X)) and not (Controls_check(oldpad,KEY_X)) and beam_id < 0 then
- weapon = weapon + 1
- if weapon > 5 then weapon = 1 end
- end
- end
- player_shot = player_shot + 1
- Graphics_initBlend(TOP_SCREEN) --\\\\\
- Graphics_drawImage(0, 0, img_bg_game)
- --OBJECT EVENT LIST \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
- --enemy actions
- local i = 0
- while i<enemylist.size do
- local id = ds_list_find_value(enemylist, i)
- local t = obj.type[id]
- local ox = obj.x[id]
- local oy = obj.y[id]
- if t == 'en01' then --enemy ship 1 (targeter)
- if obj.target[id] > 0 then
- obj.y[id] = oy + (math.cos(math.rad(obj.dir[id]))*2)
- obj.x[id] = ox + (math.sin(math.rad(obj.dir[id]))*2)
- obj.target[id] = obj.target[id] - 2
- end
- Graphics_drawImage(obj.x[id]-6, obj.y[id]-6, img_en01)
- obj.clock[id] = obj.clock[id] + 1
- if obj.clock[id] > 100 then
- obj.clock[id] = 0
- object_create(ox, oy+4, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y))
- if difficulty > 5 then
- object_create(ox, oy+4, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)+(30 - difficulty))
- object_create(ox, oy+4, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)-(30 - difficulty))
- end
- if difficulty > 10 then
- object_create(ox, oy+4, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)+2*(30 - difficulty))
- object_create(ox, oy+4, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)-2*(30 - difficulty))
- end
- end
- elseif t == 'en02' then --enemy ship 2 (bomber)
- if obj.target[id] > 0 then
- obj.y[id] = oy + (math.cos(math.rad(obj.dir[id]))*2)
- obj.x[id] = ox + (math.sin(math.rad(obj.dir[id]))*2)
- obj.target[id] = obj.target[id] - 2
- end
- Graphics_drawImage(ox-6, oy-7, img_en02)
- obj.clock[id] = obj.clock[id] + 1
- if obj.clock[id] > 128 then
- obj.clock[id] = difficulty*5
- object_create(ox, oy, 'b02', img_bullet02, bulletlist, 180)
- end
- elseif t == 'en03' then --enemy ship 3 (strafer)
- obj.y[id] = oy + (math.cos(math.rad(obj.dir[id]))*0.5)
- obj.x[id] = ox + (math.sin(math.rad(obj.dir[id]))*0.5)
- Graphics_drawImage(ox-10, oy-4, img_en03)
- obj.clock[id] = obj.clock[id] + 1
- if obj.clock[id] > 20 then
- obj.clock[id] = difficulty/3
- object_create(ox, oy, 'b03', img_bullet03, bulletlist, 180)
- end
- obj.target[id] = obj.target[id] - 1
- if obj.target[id] < 0 then
- if not onscreen(ox,oy) then
- object_destroy(enemylist, id)
- end
- end
- elseif t == 'bo01' then --boss 01
- local bhp = obj.hp[id]
- if obj.target[id] > 0 then
- obj.y[id] = oy + 0.25
- obj.target[id] = obj.target[id] - 0.25
- if obj.target[id] < 0.25 then
- obj.hp[id] = stage_boss_hp
- end
- else
- obj.clock[id] = obj.clock[id] + 1 --clock doesn't tick if boss isn't onscreen
- end
- Graphics_drawImage(ox-29, oy-16, img_boss01)
- if bhp > 0.66*stage_boss_hp then
- if obj.clock[id] == 35 then
- object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y))
- object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)+(25 - difficulty))
- object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)-(25 - difficulty))
- object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)+2*(25 - difficulty))
- object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)-2*(25 - difficulty))
- if difficulty > 5 then
- object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)+3*(25 - difficulty))
- object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)-3*(25 - difficulty))
- end
- if difficulty > 10 then
- object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)+4*(25 - difficulty))
- object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)-4*(25 - difficulty))
- end
- elseif obj.clock[id] == 70 then
- object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)+0.5*(25 - difficulty))
- object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)-0.5*(25 - difficulty))
- object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)+1.5*(25 - difficulty))
- object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)-1.5*(25 - difficulty))
- if difficulty > 5 then
- object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)+2.5*(25 - difficulty))
- object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)-2.5*(25 - difficulty))
- end
- if difficulty > 10 then
- object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)+3.5*(25 - difficulty))
- object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)-3.5*(25 - difficulty))
- end
- elseif obj.clock[id] > 70 then
- obj.clock[id] = 1
- end
- elseif bhp > 0.33*stage_boss_hp then
- if obj.clock[id] == 50 then
- local o=0 --please replace the following with a while statement and an incrementally increasing i, for the love of god
- o=object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)+6*(22 - difficulty)); obj.hp[o]=-0.5
- o=object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)+4*(22 - difficulty)); obj.hp[o]=-0.5
- o=object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)+2*(22 - difficulty)); obj.hp[o]=-0.5
- o=object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)-0*(22 - difficulty)); obj.hp[o]=-0.5
- o=object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)-2*(22 - difficulty)); obj.hp[o]=-0.5
- o=object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)-4*(22 - difficulty)); obj.hp[o]=-0.5
- o=object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)-6*(22 - difficulty)); obj.hp[o]=-0.5
- o=object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)-8*(22 - difficulty)); obj.hp[o]=-0.5
- if difficulty > 3 then
- object_create(ox-18, oy, 'b02', img_bullet02, bulletlist, 0);
- end
- elseif obj.clock[id] ==100 then
- local o=0
- o=object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)-6*(25 - difficulty)); obj.hp[o]=0.5
- o=object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)-4*(25 - difficulty)); obj.hp[o]=0.5
- o=object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)-2*(25 - difficulty)); obj.hp[o]=0.5
- o=object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)+0*(25 - difficulty)); obj.hp[o]=0.5
- o=object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)+2*(25 - difficulty)); obj.hp[o]=0.5
- o=object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)+4*(25 - difficulty)); obj.hp[o]=0.5
- o=object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)+6*(25 - difficulty)); obj.hp[o]=0.5
- o=object_create(ox, oy, 'b01', img_bullet01, bulletlist, angle(ox, oy, player_x, player_y)+8*(25 - difficulty)); obj.hp[o]=0.5
- if difficulty > 3 then
- object_create(ox+18, oy, 'b02', img_bullet02, bulletlist, 0);
- end
- elseif obj.clock[id] >100 then
- obj.clock[id] = 1
- end
- else
- local cl = obj.clock[id]
- local sw = 45+difficulty*3 --point at which the rotation direction "switches"
- local ang = 0.1+(difficulty>>7)
- if ang*cl < sw then
- if cl % (15 - math.floor(difficulty/5)) == 0 then
- object_create(ox, oy, 'b01', img_bullet01, bulletlist, ang*cl)
- object_create(ox, oy, 'b01', img_bullet01, bulletlist, ang*cl+60)
- object_create(ox, oy, 'b01', img_bullet01, bulletlist, ang*cl+120)
- object_create(ox, oy, 'b01', img_bullet01, bulletlist, ang*cl+180)
- object_create(ox, oy, 'b01', img_bullet01, bulletlist, ang*cl+240)
- object_create(ox, oy, 'b01', img_bullet01, bulletlist, ang*cl+300)
- end
- else
- if cl % (15 - math.floor(difficulty/5)) == 0 then
- object_create(ox, oy, 'b01', img_bullet01, bulletlist, 2*sw - ang*cl)
- object_create(ox, oy, 'b01', img_bullet01, bulletlist, 2*sw - ang*cl +60)
- object_create(ox, oy, 'b01', img_bullet01, bulletlist, 2*sw - ang*cl +120)
- object_create(ox, oy, 'b01', img_bullet01, bulletlist, 2*sw - ang*cl +180)
- object_create(ox, oy, 'b01', img_bullet01, bulletlist, 2*sw - ang*cl +240)
- object_create(ox, oy, 'b01', img_bullet01, bulletlist, 2*sw - ang*cl +300)
- end
- if ang*cl == 2*sw then
- obj.clock[id] = 0
- end
- end
- end
- end
- i = i+1
- end
- --enemy bullets
- local i = 0
- while i<bulletlist.size do
- local id = ds_list_find_value(bulletlist, i)
- local t = obj.type[id]
- local ox = obj.x[id]
- local oy = obj.y[id]
- if t == 'b01' then
- if not onscreen(ox,oy) then
- object_destroy(bulletlist, id)
- else
- obj.y[id] = obj.y[id] + (math.cos(math.rad(obj.dir[id]))*2)
- obj.x[id] = obj.x[id] + (math.sin(math.rad(obj.dir[id]))*2)
- Graphics_drawImage(obj.x[id]-1, obj.y[id]-1, img_bullet01)
- obj.dir[id] = obj.dir[id] + obj.hp[id] --b01 bullets can have a "spin" applied to them
- --collision check
- local px = player_x
- local py = player_y
- if ox<px+3 and ox>px-3 and oy<py+3 and oy>py-3 then
- object_destroy(bulletlist, id)
- player_alive = false
- end
- end
- elseif t == 'b02' then
- if not onscreen(ox,oy) then
- object_destroy(bulletlist, id)
- else
- obj.y[id] = obj.y[id] + 1
- Graphics_drawImage(obj.x[id]-1, obj.y[id]-5, img_bullet02)
- --collision check (also, make this bullet explode into more)
- local px = player_x
- local py = player_y
- if ox<px+3 and ox>px-3 and oy<py+6 and oy>py-6 then
- object_destroy(bulletlist, id)
- player_alive = false
- end
- end
- elseif t == 'b03' then
- if not onscreen(ox,oy) then
- object_destroy(bulletlist, id)
- else
- obj.y[id] = obj.y[id] +1.5+(difficulty>>3)
- Graphics_drawImage(obj.x[id]-4, obj.y[id]-3, img_bullet03)
- --collision check
- local px = player_x
- local py = player_y
- if ox<px+5 and ox>px-5 and oy<py+4 and oy>py-4 then
- object_destroy(bulletlist, id)
- player_alive = false
- end
- end
- elseif t == 'b04' then
- end
- i = i+1
- end
- --friendly bullets
- local i = 0
- while i<shotlist.size do
- local id = ds_list_find_value(shotlist, i)
- local t = obj.type[id]
- local ox = obj.x[id]
- local oy = obj.y[id]
- local shotw = 0
- local shoth = 0
- local speed = 0
- local power = 0
- local graph = img_shot01
- if t=='shot01' then
- shotw = 9; shoth = 3; speed = 8; power = 4; graph = img_shot01
- elseif t=='shot02' then
- shotw = 23; shoth = 6; speed = obj.clock[id]/8; power = 12; graph = img_shot02
- obj.clock[id]=obj.clock[id]+1
- elseif t=='shot03' then
- shotw = 9; shoth = 9; speed = 4; power = 8; graph = img_shot03
- elseif t=='shot04' then
- shotw = 9; shoth = 480; speed = 0; power = 0.3; graph = img_shot04
- ox = player_x
- oy = player_y - 10
- elseif t=='shot05' then
- shotw = 5; shoth = 5; speed = 5; power = 3; graph = img_shot05
- end
- obj.y[id] = oy + (math.cos(math.rad(obj.dir[id]))*speed)
- obj.x[id] = ox + (math.sin(math.rad(obj.dir[id]))*speed)
- if not onscreen(ox,oy) then --once the ship is prevented from leaving bounds, you can remove the latter part of this check
- object_destroy(shotlist, id)
- else
- --collision check
- local j=0
- local range=400; local target=-1; --tracer variables
- while j<enemylist.size do
- local idc = ds_list_find_value(enemylist, j)
- local tx=obj.x[idc]
- local ty=obj.y[idc]
- if t=='shot05' then --tracer calculations
- local nr = math.sqrt((tx-ox)^2 + (ty-oy)^2)
- if range > nr then
- range = nr
- target = idc
- end
- end
- 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
- obj.hp[idc] = obj.hp[idc] - power
- if obj.hp[idc] < 1 then
- local dty = obj.type[idc]
- if dty == 'en01' or dty == 'en02' or dty == 'en03' then
- object_create(tx, ty, 'end', img_en_death, fxlist)
- elseif dty == 'bo01' then
- object_create(tx, ty, 'bod', img_boss_death, fxlist)
- end
- object_destroy(enemylist, idc)
- end
- if t~='shot04' then --beam continues to hit, so we don't delete it yet unlike other bullets
- object_destroy(shotlist, id)
- target = -1
- j=enemylist.size
- end
- end
- j=j+1
- end
- if target>0 then --turning to face a close target
- local ang = angle(ox,oy, obj.x[target], obj.y[target])
- local fac = obj.dir[id]
- local off = ((ang-fac+180)%360)-180
- obj.dir[id]=obj.dir[id] + (off / math.abs(off))
- end
- Graphics_drawImage(math.floor(ox-shotw/2), math.floor(oy-shoth/2), graph)
- --end collision check
- end
- i = i+1
- end
- --effects handling
- local i = 0
- while i<fxlist.size do
- local id = ds_list_find_value(fxlist, i)
- local g = obj.graphic[id]
- local t = obj.type[id]
- local ox = obj.x[id]
- local oy = obj.y[id]
- local cl = obj.clock[id]
- local fxw = 0
- local fyh = 0
- if t== 'end' then fxw = 11; fyh = 11;
- elseif t=='bod' then fxw=49; fyh= 19; end
- Graphics_drawPartialImage(math.floor(ox-fxw/2), math.floor(oy-fyh/2), math.floor(cl)*fxw, 0, fxw,fyh, g)
- if cl>6 then
- object_destroy(fxlist, id)
- else
- obj.clock[id] = cl + 0.125
- end
- i=i+1
- end
- --reading data from level array
- local morespawn = true
- while morespawn == true do
- if larray.time[spawnindex] == nil then
- morespawn = false
- stage_clear = 0
- elseif (larray.time[spawnindex] < timer) then
- local ty = larray.enid[spawnindex]
- local D = larray.dir[spawnindex]
- local P = larray.pix[spawnindex]
- local nx =0
- local ny =0
- local dmov=0
- if D == "T" then
- nx = P
- ny = -30
- dmov = 0
- else
- ny = P
- if D == "L" then
- nx = -30
- dmov = 90
- else
- nx = 430
- dmov = 270
- end
- end
- local img_ = -1
- local hp_ = -1
- local targ_ = -1
- local spawn_ = -1
- if ty == 'en01' then
- img_ = img_en01
- hp_ = 6
- targ_ = 60
- spawn_ = 1
- elseif ty == 'en02' then
- img_ = img_en02
- hp_ = 14
- targ_ = 60
- spawn_ = 1
- elseif ty == 'en03' then
- img_ = img_en03
- hp_ = 10
- targ_ = 60
- spawn_ = 1
- elseif ty == 'bo01' then
- stage_boss = ty
- stage_boss_hp = 300
- warning_flash = 1
- end
- if spawn_ == 1 then
- local o = object_create(nx, ny, ty, img_, enemylist, dmov)
- obj.hp[o] = hp_
- obj.target[o] = targ_
- end
- spawnindex = spawnindex + 1
- else
- morespawn = false
- end
- end
- --player sprite and death animation
- if player_alive == true then
- Graphics_drawImage(math.floor(player_x-11.5), math.floor(player_y-9), img_ship01)
- elseif player_death < 4 then
- 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)
- player_death = player_death + 0.125
- end
- if warning_flash > 0 then
- warning_flash = warning_flash + 1
- if warning_flash % 30 > 8 then
- Graphics_drawImage(174, 115, img_warning)
- end
- if warning_flash > 120 then
- warning_flash = 0
- local o = object_create(200, -100, 'bo01', img_boss01, enemylist, 0)
- obj.hp[o] = 9999
- obj.target[o] = 150
- end
- end
- if stage_clear == 0 then
- if enemylist.size < 1 then
- stage_clear = 1
- end
- elseif stage_clear == 1 then
- Graphics_drawImage(161, 112, img_clear)
- end
- timer = timer + 1
- Graphics_termBlend()
- if (Controls_check(pad,KEY_START)) and not (Controls_check(oldpad,KEY_START)) then
- menu_init()
- end
- end
- Screen_flip()
- oldpad = pad
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement