Pongout by Monk13th Feb 2009 6:39
|
---|
Summary Its just a fairly simple game of pong mixed with breakout - at the same time. Completely media free and works quite well... If you find any bugs please post =) Have fun! Ps it does Description Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com `Setup disable escapekey window = 1 gosub window set text size 25 ink rgb(255,255,255),0 set text opaque randomize timer() gosub mainmenu `variables for file reading global file$ as string : file$ = "highscore.mon" global hieasy# as float : hieasy# = 0 global himed# as float : himed# = 0 global hihard# as float : hihard# = 0 `reads hiscores if file exist(file$) open to read 1, file$ read float 1, e# : hieasy# = e# read float 1, m# : himed# = m# read float 1, h# : hihard# = h# close file 1 endif `ready to start playing gosub countdown gosub pongout end `sets full screen according to if window = 1 or 0 window: cls input "set screen height", screenheight sync input "set screen width", screenwidth sync input "set display depth", screendepth sync if check display mode (screenheight,screenwidth,screendepth) = 1 set display mode screenheight,screenwidth,screendepth set window on : set window position 100,100 endif if check display mode (screenheight,screenwidth,screendepth) = 0 gosub window endif return `the menu screen `draws the text on screen mainmenu: set text size 80 center text 512,200,"Pongout!" set text size 30 center text 512,320,"Select Difficulty" ink 0,rgb(255,255,255) center text 300,400,"Easy" center text 500,400,"Medium" center text 700,400,"Hard" center text 400,450,"Mouse" ink rgb(255,255,255),0 center text 600,450,"Keyboard" set text size 25 ink rgb(255,255,255),0 center text 512,500,"Created by Monk" control$ = "mouse" `basic mouse pos checking repeat if mouseclick() = 1 if mousey() > 400 and mousey() < 430 if mousex() > 267 and mousex() < 333 level$ = "easy" endif if mousex() > 450 and mousex() < 550 level$ = "medium" endif if mousex() > 667 and mousex() < 733 level$ = "hard" endif endif if mousey() > 450 and mousey() < 480 if mousex() > 360 and mousex() < 440 set text size 30 ink 0,rgb(255,255,255) center text 400,450,"Mouse" ink rgb(255,255,255),0 center text 600,450,"Keyboard" control$ = "mouse" set text size 25 endif if mousex() > 535 and mousex() < 665 set text size 30 ink 0,rgb(255,255,255) center text 600,450,"Keyboard" ink rgb(255,255,255),0 center text 400,450,"Mouse" control$ = "keyboard" set text size 25 endif endif endif until level$ = "easy" or level$ = "medium" or level$ = "hard" return `lets player get ready countdown: cls set text size 100 center text 512,200,"3" wait 1000 center text 512,200,"2" wait 1000 center text 512,200,"1" wait 1000 center text 512,200,"Play!" wait 100 set text size 25 return `actual game pongout: `dont want to see the mouse so we hide it and pos ready fro start Position mouse 212,389 hide mouse `variables for the game global pbx# as float : pbx# = 662.0 global pby# as float : pby# = 389.0 global bbx# as float : bbx# = 212.0 global bby# as float : bby# = 480.0 global pex# as float : pex# = 950.0 global pey# as float : pey# = 389.0 global pbky# as float : pbky# = 389.0 global bbkx# as float : bbkx# = 212.0 global points# as float : points# = 0 global lives as integer : lives = 5 global pespd as integer : pespd = 10 `sets all block to visible dim blocks(48,1) for block = 1 to 32 blocks(block,1) = 1 next block `draws objects Makepball(662,389,8) Makepebat(950,389,70,10) Makepbat(400,389,70,10) Makebball(212,480,10) Makebbat(212,530,10,70) gosub Makebblocks `inital figures bba# = rnd(40)+160 pba# = rnd(40)+70 spd# = 8 do `pause if inkey$() = "p" repeat until spacekey() = 1 endif `keyboard controls if control$ = "keyboard" if upkey() = 1 then pbky# = pbky# - 15 if downkey() = 1 then pbky# = pbky# + 15 if leftkey() = 1 then bbkx# = bbkx# - 15 if rightkey() = 1 then bbkx# = bbkx# + 15 if pbky# < 263 then pbky# = 263 if pbky# > 514 then pbky# = 514 if bbkx# < 87 then bbkx# = 87 if bbkx# > 317 then bbkx# = 317 endif `goes to manual checks gosub Pongchecks gosub breakoutchecks `changes ball speed pbx# = pbx# + (spd#*sin(pba#)) pby# = pby# + (spd#*cos(pba#)) spd# = spd# + 0.1 if spd# > 20 then spd# = 20 `block hit checking if bby# < 339 and bby# >= 323 then brow = 4 if bby# < 323 and bby# >= 307 then brow = 3 if bby# < 307 and bby# >= 291 then brow = 2 if bby# < 291 and bby# >= 275 then brow = 1 if bbx# < 335 and bbx# >= 304 then bcol = 8 if bbx# < 304 and bbx# >= 273 then bcol = 7 if bbx# < 273 and bbx# >= 242 then bcol = 6 if bbx# < 242 and bbx# >= 211 then bcol = 5 if bbx# < 211 and bbx# >= 180 then bcol = 4 if bbx# < 180 and bbx# >= 149 then bcol = 3 if bbx# < 149 and bbx# >= 118 then bcol = 2 if bbx# < 118 and bbx# >= 87 then bcol = 1 if bby# > 339 or bby# < 276 then brow = 6 bblock = (brow-1)*8 + bcol blocks(bblock,1) = 0 `if hit then block become invisible for block = 1 to 32 if blocks(block,1) = 1 b = 1 endif next block `if no blocks are left visible, next level if b = 0 then blevel = 1 else b = 0 `breakout ball speed bbx# = bbx# + (10*sin(bba#)) bby# = bby# + (10*cos(bba#)) `changes the wait speed depending on chosen level gosub level `clears screen cls `redraws objects gosub background Movebbat(212,530,10,70) Movepbat(400,389,70,10) gosub Movepebat gosub blocks Movebball(bbx#,bby#,10,bba#) Movepball(pbx#,pby#,8,pba#) gosub scored `text text 50,60, "Points scored: "+ str$(points#)+" : Lives left: "+str$(lives) text 0,0,"Highscore easy "+str$(hieasy#) text 0,20,"Highscore medium " + str$(himed#) text 0,40, "Highscore hard "+str$(hihard#) `general parameters points# = points# + 2 if lives <= 0 then gosub endscreen if escapekey() = 1 then gosub writefile `moves mouse according to key presses if control$ = "keyboard" position mouse bbkx#, pbky# endif loop breakoutchecks: `checks balls position against bats mx = mousex() if mx > 342 then mx = 342 if mx < 62 then mx = 62 if bby# > 515 and bby# < 530 and bhit = 0 dx# = bbx# - mx if bbx# <= mx + 50 if bbx# > mx - 50 bba# = wrapvalue((180-bba#)-dx#) bhit = 1 endif endif endif `if passed bat players loses a life if bby# >= 536 then bdead = 1 `bounce off walls if bby# < 239 bba# = wrapvalue(180-bba#) endif if bbx# < 62 or bbx# > 342 bba# = wrapvalue(360 - bba#) endif `resets hit value if bby# < 505 and bhit = 1 then bhit = 0 `stops ball from going at silly angles if bba# < 110.0 and bba# > 90.0 then bba# = bba# + 2 if bba# < 270.0 and bba# > 250.0 then bba# = bba# - 2 if bba# > 270.0 and bba# < 290.0 then bba# = bba# + 2 if bba# > 70.0 and bba# < 90.0 then bba# = bba# - 2 return Pongchecks: `checks if ball is near player bat if pbx# < 415 and pbx# > (410 - spd#) and phit = 0 dy# = pby# - mousey() if pby# < mousey() + 42 and pby# >= mousey() pba# = wrapvalue((360-pba#)-dy#) phit = 1 endif if pby# > mousey() - 42 and pby# < mousey() pba# = wrapvalue((360-pba#)-dy#) phit = 1 endif endif `checks if ball is near enemy bat if pbx# > 935 and pbx# < 940 + spd# and pehit = 0 dy# = pby# - pey# if pby# < pey#+42 and pby# >= pey# pba# = wrapvalue((360-pba#)+dy#) endif if pby# > pey# - 42 and pby# < pey# pba# = wrapvalue((360-pba#)+dy#) pehit = 1 endif if pby# < pey# - 42 or pby# > pey# + 42 pba# = pba# pehit = 1 endif endif `bounce off top and bottom if pby# < 240 or pby# > 539 pba# = wrapvalue(180-pba#) endif `increase scores if passed a bat if pbx# < 375 pescored = 1 endif if pbx# > 975 pscored = 1 endif `resets hits if pbx# > 420 and phit = 1 then phit = 0 if pbx# < 930 and pehit = 1 then pehit = 0 `stops ball going at silly angles if pba# < 20.0 and pba# > 0.0 then pba# = pba# + 2 if pba# < 180.0 and pba# > 160.0 then pba# = pba# - 2 if pba# > 180.0 and pba# < 200.0 then pba# = pba# + 2 if pba# > 340.0 and pba# < 360.0 then pba# = pba# - 2 return scored: `resets pong if player scores if pscored = 1 spd# = 8 pbx# = 662.0 pby# = 389.0 pba# = rnd(40)+70 pscored = 0 points = points + 100 playerpscore = playerpscore + 1 endif `resets pong if enemy scores if pescored = 1 spd# = 8 pbx# = 662.0 pby# = 389.0 pba# = rnd(40)+70 pescored = 0 lives = lives - 1 playerpescore = playerpescore + 1 endif `resets breakout ball if ball passes bat if bdead = 1 bbx# = 212.0 bby# = 480.0 bba# = rnd(10)+170 bdead = 0 lives = lives - 1 playerbdead = playerbdead + 1 endif `redraws blocks if all blocks are invisible if blevel = 1 bbx# = 212.0 bby# = 480.0 bba# = rnd(10)+170 blevel = 0 points = points + 1000 playerblevel = playerblevel + 1 for block = 1 to 32 blocks(block,1) = 1 next block endif return function Makebball(x,y,rad) `draws breakout ball Box x-rad,y-rad,x+rad,y+rad endfunction function Makebbat(x,y,height,width) `draws breakout bat Box x-(width/2),y-(height/2),x+(width/2),y+(height/2) endfunction Makebblocks: `draws the breakout blocks xtop = 88 ytop = 276 sizex = 30 sizey = 15 by = 1 bx = 1 for block = 1 to 32 if block <= 8 then bx = block : ink rgb(255,0,0),0 if block > 8 and block <= 16 then by = 2 : bx = block - 8 : ink rgb(255,255,0),0 if block > 16 and block <= 24 then by = 3 : bx = block - 16 : ink rgb(0,255,0),0 if block > 24 and block <= 32 then by = 4 : bx = block - 24 : ink rgb(0,255,255),0 blocks(block,1) = 1 box xtop+((bx-1)*sizex)+(bx-1),ytop+((by-1)*sizey)+(by-1),xtop+(bx-1)+(bx*sizex),ytop+(by-1)+(by*sizey) next block return function Movebbat(x,y,height,width) `redraws breakout bat at new position mx = Mousex() if mx > 317 then mx = 317 if mx < 87 then mx = 87 Box mx-(width/2),y-(height/2),mx+(width/2),y+(height/2) endfunction function Movebball(x,y,rad,ang) `redraws the breakout ball at new position Box x-rad,y-rad,x+rad,y+rad endfunction blocks: `draws the breakout blocks xtop = 88 ytop = 276 sizex = 30 sizey = 15 by = 1 bx = 1 for block = 1 to 32 if block <= 8 then bx = block : ink rgb(255,0,0),0 if block > 8 and block <= 16 then by = 2 : bx = block - 8 : ink rgb(255,255,0),0 if block > 16 and block <= 24 then by = 3 : bx = block - 16 : ink rgb(0,255,0),0 if block > 24 and block <= 32 then by = 4 : bx = block - 24 : ink rgb(0,255,255),0 if blocks(block,1) = 1 box xtop+((bx-1)*sizex)+(bx-1),ytop+((by-1)*sizey)+(by-1),xtop+(bx-1)+(bx*sizex),ytop+(by-1)+(by*sizey) endif `draws black if iinvisible if blocks(block,1) = 0 ink 0,0 box xtop+((bx-1)*sizex)+(bx-1),ytop+((by-1)*sizey)+(by-1),xtop+(bx-1)+(bx*sizex),ytop+(by-1)+(by*sizey) endif next block ink rgb(255,255,255),0 return function Makepball(x,y,rad) `Draw square for pong ball Box x-rad,y-rad,x+rad,y+rad endfunction function Makepbat(x,y,height,width) `Draw a box as the pong bat Box x-(width/2),y-(height/2),x+(width/2),y+(height/2) endfunction function Makepebat(x,y,height,width) `Draw a box as the pong enemy bat Box x-(width/2),y-(height/2),x+(width/2),y+(height/2) endfunction function Movepbat(x,y,height,width) `Should move the pong bat along the y-axis in relation with mousey my = mousey() if my > 514 then my = 514 if my < 263 then my = 263 Box x-(width/2),my-(height/2),x+(width/2),my+(height/2) endfunction Movepebat: `Should move enemy bat towards ball position if pbx# < 950 if pby# >= pey# then pey# = pey# + pespd if pby# < pey# then pey# = pey# - pespd endif if pey# > 514 then pey# = 514 if pey# < 263 then pey# = 263 Box pex#-5,pey#-35,pex#+5,pey#+35 return function Movepball(x,y,rad,ang) `Draw square for pong ball Box x-rad,y-rad,x+rad,y+rad endfunction background: `draws the lines for the court lines line 52,549,52,229 line 52,229,990,229 line 52,549,990,549 line 990,229,990,549 line 352,229,352,549 line 950,229,950,549 line 400,229,400,549 line 52,530,352,530 return endscreen: `game over hiscore screen cls set text size 50 p$ = str$(points#) if len(p$) < 5 repeat p$ = str$(0) + p$ until len(p$) = 5 endif `sets hiscores if level$ = "easy" if points# > hieasy# then hieasy# = points# hiscore# = hieasy# endif if level$ = "medium" if points# > himed# then himed# = points# hiscore# = himed# endif if level$ = "hard" if points# > hihard# then hihard# = points# hiscore# = hihard# endif hs$ = str$(hiscore#) if len(hs$) < 5 repeat hs$ = str$(0) + hs$ until len(hs$) = 5 endif `draws screen repeat text 100,100,"Game over!!" text 100,200,"Your Score: " + p$ text 100,300,"Highscore: " + hs$ text 100,400,"Play Again? Y/N" until keystate(21) = 1 or keystate(49) = 1 set text size 25 if keystate(49) = 1 then gosub writefile if keystate(21) = 1 then gosub mainmenu end return writefile: `adds zeros to score until 5 figures long he$ = str$(hieasy#) if len(he$) < 5 repeat he$ = str$(0) + he$ until len(he$) = 5 endif hm$ = str$(himed#) if len(hm$) < 5 repeat hm$ = str$(0) + hm$ until len(hm$) = 5 endif hh$ = str$(hihard#) if len(hh$) < 5 repeat hh$ = str$(0) + hh$ until len(hh$) = 5 endif `deletes, makes open and writes a new hiscore file delete file file$ open to write 1,file$ if level$ = "easy" write float 1, val(he$) endif if level$ = "medium" write float 1, val(he$) write float 1, val(hm$) endif if level$ = "hard" write float 1, val(he$) write float 1, val(hm$) write float 1, val(hh$) endif close file 1 end return level: `sets wait value and ai speed dependin on level if level$ = "easy" wait 40 pespd = 8 endif if level$ = "medium" wait 30 pespd = 12 endif if level$ = "hard" wait 20 pespd = 15 endif return return `pongout |