News:

Building a 3D Ray Tracer  By stevmjon

Main Menu

fruit squash

Started by micky4fun, August 07, 2010, 02:50:42 PM

Previous topic - Next topic

micky4fun

#15
hi all

well been on this all day yep all day , other half aint to pleased , i wanted to do it the way kevin has done in he's example as i know its the right way and will save time in the long run and will be error free , but i could not get to grips with it , i gave up countless times , but i thought i would just keep given it one more try and another etc , well how can something that is so frustrating be so much fun , i dont know but it seems that way , to others on here its proberly a simple task but to other people like me its a brick wall.

but alas i think ive done it at last , well past my bed time , so heres a snippet of it in action on a cut down version of my game , some newbies might want to take a look so i thought ile post it , you can un remark the displaymap(100,60) if you want to see numbers displayed

press the spacebar to randomise fruits

mick ;D

ps thanks for the code Kevin

kevin

#16
  erm ? - I really didn't write the example for you to cut and paste it into your game (big no no).  It's simply to show how using a 2D array makes solving such problems easier in this case.

 All the matching code is doing, is stepping through and 'tagging' any runs of tiles across the x axis in the 2d array.  So it's just a 2d loop that iterates through each tile.  

  For each tile, it checks if the current tile is the start of a run of two or more tiles.  So we're checking the current tile against the tile to our RIGHT.   If they're the same type, then we know there's at least a run of 2 tiles.   Then it's looping through and counting up the number of tiles are that the same in the row.   We could have  a series of IF/THEN statements  checking the the current tile with the tile on the right two tiles over, then three etc etc.  But a loop a far more generic.  

  In the original example, when a row of tiles are same, the code tags these tiles with the tile that's first in the row and the length of the row.  This information is used while drawing the data.  


micky4fun

#17
hi all

QuoteI didn't write the example so you cut and paste it into your game (big no no).  
ahh sorry , but i thought i could get your code into my game , its just something i could not do myself , its just a bit over my head this type of coding , took me ages to see how i could use the example with a few changes , i have the daunting task now of try to do the down columns now using a simular code
i knew it would be this part of the game that would prove big big problems for me , but thought i would like to do a game like this and if i ran into trouble i could get some help here maybe ,
anyway the down columns detection is the least of my worries today , i have a lot of groverling to do today , hahah , spent so much time yesterday on this.

thanks
mick ;D

update , ok row and columns now done , now trying to put code into game

micky4fun

#18
hi all

been a while , a small update , i have been working on this game every day for at least 3 hours a time , i just cant seem to make it do what i want , to get 3 or more in a row horizontal or vertical , so alas i have now given up that idea for now , i cant seem to do it , i can find the 3 or more fruits in either direction get them to drop , but its when the new fruits enter the game from the top that eludes me , so i have totally changed the game now its still kinda what i wanted to do , just in a slightly differant way , so from tomorrow i sould be off and running full steam ahead ,

the game has now changed name to gold rush or something along them lines , will grab all the gfx's tomorrow and work the game along what i manage to get

mick :)

kevin


  i'm still wondering as to what exactly about the 2d example you don't understand ?  So i've no idea how to help.

micky4fun

#20
Hi all

Quotei'm still wondering as to what exactly about the 2d example you don't understand ?  So i've no idea how to help.
no the code works fine , but i cant seem to get the blocks to goto the top of the screen and then fall down in the correct level , when detecting the vertical rows of 3 or more , as you can see i think ive managed to do the horizontal blocks but the vertical is just not happening for me , maybe if someone see's a way of doing it they could do it for me after ive finished the game , thats if its work doing once complete , depends if the game turns out ok or not , anyway heres the latest code ,

mick :)

BlinkOk


micky4fun

#22
Hi all

yep thanks BlinkOk , well better than i can draw anyway , lol , tried to tart it up a bit ,

