Advertisement
xThomas

love2d_paste001

Jun 27th, 2018
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 29.28 KB | None | 0 0
  1. io.stdout:setvbuf("no")
  2.  
  3. require 'math'
  4.  
  5. vec2 = {}
  6.  
  7. function vec2:new(x,y)
  8.   assert(x,y)
  9.   return {x=x,y=y}
  10. end
  11.  
  12. local metatable = {}
  13.  
  14. function metatable.__call(...)
  15.     return vec2.new(...)
  16. end
  17.  
  18. setmetatable(vec2, metatable)party_names = {}
  19.  
  20. player = ''
  21.  
  22. trail_setup_screen = {}
  23.  
  24. function trail_setup_screen:load()
  25.     local options = "Many kinds of people made the\ntrip to Oregon.\n\nYou may:\n\n\t1. Be a banker from Boston\n\t2. Be a carpenter from Ohio\n\t3. Be a farmer from Illinois\n\t4. Find out the differences between these choices\n\nWhat is your choice?"
  26.     self.options = love.graphics.newText(font3, options)
  27.     self.text = ''
  28.     self.size = love.graphics.newText(font3, "What is your choice?")
  29.     self.size = {self.size:getWidth(), self.size:getHeight()}
  30.     self.height = self.options:getHeight()
  31.     self.timer = 1
  32.     return self
  33. end
  34.  
  35. function trail_setup_screen:draw()
  36.     love.graphics.draw(self.options, 0, 50)
  37.     if self.timer%25>=10 then
  38.         love.graphics.setColor(1,1,1,0.5)
  39.         love.graphics.rectangle("fill", self.size[1]+16+font3:getWidth(self.text), self.size[2]*1.25+self.height, 20, 20)
  40.     end
  41.     love.graphics.setColor(1,1,1,1)
  42.     love.graphics.setFont(font3)
  43.     love.graphics.print(self.text, self.size[1]+16, self.size[2]*1.25+self.height)
  44.  
  45.     -- debug
  46.     love.graphics.print("trail_setup_screen", 0, love.graphics.getHeight()-23)
  47.     love.graphics.print("timer:"..self.timer,316,love.graphics.getHeight()-23)
  48. end
  49.  
  50. function trail_setup_screen:update()
  51.     self.timer = self.timer + 1
  52. end
  53.  
  54. function trail_setup_screen:textinput(text)
  55.     local text = string.match(text, "%d") -- only accept digits
  56.     self.text = text and self.text .. text or self.text
  57. end
  58.  
  59. function trail_setup_screen:keypressed(key)
  60.     if key == "backspace" then
  61.         self.text = string.sub(self.text, 1, #self.text-1) --self.text:sub(1, #self.text-1)
  62.     elseif key == "return" then
  63.         if self.text == '1' then
  64.             --current_screen = trail_setup_screen:load()
  65.             current_screen = trail_setup_screen_two:load()
  66.             player = 'banker'
  67.         elseif self.text == '2' then
  68.             --current_screen = trail_learn_screen:load()
  69.             current_screen = trail_setup_screen_two:load()
  70.             player = 'carpenter'
  71.         elseif self.text == '3' then
  72.             --current_screen = top_ten_screen:load()
  73.             current_screen = trail_setup_screen_two:load()
  74.             player = 'farmer'
  75.         elseif self.text == '4' then
  76.            
  77.         end
  78.     elseif key == "escape" then
  79.         current_screen = title_screen:load()
  80.     end
  81. end
  82.  
  83. trail_setup_screen_two = {}
  84.  
  85. function trail_setup_screen_two:load()
  86.     local question = "What is the first name of the\nwagon leader?"
  87.     self.question = love.graphics.newText(font3, question)
  88.     self.text = ''
  89.     self.size = love.graphics.newText(font3, "wagon leader?")
  90.     self.size = {self.size:getWidth(), self.size:getHeight()}
  91.     self.height = self.question:getHeight()
  92.     self.timer = 1
  93.     return self
  94. end
  95. function trail_setup_screen_two:textinput(text)
  96.     self.text = self.text .. text
  97. end
  98. function trail_setup_screen_two:keypressed(key)
  99.     if key == "backspace" then
  100.         self.text = string.sub(self.text, 1, #self.text-1) --self.text:sub(1, #self.text-1)
  101.     elseif key == "return" and self.text ~= '' then
  102.         party_names[1] = self.text
  103.         current_screen = trail_setup_screen_three:load()
  104.     elseif key == "escape" then
  105.         current_screen = trail_setup_screen:load()
  106.     end
  107. end
  108. function trail_setup_screen_two:draw()
  109.     love.graphics.draw(self.question)
  110.     if self.timer%25>=10 then
  111.         love.graphics.setColor(1,1,1,0.5)
  112.         love.graphics.rectangle("fill", self.size[1]+16+font3:getWidth(self.text), self.height-self.size[2], 20, 20)
  113.     end
  114.     love.graphics.setColor(1,1,1,1)
  115.     love.graphics.setFont(font3)
  116.     love.graphics.print(self.text, self.size[1]+16, self.height-self.size[2])
  117.  
  118.     -- debug
  119.     love.graphics.print("trail_setup_screen_two", 0, love.graphics.getHeight()-23)
  120.     love.graphics.print("timer:"..self.timer,316,love.graphics.getHeight()-23)
  121.  
  122. end
  123. function trail_setup_screen_two:update()
  124.     self.timer = self.timer + 1
  125. end
  126.  
  127.  
  128.  
  129. trail_setup_screen_three = {}
  130.  
  131. function trail_setup_screen_three:load()
  132.     local question = "What are the first names of the\nfour other members in your party?"
  133.     self.question = love.graphics.newText(font3, question)
  134.     self.qs = {"(Enter names or press ENTER)","Are these names correct?","Change which name?"}
  135.  
  136.     self.q_index = 1
  137.  
  138.     self.width = {  font3:getWidth("1. "),font3:getWidth("2. "),font3:getWidth("3. "),
  139.                     font3:getWidth("4. "),font3:getWidth("5. ")}
  140.     self.height = self.question:getHeight()
  141.     self.lineHeight = font3:getLineHeight() * font3:getHeight()
  142.     self.timer = 1
  143.     self.transition_timer = false
  144.     self.text = '' -- used in 'Are these names correct?' and 'Change which name?'
  145.     for i = 1,5 do
  146.         party_names[i] = party_names[i] or ''
  147.     end
  148.     self.current_name_index = 2
  149.     self.isChangingNames = false -- set when q_index = 3
  150.     return self
  151. end
  152.  
  153. function trail_setup_screen_three:textinput(text)
  154.     if self.q_index == 1 then
  155.         party_names[self.current_name_index] = party_names[self.current_name_index] .. text
  156.     elseif self.q_index == 2 then
  157.         local s = string.match(text,'[YyEeSsNnOo]') or ''
  158.         self.text = self.text ..s
  159.     elseif self.q_index == 3 then
  160.         if not self.isChangingNames then
  161.             self.text = string.match(text,'[1-5]') or ''
  162.         else
  163.            
  164.             party_names[self.current_name_index] = party_names[self.current_name_index] .. text
  165.         end
  166.     end
  167. end
  168.  
  169. function trail_setup_screen_three:keypressed(key)
  170.     if key == 'return' then
  171.         if self.q_index == 1 then -- (Enter names or press ENTER)
  172.             if self.current_name_index < 5 and party_names[self.current_name_index] ~= '' then
  173.                 self.current_name_index = self.current_name_index + 1
  174.             elseif self.current_name_index == 5 and #party_names[self.current_name_index] > 0 then
  175.                 self.q_index = 2 -- Are these names correct?
  176.             end
  177.         elseif self.q_index == 2 then -- Are these names correct?
  178.             local s = string.sub(self.text,1,1)
  179.             if s == 'Y' or s == 'y' then
  180.                 trail_setup_screen_three:transition_to_screen_four()
  181.             elseif s == 'N' or s == 'n' then
  182.                 self.text = ''
  183.                 self.q_index = 3 -- Change which name?
  184.             end
  185.         elseif self.q_index == 3 then -- Change which name?
  186.             if not self.isChangingNames and #self.text == 1 then
  187.                 self.current_name_index = tonumber(self.text)
  188.                 self.isChangingNames = true
  189.                 self.text = ''
  190.             else
  191.                 if self.current_name_index < 5 and party_names[self.current_name_index] ~= '' then
  192.                     self.current_name_index = self.current_name_index + 1
  193.                 elseif self.current_name_index == 5 and #party_names[self.current_name_index] > 0 then
  194.                     self.q_index = 2 -- Are these names correct?
  195.                 end
  196.             end
  197.         end
  198.     elseif key == 'escape' then
  199.         current_screen = trail_setup_screen_two:load()
  200.     elseif key == 'backspace' then
  201.         if self.q_index == 2 then
  202.             self.text = ''
  203.         elseif self.q_index == 3 and not self.isChangingNames then
  204.             self.text = ''
  205.         else
  206.             party_names[self.current_name_index] = string.sub(party_names[self.current_name_index], 1, #party_names[self.current_name_index]-1)
  207.         end
  208.     end
  209. end
  210.  
  211. function trail_setup_screen_three:draw()
  212.     love.graphics.draw(self.question)
  213.  
  214.     local v = party_names
  215.     local c = self.current_name_index
  216.     local q = self.qs[self.q_index]
  217.  
  218.     love.graphics.setColor(1,1,1,1)
  219.     love.graphics.setFont(font3)
  220.     for i = 1,5 do
  221.         love.graphics.print(i..". "..v[i], 0, self.height+self.lineHeight*i)
  222.     end
  223.  
  224.     if self.q_index == 1 then -- (Enter names or press ENTER)
  225.         love.graphics.print(self.qs[1], 0, self.height+self.lineHeight*7)
  226.         if self.timer%25>=10 then
  227.             love.graphics.setColor(1,1,1,0.5)
  228.             love.graphics.rectangle("fill", self.width[c]+font3:getWidth(v[c]),
  229.             self.height+self.lineHeight*c, 20, 20)
  230.         end
  231.  
  232.     elseif self.q_index == 2 then -- Are these names correct?
  233.         love.graphics.print(self.qs[2], 0, self.height+self.lineHeight*7)
  234.         local h = self.height+self.lineHeight*7
  235.         local w = font3:getWidth(q)+16
  236.         love.graphics.print(self.text, w, h)
  237.         if self.timer%25>=10 then
  238.             love.graphics.setColor(1,1,1,0.5)
  239.             love.graphics.rectangle("fill", font3:getWidth(q)+16+font3:getWidth(self.text),
  240.             self.height+self.lineHeight*7, 20, 20)
  241.         end
  242.     elseif self.q_index == 3 then -- Change which name?
  243.         love.graphics.print(self.qs[3], 0, self.height+self.lineHeight*7)
  244.        
  245.         if self.isChangingNames then
  246.             local h = self.height+self.lineHeight*c
  247.             local w = font3:getWidth(v[c])
  248.             if self.timer%25>=10 then
  249.                 love.graphics.setColor(1,1,1,0.5)
  250.                 love.graphics.rectangle("fill", self.width[c]+font3:getWidth(v[c]),
  251.                 self.height+self.lineHeight*c, 20, 20)
  252.             end
  253.         else -- pick a name to change
  254.             local h = self.height+self.lineHeight*7
  255.             local w = font3:getWidth(q)+16
  256.             love.graphics.print(self.text, w, h)
  257.             if self.timer%25>=10 then
  258.                 love.graphics.setColor(1,1,1,0.5)
  259.                 love.graphics.rectangle("fill", w, h, 20, 20)
  260.             end
  261.  
  262.         end
  263.     end
  264.  
  265.    
  266.     local height = love.graphics.getHeight()
  267.     if self.transition_timer then
  268.         local width = love.graphics.getWidth()
  269.         love.graphics.setColor(1,0,0,1)
  270.         love.graphics.rectangle('fill',0,0, width*roundToFive(self.transition_timer), height)
  271.        
  272.         -- debug
  273.         love.graphics.setColor(1,1,1,1)
  274.         love.graphics.print("trail_setup_screen_three:transition_to_screen_four",0, height-23)
  275.         love.graphics.print("timer:"..self.timer,316,love.graphics.getHeight()-23)
  276.     else
  277.         -- debug
  278.         love.graphics.setColor(1,1,1,1)
  279.         love.graphics.print("trail_setup_screen_three", 0, height-23)
  280.         love.graphics.print("timer:"..self.timer,316,love.graphics.getHeight()-23)
  281.     end
  282. end
  283.  
  284. function roundToFive(n)
  285.     if n < 2 then return 1/6
  286.     elseif n < 4 then return 1/3
  287.     elseif n < 6 then return 1/2
  288.     elseif n < 8 then return 2/3
  289.     elseif n < 10 then return 5/6
  290.     else return 1
  291.     end
  292. end
  293.  
  294. function trail_setup_screen_three:update()
  295.     self.timer = self.timer + 2
  296.     if self.transition_timer then
  297.         self.transition_timer = self.transition_timer + 1
  298.         if self.transition_timer >= 12 then
  299.             current_screen = trail_setup_screen_four:load()
  300.         end
  301.     end
  302. end
  303. function trail_setup_screen_three:transition_to_screen_four()
  304.     self.transition_timer = 1 -- creates self.transition_timer
  305. end
  306.  
  307.  
  308.  
  309.  
  310. trail_setup_screen_four = {}
  311.  
  312. function trail_setup_screen_four:load()
  313. local intro = [[It is 1848.  Your jumping off
  314. place for Oregon is Independence,
  315. Missouri.  You must decide which
  316. month to leave Independence.]]
  317. self.advice = [[You attend a public meeting held
  318. for "folks with the California -
  319. Oregon fever."  You're told:
  320.  
  321. If you leave too early, there
  322. won't be any grass for your
  323. oxen to eat.  If you leave too
  324. late, you may not get to Oregon
  325. before winter comes.  If you
  326. leave at just the right time,
  327. there will be green grass and
  328. the weather will still be cool.]]
  329.     self.intro = love.graphics.newText(font3,intro)
  330.     local t = {"March\n","April\n","May\n","June\n","July\n","Ask for advice"}
  331.     self.text = ''
  332.     self.timer = 1
  333.     local i_height = self.intro:getHeight()
  334.     local lineHeight = font3:getLineHeight() * font3:getHeight()
  335.  
  336.     local options = ''
  337.     for i,v in ipairs(t) do
  338.         options = options .. i ..'. '..v
  339.     end
  340.     self.options = love.graphics.newText(font3,options)
  341.     self.o = vec2(font3:getWidth("\t\t"), i_height+lineHeight*2)
  342.  
  343.     self.question = "What is your choice?"
  344.     self.qWidth = font3:getWidth(self.question)
  345.     self.q = vec2(   0, self.o.y + self.options:getHeight() + lineHeight*2  )
  346.     self.viewingAdvice = false
  347.     return self
  348. end
  349.  
  350. function trail_setup_screen_four:textinput(text)
  351.     if string.match(text,'[1-6]') then
  352.         self.text = text
  353.     end
  354. end
  355.  
  356. function trail_setup_screen_four:keypressed(key)
  357.     if key =='space' and self.viewingAdvice then
  358.         self.viewingAdvice = false
  359.     elseif key == 'return' then
  360.         if self.viewingAdvice then
  361.             self.viewingAdvice = false
  362.         elseif #self.text == 1 then
  363.             current_screen = trail_setup_screen_five:load()
  364.         end
  365.     elseif key == 'escape' then
  366.         if self.viewingAdvice then
  367.             self.viewingAdvice = false
  368.         else
  369.             self:back()
  370.         end
  371.     elseif key == 'backspace' then
  372.         self.text = ''
  373.     end
  374. end
  375.  
  376. function trail_setup_screen_four:draw()
  377.     if self.viewingAdvice then
  378.         love.graphics.setColor(1,1,1,1)
  379.         love.graphics.setFont(font3)
  380.         love.graphics.print(self.advice, 0, 0)
  381.         love.graphics.printf("Press SPACE BAR to continue",
  382.             0,
  383.             love.graphics.getHeight()-font3:getHeight()*font3:getLineHeight(),
  384.             love.graphics.getWidth(),
  385.             "center")
  386.         return
  387.     end
  388.     if self.timer%25>=10 then
  389.         love.graphics.setColor(1,1,1,0.5)
  390.         love.graphics.rectangle("fill",
  391.             self.q.x+self.qWidth+16+font3:getWidth(self.text),
  392.             self.q.y, 20, 20)
  393.     end
  394.     love.graphics.setColor(1,1,1,1)
  395.     love.graphics.setFont(font3)
  396.     love.graphics.draw(self.intro)
  397.     love.graphics.draw(self.options, self.o.x, self.o.y)
  398.     love.graphics.print(self.question, self.q.x, self.q.y)
  399.     love.graphics.print(self.text, self.q.x+self.qWidth+16, self.q.y)
  400.     -- debug
  401.     love.graphics.print("trail_setup_screen_four", 0, love.graphics.getHeight()-23)
  402.     love.graphics.print("timer:"..self.timer,316,love.graphics.getHeight()-23)
  403. end
  404.  
  405. function trail_setup_screen_four:update()
  406.     self.timer = self.timer + 1
  407. end
  408. function trail_setup_screen_four:back()
  409.     current_screen = trail_setup_screen_three:load()
  410. end
  411.  
  412.  
  413. trail_setup_screen_five = {}
  414.  
  415. function trail_setup_screen_five:load()
  416.     self.strings = {love.graphics.newText(font3,[[Before leaving Independence you
  417. should buy equipment and
  418. supplies.  You have $1600.00 in
  419. cash, but you don't have to
  420. spend it all now.]]),
  421.    love.graphics.newText(font3,[[You can buy whatever you need at
  422. Matt's General Store.]])}
  423.     self.page = 1
  424.     return self
  425. end
  426. function trail_setup_screen_five:update()           end
  427. function trail_setup_screen_five:draw()
  428.     love.graphics.draw(self.strings[self.page], 0, love.graphics.getHeight()*0.5-
  429.         self.strings[self.page]:getHeight()*0.5)
  430.     love.graphics.printf("Press SPACE BAR to continue",
  431.         0,
  432.         love.graphics.getHeight()-font3:getHeight()*font3:getLineHeight(),
  433.         love.graphics.getWidth(),
  434.         "center")
  435. end
  436. function trail_setup_screen_five:keypressed(key)
  437.     if key == "space" or key == "return" then
  438.         if self.page == 1 then self.page = 2
  439.         else current_screen = matts_store_screen:load()
  440.         end
  441.     elseif key == "escape" then
  442.         if self.page == 2 then self.page = 1
  443.         else current_screen = trail_setup_screen_four:load()
  444.         end
  445.     end
  446. end
  447. function trail_setup_screen_five:textinput(text)    end
  448.  
  449.  
  450. matts_store_screen = {}
  451.  
  452. function matts_store_screen:load()
  453.     self.title = love.graphics.newText(font3,"Hello, I'm Matt.  So you're going\nto Oregon!  I can fix you up with\nwhat you need:")
  454.     self.items={
  455.     love.graphics.newText(font3,"- a team of oxen to pull\n\tyour wagon\n\n- clothing for both\n\tsummer and winter"),
  456.     love.graphics.newText(font3,"- plenty of food for the\n\ttrip\n\n- ammunition for your\n\trifles\n\n- spare parts for your\n\twagon")}
  457.     self.page = 1
  458.     return self
  459. end
  460. function matts_store_screen:draw()
  461.     local x,y,h = 0,0,love.graphics.getHeight()
  462.     love.graphics.draw(self.title, x, y)
  463.     x = x + font3:getWidth("      ")
  464.     y = h*0.5-self.items[self.page]:getHeight()*0.5
  465.     love.graphics.draw(self.items[self.page], x, y)
  466.     love.graphics.printf("Press SPACE BAR to continue", 0, h-font3:getHeight()*font3:getLineHeight(),
  467.         love.graphics.getWidth(),"center")
  468. end
  469. function matts_store_screen:update()
  470. end
  471. function matts_store_screen:keypressed(key)
  472.     if key == "space" or key == "return" then
  473.         if self.page == 1 then
  474.             self.page = 2
  475.         else
  476.             current_screen = matts_store_screen_two:load()
  477.         end
  478.     elseif key == "escape" then
  479.         if self.page == 1 then
  480.             current_screen = title_screen:load()
  481.         else
  482.             current_page = 1
  483.         end
  484.     end
  485. end
  486. function matts_store_screen:textinput(text)
  487. end
  488.  
  489. --[==[
  490. matts_store = {title="Matt's General Store\nIndependence, Missouri",
  491.  
  492. oxen={price=40,text=[[There are 2 oxen in a yoke;
  493. I recommend at least 3 yoke.
  494. I charge $40 a yoke.]],question="How many yoke do you\nwant?"},
  495.  
  496. food={price=20,text=
  497. [[I recommend you take at
  498. least 200 pounds of food
  499. for each person in your
  500. family.  I see that you have
  501. 5 people in all.  You'll need
  502. flour, sugar, bacon, and
  503. coffee.  My price is 20
  504. cents a pound.]],question="How many pounds of food do\nyou want?"},
  505.  
  506. clothing={price=10,text=
  507. [[You'll need warm clothing in
  508. the mountains.  I recommend
  509. taking at least 2 sets of
  510. clothes per person.  Each
  511. set is $10.00.]],question="How many sets of clothes do\nyou want?"},
  512.  
  513. ammo={price=2,text=[[I sell ammunition in boxes
  514. of 20 bullets.  Each box
  515. costs $2.00.]],question="How many boxes do you want?"},
  516.  
  517. parts={
  518. text=[[It's a good idea to have a
  519. few spare parts for your wagon.  Here are the prices:
  520.  
  521. \twagon wheel\t- $10 each
  522. \twagon axle\t- $10 each
  523. \twagon tongue\t- $10 each"]],
  524. }
  525. ]==]--
  526.  
  527.  
  528.  
  529. title_screen = {}
  530.  
  531.  
  532. function hs(name, points, rating)
  533.     return {name=name,points=points,rating=rating}
  534. end
  535.  
  536. high_scores_screen = {}
  537.     high_scores = {
  538.     hs("Stephen Meek",7650,"Trail Guide"),
  539.     hs("Celinda Hines",5694,"Adventurer"),
  540.     hs("Jiffer Lawson",5178,"Adventurer"),
  541.     hs("Jiffer Lawson",4794,"Adventurer"),
  542.     hs("Jiffer Lawson",4342,"Adventurer"),
  543.     hs("Andrew Sublette",4138,"Adventurer"),
  544.     hs("David Hastings",2945,"Greenhorn"),
  545.     hs("Kevin Kriebel",2152,"Greenhorn"),
  546.     hs("Ezra Meeker",2052,"Greenhorn"),
  547.     hs("William Vaughn",1401,"Greenhorn")
  548.     }
  549.  
  550.     on_arriving_in_oregon =
  551.     {
  552. [[Your most important resource is the
  553. people you have with you.  You
  554. receive points for each member of
  555. your party who arrives safely; you
  556. receive more points if they arrive
  557. in good health!]],
  558. [[The resources you arrive with will
  559. help you get started in the new
  560. land.  You receive points for each
  561. item you bring safely to Oregon.]],
  562. [[You receive points for your
  563. occupation in the new land.
  564. Because more farmers and
  565. carpenters were needed than
  566. bankers, you receive double
  567. points upon arriving in Oregon
  568. as a carpenter, and triple
  569. points for arriving as a farmer.]]
  570.     }
  571.     health_of_party__points_per_person = {good = 500, fair = 400, poor = 300, ["very poor"] = 200}
  572.     resources_of_party__points_per_item = {wagon = 50, ox = 4, ["spare wagon part"] = 2, ['set of clothing'] = 2,
  573.         ['bullets (each 50)'] = 1, ['food (each 25 pounds)'] = 1, ['cash (each 5 dollars)'] = 1}
  574.  
  575.  
  576. function high_scores_screen:load()
  577.     self.question = love.graphics.newText(font3,"Would you like to see how\npoints are earned?")
  578.     self.QWidth = self.question:getWidth()
  579.     self.width = font3:getWidth("points are earned?")
  580.     self.height = self.question:getHeight()
  581.     self.lineHeight = font3:getLineHeight()*font3:getHeight()
  582.     self.n = vec2(23,self.height+self.lineHeight*2)
  583.     self.p = vec2(love.graphics.getWidth()*0.5, self.n.y)
  584.     self.r = vec2(love.graphics.getWidth()-font3:getWidth("Trail Guide")-46, self.n.y)
  585.     local names,points,ratings = '','',''
  586.     for i,v in ipairs(high_scores) do
  587.         names = names ..v.name .."\n"
  588.         points = points ..v.points .."\n"
  589.         ratings = ratings ..v.rating ..'\n'
  590.     end
  591.     self.n2 = vec2(self.n.x, self.n.y+self.lineHeight*2)
  592.     self.p2 = vec2(self.p.x, self.p.y+self.lineHeight*2)
  593.     self.r2 = vec2(self.r.x, self.r.y+self.lineHeight*2)
  594.     self.names = love.graphics.newText(font3,names)
  595.     self.points = love.graphics.newText(font3,points)
  596.     self.ratings = love.graphics.newText(font3,ratings)
  597.     self.q = vec2(self.n.x+46, self.n2.y+self.ratings:getHeight()+self.lineHeight*2)
  598.     self.rect = {x=self.q.x-23, y=self.q.y-23, w=self.QWidth+46, h=self.height+46}
  599.     self.t = vec2(self.q.x+self.width+16, self.q.y+self.lineHeight)
  600.     self.text = ''
  601.     self.timer = 1
  602.     self.page = 0
  603.     return self
  604. end
  605. function high_scores_screen:draw()
  606.     if self.page == 0 then
  607.         love.graphics.print("The Oregon Top Ten")
  608.         love.graphics.print("Name", self.n.x, self.n.y)
  609.         love.graphics.print("Points", self.p.x, self.p.y)
  610.         love.graphics.print("Rating", self.r.x, self.r.y)
  611.         love.graphics.draw(self.names, self.n2.x, self.n2.y)
  612.         love.graphics.draw(self.points, self.p2.x, self.p2.y)
  613.         love.graphics.draw(self.ratings, self.r2.x, self.r2.y)
  614.  
  615.         love.graphics.draw(self.question,self.q.x, self.q.y)
  616.         love.graphics.rectangle("line",self.rect.x,self.rect.y,self.rect.w,self.rect.h,4,4,3)
  617.  
  618.         if self.timer%25>=10 then
  619.             love.graphics.setColor(1,1,1,0.5)
  620.             love.graphics.rectangle("fill",self.q.x+self.width+16+font3:getWidth(self.text),
  621.                 self.q.y+self.lineHeight, 20, 20)
  622.         end
  623.         love.graphics.setColor(1,1,1,1)
  624.         love.graphics.setFont(font3)
  625.         love.graphics.print(self.text, self.t.x, self.t.y)
  626.  
  627.         -- debug
  628.         love.graphics.print("high_scores_screen, page "..self.page, 0, love.graphics.getHeight()-23)
  629.         love.graphics.print("timer:"..self.timer,316,love.graphics.getHeight()-23)
  630.     elseif self.page>=1 and self.page <=3 then
  631.         love.graphics.printf("On Arriving in Oregon", 0, 0, love.graphics.getWidth(), "center")
  632.         love.graphics.print(on_arriving_in_oregon[self.page], self.n.x, self.n.y)
  633.         -- debug
  634.         love.graphics.print("high_scores_screen, page "..self.page, 0, love.graphics.getHeight()-23)
  635.         love.graphics.print("timer:"..self.timer,316,love.graphics.getHeight()-23)
  636.     end
  637. end
  638. function high_scores_screen:update()
  639.     self.timer = self.timer + 1
  640. end
  641. function high_scores_screen:keypressed(key)
  642.     if self.page == 0 then
  643.         if key == 'return' then
  644.             local s = string.sub(self.text, 1, 1)
  645.             if string.match(s, '[Yy]') then
  646.                 self.page = self.page + 1
  647.             elseif string.match(s, '[Nn]') then
  648.                 current_screen = title_screen:load()
  649.             end
  650.         elseif key == 'backspace' then
  651.             self.text = string.sub(self.text, 1, #self.text-1)
  652.         end
  653.     elseif self.page <=2 then
  654.         if key == 'space' or key == 'return' then
  655.             self.page = self.page + 1
  656.         end
  657.     elseif self.page == 3 then
  658.         if key == 'space' or key == 'return' then
  659.             high_scores_screen:last_page()
  660.         end
  661.     end
  662. end
  663. function high_scores_screen:last_page()
  664.     current_screen = title_screen:load()
  665. end
  666.  
  667. function high_scores_screen:textinput(text)
  668.     if string.match(text, '[yesnoYESNO]') and #self.text <3 then
  669.         self.text = self.text .. text
  670.     end
  671. end
  672.  
  673. -- learn is used in title_screen, option 2
  674. learn =     {
  675. [[Try taking a journey by
  676. covered wagon across 2000
  677. miles of plains, rivers, and
  678. mountains.  Try!  On the
  679. plains, will you slosh your
  680. oxen through mud and
  681. water-filled ruts or will you
  682. plod through dust six inches
  683. deep?]],
  684. [[How will you cross the rivers?
  685. If you have money, you might
  686. take a ferry (if there is a
  687. ferry).  Or, you can ford the
  688. river and hope you and your
  689. wagon aren't swallowed alive!]],
  690. [[What about supplies?  Well, if
  691. you're low on food you can
  692. hunt.  You might get a buffalo...
  693. you might.  And there are
  694. bear in the mountains.]],
  695. [[At the Dalles, you can try
  696. navigating the Columbia River,
  697. but if running the rapids with
  698. a makeshift raft makes you
  699. queasy, better take the Barlow
  700. Road.]],
  701. [[If for some reason you don't
  702. survive -- your wagon burns,
  703. or thieves steal your oxen, or
  704. you run out of provisions, or
  705. you die of cholera -- don't
  706. give up!  Try again...and
  707. again...until your name is up
  708. with the others on The Oregon
  709. Top Ten.]],
  710. [[         Control-S key
  711. You may turn the sound on or
  712. off during the program by
  713. pressing Control-S.]],
  714. [[            Esc key
  715. You may want to quit in the
  716. middle of the program.  If so,
  717. press the Escape (Esc) key
  718. twice whenever the computer is
  719. waiting for a response.]],
  720. [[     The software team responsible
  721. for creation of this product includes:
  722. Ed Gratz
  723. Charolyn Kapplinger
  724. Mark Paquette
  725. Larry Phenow
  726. Julie Redland]]
  727.     }
  728.  
  729. SOUND_STATE = "on"
  730. function title_screen:load()
  731.     local title = "The Oregon Trail"
  732.     local options = "You may:\n\n\t1. Travel the trail\n\t2. Learn about the trail\n\t3. See the Oregon Top Ten\n\t4. Turn sound "..SOUND_STATE .."\n\nWhat is your choice?"
  733.     self.title = love.graphics.newText(font, title)
  734.     self.options = love.graphics.newText(font3, options)
  735.     self.text = ''
  736.     self.size = {font3:getWidth("What is your choice?"), font3:getHeight()}
  737.     self.height = self.options:getHeight()
  738.     self.timer = 1
  739.     self.learn = learn
  740.     self.page = 0 -- when page is 0 you aren't learning!
  741.     return self
  742. end
  743.  
  744. function title_screen:textinput(text)
  745.     local text = string.match(text, "%d") -- only accept digits
  746.     if self.page == 0 and text then
  747.         self.text = self.text .. text
  748.     end
  749. end
  750.  
  751. function title_screen:keypressed(key)
  752.     if self.page == 0 then
  753.         if key == "backspace" then
  754.             self.text = string.sub(self.text, 1, #self.text-1) --self.text:sub(1, #self.text-1)
  755.         elseif key == "return" then
  756.             if self.text == '1' then
  757.                 current_screen = trail_setup_screen:load()
  758.             elseif self.text == '2' then
  759.                 self:start_learn()
  760.             elseif self.text == '3' then
  761.                 current_screen = high_scores_screen:load()
  762.             elseif self.text == '4' then
  763.                 SOUND_STATE = SOUND_STATE=="on" and "off" or "on"
  764.                 current_screen = self:load()
  765.             end
  766.         elseif key == "escape" then
  767.             love.event.quit()
  768.         end
  769.  
  770.     elseif self.page >= 1 and self.page <= 7 then
  771.         if key == "space" or key == "return" then
  772.             self:next_page()
  773.         end
  774.  
  775.     elseif self.page == 8 then
  776.         if key == "space" or key == "return" then
  777.             self:last_page()
  778.         end
  779.     end
  780. end
  781.  
  782. function title_screen:reload()
  783.     current_screen = self:load()
  784. end
  785. function title_screen:draw()
  786.     if self.page == 0 then
  787.         love.graphics.draw(self.title)
  788.         love.graphics.draw(self.options, 0, 50)
  789.        
  790.         if self.timer%25>=10 then
  791.             love.graphics.setColor(1,1,1,0.5)
  792.             love.graphics.rectangle("fill", self.size[1]+16+font3:getWidth(self.text), self.size[2]*1.25+self.height, 20, 20)
  793.         end
  794.         love.graphics.setColor(1,1,1,1)
  795.         love.graphics.setFont(font3)
  796.         love.graphics.print(self.text, self.size[1]+16, self.size[2]*1.25+self.height)
  797.  
  798.         -- debug
  799.         love.graphics.print("title_screen, page "..self.page, 0, love.graphics.getHeight()-23)
  800.         love.graphics.print("timer:"..self.timer,255,love.graphics.getHeight()-23)
  801.     elseif self.page >=1 then
  802.         love.graphics.setColor(0,0,0,1)
  803.         love.graphics.rectangle("fill",0,0,love.graphics.getWidth(),love.graphics.getHeight())
  804.         love.graphics.setColor(1,1,1,1)
  805.         love.graphics.setFont(font3)
  806.         love.graphics.print(self.learn[self.page])
  807.         -- debug
  808.         love.graphics.print("title_screen, learning, page "..self.page, 0, love.graphics.getHeight()-23)
  809.         love.graphics.print("timer:"..self.timer,316,love.graphics.getHeight()-23)
  810.     end
  811. end
  812.  
  813. function title_screen:update()
  814.     self.timer = self.timer + 1
  815. end
  816.  
  817. function title_screen:start_learn()
  818.     self.page = 1
  819. end
  820.  
  821. function title_screen:next_page()
  822.     self.page = self.page + 1
  823. end
  824.  
  825. function title_screen:last_page()
  826.     current_screen = title_screen:load()
  827. end
  828.  
  829. function love.load()
  830.     -- enable key repeat so backspace can be held down to trigger love.keypressed multiple times.
  831.     love.keyboard.setKeyRepeat(true)
  832.  
  833.     font = love.graphics.newFont(48)
  834.     font3 = love.graphics.newFont(20)
  835.  
  836.     current_screen = title_screen:load()
  837. end
  838.  
  839. function love.textinput (text)
  840.     current_screen:textinput(text)
  841. end
  842.  
  843. function love.keypressed(key)
  844.     current_screen:keypressed(key)
  845. end
  846.  
  847. function love.draw ()
  848.     current_screen:draw()
  849. end
  850.  
  851. function love.update()
  852.     current_screen:update()
  853. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement