Skip to content

Commit

Permalink
Improved the generic lesson code.
Browse files Browse the repository at this point in the history
  • Loading branch information
bblodget committed Oct 14, 2010
1 parent 2c8f153 commit ad21a65
Show file tree
Hide file tree
Showing 12 changed files with 231 additions and 17 deletions.
2 changes: 1 addition & 1 deletion conf.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-- conf.lua

function love.conf(t)
t.title = "Touch Typing Tutor"
t.title = "Love To Type"
t.author = "Brandon Blodget"
t.screen.width = 800
t.screen.height = 600
Expand Down
87 changes: 87 additions & 0 deletions data_1a.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
-- data_1a.lua

module(..., package.seeall);

target_wpm = 15
actual_wpm = 0
nonsense_rep = 1

nonsense = {}
nonsense.size = 8
nonsense[1] = "aaa jjj"
nonsense[2] = "sss kkk"
nonsense[3] = "ddd lll"
nonsense[4] = "fff ;;;"
nonsense[5] = "kkk sss"
nonsense[6] = ";;; fff"
nonsense[7] = "jjj aaa"
nonsense[8] = "lll ddd"

intro = {}
intro.size = 8
intro[1] = "key: home\nHome row"
intro[2] = intro[1]
intro[3] = intro[1]
intro[4] = intro[1]
intro[5] = intro[1]
intro[6] = intro[1]
intro[7] = intro[1]
intro[8] = intro[1]

letter = {}
letter.size = 8
letter[1] = "a"
letter[2] = "s"
letter[3] = "d"
letter[4] = "f"
letter[5] = "j"
letter[6] = "k"
letter[7] = "l"
letter[8] = ";"

short ={}
short.size = 13
short[1] = "skd"
short[2] = "add"
short[3] = "all"
short[4] = "as"
short[5] = "kaf"
short[6] = "sad"
short[7] = "fad"
short[8] = "ja;"
short[9] = "ask;"
short[10] = "all;"
short[11] = "jal"
short[12] = "lad"
short[13] = "dad"

long ={}
long.size = 13
long[1] = "lads"
long[2] = "daks"
long[3] = "lakf"
long[4] = "dlsk"
long[5] = "ajds"
long[6] = "jal;"
long[7] = "salad"
long[8] = "flask"
long[9] = "lass"
long[10] = "lads"
long[11] = "jakl"
long[12] = "falls"
long[13] = "alas"

-- The Flow
-- nonsense x1 (first time x2 2nd time) (intro text)
-- letter
-- nonsense x1 (first time x2 2nd time) (no intro text)
-- letter
-- short x2 x8 (timed)
-- actual wpm / target wpm 15
-- long x4 x4 (timed)
-- actual wpm / target wpm 15 (repeat or continue)





32 changes: 32 additions & 0 deletions do_lesson.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
-- do_lesson.lua

module(..., package.seeall);

require "levels"
require "nonsense"
require "letters"

local step = 0

function load(lesson_data)
step = step + 1
love.graphics.setBackgroundColor(128,255,128) -- light green
love.graphics.setColor(0,0,0) -- black

if (step == 1) then nonsense.load(lesson_data,true,1)
elseif (step == 2) then letters.load(lesson_data)
elseif (step == 3) then nonsense.load(lesson_data,false,1)
elseif (step == 4) then letters.load(lesson_data)
else
-- back to the levels selection
step = 0
levels.load()
end



end




Binary file added images/love-ball.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/love-big-ball.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/love.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 7 additions & 11 deletions letters.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,13 @@ local l_height = 0
local count = 0

local letter = {}
letter.size = 8
letter[1] = "a"
letter[2] = "s"
letter[3] = "d"
letter[4] = "f"
letter[5] = "j"
letter[6] = "k"
letter[7] = "l"
letter[8] = ";"

function load()
local lesson_data_ = {}

function load(lesson_data)
lesson_data_ = lesson_data
letter = lesson_data.letter