ok heres where i am now in the game , just putting the gfx's together , it plays at the moment but only very basic play
once i get all the bits i need then i shall start to put it together , still pondering about exacly how its going to end up , but for now you get 1 more to get 3 in a line across the screen
if you need more that 1 more , you can still move but you will get a penalty of a red bomb apearing at random , now get 3 of these in a line across the screen and its game over ,
( this is not programed in the game yet) , you can help yourself by moving them if they get near each other , but thats 1 move you have made , think you get the drift

mick ;D

kevin

Mick,
 
   it's getting a bit slow here for what it does.  Is there any reason for drawing all the sprites twice ?  once in the main loop and again in the Checklines subroutine ? 

  Another logical thing to look at would be the loop nesting.  Running a loop inside a loop.  An example of this can be foudn in the nested moving boxes routine..

so this,


; line up and position fruits , also if there level changes update that as well
for p=1 to 7
for amount=1 to 72

   if boxes(amount).level=9 and boxes(amount).move=1
   if boxes(amount).y#<567 then boxes(amount).y#=boxes(amount).y#+1
      if boxes(amount).y#>567 then boxes(amount).y#=boxes(amount).y#-1
      if boxes(amount).y#=567 then boxes(amount).move=0
      endif
if boxes(amount).level=8 and boxes(amount).move=1
   if boxes(amount).y#<503 then boxes(amount).y#=boxes(amount).y#+1
   if boxes(amount).y#>503 then boxes(amount).y#=boxes(amount).y#-1
   if boxes(amount).y#=503 then boxes(amount).move=0
   endif
   if boxes(amount).level=7 and boxes(amount).move=1
   if boxes(amount).y#<439 then boxes(amount).y#=boxes(amount).y#+1
   if boxes(amount).y#>439 then boxes(amount).y#=boxes(amount).y#-1
   if boxes(amount).y#=439 then boxes(amount).move=0
   endif
    if boxes(amount).level=6 and boxes(amount).move=1
   if boxes(amount).y#<375 then boxes(amount).y#=boxes(amount).y#+1
   if boxes(amount).y#>375 then boxes(amount).y#=boxes(amount).y#-1
   if boxes(amount).y#=375 then boxes(amount).move=0
     endif
      if boxes(amount).level=5 and boxes(amount).move=1
   if boxes(amount).y#<311 then boxes(amount).y#=boxes(amount).y#+1
   if boxes(amount).y#>311 then boxes(amount).y#=boxes(amount).y#-1
   if boxes(amount).y#=311 then boxes(amount).move=0
      endif
   if boxes(amount).level=4 and boxes(amount).move=1
   if boxes(amount).y#<247 then boxes(amount).y#=boxes(amount).y#+1
   if boxes(amount).y#>247 then boxes(amount).y#=boxes(amount).y#-1
   if boxes(amount).y#=247 then boxes(amount).move=0
   endif
      if boxes(amount).level=3 and boxes(amount).move=1
   if boxes(amount).y#<183 then boxes(amount).y#=boxes(amount).y#+1
   if boxes(amount).y#>183 then boxes(amount).y#=boxes(amount).y#-1
   if boxes(amount).y#=183 then boxes(amount).move=0
      endif
    if boxes(amount).level=2 and boxes(amount).move=1
   if boxes(amount).y#<119 then boxes(amount).y#=boxes(amount).y#+1
   if boxes(amount).y#>119 then boxes(amount).y#=boxes(amount).y#-1
   if boxes(amount).y#=119 then boxes(amount).move=0
      endif
      if boxes(amount).level=1 and boxes(amount).move=1
   if boxes(amount).y#<55 then boxes(amount).y#=boxes(amount).y#+1
   if boxes(amount).y#>55 then boxes(amount).y#=boxes(amount).y#-1
   if boxes(amount).y#=55 then boxes(amount).move=0
   endif
positionsprite amount,boxes(amount).x#,boxes(amount).y#+down
next amount
next p


  can be trimmed down to something more like this,



for p=1 to 7
for amount=1 to 72
if boxes(amount).move
Ypos=boxes(amount).y#
RowPos=55+((boxes(amount).level-1)*64)
   if Ypos<RowPos then Ypos=Ypos+1
   if Ypos>RowPos then Ypos=Ypos-1
   if Ypos=RowPos then boxes(amount).move=0
