Whoa! Old post! WIP was here (no download):
WIP Thread.
--
Hi. This thread is to become a small side-project of mine, in which I replicate the games from
Dr. Kawashima's Brain Training. You will need
Cloggy's D3D Plugin to play these games, as it is used for text functions. These games are designed to run in 640x480 resolution.
Games List
Word Vs Color - Created 1/July (Not Updated Since)
Sums x Infinity - Created 1/July (Not Updated Since)
Low To High - Created 2/July (Updated 3/July)
Head Count - Created 5/July (Not Updated Since)
Sequence - Created 7/July (Not Updated Since)
Word Vs Colour
In this game, words appear on the screen in different colours. You must press the key that corresponds to the color of the word, not the word itself. The colours are
Red,
Green,
Blue,
Pink,
Cyan (light blue), and
Yellow.
sync on
sync rate 0
d3d_font 1, "times new roman", 100, 0, 0, 100
d3d_font 2, "times new roman", 20, 0, 0, 20
global prevword as integer = 0
global prevcolor as integer = 0
global currentword as integer = 0
global currentcolor as integer = 0
global score as integer = 0
global total as integer = 0
do
rem pick random word and color
prevword = currentword
prevcolor = currentcolor
repeat
currentword = rnd( 5 )
currentcolor = rnd( 5 )
until currentword <> currentcolor and ( currentword <> prevword or currentcolor <> prevcolor )
rem move prev word out of screen, move current word into screen
for n = 1 to 580 step 2
d3d_starttext
if key > 0 then d3d_text 1, 320, 240 - ( d3d_gettextheight( 1, pickword( prevword ) ) / 2 ) - n, 1, pickword( prevword ), pickcolor( prevcolor )
d3d_text 1, 320, 820 - ( d3d_gettextheight( 1, pickword( currentword ) ) / 2 ) - n, 1, pickword( currentword ), pickcolor( currentcolor )
draw_score()
d3d_endtext
sync
if key = 1
cls rgb( 255, 128, 128 )
else
if key = 2
cls rgb( 128, 255, 128 )
else
cls rgb( 255, 255, 255 )
endif
endif
next n
rem show word, wait for response
key = 0
repeat
if keystate( 19 ) = 1 then key = 1
if keystate( 34 ) = 1 then key = 2
if keystate( 48 ) = 1 then key = 3
if keystate( 25 ) = 1 then key = 4
if keystate( 46 ) = 1 then key = 5
if keystate( 21 ) = 1 then key = 6
d3d_starttext
d3d_text 1, 320, 240 - ( d3d_gettextheight( 1, pickword( currentword ) ) / 2 ), 1, pickword( currentword ), pickcolor( currentcolor )
draw_score()
d3d_endtext
sync
cls rgb( 255, 255, 255 )
until key > 0
if key - 1 = currentcolor
score = score + 1
key = 2
else
key = 1
endif
total = total + 1
loop
function pickword( temp )
if temp = 0 then exitfunction "RED"
if temp = 1 then exitfunction "GREEN"
if temp = 2 then exitfunction "BLUE"
if temp = 3 then exitfunction "PINK"
if temp = 4 then exitfunction "CYAN"
if temp = 5 then exitfunction "YELLOW"
endfunction ""
function pickcolor( temp )
if temp = 0 then exitfunction rgb( 255, 0, 0 )
if temp = 1 then exitfunction rgb( 0, 255, 0 )
if temp = 2 then exitfunction rgb( 0, 0, 225 )
if temp = 3 then exitfunction rgb( 255, 0, 255 )
if temp = 4 then exitfunction rgb( 0, 236, 255 )
if temp = 5 then exitfunction rgb( 255, 255, 0 )
endfunction 0
function draw_score()
d3d_text 2, 20, 410, 0, "CORRECT:", rgb( 0, 128, 0 )
d3d_text 2, 20, 440, 0, str$( score ), rgb( 0, 128, 0 )
d3d_text 2, 620, 410, 2, "INCORRECT:", rgb( 128, 0, 0 )
d3d_text 2, 620, 440, 2, str$( total - score ), rgb( 128, 0, 0 )
endfunction
Sums x Infinity
In this game, simple maths questions appear on the left of the screen. The questions can be sums, subtractions, or multiplications. You must enter the correct answer to each sum (pressing enter to confirm). The number of correct answers is displayed at the bottom-right next to the total number of questions answered.
sync on
sync rate 0
d3d_font 1, "times new roman", 100, 0, 0, 100
d3d_font 2, "times new roman", 20, 0, 0, 20
d3d_font 3, "times new roman", 40, 0, 0, 40
type calc
loperand as integer
operator as string
roperand as integer
answer as string
correct as boolean
endtype
rem array for holding sums.
rem only 6 stored; 1-2: previous, 3: current, 4-5: next, 6: next off-screen
dim calc( 6 ) as calc
rem prepare first 2 questions
for n = 4 to 5
calc( n ).loperand = rnd( 10 )
calc( n ).operator = pickoperator( rnd( 2 ) )
calc( n ).roperand = rnd( 10 )
if calc( n ).operator = "-" and calc( n ).roperand > calc( n ).loperand then calc( n ).operator = "+"
next n
global answer as string = ""
global score as integer = 0
global total as integer = 0
global hreturn as boolean = 0
do
rem create next random sum
calc( 6 ).loperand = rnd( 10 )
calc( 6 ).operator = pickoperator( rnd( 2 ) )
calc( 6 ).roperand = rnd( 10 )
if calc( 6 ).operator = "-" and calc( 6 ).roperand > calc( 6 ).loperand then calc( 6 ).operator = "+"
answer = ""
rem move sums
for n = 1 to 96 step 3
draw( 0 - n )
sync
cls rgb( 255, 255, 255 )
next n
rem move data
for n = 1 to 5
calc( n ).loperand = calc( n + 1 ).loperand
calc( n ).operator = calc( n + 1 ).operator
calc( n ).roperand = calc( n + 1 ).roperand
calc( n ).answer = calc( n + 1 ).answer
calc( n ).correct = calc( n + 1 ).correct
next n
calc( 6 ).loperand = 0
calc( 6 ).operator = ""
calc( 6 ).roperand = 0
rem show sum, wait for answer
hreturn = 1
repeat
if returnkey() = 0 then hreturn = 0
answer = add_to_string( answer, entry$(), 3, 1 )
clear entry buffer
draw( 0 )
sync
cls rgb( 255, 255, 255 )
until returnkey() = 1 and hreturn = 0
rem scoring
if answer = ""
answer = "..."
temp = 0
else
temp = checksum( calc( 3 ).loperand, calc( 3 ).operator, calc( 3 ).roperand, val( answer ) )
score = score + temp
endif
calc( 3 ).correct = temp
calc( 3 ).answer = answer
total = total + 1
loop
function add_to_string( temp as string, new as string, limit as integer, numonly as boolean )
for n = 1 to len( new )
if asc( mid$( new, n ) ) = 8
temp = left$( temp, len( temp ) - 1 )
else
if ( limit > 0 and len( temp ) = limit ) = 0
if numonly = 0 or ( numonly = 1 and ( ( val( mid$( new, n ) ) > 0 and val( mid$( new, n ) ) =< 9 ) or mid$( new, n ) = "0" ) )
temp = temp + mid$( new, n )
endif
endif
endif
next n
endfunction temp
function pickoperator( temp )
if temp = 0 then exitfunction "+"
if temp = 1 then exitfunction "-"
if temp = 2 then exitfunction "x"
endfunction ""
function pickcolor( temp )
if temp = 0 then exitfunction rgb( 255, 0, 0 )
if temp = 1 then exitfunction rgb( 0, 255, 0 )
if temp = 2 then exitfunction rgb( 0, 0, 225 )
if temp = 3 then exitfunction rgb( 255, 0, 255 )
if temp = 4 then exitfunction rgb( 0, 236, 255 )
if temp = 5 then exitfunction rgb( 255, 255, 0 )
endfunction 0
function checksum( l as integer, o as string, r as integer, a as integer )
if o = "+"
if a = l + r then exitfunction 1
else
if o = "-"
if a = l - r then exitfunction 1
else
if o = "x"
if a = l * r then exitfunction 1
endif
endif
endif
endfunction 0
function draw( yoffset )
local sum$ as string
local temp$ as string
d3d_color 0, 0, 0, 32 : d3d_box 40, 210, 300, 280 : d3d_box 300, 170, 630, 320
d3d_starttext
for t = 1 to 6
sum$ = str$( calc( t ).loperand ) + " " + calc( t ).operator + " " + str$( calc( t ).roperand )
if t < 3 and calc( t ).answer <> ""
temp$ = " = " + calc( t ).answer
if calc( t ).correct = 0
d3d_color 255, 128, 128, 255 : d3d_box 50, ( t * 96 ) - 58 + yoffset, 50 + d3d_gettextwidth( 3, sum$ + temp$ ), ( t * 96 ) - 18 + yoffset
d3d_color 255, 0, 0, 255 : d3d_text 1, 60, ( t * 96 ) - 108 + yoffset, 1, "X"
else
d3d_color 128, 255, 128, 255 : d3d_box 50, ( t * 96 ) - 58 + yoffset, 50 + d3d_gettextwidth( 3, sum$ + temp$ ), ( t * 96 ) - 18 + yoffset
d3d_color 0, 255, 0, 255 : d3d_text 1, 60, ( t * 96 ) - 108 + yoffset, 1, "O"
endif
endif
if t = 3 then temp$ = " ="
if calc( t ).operator <> "" then d3d_text 3, 50, ( t * 96 ) - 68 + yoffset, 0, sum$ + temp$, rgb( 32, 32, 32 )
next t
d3d_text 1, 475, 170, 1, answer, rgb( 2, 2, 2 )
draw_score()
d3d_endtext
endfunction
function draw_score()
d3d_color 32, 255, 64, 255
d3d_text 2, 620, 440, 2, str$( score ) +"/" + str$( total )
endfunction
Low To High
In this memory game, a group of boxes containing numbers appear on screen, then disappear promptly, leaving empty boxes. You must then click each box, starting with the one in which the lowest value was contained, and ending with the highest. The groups become bigger each time you progress.
3/July: Now Timer-Based. Grid re-centered. Countdown added.
sync on
sync rate 0
d3d_font 1, "times new roman", 100, 0, 0, 100
d3d_font 2, "times new roman", 20, 0, 0, 20
d3d_font 3, "times new roman", 40, 0, 0, 40
rem array for grid (maximum size: 8x8) (value = 0 means grid square not used)
type grid
value as integer
revealed as boolean
endtype
dim grid( 8, 8 ) as grid
global level as integer = 1
rem array from which to pick random numbers (without picking one twice)
dim random( 10 )
global leveltime as float = 0
global score as integer = 0
global total as integer = 0
global mc as boolean = 0
global mh as boolean = 0
global mx as integer = 0
global my as integer = 0
global maxcorrect as integer = 0
global xoff as integer = 0 rem use to offset grid when centering one even-numbered coord
global yoff as integer = 0 rem use to offset grid when centering one even-numbered coord
init_time()
do
rem create next grid
newgrid()
rem game
leveltime = 0
correct = 0
pass = 0
repeat
update_time()
leveltime = leveltime + dtime
mx = mousex()
my = mousey()
mc = mouseclick()
if mc = 1
if mh = 0
if leveltime > 4400 + ( maxcorrect * 50 )
temp = interact()
if temp = 1 then correct = correct + 1
if temp = 0 then correct = -1
endif
endif
mh = 1
else
mh = 0
endif
pass = ( correct = maxcorrect )
draw()
sync
cls rgb( 255, 255, 255 )
until pass = 1 or correct = -1
rem scoring
total = total + level
if pass = 1
score = score + level
if level < 7 then level = level + 1
else
if level > 1 then level = level - 1
endif
loop
function newgrid()
for x = 1 to 8
for y = 1 to 8
grid( x, y ).value = 0
grid( x, y ).revealed = 0
next y
next x
for n = 1 to 10
random( n ) = 0
next n
if level = 1
grid( 4, 4 ).value = pickrandom()
grid( 4, 5 ).value = pickrandom()
grid( 5, 4 ).value = pickrandom()
grid( 5, 5 ).value = pickrandom()
maxcorrect = 4
xoff = -12
yoff = 0
endif
if level = 2
grid( 3, 3 ).value = pickrandom()
grid( 5, 3 ).value = pickrandom()
grid( 4, 4 ).value = pickrandom()
grid( 3, 5 ).value = pickrandom()
grid( 5, 5 ).value = pickrandom()
maxcorrect = 5
xoff = 14
yoff = 22
endif
if level = 3
grid( 5, 3 ).value = pickrandom()
grid( 4, 4 ).value = pickrandom()
grid( 5, 4 ).value = pickrandom()
grid( 3, 5 ).value = pickrandom()
grid( 4, 5 ).value = pickrandom()
grid( 5, 5 ).value = pickrandom()
maxcorrect = 6
xoff = 14
yoff = 22
endif
if level = 4
grid( 4, 3 ).value = pickrandom()
grid( 5, 3 ).value = pickrandom()
grid( 3, 4 ).value = pickrandom()
grid( 4, 4 ).value = pickrandom()
grid( 5, 4 ).value = pickrandom()
grid( 3, 5 ).value = pickrandom()
grid( 4, 5 ).value = pickrandom()
maxcorrect = 7
xoff = 14
yoff = 22
endif
if level = 5
grid( 3, 4 ).value = pickrandom()
grid( 4, 4 ).value = pickrandom()
grid( 5, 4 ).value = pickrandom()
grid( 6, 4 ).value = pickrandom()
grid( 3, 5 ).value = pickrandom()
grid( 4, 5 ).value = pickrandom()
grid( 5, 5 ).value = pickrandom()
grid( 6, 5 ).value = pickrandom()
maxcorrect = 8
xoff = -12
yoff = 0
endif
if level = 6
grid( 3, 3 ).value = pickrandom()
grid( 4, 3 ).value = pickrandom()
grid( 5, 3 ).value = pickrandom()
grid( 3, 4 ).value = pickrandom()
grid( 4, 4 ).value = pickrandom()
grid( 5, 4 ).value = pickrandom()
grid( 3, 5 ).value = pickrandom()
grid( 4, 5 ).value = pickrandom()
grid( 5, 5 ).value = pickrandom()
maxcorrect = 9
xoff = 14
yoff = 22
endif
if level = 7
grid( 4, 3 ).value = pickrandom()
grid( 5, 3 ).value = pickrandom()
grid( 3, 4 ).value = pickrandom()
grid( 4, 4 ).value = pickrandom()
grid( 5, 4 ).value = pickrandom()
grid( 6, 4 ).value = pickrandom()
grid( 3, 5 ).value = pickrandom()
grid( 4, 5 ).value = pickrandom()
grid( 5, 5 ).value = pickrandom()
grid( 6, 5 ).value = pickrandom()
maxcorrect = 10
xoff = -12
yoff = 22
endif
endfunction
function pickrandom()
repeat
temp = 1 + rnd( 9 )
until random( temp ) = 0
random( temp ) = 1
endfunction temp
function interact()
for x = 0 to 7
for y = 0 to 7
if grid( x + 1, y + 1 ).value > 0 and grid( x + 1, y + 1 ).revealed = 0
if mx => 120 + ( x * 55 ) + xoff and my => 30 + ( y * 55 ) + yoff and mx =< 160 + ( x * 55 ) + xoff and my =< 70 + ( y * 55 ) + yoff
temp = 0
for a = 1 to 8
for b = 1 to 8
if ( a <> x or b <> y ) and grid( a, b ).value > 0
if grid( a, b ).revealed = 0 and grid( a, b ).value < grid( x + 1, y + 1 ).value then temp = 1
endif
next b
next a
if temp = 0
grid( x + 1, y + 1 ).revealed = 1
exitfunction 1
else
exitfunction 0
endif
endif
endif
next y
next x
endfunction -1
function draw()
for x = 0 to 7
for y = 0 to 7
if grid( x + 1, y + 1 ).value > 0
d3d_color 239, 239, 239, 255
d3d_box 120 + ( x * 55 ) + xoff, 30 + ( y * 55 ) + yoff, 160 + ( x * 55 ) + xoff, 70 + ( y * 55 ) + yoff
d3d_color 64, 64, 64, 255
d3d_line 120 + ( x * 55 ) + xoff, 30 + ( y * 55 ) + yoff, 120 + ( x * 55 ) + xoff, 70 + ( y * 55 ) + yoff
d3d_line 160 + ( x * 55 ) + xoff, 30 + ( y * 55 ) + yoff, 160 + ( x * 55 ) + xoff, 70 + ( y * 55 ) + yoff
d3d_line 120 + ( x * 55 ) + xoff, 30 + ( y * 55 ) + yoff, 160 + ( x * 55 ) + xoff, 30 + ( y * 55 ) + yoff
d3d_line 120 + ( x * 55 ) + xoff, 70 + ( y * 55 ) + yoff, 160 + ( x * 55 ) + xoff, 70 + ( y * 55 ) + yoff
d3d_color 16, 16, 16, 255
if leveltime > 1000 and leveltime < 4000
d3d_starttext : d3d_text 1, 320, 10, 1, str$( 4 - int( leveltime / 1000 ) ) : d3d_endtext
endif
d3d_starttext
if ( leveltime > 4000 and leveltime < 4400 + ( maxcorrect * 50 ) ) or grid( x + 1, y + 1 ).revealed = 1
d3d_text 3, 140 + ( x * 55 ) + xoff, 20 + ( y * 55 ) + yoff, 1, str$( grid( x + 1, y + 1 ).value )
endif
d3d_endtext
endif
next y
next x
d3d_starttext
draw_score()
d3d_endtext
endfunction
function draw_score()
d3d_color 32, 255, 64, 255
d3d_text 2, 620, 440, 2, str$( score ) +"/" + str$( total )
endfunction
function init_time()
global starttime as float = 0 rem initialise timer (just before loop)
global startpausetime as float = 0 rem the time for this pause
global paused as boolean = 0 rem pause flag
global pausetime as float = 0 rem current pause duration
global totalpausetime as float = 0 rem the total time for all pauses
global time as float = 0 rem current time
global dtime as float = 0 rem change in time
global otime as float = 0 rem time on previous loop
starttime = timer()
endfunction
function update_time()
if paused = 0
time = ( timer() - starttime - pausetime - totalpausetime )
dtime = time - otime
otime = time
else
pausetime = timer() - startpausetime
endif
endfunction
function pause( flag as boolean )
if flag = 0 and paused = 1
paused = 0
else
if paused = 0
paused = 1
totalpausetime = totalpausetime + pausetime
startpausetime = timer()
endif
endif
endfunction
function stats()
print "Current Time: ", time
print "Loop Time: ", dtime
print "Time Last Loop: ", otime
print "Pause Duration: ", pausetime
print "Total Time Paused: ", totalpausetime
if paused = 1 then print "Paused" else print "Running"
endfunction
Head Count
In this frantic game, there is a house that people enter and exit. Before the level starts, the number of people already in the house is displayed. The house then appears, and people begin going in and out. You must keep up with the flow, and write the total number of people remaining in the house at the end of the level.
sync on
sync rate 0
d3d_font 1, "times new roman", 100, 0, 0, 100
d3d_font 2, "times new roman", 20, 0, 0, 20
d3d_font 3, "times new roman", 40, 0, 0, 40
rem heads to count
type unit
xstart as float
ystart as float
xend as float
yend as float
starttime as float
endtime as float
exist as boolean
endtype
dim unit( 10 ) as unit
global leveltime as float = 0
global levelendtime as integer = 0
global level as float = 1.0
global spawnremaining as integer = 0
global spawndirection as integer = 0
global spawndelay as float = 0
global groupdelay as integer = 0
global headcount as integer = 0
global answer as string = ""
global score as integer = 0
global total as integer = 0
global hreturn as boolean = 0
init_time()
do
leveltime = 0
levelendtime = 7200 + ( ( level - 1 ) * 4000.0 )
hreturn = 1
headcount = 1 + rnd( 3 + ( level * 2 ) )
if headcount > 20 then headcount = 20
answer = ""
rem game
repeat
update_time()
leveltime = leveltime + dtime
if leveltime < levelendtime then spawndelay = spawndelay - dtime
control_units()
if leveltime => levelendtime and spawnremaining = 0
temp = 0
for n = 1 to 10
if unit( n ).exist = 1 then temp = 1
next n
if temp = 0
if returnkey() = 0 then hreturn = 0
answer = add_to_string( answer, entry$(), 2, 1 )
clear entry buffer
else
clear entry buffer
endif
else
clear entry buffer
endif
draw()
sync
cls rgb( 255, 255, 255 )
until returnkey() = 1 and hreturn = 0
rem scoring
total = total + 1
if answer = str$( headcount )
score = score + 1
if level < 5 then level = int( level + 1 )
else
if level > 1 then level = int( level - 1 )
endif
loop
function control_units()
if spawndelay =< 0
spawndelay = ( ( 5 / ( 4.5 + ( level * 0.2 ) ) ) * 350.0 ) - spawndelay
if groupdelay > 0 then groupdelay = groupdelay - 1
if groupdelay = 0
if spawnremaining = 0 and leveltime => 2200 and leveltime < levelendtime
spawnremaining = 1 + randomunits( int( level / 1.5 ) )
if spawnremaining > 1 then groupdelay = 4
spawndirection = rnd( 1 )
if headcount < spawnremaining and spawndirection = 1 then spawndirection = 0
if headcount > 20 - spawnremaining and spawndirection = 0 then spawndirection = 1
endif
endif
if spawnremaining > 0
spawnunit()
spawnremaining = spawnremaining - 1
endif
endif
if leveltime => levelendtime then spawnremaining = 0
for n = 1 to 10
if unit( n ).exist = 1
if leveltime => unit( n ).endtime
unit( n ).xstart = 0
unit( n ).ystart = 0
unit( n ).xend = 0
unit( n ).yend = 0
unit( n ).starttime = 0
unit( n ).endtime = 0
unit( n ).exist = 0
endif
endif
next n
endfunction
function spawnunit()
rem find free unit
for n = 10 to 1 step -1
if unit( n ).exist = 0 then temp = n
next n
rem if available, spawn unit
if temp > 0
if spawndirection = 0
unit( temp ).xstart = - 24
unit( temp ).ystart = 276
unit( temp ).xend = 320
unit( temp ).yend = 276
unit( temp ).starttime = leveltime
unit( temp ).endtime = leveltime + ( ( 5 / ( 4.5 + ( level * 0.2 ) ) ) * 2000.0 )
unit( temp ).exist = 1
headcount = headcount + 1
endif
if spawndirection = 1
unit( temp ).xstart = 320
unit( temp ).ystart = 276
unit( temp ).xend = 656
unit( temp ).yend = 276
unit( temp ).starttime = leveltime
unit( temp ).endtime = leveltime + ( ( 5 / ( 4.5 + ( level * 0.2 ) ) ) * 2000.0 )
unit( temp ).exist = 1
headcount = headcount - 1
endif
endif
endfunction
function randomunits( temp )
random = 1 + rnd( 19 )
value = ( temp / 4 ) * ( random )
value = value * ( temp / random )
value = int( value )
endfunction value
function add_to_string( temp as string, new as string, limit as integer, numonly as boolean )
for n = 1 to len( new )
if asc( mid$( new, n ) ) = 8
temp = left$( temp, len( temp ) - 1 )
else
if ( limit > 0 and len( temp ) = limit ) = 0
if numonly = 0 or ( numonly = 1 and ( ( val( mid$( new, n ) ) > 0 and val( mid$( new, n ) ) =< 9 ) or mid$( new, n ) = "0" ) )
temp = temp + mid$( new, n )
endif
endif
endif
next n
endfunction temp
function draw()
draw_units()
draw_house()
d3d_starttext
if leveltime => levelendtime and spawnremaining = 0
temp = 0
for n = 1 to 10
if unit( n ).exist = 1 then temp = 1
next n
if temp = 0
d3d_text 2, 320, 345, 1, "Answer"
d3d_text 1, 320, 350, 1, answer, rgb( 2, 2, 2 )
endif
endif
draw_score()
d3d_endtext
endfunction
function draw_units()
d3d_color 0, 0, 0, 255
for n = 1 to 10
if unit( n ).exist = 1
timespace = ( unit( n ).endtime - unit( n ).starttime )
distance = sqrt( ( ( unit( n ).xend - unit( n ).xstart ) ^ 2 ) + ( ( unit( n ).yend - unit( n ).ystart ) ^ 2 ) )
angle = wrapvalue ( 270 + atanfull ( unit( n ).xend - unit( n ).xstart, unit( n ).yend - unit( n ).ystart ) )
x = unit( n ).xstart - ( cos( angle ) * distance ) * ( ( unit( n ).starttime - leveltime ) / timespace )
y = unit( n ).ystart + ( sin( angle ) * distance ) * ( ( unit( n ).starttime - leveltime ) / timespace )
d3d_box x - 24, y - 64, x + 24, y + 64
endif
next n
endfunction
function draw_house()
if leveltime < 2000
d3d_color 0, 0, 0, 255
d3d_starttext
d3d_text 1, 320, 190, 1, str$( headcount ), rgb( 2, 2, 2 )
d3d_endtext
endif
if leveltime => 2000
d3d_color 0, 0, 0, 255
d3d_box 220, 140, 420, 340
endif
endfunction
function draw_score()
d3d_color 32, 255, 64, 255
d3d_text 2, 620, 440, 2, str$( score ) +"/" + str$( total )
endfunction
function init_time()
global starttime as float = 0 rem initialise timer (just before loop)
global startpausetime as float = 0 rem the time for this pause
global paused as boolean = 0 rem pause flag
global pausetime as float = 0 rem current pause duration
global totalpausetime as float = 0 rem the total time for all pauses
global time as float = 0 rem current time
global dtime as float = 0 rem change in time
global otime as float = 0 rem time on previous loop
starttime = timer()
endfunction
function update_time()
if paused = 0
time = ( timer() - starttime - pausetime - totalpausetime )
dtime = time - otime
otime = time
else
pausetime = timer() - startpausetime
endif
endfunction
function pause( flag as boolean )
if flag = 0 and paused = 1
paused = 0
else
if paused = 0
paused = 1
totalpausetime = totalpausetime + pausetime
startpausetime = timer()
endif
endif
endfunction
function stats()
print "Current Time: ", time
print "Loop Time: ", dtime
print "Time Last Loop: ", otime
print "Pause Duration: ", pausetime
print "Total Time Paused: ", totalpausetime
if paused = 1 then print "Paused" else print "Running"
endfunction
Sequence
In this game, a sequence of four numbers, one of which is missing, appears on screen, and you must fill in the missing number (using enter to confirm).
sync on
sync rate 0
d3d_font 1, "times new roman", 100, 0, 0, 100
d3d_font 2, "times new roman", 20, 0, 0, 20
d3d_font 3, "times new roman", 40, 0, 0, 40
rem array for holding sequence ( sequence number, value in sequence ( 0 - answer position, 5 - given answer, 6 - exist flag ) )
dim sequence( 6, 6 )
rem prepare first 2 questions
for n = 4 to 5
value = rnd( 20 )
stepvalue = 1 + rnd( 4 )
sequence( n, 0 ) = 1 + rnd( 3 )
sequence( n, 6 ) = 1
for o = 1 to 4
sequence( n, o ) = value
value = value + stepvalue
next o
next n
global leveltime as float = 0
global cursortime as float = 0
global level as integer = 1
global answer as string = ""
global score as integer = 0
global total as integer = 0
global hreturn as boolean = 0
global value as integer = 0
global stepvalue as integer = 0
init_time()
do
leveltime = 0
hreturn = 1
answer = ""
rem create next sequence
value = rnd( 20 )
stepvalue = 1 + rnd( 4 )
sequence( 6, 0 ) = 1 + rnd( 3 )
sequence( 6, 6 ) = 1
for n = 1 to 4
sequence( 6, n ) = value
value = value + stepvalue
next n
rem move sequence
for n = 1 to 96 step 3
draw( 0 - n, 0 )
sync
cls rgb( 255, 255, 255 )
next n
rem move data
for n = 1 to 5
for o = 0 to 6
sequence( n, o ) = sequence( n + 1, o )
next o
next n
for o = 0 to 5
sequence( 6, o ) = 0
next o
rem show sequence, wait for answer
hreturn = 1
repeat
update_time()
cursortime = cursortime + dtime
if cursortime > 1600 then cursortime = cursortime - 1600
if returnkey() = 0 then hreturn = 0
answer = add_to_string( answer, entry$(), 2, 1 )
clear entry buffer
draw( 0, 1 )
sync
cls rgb( 255, 255, 255 )
until returnkey() = 1 and hreturn = 0
rem scoring
sequence( 3, 5 ) = val( answer )
if answer = str$( sequence( 3, sequence( 3, 0 ) ) ) then score = score + 1
total = total + 1
loop
function add_to_string( temp as string, new as string, limit as integer, numonly as boolean )
for n = 1 to len( new )
if asc( mid$( new, n ) ) = 8
temp = left$( temp, len( temp ) - 1 )
else
if ( limit > 0 and len( temp ) = limit ) = 0
if numonly = 0 or ( numonly = 1 and ( ( val( mid$( new, n ) ) > 0 and val( mid$( new, n ) ) =< 9 ) or mid$( new, n ) = "0" ) )
temp = temp + mid$( new, n )
endif
endif
endif
next n
endfunction temp
function draw( yoffset, entrybox )
d3d_color 0, 0, 0, 32 : d3d_box 140, 200, 500, 270
d3d_starttext
for n = 1 to 6
if sequence( n, 6 ) = 1
if n < 3
if sequence( n, 5 ) <> sequence( n, sequence( n, 0 ) )
d3d_color 255, 128, 128, 255 : d3d_box 160, ( n * 96 ) - 70 + yoffset, 480, ( n * 96 ) - 37 + yoffset
d3d_color 255, 0, 0, 255 : d3d_text 1, 170, ( n * 96 ) - 124 + yoffset, 1, "X"
else
d3d_color 128, 255, 128, 255 : d3d_box 160, ( n * 96 ) - 70 + yoffset, 480, ( n * 96 ) - 37 + yoffset
d3d_color 0, 255, 0, 255 : d3d_text 1, 170, ( n * 96 ) - 124 + yoffset, 1, "O"
endif
endif
for o = 1 to 4
if ( n => 3 and sequence( n, 0 ) = o ) = 0
if ( n < 3 and sequence( n, 0 ) = o ) = 0
d3d_text 2, 170 + ( 100 * ( o - 1 ) ), ( n * 96 ) - 68 + yoffset, 1, str$( sequence( n, o ) ), rgb( 2, 2, 2 )
else
d3d_text 2, 170 + ( 100 * ( o - 1 ) ), ( n * 96 ) - 68 + yoffset, 1, str$( sequence( n, 5 ) ), rgb( 2, 2, 2 )
endif
endif
next o
endif
next n
d3d_text 1, 170 + ( 100 * ( sequence( 3, 0 ) - 1 ) ), 165, 1, answer, rgb( 2, 2, 2 )
if entrybox = 1
d3d_color 223, 223, 223, 255 : d3d_box 105 + ( 100 * ( sequence( 3, 0 ) - 1 ) ), 180, 235 + ( 100 * ( sequence( 3, 0 ) - 1 ) ), 299
if cursortime < 1120 then d3d_color 2, 2, 2, 255 : d3d_box 110 + ( 100 * ( sequence( 3, 0 ) - 1 ) ), 290, 230 + ( 100 * ( sequence( 3, 0 ) - 1 ) ), 294
endif
draw_score()
d3d_endtext
endfunction
function draw_score()
d3d_color 32, 255, 64, 255
d3d_text 2, 620, 440, 2, str$( score ) +"/" + str$( total )
endfunction
function init_time()
global starttime as float = 0 rem initialise timer (just before loop)
global startpausetime as float = 0 rem the time for this pause
global paused as boolean = 0 rem pause flag
global pausetime as float = 0 rem current pause duration
global totalpausetime as float = 0 rem the total time for all pauses
global time as float = 0 rem current time
global dtime as float = 0 rem change in time
global otime as float = 0 rem time on previous loop
starttime = timer()
endfunction
function update_time()
if paused = 0
time = ( timer() - starttime - pausetime - totalpausetime )
dtime = time - otime
otime = time
else
pausetime = timer() - startpausetime
endif
endfunction
There are more games to appear as they are completed, and existing games will be improved over time. Improvements will include features such as time restraints and results summations, and perhaps when a large number are up and running, I might begin amalgamating them into one program.
Please feedback!
Have Fun!