|
Post by williac on Feb 22, 2005 19:23:26 GMT -5
Ive been working on making a matching game like pogo's sweettooth.
So far I have the basic block physics done. It was alot harder than I thought. I could have done the physics a different(easier) way, but I did it with the future score sytem in mind.
You can change the variable grid to change the number of playing pieces in the game.
Im sure I could have coded this more effieciently. If you see some redundancy please tell me, as I would like to become a better programmer. Anyway heres the code
|
|
|
Post by williac on Feb 22, 2005 19:23:56 GMT -5
'B4GL_match 'Written by Williac 'Date completed ??????
dim debug'this is used for various debuggin purposes and will be deleted sometime dim random'this is for making random blocks 'GRID is how many places horizontally and vertically the game area is minus one(for locating purposes later) dim grid:grid=6 dim offsetx:offsetx=((SpriteAreaHeight()/grid)/2)+((SpriteAreaWidth()-SpriteAreaHeight())/2)'this moves the blocks right toward the middle of the screen dim offsety:offsety=(SpriteAreaHeight()/grid)/2'this moves the blocks down toward the middle of the screen 'these will be used in the routine blockphysics, to cycle thru the 2dimensional array gamegrid(grid)(grid) dim g_collum,g_row 'this will be used to replace destroyed blocks dim empty(grid)(grid)
'NEWGAME is true when a newgame is started false when the game is in play 'textures for the game dim txt_ciel,txt_floor,txt_water,txt_cement,txt_cursor dim cursor,cursorx,cursory
'load all the textures for the game txt_ciel=LoadTexture("Textures\Ceil01.jpg") txt_floor=LoadTexture("Textures\floor01.jpg") txt_water=LoadTexture("Textures\001.jpg") txt_cement=LoadTexture("Textures\00003.jpg") txt_cursor=LoadTexture("Data\F117.png") cursor=NewSprite(txt_cursor)
struc Sgrid dim type$ dim sprite endstruc 'GAMEGRID(GRID)(GRID) hold the variables for the entire game area dim Sgrid gamegrid(grid)(grid)
'sets all gamegrid types to empty While g_collum<grid and g_row<grid gamegrid(g_row)(g_collum).type$="empty" g_row = g_row + 1 if g_row = grid then g_collum = g_collum + 1 g_row = 0 endif printr"g_collum: "+g_collum+" g_row: "+g_row Wend g_collum=0:g_row=0' this sets gamegrid()() back to 0,0 for when the routine blockpyhsics is ran 'strut for the blocks struc Sblock dim sprite dim x,y dim type$ endstruc 'sets up the four differnt block types, and thier textures dim Sblock cieling cieling.type$="cieling" dim Sblock floor floor.type$="floor" dim Sblock water water.type$="water" dim Sblock cement cement.type$="cement"
Gosub blockmaker'places blocks on the screen '////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// While true'start main loop ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
'checks NEWGAME, if it is a new game goto startup Gosub cusorhandler'controls cursor movement If Mouse_Button(0) then Gosub cursorcollide:gosub blockfaller endif'handles cursor block interaction
Wend'end main loop ///////////////////////////////////////////////////////////////////////////////////////////////////////////// '/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
'code routines here
'startup routine ##################################################################
'display startup image 'set all game variable to their starting values 'display instructions 'start a loop//////////////////////// 'check for userinput based on instructions 'end a loop when userinput is recieved 'return to main loop //////////////////////// '###################################################################################
blockmaker:'blockmaker routine############################################################### 'loop thru the first row of the GAMEGRID()(). GAMEGRID(1)(1) to GAMEGRID(1)(GRID) checking if each has been assigned an object, if not assign it an object 'g_collum=0:g_row=0 While g_collum<grid and g_row<grid If gamegrid(g_row)(g_collum).type$="empty" then gosub randomblock g_row = g_row+1 if g_row=grid then g_collum = g_collum + 1 g_row =0 endif endif
Wend sleep(100) cls locate 10,10:Print"no errors!!!!!" sleep(1000) cls
Return'################################################################################### blockfaller:'#the blockfaller routine########################################################## '' start on the bottom row checking each collum for a space thats "empty". If its empty fill it with the type of ''block directly above it. then set the block type of the block above it to empty, deleting whatever sprite it held. g_row=grid g_collum=grid 'cycle thru all the rows untill the next to the top row. the top row is treated differently While g_row>0 If gamegrid(g_row)(g_collum).type$="empty" then gamegrid(g_row)(g_collum).type$=gamegrid(g_row-1)(g_collum).type$ gamegrid(g_row-1)(g_collum).type$="empty" DeleteSprite(gamegrid(g_row-1)(g_collum).sprite) gosub whichblock Endif g_collum = g_collum - 1 if g_collum < 0 then g_collum=grid:g_row = g_row - 1 endif 'sleep(100)'moves things slowly for debugging purposes
Wend ' this is where the top row makes new blocks while g_collum > -1 If gamegrid(g_row)(g_collum).type$="empty" then gosub randomblock endif g_collum = g_collum - 1 wend
Return'#####################################################################################
cusorhandler:'cursor routine##############################################################
' X will be a percentage (given by the mouse X position) of screen width. cursorx=mouse_x ()* SpriteAreaWidth () ' Y will be a percentage (given by the mouseY position) of screen hieght. cursory=mouse_y ()* SpriteAreaHeight () 'moves crosshair with mouse bindsprite(cursor) sprsetPos (cursorx,cursory)
Return'###################################################################################
cursorcollide:'handles the cursor interacting with the blocks################################################# BindSprite(cursor) g_collum=0:g_row=0 While g_collum<grid and g_row<grid if SprLeft(gamegrid(g_row)(g_collum).sprite)<SprX() and SprRight(gamegrid(g_row)(g_collum).sprite)>SprX() and SprTop(gamegrid(g_row)(g_collum).sprite)< SprY() and SprBottom(gamegrid(g_row)(g_collum).sprite)>SprY() then gamegrid(g_row)(g_collum).type$="empty" DeleteSprite(gamegrid(g_row)(g_collum).sprite) endif g_row = g_row + 1 if g_row = grid then g_collum = g_collum + 1 g_row = 0 endif Wend
Return'########################################################################################################
randomblock:'creates random blocks for the top row############################################################## random=rnd()%20 if random>10 then random=rnd()%20 if random>10 then gamegrid(g_row)(g_collum).type$="floor" else gamegrid(g_row)(g_collum).type$="ciel" endif else random=rnd()%20 if random>10 then gamegrid(g_row)(g_collum).type$="water" else gamegrid(g_row)(g_collum).type$="cement" endif endif gosub whichblock Return'#########################################################################################################
whichblock:'creates a block based on its new type################################################################ if gamegrid(g_row)(g_collum).type$="floor" then gamegrid(g_row)(g_collum).sprite=NewSprite(txt_floor) SprSetSize((SpriteAreaHeight())/grid-1,(SpriteAreaHeight())/grid-1) SprSetPos(g_collum*(SprXSize()+1)+offsetx,g_row*(SprYSize()+1)+offsety) endif if gamegrid(g_row)(g_collum).type$="ciel" then gamegrid(g_row)(g_collum).sprite=NewSprite(txt_ciel) SprSetSize((SpriteAreaHeight())/grid-1,(SpriteAreaHeight())/grid-1) SprSetPos(g_collum*(SprXSize()+1)+offsetx,g_row*(SprYSize()+1)+offsety) endif
if gamegrid(g_row)(g_collum).type$="water" then gamegrid(g_row)(g_collum).sprite=NewSprite(txt_water) SprSetSize((SpriteAreaHeight())/grid-1,(SpriteAreaHeight())/grid-1) SprSetPos(g_collum*(SprXSize()+1)+offsetx,g_row*(SprYSize()+1)+offsety) endif if gamegrid(g_row)(g_collum).type$="cement" then gamegrid(g_row)(g_collum).sprite=NewSprite(txt_cement) SprSetSize((SpriteAreaHeight())/grid-1,(SpriteAreaHeight())/grid-1) SprSetPos(g_collum*(SprXSize()+1)+offsetx,g_row*(SprYSize()+1)+offsety) endif
Return'#########################################################################################################
#nosmileys
|
|
|
Post by 8XenoTrogdor8 on Feb 23, 2005 1:20:27 GMT -5
(I just took a glance at the code...) But there are a few easy things to make this run smoother -
first, fix the mouse hold thing.
If Mouse_Button(0) then if not MouseDown then ' only proceed if mouse button wasn't pressed last frame. Gosub cursorcollide gosub blockfaller MouseDown = TRUE endif else MouseDown = FALSE endif'handles cursor block interaction
(this will make it only select once each time the mouse is pressed, instead of selecting infinitely as the mouse is pressed).
And maybe put this in there somewhere- "TextMode (TEXT_BUFFERED)" you will have to call "DrawText ()" at the end of your main loop and anywhere else you want text (and sprites) to be drawn though. But the program runs a lot smoother with that.
But other than that, it seems you are well on your way to becomming a pro programmer! (pun intended...) Especially with the way you're using while/wend loops already. Keep up the good work! ;D
|
|
|
Post by williac on Feb 23, 2005 17:20:53 GMT -5
thanks for the reply 8XenoTrogdor8.
The mouse thing was on my todo list. I had something similar in my last wip space gunner. I had just forgoten about it OOPS!!!!!!!!! thanks for the reminder.
and thanks for the textbuffered suggestion!
Man what a difference that made. I was actually stressing that the scoring code was going to run so slow that the game wouldnt be playable with a grid value of more than 4 or 6. But It runs smooth with a grid value of 40!(not that youd want to play with it that high). I had totally forgotten about the diff textbuffering modes!!!!!!!!!
well Im off to code the scoring system now. Ill post more when as I complete it!!
|
|