-- tpt.set_console(0) local wn = 100 local hn = 61 local weapon = 0 local strike = Window:new((sim.XRES - wn)/2, (sim.YRES - hn)/2, wn, hn) local bomber = Button:new(0, 0, 100, 16, "Bomber") local rocket = Button:new(0, 15, 100, 16, "Rocket strike") local orbital = Button:new(0, 30, 100, 16, "Orbital strike") local bomb = Button:new(0,45,100,16,"Explosion") -- bomber:action(function() weapon = 1 interface.closeWindow(strike) end) rocket:action(function() weapon = 2 interface.closeWindow(strike) end) orbital:action(function() weapon = 3 interface.closeWindow(strike) end) bomb:action(function() weapon = 4 interface.closeWindow(strike) end) strike:onTryExit(function() interface.closeWindow(strike) end) -- strike:addComponent(bomber) strike:addComponent(rocket) strike:addComponent(orbital) strike:addComponent(bomb) -- local y local cur_pos_y local timer = 0 local timer2 = 0 local b = 0 local fly = 0 local cycle = 0 local start_x = 4 local x = start_x local end_x = 607 local shoot_x local shoot_y local function fastbomb() tpt.delete(shoot_x, shoot_y) tpt.create(shoot_x, shoot_y, "sing") tpt.set_property("life", 0, shoot_x, shoot_y) tpt.set_property("tmp", -500, shoot_x, shoot_y) b = 0 tpt.unregister_step(fastbomb) end local function orbitalbomb() if cur_pos_y == shoot_y then tpt.delete(shoot_x, cur_pos_y) tpt.create(shoot_x, cur_pos_y, "sing") tpt.set_property("life", 0, shoot_x, cur_pos_y) tpt.set_property("tmp", -500, shoot_x, cur_pos_y) b = 0 cur_pos_y = y - 1 if fly == 0 then tpt.register_step(check) end tpt.unregister_step(orbitalbomb) else while cur_pos_y ~= shoot_y do tpt.create(shoot_x, cur_pos_y, "bray") cur_pos_y = cur_pos_y + 1 end end end local function bomb() if timer2 < socket.gettime() then if cur_pos_y == shoot_y then tpt.delete(shoot_x, cur_pos_y) tpt.create(shoot_x, cur_pos_y, "sing") tpt.set_property("life", 0, shoot_x, cur_pos_y) tpt.set_property("tmp", -500, shoot_x, cur_pos_y) b = 0 cur_pos_y = y - 1 if fly == 0 then tpt.register_step(check) end tpt.unregister_step(bomb) else tpt.set_pause(0) tpt.set_console(0) tpt.create(shoot_x, cur_pos_y, "bray") cur_pos_y = cur_pos_y + 1 timer2 = socket.gettime()+.0001 end end end local function move() if timer < socket.gettime() then cycle = cycle + 1 if cycle == 605 then fly = 0 x = start_x tpt.unregister_step(move) if fly == 0 then tpt.register_step(check) end else tpt.set_pause(0) tpt.set_console(0) tpt.delete(x, y - 1) tpt.delete(x, y) tpt.delete(x + 1, y) tpt.delete(x + 2, y) tpt.delete(x + 2, y + 1) tpt.delete(x + 3, y) x = x + 1 tpt.create(x, y - 1, "DMND") tpt.create(x, y, "DMND") tpt.create(x + 1, y, "DMND") tpt.create(x + 2, y, "DMND") tpt.create(x + 2, y + 1, "DMND") tpt.create(x + 3, y, "DMND") tpt.set_property("dcolor", 0xFF404060, x, y - 1) tpt.set_property("dcolor", 0xFF404060,x, y) tpt.set_property("dcolor", 0xFF404060,x + 1, y) tpt.set_property("dcolor", 0xFF404060,x + 2, y) tpt.set_property("dcolor", 0xFF404060,x + 2, y + 1) tpt.set_property("dcolor", 0xFF404060,x + 3, y) if x + 1 == shoot_x then tpt.register_step(bomb) timer2 = socket.gettime()+.0001 end timer = socket.gettime()+.0001 end end end local function keycheck(char, code, modifiers, event) if event == 1 and char == 'j' and b == 0 and fly == 0 and bit.band(modifiers, 0x3) == 0 then shoot_x, shoot_y = sim.adjustCoords(tpt.mousex, tpt.mousey) if weapon == 1 then y = 70 cur_pos_y = y - 1 if shoot_y < y then shoot_y = y + 1 end tpt.create(x, y - 1, "DMND") tpt.create(x, y, "DMND") tpt.create(x + 1, y, "DMND") tpt.create(x + 2, y, "DMND") tpt.create(x + 2, y + 1, "DMND") tpt.create(x + 3, y, "DMND") fly = 1 tpt.set_property("dcolor", 0xFF404060, x, y - 1) tpt.set_property("dcolor", 0xFF404060,x, y) tpt.set_property("dcolor", 0xFF404060,x + 1, y) tpt.set_property("dcolor", 0xFF404060,x + 2, y) tpt.set_property("dcolor", 0xFF404060,x + 2, y + 1) tpt.set_property("dcolor", 0xFF404060,x + 3, y) timer = socket.gettime()+.05 cycle = 0 tpt.register_step(move) tpt.unregister_step(check) elseif weapon == 2 then y = 0 cur_pos_y = y - 1 tpt.register_step(bomb) timer2 = socket.gettime()+.0001 elseif weapon == 3 then y = 0 cur_pos_y = y - 1 tpt.register_step(orbitalbomb) timer2 = socket.gettime()+.0001 elseif weapon == 4 then tpt.register_step(fastbomb) end b = 1 elseif event == 1 and char == 'j' and bit.band(modifiers, 0x3) ~= 0 then interface.showWindow(strike) end end function check() tpt.register_keypress(keycheck) end tpt.register_step(check)