love.graphics.setBackgroundColor(130,41,79) -- purple
love.graphics.setColor(255,255,255) -- white
love.graphics.setLineWidth( 3 )
Expand Down Expand Up @@ -62,7 +58,7 @@ function keypressed(key, unicode)
l_width = bigfont:getWidth(target)
count = count + 1
if (count == 30) then
level1a.load()
do_lesson.load(lesson_data_)
end
end
end
Expand Down
7 changes: 5 additions & 2 deletions levels.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
module(..., package.seeall);

require "lessons"
require "level1a"
-- require "level1a"
require "do_lesson"
require "data_1a"

local level=0
local submenu = ""
Expand Down Expand Up @@ -39,7 +41,8 @@ function submenu_kp(key, unicode)

if key == "1" then
if level == 1 then
level1a.load()
-- level1a.load()
do_lesson.load(data_1a)
end
end

Expand Down
4 changes: 2 additions & 2 deletions main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ function love.load()
bigfont = love.graphics.newFont(34) -- font size
smallfont = love.graphics.newFont(24) -- font size
love.graphics.setBackgroundColor(128,128,255) -- light blue
love.graphics.setColor(0,0,0) -- black
keysnd = love.audio.newSource("button-pressed.ogg", "static")
keysnd = love.audio.newSource("sounds/button-pressed.ogg", "static")
love_img = love.graphics.newImage("images/love-ball.png")
love.mouse.setVisible(false)
title.load()
--letters.load()
Expand Down
91 changes: 91 additions & 0 deletions nonsense.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
-- nonsense.lua

module(..., package.seeall);

require "levels"
require "letters"

local input = ""
local line = 1

local text = {}
local line1 = ""
local index = 1 -- index into pattern array

local pattern = {}
local info = {}
local show
local lineSize
local lesson_data_ = {}

-- lesson_data: the data for this level
-- showInfo: boolean, true if new key info should be displayed
-- size: how many pattern entries should be put on a line (1 or 2)
function load(lesson_data,showInfo,size)
lesson_data_ = lesson_data
pattern = lesson_data.nonsense

info = lesson_data.intro
show = showInfo
lineSize = size

love.graphics.setBackgroundColor(128,255,128) -- light green
love.graphics.setColor(0,0,0) -- black
love.draw = draw
love.keypressed = keypressed
input = ""
line = 1
line1 = ""
index = 1
end


function draw()
love.graphics.setFont(bigfont)
if (show) then
-- love.graphics.printf("Key: home \nHome row",10,50,800, 'left')
love.graphics.printf(info[index],10,50,800, 'left')
end
love.graphics.printf(pattern[index], 350,150,740, 'left')
if (line == 1) then
love.graphics.printf(input .. "_", 350,250,740, 'left')
else
love.graphics.printf(line1, 350,250,740, 'left')
love.graphics.printf(input .. "_", 350,300,740, 'left')
end
end

function keypressed(key, unicode)
if key == "escape" then
levels.load()
elseif key == "return" then
love.audio.play(keysnd)
if (input == pattern[index]) then
if (line == 1) then
line1 = input
input = ""
line = 2
else
input = ""
line1 = ""
line = 1
index = index + 1
if (index > pattern.size) then
--letters.load()
do_lesson.load(lesson_data_)
end
end
else
input = ""
end
elseif (key == "backspace" or
key == "rshift" or
key == "lshift"
) then
-- do nothing
else
input = input .. key
end
end


Binary file added sounds/button-pressed.ogg
Binary file not shown.
7 changes: 6 additions & 1 deletion title.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ end
function draw()
love.graphics.setFont(bigfont)

love.graphics.printf("Touch Typing Tutor",0,120,800, 'center')
love.graphics.setColor(255,255,255) -- white?
love.graphics.draw(love_img, 250,110)

love.graphics.setColor(0,0,0) -- black

love.graphics.printf("To Type",320,120,800, 'left')

if (not full_screen) then
love.graphics.printf("1. Lessons\n" ..
Expand Down

0 comments on commit ad21a65

Please sign in to comment.