Challenge:
Version:
2
Winner?:
No
Code Snippet:
Rem Project: Coin Collectors Rem Created: 12/23/2006 1:53:05 PM Rem ***** Main Source File ***** sync on sync rate 60 autocam off hide mouse randomize timer() type snowspot x as dword y as dword speed as dword endtype make_player() make_grass() make_ground() make_snow() make_rock() make_rocks() make_tree() make_coin() make_coins() make_snowflakes() process_player() position camera 1200, 400, 700 global go as boolean global smooth as dword global score as integer global time as double integer global lockcontrols as boolean lockcontrols = 1 set text size 32 set text font "Lucida Console" set text to bold ink rgb(0, 0, 255), 0 smooth = 100 do if go process_inventory() process_player() process_hud() color = (time - timer())/235 else process_instructions() color = 255 endif process_coins() process_camera() process_snowflakes() color backdrop rgb(color, color, color) sync loop function process_snowflakes() ink -1, 0 for t = 0 to 20 x = snowflakes(t).x y = snowflakes(t).y box x, y, x+8, y+8 inc y, snowflakes(t).speed if lockcontrols = 0 then inc x, (leftkey() - rightkey()) * snowflakes(t).speed if y > screen height() x = rnd(screen width()) y = 10 endif snowflakes(t).x = x snowflakes(t).y = y next t ink rgb(0, 0, 255), 0 endfunction function process_instructions() center text screen width()/2, screen height()/2-60, "Use the arrowkeys to collect" center text screen width()/2, screen height()/2-30, "goodness coins for Santa." center text screen width()/2, screen height()/2, "The more coins you collect," center text screen width()/2, screen height()/2+30, "the more presents Santa gives you!" center text screen width()/2, screen height()/2+60, "Press enter to start." if returnkey() make_inventory() go = 1 time = timer() + 60*1000 smooth = 25 lockcontrols = 0 endif endfunction function process_hud() rotate sprite 1, sin(timer()/5)*10 text sprite width(1) + 10, sprite height(1)/3, "x " + str$(score) text screen width() - text width("Time: " + str$((time - timer())/1000)) - 10, 20, "Time: " + str$((time - timer())/1000) if time - timer() < 0 make_presents() endif text 0, screen height() - 30, "FPS: " + str$(screen fps()) endfunction function make_presents() local present as integer clear_inventory() dim presents() as dword present = (score / 2) + 3 if present < 10 make_coal() bad = 20 - present present = bad p$ = "lump" c$ = " of coal" else make_paper() p$ = "present" endif delaytime = 50 ink rgb(0, 0, 255), 0 color backdrop -1 lockcontrols = 1 do for t = 1 to 360 set camera to follow 500, 0, 500, t, 200 + p*9, 75, 50, 0 point camera 500, 0, 500 process_coins() process_snowflakes() dec delay if p < present and delay <= 0 delay = delaytime dec delaytime array insert at bottom presents() if bad > 0 presents() = make_obj_sphere(20) texture object presents(), 4 else presents() = make_obj_cube(20) texture object presents(), 4+rnd(2) endif x = newxvalue(500, wrapvalue(t+130), 40 + p*8) z = newzvalue(500, wrapvalue(t+130), 40 + p*8) position object presents(), x, get ground height(1, x, z) + object size y(presents())/4, z inc p endif if p > 1 then s$ = "s" center text screen width()/2, text height("Y"), "You got " + str$(p) + " " + p$ + s$ + c$ + " for Christmas!" sync next t loop endfunction function make_coal() ink 0, 0 box 0, 0, 4, 4 get image 4, 0, 0, 4, 4, 1 endfunction function make_paper() `paper 1 ink rgb(255, 0, 0), 0 box 0, 0, 32, 32 ink rgb(0, 255, 0), 0 s = 3 for t = 1 to 10 x = rnd(32-s) y = rnd(32-s) circle x, y, s next t get image 4, 0, 0, 32, 32, 1 `paper 2 ink rgb(0, 0, 255), 0 box 0, 0, 32, 32 ink rgb(255, 0, 255), 0 s = 3 for t = 1 to 10 x = rnd(32-s) y = rnd(32-s) circle x, y, s next t get image 5, 0, 0, 32, 32, 1 `paper 3 ink rgb(255, 255, 0), 0 box 0, 0, 32, 32 ink rgb(0, 255, 0), 0 s = 3 for t = 1 to 10 x = rnd(32-s) y = rnd(32-s) circle x, y, s next t get image 6, 0, 0, 32, 32, 1 endfunction function clear_inventory() inc score, array count(inventory(0)) for t = 0 to array count(inventory(0)) delete sprite inventory(t) next t delete sprite 1 endfunction function process_inventory() for t = 0 to array count(inventory(0)) sprite inventory(t), sprite x(inventory(t)) - 18, sprite y(inventory(t)) - 18, 3 if sprite x(inventory(t)) < 0 and sprite y(inventory(t)) < 0 inc score delete sprite inventory(t) array delete element inventory(0), t endif next t endfunction function make_inventory() dim inventory() as dword sprite 1, 32, 32, 3 offset sprite 1, 32, 32 endfunction function process_coins() for t = 0 to array count(coins(0)) if object visible(coins(t)) turn object right coins(t), 3 if object collision(player(0), coins(t)) array insert at bottom inventory(0) inventory() = make_spr(object screen x(coins(t)), object screen y(coins(t)), 3) exclude object on coins(t) endif endif next t endfunction function process_camera() set camera to follow object position x(player(0)), object position y(player(0)), object position z(player(0)), object angle y(player(0)), 50, 20, smooth, 0 endfunction function process_player() move object player(0), upkey() - downkey() YRotate Object player(0),Object Angle Y(player(0))+(RightKey()-LeftKey())*1.5 x# = object position x(player(0)) z# = object position z(player(0)) if x# < 20 then x# = 20 if x# > 980 then x# = 980 if z# < 20 then z# = 20 if z# > 980 then z# = 980 position object player(0), x#, get ground height(1, x#, z#) + object size y(player(0)) / 2, z# endfunction function make_player() dim player(0) as dword player(0) = make_obj_sphere(5) color object player(0), rgb(0, 0, 255) position object player(0), 250, 0, 250 endfunction function make_ground() make matrix 1, 1000, 1000, 50, 50 randomize matrix 1, 12.5 for t = 0 to 50 set matrix height 1, t, 0, 40 set matrix height 1, 0, t, 40 set matrix height 1, t, 50, 40 set matrix height 1, 50, t, 40 next t prepare matrix texture 1, 1, 1, 1 update matrix 1 endfunction function make_snowflakes() dim snowflakes(20) as snowspot for t = 0 to 20 snowflakes(t).x = rnd(screen width()) snowflakes(t).y = rnd(screen height()) snowflakes(t).speed = rnd(3) + 3 next t endfunction function make_snow() dim snow(0) as dword snow(0) = make_obj_plain(1000) position object snow(0), 500, 4, 500 xrotate object snow(0), 270 color object snow(0), -1 endfunction function make_grass() ink rgb(0, 255, 0), 0 box 0, 0, 32, 32 ink rgb(0, 128, 0), 0 s = 3 for t = 1 to 40 x = rnd(32-s) y = rnd(32-s) box x, y, x+s, y+s next t get image 1, 0, 0, 32, 32, 1 endfunction function make_rocks() r = 100 dim rocks(r-1) as dword for t = 0 to r-1 rocks(t) = make_obj_cube(4) texture object rocks(t), 2 rotate object rocks(t), rnd(360), rnd(360), rnd(360) x = rnd(960)+20 z = rnd(960)+20 position object rocks(t), x, get ground height(1, x, z) - object size y(rocks(t)) / 4, z next t endfunction function make_obj_cube(size as dword) id = free_obj() make object cube id, size endfunction id function free_obj() repeat inc id until object exist(id) = 0 endfunction id function make_spr(x as dword, y as dword, img as dword) id = free_spr() sprite id, x, y, img endfunction id function free_spr() repeat inc id until sprite exist(id) = 0 endfunction id function make_obj_plain(size as dword) id = free_obj() make object plain id, size, size endfunction id function make_obj_cylinder(size as dword) id = free_obj() make object cylinder id, size endfunction id function make_obj_cone(size as dword) id = free_obj() make object cone id, size endfunction id function make_obj_sphere(size as dword) id = free_obj() make object sphere id, size endfunction id function make_rock() ink rgb(128, 128, 128), 0 box 0, 0, 32, 32 ink rgb(100, 100, 120), 0 s = 4 for t = 1 to 50 x = rnd(32-s) y = rnd(32-s) box x, y, x+s, y+s next t get image 2, 0, 0, 32, 32, 1 endfunction function make_coin() datatoimage(3) endfunction function make_coins() c = 200 dim coins(c-1) as dword for t = 0 to c-1 coins(t) = make_obj_plain(7) texture object coins(t), 3 set object transparency coins(t), 1 x = rnd(960)+20 z = rnd(960)+20 position object coins(t), x, get ground height(1, x, z) + object size y(coins(t))/2, z next t endfunction function make_tree() dim tree(3) as dword for t = 1 to 3 tree(t) = make_obj_cone(50*(5-t)) scale object tree(t), 100, 75, 100 color object tree(t), rgb(0, 255, 0) position object tree(t), 500, 75 + t*39, 500 next t tree(0) = make_obj_cylinder(50) color object tree(0), rgb(128, 64, 0) position object tree(0), 500, 25, 500 endfunction function datatoimage(image) memblock=1 read size make memblock 1,size read sx `as dword read sy `as dword read depth `as dword write memblock dword 1,0,sx write memblock dword 1,4,sy write memblock dword 1,8,depth for x=0 to sx-1 for y=0 to sy-1 pos=(y*sx+x)*4+12 read b `as byte read g `as byte read r `as byte read a `as byte write memblock byte 1,pos,b write memblock byte 1,pos+1,g write memblock byte 1,pos+2,r write memblock byte 1,pos+3,a next y next x make image from memblock image,1 endfunction data 16396 data 64 data 64 data 32 data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,181,183,222,1,222,222,244,19,246,243,248,54,248,248,248,105,247,247,247,164,245,250,255,206,252,252,252,209,236,242,247,215,230,236,239,241,142,185,208,242,85,133,178,242,77,166,213,242,69,210,255,229,61,211,255,209,55,209,255,206,49,206,255,168,43,203,255,135,38,198,255,77,33,191,248,25,32,176,227,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,212,212,241,6,202,202,243,63,220,220,247,156,247,250,255,212,250,251,251,242,249,249,249,255,248,252,255,255,254,254,254,255,239,244,249,255,228,234,231,255,175,202,217,255,97,150,188,255,88,140,184,255,79,176,223,255,71,214,255,255,63,212,255,255,56,210,255,255,50,208,255,255,44,205,255,255,39,200,255,251,34,196,253,219,30,192,250,164,27,188,247,98,23,182,242,36,27,156,205,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,234,234,251,6,226,226,251,63,217,217,248,168,217,217,249,241,245,245,253,255,253,253,253,255,252,255,255,255,250,250,250,255,255,255,255,255,242,243,243,255,233,238,242,255,194,213,217,255,110,167,197,255,100,146,186,255,90,168,212,255,81,210,255,255,73,214,255,255,65,212,255,255,58,210,255,255,51,208,255,255,46,207,255,255,40,203,255,255,35,198,255,255,31,195,252,255,27,190,250,254,24,186,246,226,21,181,242,142,18,176,238,43,20,154,206,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,251,251,254,1,247,247,255,57,240,240,255,168,232,232,253,241,223,223,251,255,241,241,254,255,254,254,255,255,254,254,254,255,253,255,253,255,251,254,251,255,246,249,246,255,238,241,238,255,214,224,223,255,145,185,207,255,112,154,191,255,102,161,202,255,92,202,245,255,83,217,255,255,75,215,255,255,67,213,255,255,59,210,255,255,53,209,255,255,47,207,255,255,41,205,255,255,36,201,255,255,32,196,255,255,28,193,251,255,24,188,248,255,21,183,244,255,19,179,240,228,17,175,237,142,15,171,233,43,20,138,184,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,10,255,255,255,108,251,251,255,231,244,244,255,255,236,236,254,255,236,236,254,255,254,254,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,244,247,244,255,230,235,232,255,186,204,218,255,125,169,200,255,114,160,198,255,104,190,230,255,94,219,255,255,85,218,255,255,76,215,255,255,68,213,255,255,60,211,255,255,54,209,255,255,47,207,255,255,42,206,255,255,37,203,255,255,32,198,255,255,28,194,253,255,25,189,249,255,22,186,245,255,19,181,242,255,17,178,239,255,15,173,236,228,13,168,232,108,12,159,219,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,31,255,255,255,158,255,255,255,249,255,255,255,255,247,247,255,255,239,239,255,255,250,250,255,255,255,255,255,255,255,255,255,255,255,255,255,255,253,255,253,255,255,255,255,255,240,244,248,255,220,224,232,255,146,187,209,255,128,166,199,255,116,180,217,255,105,214,255,255,95,220,255,255,86,218,255,255,77,215,255,255,69,213,255,255,61,211,255,255,54,209,255,255,48,208,255,255,42,206,255,255,37,205,255,255,33,201,255,255,29,196,255,255,25,192,251,255,22,187,248,255,19,182,244,255,17,179,240,255,15,174,237,255,13,170,233,249,12,166,230,151,11,162,226,24,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,1,255,255,255,64,255,255,255,200,255,255,255,255,255,255,255,255,255,255,255,255,249,249,255,255,247,247,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,252,253,253,255,253,254,254,255,234,239,237,255,188,210,221,255,140,176,205,255,129,174,208,255,117,205,243,255,106,223,255,255,96,221,255,255,86,218,255,255,78,216,255,255,69,213,255,255,62,211,255,255,55,209,255,255,48,208,255,255,42,206,255,255,37,205,255,255,33,203,255,255,29,199,255,255,25,194,254,255,22,189,250,255,19,185,246,255,17,181,243,255,15,177,239,255,13,172,236,255,12,168,232,254,11,165,228,187,11,161,225,45,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,10,255,255,255,108,255,255,255,231,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,250,250,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,252,254,255,255,248,252,248,255,223,230,234,255,152,192,213,255,141,175,206,255,129,192,226,255,117,221,255,255,106,223,255,255,96,221,255,255,87,218,255,255,78,216,255,255,69,213,255,255,62,211,255,255,55,209,255,255,48,208,255,255,43,206,255,255,37,205,255,255,33,203,255,255,29,200,255,255,25,188,247,255,22,145,193,255,19,102,141,255,17,152,207,255,15,178,240,255,13,173,237,255,12,170,233,255,11,166,230,255,11,162,226,217,11,150,214,74,15,102,156,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,10,255,255,255,149,255,255,255,249,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,253,253,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,255,254,255,252,250,252,255,237,239,239,255,190,210,221,255,152,184,210,255,140,181,213,255,129,214,248,255,117,226,255,255,106,223,255,255,96,221,255,255,86,218,255,255,78,216,255,255,69,213,255,255,62,211,255,255,55,209,255,255,48,208,255,255,42,206,255,255,37,205,255,255,33,203,255,255,29,188,243,255,25,123,162,255,22,38,56,255,19,19,19,255,17,104,144,255,15,180,243,255,13,176,239,255,12,172,234,255,11,168,231,255,11,165,227,255,11,160,224,238,11,134,197,97,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0