Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- io.stdout:setvbuf("no")
- require 'math'
- vec2 = {}
- function vec2:new(x,y)
- assert(x,y)
- return {x=x,y=y}
- end
- local metatable = {}
- function metatable.__call(...)
- return vec2.new(...)
- end
- setmetatable(vec2, metatable)party_names = {}
- player = ''
- trail_setup_screen = {}
- function trail_setup_screen:load()
- 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?"
- self.options = love.graphics.newText(font3, options)
- self.text = ''
- self.size = love.graphics.newText(font3, "What is your choice?")
- self.size = {self.size:getWidth(), self.size:getHeight()}
- self.height = self.options:getHeight()
- self.timer = 1
- return self
- end
- function trail_setup_screen:draw()
- love.graphics.draw(self.options, 0, 50)
- if self.timer%25>=10 then
- love.graphics.setColor(1,1,1,0.5)
- love.graphics.rectangle("fill", self.size[1]+16+font3:getWidth(self.text), self.size[2]*1.25+self.height, 20, 20)
- end
- love.graphics.setColor(1,1,1,1)
- love.graphics.setFont(font3)
- love.graphics.print(self.text, self.size[1]+16, self.size[2]*1.25+self.height)
- -- debug
- love.graphics.print("trail_setup_screen", 0, love.graphics.getHeight()-23)
- love.graphics.print("timer:"..self.timer,316,love.graphics.getHeight()-23)
- end
- function trail_setup_screen:update()
- self.timer = self.timer + 1
- end
- function trail_setup_screen:textinput(text)
- local text = string.match(text, "%d") -- only accept digits
- self.text = text and self.text .. text or self.text
- end
- function trail_setup_screen:keypressed(key)
- if key == "backspace" then
- self.text = string.sub(self.text, 1, #self.text-1) --self.text:sub(1, #self.text-1)
- elseif key == "return" then
- if self.text == '1' then
- --current_screen = trail_setup_screen:load()
- current_screen = trail_setup_screen_two:load()
- player = 'banker'
- elseif self.text == '2' then
- --current_screen = trail_learn_screen:load()
- current_screen = trail_setup_screen_two:load()
- player = 'carpenter'
- elseif self.text == '3' then
- --current_screen = top_ten_screen:load()
- current_screen = trail_setup_screen_two:load()
- player = 'farmer'
- elseif self.text == '4' then
- end
- elseif key == "escape" then
- current_screen = title_screen:load()
- end
- end
- trail_setup_screen_two = {}
- function trail_setup_screen_two:load()
- local question = "What is the first name of the\nwagon leader?"
- self.question = love.graphics.newText(font3, question)
- self.text = ''
- self.size = love.graphics.newText(font3, "wagon leader?")
- self.size = {self.size:getWidth(), self.size:getHeight()}
- self.height = self.question:getHeight()
- self.timer = 1
- return self
- end
- function trail_setup_screen_two:textinput(text)
- self.text = self.text .. text
- end
- function trail_setup_screen_two:keypressed(key)
- if key == "backspace" then
- self.text = string.sub(self.text, 1, #self.text-1) --self.text:sub(1, #self.text-1)
- elseif key == "return" and self.text ~= '' then
- party_names[1] = self.text
- current_screen = trail_setup_screen_three:load()
- elseif key == "escape" then
- current_screen = trail_setup_screen:load()
- end
- end
- function trail_setup_screen_two:draw()
- love.graphics.draw(self.question)
- if self.timer%25>=10 then
- love.graphics.setColor(1,1,1,0.5)
- love.graphics.rectangle("fill", self.size[1]+16+font3:getWidth(self.text), self.height-self.size[2], 20, 20)
- end
- love.graphics.setColor(1,1,1,1)
- love.graphics.setFont(font3)
- love.graphics.print(self.text, self.size[1]+16, self.height-self.size[2])
- -- debug
- love.graphics.print("trail_setup_screen_two", 0, love.graphics.getHeight()-23)
- love.graphics.print("timer:"..self.timer,316,love.graphics.getHeight()-23)
- end
- function trail_setup_screen_two:update()
- self.timer = self.timer + 1
- end
- trail_setup_screen_three = {}
- function trail_setup_screen_three:load()
- local question = "What are the first names of the\nfour other members in your party?"
- self.question = love.graphics.newText(font3, question)
- self.qs = {"(Enter names or press ENTER)","Are these names correct?","Change which name?"}
- self.q_index = 1
- self.width = { font3:getWidth("1. "),font3:getWidth("2. "),font3:getWidth("3. "),
- font3:getWidth("4. "),font3:getWidth("5. ")}
- self.height = self.question:getHeight()
- self.lineHeight = font3:getLineHeight() * font3:getHeight()
- self.timer = 1
- self.transition_timer = false
- self.text = '' -- used in 'Are these names correct?' and 'Change which name?'
- for i = 1,5 do
- party_names[i] = party_names[i] or ''
- end
- self.current_name_index = 2
- self.isChangingNames = false -- set when q_index = 3
- return self
- end
- function trail_setup_screen_three:textinput(text)
- if self.q_index == 1 then
- party_names[self.current_name_index] = party_names[self.current_name_index] .. text
- elseif self.q_index == 2 then
- local s = string.match(text,'[YyEeSsNnOo]') or ''
- self.text = self.text ..s
- elseif self.q_index == 3 then
- if not self.isChangingNames then
- self.text = string.match(text,'[1-5]') or ''
- else
- party_names[self.current_name_index] = party_names[self.current_name_index] .. text
- end
- end
- end
- function trail_setup_screen_three:keypressed(key)
- if key == 'return' then
- if self.q_index == 1 then -- (Enter names or press ENTER)
- if self.current_name_index < 5 and party_names[self.current_name_index] ~= '' then
- self.current_name_index = self.current_name_index + 1
- elseif self.current_name_index == 5 and #party_names[self.current_name_index] > 0 then
- self.q_index = 2 -- Are these names correct?
- end
- elseif self.q_index == 2 then -- Are these names correct?
- local s = string.sub(self.text,1,1)
- if s == 'Y' or s == 'y' then
- trail_setup_screen_three:transition_to_screen_four()
- elseif s == 'N' or s == 'n' then
- self.text = ''
- self.q_index = 3 -- Change which name?
- end
- elseif self.q_index == 3 then -- Change which name?
- if not self.isChangingNames and #self.text == 1 then
- self.current_name_index = tonumber(self.text)
- self.isChangingNames = true
- self.text = ''
- else
- if self.current_name_index < 5 and party_names[self.current_name_index] ~= '' then
- self.current_name_index = self.current_name_index + 1
- elseif self.current_name_index == 5 and #party_names[self.current_name_index] > 0 then
- self.q_index = 2 -- Are these names correct?
- end
- end
- end
- elseif key == 'escape' then
- current_screen = trail_setup_screen_two:load()
- elseif key == 'backspace' then
- if self.q_index == 2 then
- self.text = ''
- elseif self.q_index == 3 and not self.isChangingNames then
- self.text = ''
- else
- party_names[self.current_name_index] = string.sub(party_names[self.current_name_index], 1, #party_names[self.current_name_index]-1)
- end
- end
- end
- function trail_setup_screen_three:draw()
- love.graphics.draw(self.question)
- local v = party_names
- local c = self.current_name_index
- local q = self.qs[self.q_index]
- love.graphics.setColor(1,1,1,1)
- love.graphics.setFont(font3)
- for i = 1,5 do
- love.graphics.print(i..". "..v[i], 0, self.height+self.lineHeight*i)
- end
- if self.q_index == 1 then -- (Enter names or press ENTER)
- love.graphics.print(self.qs[1], 0, self.height+self.lineHeight*7)
- if self.timer%25>=10 then
- love.graphics.setColor(1,1,1,0.5)
- love.graphics.rectangle("fill", self.width[c]+font3:getWidth(v[c]),
- self.height+self.lineHeight*c, 20, 20)
- end
- elseif self.q_index == 2 then -- Are these names correct?
- love.graphics.print(self.qs[2], 0, self.height+self.lineHeight*7)
- local h = self.height+self.lineHeight*7
- local w = font3:getWidth(q)+16
- love.graphics.print(self.text, w, h)
- if self.timer%25>=10 then
- love.graphics.setColor(1,1,1,0.5)
- love.graphics.rectangle("fill", font3:getWidth(q)+16+font3:getWidth(self.text),
- self.height+self.lineHeight*7, 20, 20)
- end
- elseif self.q_index == 3 then -- Change which name?
- love.graphics.print(self.qs[3], 0, self.height+self.lineHeight*7)
- if self.isChangingNames then
- local h = self.height+self.lineHeight*c
- local w = font3:getWidth(v[c])
- if self.timer%25>=10 then
- love.graphics.setColor(1,1,1,0.5)
- love.graphics.rectangle("fill", self.width[c]+font3:getWidth(v[c]),
- self.height+self.lineHeight*c, 20, 20)
- end
- else -- pick a name to change
- local h = self.height+self.lineHeight*7
- local w = font3:getWidth(q)+16
- love.graphics.print(self.text, w, h)
- if self.timer%25>=10 then
- love.graphics.setColor(1,1,1,0.5)
- love.graphics.rectangle("fill", w, h, 20, 20)
- end
- end
- end
- local height = love.graphics.getHeight()
- if self.transition_timer then
- local width = love.graphics.getWidth()
- love.graphics.setColor(1,0,0,1)
- love.graphics.rectangle('fill',0,0, width*roundToFive(self.transition_timer), height)
- -- debug
- love.graphics.setColor(1,1,1,1)
- love.graphics.print("trail_setup_screen_three:transition_to_screen_four",0, height-23)
- love.graphics.print("timer:"..self.timer,316,love.graphics.getHeight()-23)
- else
- -- debug
- love.graphics.setColor(1,1,1,1)
- love.graphics.print("trail_setup_screen_three", 0, height-23)
- love.graphics.print("timer:"..self.timer,316,love.graphics.getHeight()-23)
- end
- end
- function roundToFive(n)
- if n < 2 then return 1/6
- elseif n < 4 then return 1/3
- elseif n < 6 then return 1/2
- elseif n < 8 then return 2/3
- elseif n < 10 then return 5/6
- else return 1
- end
- end
- function trail_setup_screen_three:update()
- self.timer = self.timer + 2
- if self.transition_timer then
- self.transition_timer = self.transition_timer + 1
- if self.transition_timer >= 12 then
- current_screen = trail_setup_screen_four:load()
- end
- end
- end
- function trail_setup_screen_three:transition_to_screen_four()
- self.transition_timer = 1 -- creates self.transition_timer
- end
- trail_setup_screen_four = {}
- function trail_setup_screen_four:load()
- local intro = [[It is 1848. Your jumping off
- place for Oregon is Independence,
- Missouri. You must decide which
- month to leave Independence.]]
- self.advice = [[You attend a public meeting held
- for "folks with the California -
- Oregon fever." You're told:
- If you leave too early, there
- won't be any grass for your
- oxen to eat. If you leave too
- late, you may not get to Oregon
- before winter comes. If you
- leave at just the right time,
- there will be green grass and
- the weather will still be cool.]]
- self.intro = love.graphics.newText(font3,intro)
- local t = {"March\n","April\n","May\n","June\n","July\n","Ask for advice"}
- self.text = ''
- self.timer = 1
- local i_height = self.intro:getHeight()
- local lineHeight = font3:getLineHeight() * font3:getHeight()
- local options = ''
- for i,v in ipairs(t) do
- options = options .. i ..'. '..v
- end
- self.options = love.graphics.newText(font3,options)
- self.o = vec2(font3:getWidth("\t\t"), i_height+lineHeight*2)
- self.question = "What is your choice?"
- self.qWidth = font3:getWidth(self.question)
- self.q = vec2( 0, self.o.y + self.options:getHeight() + lineHeight*2 )
- self.viewingAdvice = false
- return self
- end
- function trail_setup_screen_four:textinput(text)
- if string.match(text,'[1-6]') then
- self.text = text
- end
- end
- function trail_setup_screen_four:keypressed(key)
- if key =='space' and self.viewingAdvice then
- self.viewingAdvice = false
- elseif key == 'return' then
- if self.viewingAdvice then
- self.viewingAdvice = false
- elseif #self.text == 1 then
- current_screen = trail_setup_screen_five:load()
- end
- elseif key == 'escape' then
- if self.viewingAdvice then
- self.viewingAdvice = false
- else
- self:back()
- end
- elseif key == 'backspace' then
- self.text = ''
- end
- end
- function trail_setup_screen_four:draw()
- if self.viewingAdvice then
- love.graphics.setColor(1,1,1,1)
- love.graphics.setFont(font3)
- love.graphics.print(self.advice, 0, 0)
- love.graphics.printf("Press SPACE BAR to continue",
- 0,
- love.graphics.getHeight()-font3:getHeight()*font3:getLineHeight(),
- love.graphics.getWidth(),
- "center")
- return
- end
- if self.timer%25>=10 then
- love.graphics.setColor(1,1,1,0.5)
- love.graphics.rectangle("fill",
- self.q.x+self.qWidth+16+font3:getWidth(self.text),
- self.q.y, 20, 20)
- end
- love.graphics.setColor(1,1,1,1)
- love.graphics.setFont(font3)
- love.graphics.draw(self.intro)
- love.graphics.draw(self.options, self.o.x, self.o.y)
- love.graphics.print(self.question, self.q.x, self.q.y)
- love.graphics.print(self.text, self.q.x+self.qWidth+16, self.q.y)
- -- debug
- love.graphics.print("trail_setup_screen_four", 0, love.graphics.getHeight()-23)
- love.graphics.print("timer:"..self.timer,316,love.graphics.getHeight()-23)
- end
- function trail_setup_screen_four:update()
- self.timer = self.timer + 1
- end
- function trail_setup_screen_four:back()
- current_screen = trail_setup_screen_three:load()
- end
- trail_setup_screen_five = {}
- function trail_setup_screen_five:load()
- self.strings = {love.graphics.newText(font3,[[Before leaving Independence you
- should buy equipment and
- supplies. You have $1600.00 in
- cash, but you don't have to
- spend it all now.]]),
- love.graphics.newText(font3,[[You can buy whatever you need at
- Matt's General Store.]])}
- self.page = 1
- return self
- end
- function trail_setup_screen_five:update() end
- function trail_setup_screen_five:draw()
- love.graphics.draw(self.strings[self.page], 0, love.graphics.getHeight()*0.5-
- self.strings[self.page]:getHeight()*0.5)
- love.graphics.printf("Press SPACE BAR to continue",
- 0,
- love.graphics.getHeight()-font3:getHeight()*font3:getLineHeight(),
- love.graphics.getWidth(),
- "center")
- end
- function trail_setup_screen_five:keypressed(key)
- if key == "space" or key == "return" then
- if self.page == 1 then self.page = 2
- else current_screen = matts_store_screen:load()
- end
- elseif key == "escape" then
- if self.page == 2 then self.page = 1
- else current_screen = trail_setup_screen_four:load()
- end
- end
- end
- function trail_setup_screen_five:textinput(text) end
- matts_store_screen = {}
- function matts_store_screen:load()
- 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:")
- self.items={
- love.graphics.newText(font3,"- a team of oxen to pull\n\tyour wagon\n\n- clothing for both\n\tsummer and winter"),
- 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")}
- self.page = 1
- return self
- end
- function matts_store_screen:draw()
- local x,y,h = 0,0,love.graphics.getHeight()
- love.graphics.draw(self.title, x, y)
- x = x + font3:getWidth(" ")
- y = h*0.5-self.items[self.page]:getHeight()*0.5
- love.graphics.draw(self.items[self.page], x, y)
- love.graphics.printf("Press SPACE BAR to continue", 0, h-font3:getHeight()*font3:getLineHeight(),
- love.graphics.getWidth(),"center")
- end
- function matts_store_screen:update()
- end
- function matts_store_screen:keypressed(key)
- if key == "space" or key == "return" then
- if self.page == 1 then
- self.page = 2
- else
- current_screen = matts_store_screen_two:load()
- end
- elseif key == "escape" then
- if self.page == 1 then
- current_screen = title_screen:load()
- else
- current_page = 1
- end
- end
- end
- function matts_store_screen:textinput(text)
- end
- --[==[
- matts_store = {title="Matt's General Store\nIndependence, Missouri",
- oxen={price=40,text=[[There are 2 oxen in a yoke;
- I recommend at least 3 yoke.
- I charge $40 a yoke.]],question="How many yoke do you\nwant?"},
- food={price=20,text=
- [[I recommend you take at
- least 200 pounds of food
- for each person in your
- family. I see that you have
- 5 people in all. You'll need
- flour, sugar, bacon, and
- coffee. My price is 20
- cents a pound.]],question="How many pounds of food do\nyou want?"},
- clothing={price=10,text=
- [[You'll need warm clothing in
- the mountains. I recommend
- taking at least 2 sets of
- clothes per person. Each
- set is $10.00.]],question="How many sets of clothes do\nyou want?"},
- ammo={price=2,text=[[I sell ammunition in boxes
- of 20 bullets. Each box
- costs $2.00.]],question="How many boxes do you want?"},
- parts={
- text=[[It's a good idea to have a
- few spare parts for your wagon. Here are the prices:
- \twagon wheel\t- $10 each
- \twagon axle\t- $10 each
- \twagon tongue\t- $10 each"]],
- }
- ]==]--
- title_screen = {}
- function hs(name, points, rating)
- return {name=name,points=points,rating=rating}
- end
- high_scores_screen = {}
- high_scores = {
- hs("Stephen Meek",7650,"Trail Guide"),
- hs("Celinda Hines",5694,"Adventurer"),
- hs("Jiffer Lawson",5178,"Adventurer"),
- hs("Jiffer Lawson",4794,"Adventurer"),
- hs("Jiffer Lawson",4342,"Adventurer"),
- hs("Andrew Sublette",4138,"Adventurer"),
- hs("David Hastings",2945,"Greenhorn"),
- hs("Kevin Kriebel",2152,"Greenhorn"),
- hs("Ezra Meeker",2052,"Greenhorn"),
- hs("William Vaughn",1401,"Greenhorn")
- }
- on_arriving_in_oregon =
- {
- [[Your most important resource is the
- people you have with you. You
- receive points for each member of
- your party who arrives safely; you
- receive more points if they arrive
- in good health!]],
- [[The resources you arrive with will
- help you get started in the new
- land. You receive points for each
- item you bring safely to Oregon.]],
- [[You receive points for your
- occupation in the new land.
- Because more farmers and
- carpenters were needed than
- bankers, you receive double
- points upon arriving in Oregon
- as a carpenter, and triple
- points for arriving as a farmer.]]
- }
- health_of_party__points_per_person = {good = 500, fair = 400, poor = 300, ["very poor"] = 200}
- resources_of_party__points_per_item = {wagon = 50, ox = 4, ["spare wagon part"] = 2, ['set of clothing'] = 2,
- ['bullets (each 50)'] = 1, ['food (each 25 pounds)'] = 1, ['cash (each 5 dollars)'] = 1}
- function high_scores_screen:load()
- self.question = love.graphics.newText(font3,"Would you like to see how\npoints are earned?")
- self.QWidth = self.question:getWidth()
- self.width = font3:getWidth("points are earned?")
- self.height = self.question:getHeight()
- self.lineHeight = font3:getLineHeight()*font3:getHeight()
- self.n = vec2(23,self.height+self.lineHeight*2)
- self.p = vec2(love.graphics.getWidth()*0.5, self.n.y)
- self.r = vec2(love.graphics.getWidth()-font3:getWidth("Trail Guide")-46, self.n.y)
- local names,points,ratings = '','',''
- for i,v in ipairs(high_scores) do
- names = names ..v.name .."\n"
- points = points ..v.points .."\n"
- ratings = ratings ..v.rating ..'\n'
- end
- self.n2 = vec2(self.n.x, self.n.y+self.lineHeight*2)
- self.p2 = vec2(self.p.x, self.p.y+self.lineHeight*2)
- self.r2 = vec2(self.r.x, self.r.y+self.lineHeight*2)
- self.names = love.graphics.newText(font3,names)
- self.points = love.graphics.newText(font3,points)
- self.ratings = love.graphics.newText(font3,ratings)
- self.q = vec2(self.n.x+46, self.n2.y+self.ratings:getHeight()+self.lineHeight*2)
- self.rect = {x=self.q.x-23, y=self.q.y-23, w=self.QWidth+46, h=self.height+46}
- self.t = vec2(self.q.x+self.width+16, self.q.y+self.lineHeight)
- self.text = ''
- self.timer = 1
- self.page = 0
- return self
- end
- function high_scores_screen:draw()
- if self.page == 0 then
- love.graphics.print("The Oregon Top Ten")
- love.graphics.print("Name", self.n.x, self.n.y)
- love.graphics.print("Points", self.p.x, self.p.y)
- love.graphics.print("Rating", self.r.x, self.r.y)
- love.graphics.draw(self.names, self.n2.x, self.n2.y)
- love.graphics.draw(self.points, self.p2.x, self.p2.y)
- love.graphics.draw(self.ratings, self.r2.x, self.r2.y)
- love.graphics.draw(self.question,self.q.x, self.q.y)
- love.graphics.rectangle("line",self.rect.x,self.rect.y,self.rect.w,self.rect.h,4,4,3)
- if self.timer%25>=10 then
- love.graphics.setColor(1,1,1,0.5)
- love.graphics.rectangle("fill",self.q.x+self.width+16+font3:getWidth(self.text),
- self.q.y+self.lineHeight, 20, 20)
- end
- love.graphics.setColor(1,1,1,1)
- love.graphics.setFont(font3)
- love.graphics.print(self.text, self.t.x, self.t.y)
- -- debug
- love.graphics.print("high_scores_screen, page "..self.page, 0, love.graphics.getHeight()-23)
- love.graphics.print("timer:"..self.timer,316,love.graphics.getHeight()-23)
- elseif self.page>=1 and self.page <=3 then
- love.graphics.printf("On Arriving in Oregon", 0, 0, love.graphics.getWidth(), "center")
- love.graphics.print(on_arriving_in_oregon[self.page], self.n.x, self.n.y)
- -- debug
- love.graphics.print("high_scores_screen, page "..self.page, 0, love.graphics.getHeight()-23)
- love.graphics.print("timer:"..self.timer,316,love.graphics.getHeight()-23)
- end
- end
- function high_scores_screen:update()
- self.timer = self.timer + 1
- end
- function high_scores_screen:keypressed(key)
- if self.page == 0 then
- if key == 'return' then
- local s = string.sub(self.text, 1, 1)
- if string.match(s, '[Yy]') then
- self.page = self.page + 1
- elseif string.match(s, '[Nn]') then
- current_screen = title_screen:load()
- end
- elseif key == 'backspace' then
- self.text = string.sub(self.text, 1, #self.text-1)
- end
- elseif self.page <=2 then
- if key == 'space' or key == 'return' then
- self.page = self.page + 1
- end
- elseif self.page == 3 then
- if key == 'space' or key == 'return' then
- high_scores_screen:last_page()
- end
- end
- end
- function high_scores_screen:last_page()
- current_screen = title_screen:load()
- end
- function high_scores_screen:textinput(text)
- if string.match(text, '[yesnoYESNO]') and #self.text <3 then
- self.text = self.text .. text
- end
- end
- -- learn is used in title_screen, option 2
- learn = {
- [[Try taking a journey by
- covered wagon across 2000
- miles of plains, rivers, and
- mountains. Try! On the
- plains, will you slosh your
- oxen through mud and
- water-filled ruts or will you
- plod through dust six inches
- deep?]],
- [[How will you cross the rivers?
- If you have money, you might
- take a ferry (if there is a
- ferry). Or, you can ford the
- river and hope you and your
- wagon aren't swallowed alive!]],
- [[What about supplies? Well, if
- you're low on food you can
- hunt. You might get a buffalo...
- you might. And there are
- bear in the mountains.]],
- [[At the Dalles, you can try
- navigating the Columbia River,
- but if running the rapids with
- a makeshift raft makes you
- queasy, better take the Barlow
- Road.]],
- [[If for some reason you don't
- survive -- your wagon burns,
- or thieves steal your oxen, or
- you run out of provisions, or
- you die of cholera -- don't
- give up! Try again...and
- again...until your name is up
- with the others on The Oregon
- Top Ten.]],
- [[ Control-S key
- You may turn the sound on or
- off during the program by
- pressing Control-S.]],
- [[ Esc key
- You may want to quit in the
- middle of the program. If so,
- press the Escape (Esc) key
- twice whenever the computer is
- waiting for a response.]],
- [[ The software team responsible
- for creation of this product includes:
- Ed Gratz
- Charolyn Kapplinger
- Mark Paquette
- Larry Phenow
- Julie Redland]]
- }
- SOUND_STATE = "on"
- function title_screen:load()
- local title = "The Oregon Trail"
- 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?"
- self.title = love.graphics.newText(font, title)
- self.options = love.graphics.newText(font3, options)
- self.text = ''
- self.size = {font3:getWidth("What is your choice?"), font3:getHeight()}
- self.height = self.options:getHeight()
- self.timer = 1
- self.learn = learn
- self.page = 0 -- when page is 0 you aren't learning!
- return self
- end
- function title_screen:textinput(text)
- local text = string.match(text, "%d") -- only accept digits
- if self.page == 0 and text then
- self.text = self.text .. text
- end
- end
- function title_screen:keypressed(key)
- if self.page == 0 then
- if key == "backspace" then
- self.text = string.sub(self.text, 1, #self.text-1) --self.text:sub(1, #self.text-1)
- elseif key == "return" then
- if self.text == '1' then
- current_screen = trail_setup_screen:load()
- elseif self.text == '2' then
- self:start_learn()
- elseif self.text == '3' then
- current_screen = high_scores_screen:load()
- elseif self.text == '4' then
- SOUND_STATE = SOUND_STATE=="on" and "off" or "on"
- current_screen = self:load()
- end
- elseif key == "escape" then
- love.event.quit()
- end
- elseif self.page >= 1 and self.page <= 7 then
- if key == "space" or key == "return" then
- self:next_page()
- end
- elseif self.page == 8 then
- if key == "space" or key == "return" then
- self:last_page()
- end
- end
- end
- function title_screen:reload()
- current_screen = self:load()
- end
- function title_screen:draw()
- if self.page == 0 then
- love.graphics.draw(self.title)
- love.graphics.draw(self.options, 0, 50)
- if self.timer%25>=10 then
- love.graphics.setColor(1,1,1,0.5)
- love.graphics.rectangle("fill", self.size[1]+16+font3:getWidth(self.text), self.size[2]*1.25+self.height, 20, 20)
- end
- love.graphics.setColor(1,1,1,1)
- love.graphics.setFont(font3)
- love.graphics.print(self.text, self.size[1]+16, self.size[2]*1.25+self.height)
- -- debug
- love.graphics.print("title_screen, page "..self.page, 0, love.graphics.getHeight()-23)
- love.graphics.print("timer:"..self.timer,255,love.graphics.getHeight()-23)
- elseif self.page >=1 then
- love.graphics.setColor(0,0,0,1)
- love.graphics.rectangle("fill",0,0,love.graphics.getWidth(),love.graphics.getHeight())
- love.graphics.setColor(1,1,1,1)
- love.graphics.setFont(font3)
- love.graphics.print(self.learn[self.page])
- -- debug
- love.graphics.print("title_screen, learning, page "..self.page, 0, love.graphics.getHeight()-23)
- love.graphics.print("timer:"..self.timer,316,love.graphics.getHeight()-23)
- end
- end
- function title_screen:update()
- self.timer = self.timer + 1
- end
- function title_screen:start_learn()
- self.page = 1
- end
- function title_screen:next_page()
- self.page = self.page + 1
- end
- function title_screen:last_page()
- current_screen = title_screen:load()
- end
- function love.load()
- -- enable key repeat so backspace can be held down to trigger love.keypressed multiple times.
- love.keyboard.setKeyRepeat(true)
- font = love.graphics.newFont(48)
- font3 = love.graphics.newFont(20)
- current_screen = title_screen:load()
- end
- function love.textinput (text)
- current_screen:textinput(text)
- end
- function love.keypressed(key)
- current_screen:keypressed(key)
- end
- function love.draw ()
- current_screen:draw()
- end
- function love.update()
- current_screen:update()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement