Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print('Choose mode (debug, prod) : ')
- choice = read()
- if choice == "debug" then
- screen = peripheral.wrap("left")
- debug = peripheral.wrap("bottom")
- else
- screen = peripheral.wrap("monitor_0")
- debug = peripheral.wrap("monitor_1")
- end
- width, height = screen.getSize()
- symbols = {"x", "+", "*"}
- max_star = 5
- tail_length = 3
- function draw_tail(base_pos, dir)
- local tail_char = ""
- local side = 0
- if dir == "W" then
- tail_char = "/"
- side = 1
- else
- tail_char = "\\"
- side = -1
- end
- for l=1,tail_length,1 do
- local m_x = base_pos.x + (side * l)
- local m_y = base_pos.y - (1 * l)
- screen.setCursorPos(m_x, m_y)
- screen.write(tail_char)
- end
- end
- borne = {min=-4, max=width+4}
- borne.middle = borne.max / 2
- function generate_meteor(speed)
- x_pos = math.random(borne.min, borne.max)
- n_dir = ""
- if x_pos < borne.middle then n_dir="E" else n_dir="W" end
- meteor = {pos={x=x_pos,y=-3}, speed=speed, direction=n_dir}
- debug.setCursorPos(1,1)
- debug.write(meteor.direction)
- debug.setCursorPos(1,2)
- debug.write("X : "..meteor.pos.x.."/ Y : "..meteor.pos.y)
- return meteor
- end
- function update_meteor(meteor)
- if meteor.direction == "W" then
- meteor.pos.x = meteor.pos.x - meteor.speed
- else
- meteor.pos.x = meteor.pos.x + meteor.speed
- end
- meteor.pos.y = meteor.pos.y + meteor.speed
- screen.setCursorPos(meteor.pos.x, meteor.pos.y)
- screen.write("O")
- draw_tail(meteor.pos, meteor.direction)
- -- print(meteor.pos.x, meteor.pos.y)
- -- sleep(0.1)
- end
- m1 = generate_meteor(1)
- function init_star_tab(star_count)
- tab = {index=1, list={}}
- for i=1, star_count,1 do
- rand_x = math.random(1, width)
- rand_y = math.random(1, height)
- tab.list[i] = {rand_x, rand_y}
- end
- return tab
- end
- start_char = {"/", "|", "\\"}
- end_char = {"\\", "|", "/"}
- function draw_cadre(text_pos, text_w)
- start_height = text_pos.y - 1
- for h=0,2,1 do
- new_line = ""
- new_line = start_char[h+1]..new_line
- for w=1,text_w,1 do
- new_line = new_line.."-"
- end
- new_line = new_line..end_char[h+1]
- screen.setCursorPos(text_pos.x-1, start_height+h)
- screen.write(new_line)
- end
- end
- function text_middle_screen(text)
- t_w = #text / 2
- s_w = (width / 2) - (t_w)
- s_h = (height / 2) - 1
- -- screen.setCursorPos(s_w, s_h)
- draw_cadre({x=s_w,y=s_h}, #text )
- screen.setCursorPos(s_w, s_h)
- screen.write(text)
- end
- function addStar(star_arr)
- for i=1, #star_arr.list, 1 do
- if i == star_arr.index then
- pos_x = math.random(1,width)
- pos_y = math.random(1,height)
- star_arr.list[i] = {pos_x, pos_y}
- end
- next_x = star_arr.list[i][1]
- next_y = star_arr.list[i][2]
- screen.setCursorPos(next_x, next_y)
- random_symbol = symbols[math.random(1, #symbols)]
- screen.write(random_symbol)
- end
- star_arr.index = star_arr.index + 1
- if star_arr.index > #star_arr.list then
- star_arr.index = 1
- end
- end
- test = init_star_tab(50)
- function meteor_management()
- update_meteor( m1)
- if meteor.pos.y > height+3 or
- meteor.pos.x > width+3 or
- meteor.pos.x < -3 then
- m1 = generate_meteor(math.random(1,3))
- end
- end
- while true do
- screen.clear()
- addStar(test)
- meteor_management()
- text_middle_screen("Salut les p'tits amis ! ")
- sleep(0.2)
- end
Add Comment
Please, Sign In to add comment