Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Beta Game by Just Does Games --
- sx,sy = term.getSize()
- term.clear()
- settings_menu_text_cursor = "> "
- settings_menu_text_cursor_color = "white"
- settings_menu_background_cursor_color = "black"
- settings_menu_text_selected_color = "yellow"
- settings_menu_background_selected_color = "black"
- settings_menu_text_deselected_color = "gray"
- settings_menu_background_deselected_color = "black"
- settings_gamemenu_background_color = "gray"
- settings_title_background_color = "gray"
- settings_title_text_color = "lime"
- settings_title = "Project CraftMan"
- settings_game_speed = .03
- settings_game_player_head_color = "blue"
- settings_game_player_worm_color = "lime"
- settings_game_bot_head_color = "gray"
- settings_game_bot_worm_color = "orange"
- settings_game_buffer_text = "Loading game..."
- player_direction = "right"
- bot_direction = "left"
- bot_turn_speed = 1
- bot_turn_direction_speed_low = 0.2
- bot_turn_direction_speed_high = 1
- start = true
- prev_menu = {}
- singleplayer = true
- sel = 1
- game_screen = {}
- game_player_1_controls = 0
- game_player_2_controls = 0
- sm_bot = {
- "Lobby",
- "----------",
- "Game Speed => "..settings_game_speed,
- "",
- "Player",
- "----------",
- "Worm Color => "..settings_game_player_worm_color,
- "Head Color => "..settings_game_player_head_color,
- "",
- "Bot",
- "----------",
- "Worm Color => "..settings_game_bot_worm_color,
- "Head Color => "..settings_game_bot_head_color
- }
- sm_player = {
- "Lobby",
- "----------",
- "Game Speed => "..settings_game_speed,
- "",
- "Player 1",
- "----------",
- "Worm Color => "..settings_game_player_worm_color,
- "Head Color => "..settings_game_player_head_color,
- "",
- "Player 2",
- "----------",
- "Worm Color => "..settings_game_bot_worm_color,
- "Head Color => "..settings_game_bot_head_color
- }
- function clr() term.clear() end
- function cp(x,y) term.setCursorPos(x,y) end
- function setText(col) if type(col) ~= "string" then return error("Invalid Text Color, got "..type(col)) end term.setTextColor(colors[col]) end
- function setBack(col) if type(col) ~= "string" then return error("Invalid Background Color, got "..type(col)) end term.setBackgroundColor(colors[col]) end
- function checkColors(text, back)
- if type(text) ~= "string" then return error("Text Color Invalid, got "..type(text)) end
- if type(back) ~= "string" then return error("Background Color Invalid, got "..type(back)) end
- if term.getTextColor() ~= text then
- setText(text)
- end
- if term.getBackgroundColor() ~= back then
- setBack(back)
- end
- end
- function display_title()
- local interval = 3
- local cnt = 0
- checkColors(settings_title_text_color, settings_title_background_color)
- cp(1,3)
- for i=1, sx do
- write(" ") if cnt == interval and start == true then cnt = 0 sleep(.001) else cnt = cnt + 1 end
- end
- cp(1,4)
- for i=1, sx do
- write(" ") if cnt == interval and start == true then cnt = 0 sleep(.001) else cnt = cnt + 1 end
- end
- cp(1,5)
- for i=1, sx do
- write(" ") if cnt == interval and start == true then cnt = 0 sleep(.001) else cnt = cnt + 1 end
- end
- if start then sleep(1) end
- cp(math.ceil(sx/2-string.len(settings_title)/2),4)
- if start then textutils.slowPrint(settings_title) sleep(.5) start = false else print(settings_title) end
- end
- function menu(m)
- local sel = 1
- if m ~= prev_menu then clr() display_title() end prev_menu = m sleep(.15)
- while true do
- for i=1, #m do
- cp(math.floor(sx/2-string.len(m[i])/2)-1,math.floor(sy/2)+i-3)
- if sel == i then
- checkColors(settings_menu_text_cursor_color, settings_menu_background_cursor_color)
- write(settings_menu_text_cursor)
- checkColors(settings_menu_text_selected_color, settings_menu_background_selected_color)
- else
- write(" ")
- checkColors(settings_menu_text_deselected_color, settings_menu_background_deselected_color)
- end
- print(m[i])
- end sleep(.001)
- a,i = os.pullEvent("key")
- if i == keys.w or i == keys.up then
- if sel == 1 then sel = #m else sel = sel - 1 end
- elseif i == keys.s or i == keys.down then
- if sel == #m then sel = 1 else sel = sel + 1 end
- elseif i == keys.e or i == keys.enter then
- return sel
- end
- end
- end
- function draw_gsm()
- checkColors("white", "black")
- clr() cp(2,1)
- setBack(settings_gamemenu_background_color)
- for i=1, sx/2-2 do -- top
- write(" ")
- end
- cp(1,1)
- for i=1, sy/2+5 do -- left
- print(" ")
- end
- for i=1, sx/2-2 do -- bottom
- write(" ")
- end
- for i=1, sy do
- cp(sx/2-1,i) write(" ")
- end
- sleep(.3)
- display_settings()
- end
- function display_settings()
- checkColors("black", "black")
- if singleplayer then
- for i=1, #sm_bot do
- cp(sx/2+1,i)
- write(sm_bot[i])
- end
- else
- for i=1, #sm_player do
- cp(sx/2+1,i)
- write(sm_player[i])
- end
- end
- sm_bot = {
- "Lobby",
- "----------",
- "Game Speed => "..settings_game_speed,
- "",
- "Player",
- "----------",
- "Worm Color => "..settings_game_player_worm_color,
- "Head Color => "..settings_game_player_head_color,
- "",
- "Bot",
- "----------",
- "Worm Color => "..settings_game_bot_worm_color,
- "Head Color => "..settings_game_bot_head_color
- }
- sm_player = {
- "Lobby",
- "----------",
- "Game Speed => "..settings_game_speed,
- "",
- "Player 1",
- "----------",
- "Worm Color => "..settings_game_player_worm_color,
- "Head Color => "..settings_game_player_head_color,
- "",
- "Player 2",
- "----------",
- "Worm Color => "..settings_game_bot_worm_color,
- "Head Color => "..settings_game_bot_head_color
- }
- sleep(.2)
- setText("lightGray")
- if singleplayer then
- for i=1, #sm_bot do
- cp(sx/2+1,i)
- write(sm_bot[i])
- end
- else
- for i=1, #sm_player do
- cp(sx/2+1,i)
- write(sm_player[i])
- end
- end
- end
- function gsm_menu(m)
- while true do
- for i=1, #m do
- cp(2,2+i)
- if sel == i then
- checkColors(settings_menu_text_cursor_color, settings_menu_background_cursor_color)
- write(settings_menu_text_cursor)
- checkColors(settings_menu_text_selected_color, settings_menu_background_selected_color)
- else
- write(" ")
- checkColors(settings_menu_text_deselected_color, settings_menu_background_deselected_color)
- end
- print(m[i])
- end sleep(.001)
- a,i = os.pullEvent("key")
- if i == keys.w or i == keys.up then
- if sel == 1 then sel = #m else sel = sel - 1 end
- elseif i == keys.s or i == keys.down then
- if sel == #m then sel = 1 else sel = sel + 1 end
- elseif i == keys.e or i == keys.enter then
- setText("black")
- for i=1, #m do
- cp(2,2+i)
- if sel == i then
- write(settings_menu_text_cursor)
- else
- write(" ")
- end
- print(m[i])
- end
- return sel
- end
- end
- end
- function game_settings_menu()
- local m = {}
- local m_l = {}
- local m_p = {}
- local m_b = {}
- if singleplayer then
- m = {"Lobby Settings", "Player Settings", "Bot Settings", "Start Game", "Main Menu"}
- else
- m = {"Lobby Settings", "Player 1 Settings", "Player 2 Settings", "Start Game", "Main Menu"}
- end
- local m_l = {"Game Speed", "Back"}
- if singleplayer then
- m_p = {"Player Worm Color", "Player Head Color", "Back"}
- m_b = {"Bot Worm Color", "Bot Head Color", "Back"}
- else
- m_p = {"Player 1 Worm Color", "Player 1 Head Color", "Back"}
- m_b = {"Player 2 Worm Color", "Player 2 Head Color", "Back"}
- end
- local m_sel = m
- local p_l_game_speed = {0.03,0.01,0.5,.3,0.1,0.08,0.06}
- local p_p_worm_color = {"lime","red","orange","yellow","green","blue","purple","lightGray","gray"}
- local p_p_head_color = {"blue","red","orange","yellow","green","purple","gray","lightGray"}
- local p_b_worm_color = {"orange","red","yellow","green","blue","purple","lightGray","gray"}
- local p_b_head_color = {"gray","red","orange","yellow","green","blue","purple","lightGray"}
- local p = {2,2,2,2,2}
- draw_gsm()
- while true do
- local val = gsm_menu(m_sel)
- if m_sel == m then
- if val == 1 then
- m_sel = m_l sel = 1
- elseif val == 2 then
- m_sel = m_p sel = 1
- elseif val == 3 then
- m_sel = m_b sel = 1
- elseif val == 4 then
- return true
- elseif val == #m_sel then
- clr() display_title() sel = 1
- return false
- end
- elseif m_sel == m_l then
- if val == 1 then
- settings_game_speed = p_l_game_speed[p[1]] p[1] = p[1] + 1
- if p[1] == #p_b_head_color then
- p[1] = 1
- end
- elseif val == #m_sel then
- m_sel = m sel = 1 sel = 1
- end
- display_settings()
- elseif m_sel == m_p then
- if val == 1 then
- settings_game_player_worm_color = p_p_worm_color[p[2]] p[2] = p[2] + 1
- if p[2] == #p_b_head_color then
- p[2] = 1
- end
- elseif val == 2 then
- settings_game_player_head_color = p_p_head_color[p[3]] p[3] = p[3] + 1
- if p[3] == #p_b_head_color then
- p[3] = 1
- end
- elseif val == #m_sel then
- m_sel = m sel = 1
- end
- display_settings()
- elseif m_sel == m_b then
- if val == 1 then
- settings_game_bot_worm_color = p_b_worm_color[p[4]] p[4] = p[4] + 1
- if p[4] == #p_b_head_color then
- p[4] = 1
- end
- elseif val == 2 then
- settings_game_bot_head_color = p_b_head_color[p[5]] p[5] = p[5] + 1
- if p[5] == #p_b_head_color then
- p[5] = 1
- end
- elseif val == #m_sel then
- m_sel = m sel = 1
- end
- display_settings()
- end
- end
- end
- -- Game --
- function loadingBuffer()
- clr() cp(math.floor(sx/2-string.len(settings_game_buffer_text)/2),2) checkColors("white", "black") print(settings_game_buffer_text) sleep(math.random(1,1.8))
- end
- function player_input_engine()
- local running = true
- if singleplayer then
- while running do
- local a,i = os.pullEvent("key")
- if i == keys.w or i == keys.up then
- player_direction = "up"
- elseif i == keys.a or i == keys.left then
- player_direction = "left"
- elseif i == keys.s or i == keys.down then
- player_direction = "down"
- elseif i == keys.d or i == keys.right then
- player_direction = "right"
- elseif i == keys.q then
- running = false
- end
- end
- else
- while running do
- local a,i = os.pullEvent("key")
- if i == keys.w then
- player_direction = "up"
- elseif i == keys.a then
- player_direction = "left"
- elseif i == keys.s then
- player_direction = "down"
- elseif i == keys.d then
- player_direction = "right"
- elseif i == keys.q then
- running = false
- end
- end
- end
- end
- function player_movement_engine()
- player_direction = "right"
- local player_x, player_y = 1,1
- while true do
- checkColors("black", settings_game_player_worm_color) cp(player_x,player_y) write(" ")
- if game_screen[player_x*player_y] == 0 then
- game_player_1_controls = game_player_1_controls + 1
- game_screen[player_x*player_y] = 1
- elseif game_screen[player_x*player_y] == 2 or game_screen[player_x*player_y] == 4 then
- game_player_2_controls = game_player_2_controls - 1
- game_player_1_controls = game_player_1_controls + 1
- game_screen[player_x*player_y] = 1
- end
- if player_direction == "right" then
- if player_x == sx then player_x = 1 else player_x = player_x + 1 end
- elseif player_direction == "left" then
- if player_x == 1 then player_x = sx else player_x = player_x - 1 end
- elseif player_direction == "up" then
- if player_y == 1 then player_y = sy-1 else player_y = player_y - 1 end
- elseif player_direction == "down" then
- if player_y == sy-1 then player_y = 1 else player_y = player_y + 1 end
- end
- cp(player_x,player_y) checkColors("black", settings_game_player_head_color) write(" ") sleep(settings_game_speed)
- --game_screen[player_x*player_y] = 3
- end
- end
- function bot_input_engine()
- local running = true
- local cnt = 0
- local cnt_pos = 1
- local seed = {}
- for i=1, 20 do
- seed[#seed+1] = math.random(bot_turn_direction_speed_low, bot_turn_direction_speed_high)
- end
- while true do
- sleep(bot_turn_speed)
- if cnt == seed[cnt_pos] then
- local trans = 1
- local directions = {"right", "left", "up", "down"}
- cnt = 0
- cnt_pos = cnt_pos+1
- if cnt_pos == #seed+1 then cnt_pos = 1 end
- repeat
- trans = math.random(1,4)
- until directions[trans] ~= bot_direction
- bot_direction = directions[trans]
- else
- cnt = cnt + 1
- end
- if game_player_2_controls < game_player_1_controls+60 then
- bot_turn_speed = 0.2
- elseif game_player_2_controls < game_player_1_controls+45 then
- bot_turn_speed = 0.4
- elseif game_player_2_controls < game_player_1_controls+30 then
- bot_turn_speed = 0.6
- elseif game_player_2_controls < game_player_1_controls+20 then
- bot_turn_speed = 0.8
- else
- bot_turn_speed = 1
- end
- end
- end
- function bot_movement_engine()
- while true do
- bot_direction = "left"
- local bot_x, bot_y = sx,sy-1
- while true do
- checkColors("black", settings_game_bot_worm_color) cp(bot_x,bot_y) write(" ")
- if game_screen[bot_x*bot_y] == 0 then
- game_player_2_controls = game_player_2_controls + 1
- game_screen[bot_x*bot_y] = 2
- elseif game_screen[bot_x*bot_y] == 1 or game_screen[bot_x*bot_y] == 3 then
- game_player_1_controls = game_player_1_controls - 1
- game_player_2_controls = game_player_2_controls + 1
- game_screen[bot_x*bot_y] = 2
- end
- if bot_direction == "right" then
- if bot_x == sx then bot_x = 1 else bot_x = bot_x + 1 end
- elseif bot_direction == "left" then
- if bot_x == 1 then bot_x = sx else bot_x = bot_x - 1 end
- elseif bot_direction == "up" then
- if bot_y == 1 then bot_y = sy-1 else bot_y = bot_y - 1 end
- elseif bot_direction == "down" then
- if bot_y == sy-1 then bot_y = 1 else bot_y = bot_y + 1 end
- end
- cp(bot_x,bot_y) checkColors("black", settings_game_bot_head_color) write(" ") sleep(settings_game_speed)
- --game_screen[bot_x*bot_y] = 4
- end
- end
- end
- function player_2_input_engine()
- local running = true
- while running do
- local a,i = os.pullEvent("key")
- if i == keys.up then
- bot_direction = "up"
- elseif i == keys.left then
- bot_direction = "left"
- elseif i == keys.down then
- bot_direction = "down"
- elseif i == keys.right then
- bot_direction = "right"
- elseif i == keys.q then
- running = false
- end
- end
- end
- -- Game Screen Values --
- -- 0 = Empty
- -- 1 = Player 1 Space
- -- 2 = Player/Bot 2 Space
- -- 3 = Player 1 Head
- -- 4 = Player/Bot 2 Head
- function game_text_display()
- -- display stuff like game_screen, time, and who is winning.
- while true do
- cp(1,sy)
- checkColors("white", "black")
- term.clearLine()
- checkColors("white", settings_game_player_worm_color)
- write(" ")
- checkColors("white", "black")
- write(" x "..game_player_1_controls)
- cp(sx,sy)
- checkColors("white", settings_game_bot_worm_color)
- cp(sx,sy)
- write(" ")
- checkColors("white", "black")
- cp(sx-string.len(game_player_2_controls.." x "),sy)
- write(game_player_2_controls.." x ")
- if game_player_1_controls > game_player_2_controls then
- checkColors(settings_game_player_worm_color, "black")
- cp(sx/2-string.len("Winning")/2, sy)
- write("Winning")
- elseif game_player_1_controls < game_player_2_controls then
- checkColors(settings_game_bot_worm_color, "black")
- cp(sx/2-string.len("Winning")/2, sy)
- write("Winning")
- elseif game_player_1_controls == game_player_2_controls then
- checkColors("white", "black")
- cp(sx/2-string.len("Tied")/2, sy)
- write("Tied")
- end
- sleep(settings_game_speed*9)
- end
- end
- function gameSingleplayer()
- game_screen = {} -- updated while game runs. impliment in the player_movement_engine & bot_movement_engine for a more secure and faster connection
- for i=1, sy do
- for i=1, sx do
- game_screen[#game_screen+1] = 0
- end
- end
- loadingBuffer() checkColors("black", "black") clr()
- parallel.waitForAny(player_movement_engine, player_input_engine, bot_movement_engine, bot_input_engine, game_text_display)
- checkColors("black", "black") clr() display_title()
- end
- function gameMultiplayer()
- --
- end
- function gameSameComputer()
- game_screen = {} -- updated while game runs. impliment in the player_movement_engine & bot_movement_engine for a more secure and faster connection
- for i=1, sy do
- for i=1, sx do
- game_screen[#game_screen+1] = 0
- end
- end
- loadingBuffer() checkColors("black", "black") clr()
- parallel.waitForAny(player_movement_engine, player_input_engine, bot_movement_engine, player_2_input_engine, game_text_display)
- checkColors("black", "black") clr() display_title()
- end
- -- Runtime --
- menu_main = {"Play", "Store", "Settings", "Quit Game"}
- menu_play = {"Singleplayer", "Multiplayer", "Same Computer", "Go Back"}
- menu_store = {"Nothing Here Yet", "Go Back"}
- menu_settings = {"Nothing here Yet", "Go Back"}
- menu_selected = menu_main
- local running = true
- while running do
- local r = menu(menu_selected)
- if menu_selected == menu_main then
- if r == 1 then
- menu_selected = menu_play
- elseif r == 2 then
- menu_selected = menu_store
- elseif r == 3 then
- menu_selected = menu_settings
- elseif r == #menu_main then
- running = false
- end
- elseif menu_selected == menu_play then
- if r == 1 then
- multiplayer = false
- singleplayer = true
- if game_settings_menu() == true then
- gameSingleplayer()
- end
- elseif r == 2 then
- --
- elseif r == 3 then
- multiplayer = true
- singleplayer = false
- if game_settings_menu() == true then
- gameSameComputer()
- end
- elseif r == #menu_play then
- menu_selected = menu_main
- end
- elseif menu_selected == menu_store then
- if r == 1 then
- --
- elseif r == #menu_store then
- menu_selected = menu_main
- end
- elseif menu_selected == menu_settings then
- if r == 1 then
- --
- elseif r == #menu_settings then
- menu_selected = menu_main
- end
- end
- end
Add Comment
Please, Sign In to add comment