boxes(amount).y#=Ypos
endif
positionsprite amount,boxes(amount).x#,boxes(amount).y#+down
  next amount
  next p



  Both versions iterate the same number of times, but the second version avoids a number of comparisons inside in the inner loop.  This helps us speed the routine up, as the cost of those inner compares (IF/THEN) was originally being multiply by the total number of the times the inner loop was executed.    Which is 504 times, or (502 * 9)= 4518 comparisons.     So nesting magnifies the cost of the inner loop in this case.    The second loop runs about 5 times faster than the original.   

 
  However, since the outter loop is being used as the movement speed (running the loop X number times, when they move by ones), we just merge them together into one loop like so.  Which is at least another 6 times faster again.


MovementSpeed=7
for amount=1 to 72
if boxes(amount).move
Ypos=boxes(amount).y#
RowPos=55+((boxes(amount).level-1)*64)

   if Ypos<RowPos
    Ypos=Ypos+MovementSpeed
   if Ypos=>RowPos
    boxes(amount).move=0
Ypos=RowPos
    endif
   endif
   if Ypos>RowPos
    Ypos=Ypos-MovementSpeed
   if Ypos<=RowPos
    boxes(amount).move=0
Ypos=RowPos
    endif
endif    
boxes(amount).y#=Ypos
endif
positionsprite amount,boxes(amount).x#,boxes(amount).y#+down

next amount



   Also, the backdrop images (at this point) could be stock piles onto a single image.  But I guess that depends on how this all pans out.


micky4fun

#24
Hi all

thanks for the code snippet Kevin , i dont know if i could have come up with the way you wrote it myself , i doubt it , but i can see that i was using lots more processing power my way , the only thing i just did not notice it as i have a very fast pc , but i ran it on another slower machine , and yes it was slow , but after your code snippet and layering some of the background gfx's its much faster now ,

i aint had a lot of time these last few days , but weekend will be a good time to get on with the game
i have tweeked a few things and getting everthing into the posistion its going to be in , so weekend i will start the game playing order , till then

mick ;D

micky4fun

#25
Hi all

well well what a weekend , dont ask me how , but i managed to get a virus on my pc , downloaded a program and ran it , that was that , so i tried to remove it but no joy , all my programs lost , and there me telling everyone to back up everything , lost a load of photo's whats enoying , well not much i can do now.

so i decided to install windows 7 ,was meaning to do it for ages , alas did not get much of my game done as all the work in last couple of days i did was lost , so had to start from the above download , lucky that was on here ,

so ile do as much as i can this week , but im not going to rush this game might as well take time and do something worth doing , im still not that keen on background image , but that can wait to near the end

back soon
mick :)

kevin


:(  -   Sadly learning to backup important stuff seems to be one of those things people have to go through before the penny drops..
 

Devain

I recommend Assembla and Tortoise SVN to anyone who isn't familiar with the idea:

Subversion repository: http://www.assembla.com/catalog/49-free-private-subversion-repository--package
Tortoise: http://tortoisesvn.tigris.org/

You save everything to a server. Whenever you have a new upgrade to the code, to some of the content or anything, you commit it to the server and it will be stacked on top of your previous commits. This means that you keep all saved versions and can go back to old revisions with a few mouseclicks without damaging your current work.

Works a charm.

stevmjon

to micky4fun

you may still be able to get your data back, or at least some of it anyway. i once re-formatted my hard drive, then re-installed windows, and then ran a 'recover deleted files' program, and re-covered heaps of data.

if the virus just deleted files, you should be able to get them back, as long as the windows install hasn't overwritten the same location that the hard drive the files were on.

when files are deleted, or the hard drive re-formatted, the data is not actually removed, it is just ignored by windows. i think the file heading is altered to tell windows to ignore it, like it wasn't there.

sorry you lost valued photos. hope you get them back.

hope this helps,  stevmjon.
It's easy to start a program, but harder to finish it...

I think that means i am getting old and get side tracked too easy.

OldNESJunkie

This program works pretty good usually, the best part is it's free:

http://www.piriform.com/recuva