User Name
Password
AppleNova Forums » Programmer's Nook »

Finding the center of a tetris block...


Register Members List Calendar Search FAQ Posting Guidelines
Finding the center of a tetris block...
Thread Tools
AsLan^
Not a tame lion...
 
Join Date: May 2004
Location: Narnia
 
2005-11-17, 04:13

Here's a good one,

Does anyone know an algorithm to find the center of a tetris block ?

I'm storing my blocks as x, y coordinates in multiples of 20, so the square looks like this:

blockOneX = 0;
blockOneY = 0;

blockTwoX = 20;
blockTwoY = 0;

blockThreeX = 0;
blockThreeY = 20;

blockFourX = 20;
blockFourY = 20;

and the three way looks like this:

blockOneX = 20;
blockOneY = 0;

blockTwoX = 0;
blockTwoY = 20;

blockThreeX = 20;
blockThreeY = 20;

blockFourX = 40;
blockFourY = 20;

Now, when I'm showing the next piece that the player will get, I want it to show up centered in a box on the side. The only problem is, I'm having trouble finding the center of the shape to make the correction when I draw it in my window (short of specifying the correction for each shape individually).

So, anybody come across this before ? I'm going to work on some more mundane parts of the game in the meantime.
  quote
Brad
Selfish Heathen
 
Join Date: May 2004
Location: Zone of Pain
 
2005-11-17, 04:46

Maybe I'm not seeing something, but it looks as simple as this:

(0.5*(x_min+x_max),0.5*(y_min+y_max))

No?
  quote
AsLan^
Not a tame lion...
 
Join Date: May 2004
Location: Narnia
 
2005-11-17, 05:18

Quote:
Originally Posted by Brad
Maybe I'm not seeing something, but it looks as simple as this:

(0.5*(x_min+x_max),0.5*(y_min+y_max))

No?
As SIMPLE as that Sometimes I just cant see the forest for the trees, I was adding up all the indices and dividing them trying to come up with some magic number (didn't work).

Thank you Brad, unfortunately I just got tasked with making dinner so I'll have to try it out in an hour or two.

I'll most certainly let you know how it goes.

Last edited by AsLan^ : 2005-11-17 at 05:19. Reason: I just dont like the :lol:
  quote
AWR
Veteran Member
 
Join Date: Jun 2005
Location: State of Flux
 
2005-11-17, 05:26

Damn you Brad, you beat me to it, again.
  quote
AsLan^
Not a tame lion...
 
Join Date: May 2004
Location: Narnia
 
2005-11-17, 06:13

Howabout that, it mostly worked !

Seriously though, the lowest value in all cases was zero, so that didn't really do much to be added to the highest.

I had to add twenty to each value, pick the highest one (with twenty added) and add half of that.

I had to add the twenty to allow for odd block lengths to have an oddish offset. For example the square should have an offset of 20 but the three prong should have an offset of 30.

Works great now, thank you gentlemen.
  quote
Brad
Selfish Heathen
 
Join Date: May 2004
Location: Zone of Pain
 
2005-11-17, 13:39

Excellent!

Now, I expect some quality realism in this version of Tetris. Something along the lines of this.
  quote
AsLan^
Not a tame lion...
 
Join Date: May 2004
Location: Narnia
 
2005-11-18, 01:47

Quote:
Originally Posted by Brad
Excellent!

Now, I expect some quality realism in this version of Tetris. Something along the lines of this.

It's for my wife, not quite finished yet...

  quote
Brad
Selfish Heathen
 
Join Date: May 2004
Location: Zone of Pain
 
2005-11-18, 03:06

Aww, how nice.

I trust that you saw the video, though, and realized I was trying to make a funny.
  quote
AsLan^
Not a tame lion...
 
Join Date: May 2004
Location: Narnia
 
2005-11-18, 03:09

Quote:
Originally Posted by Brad
Aww, how nice.

I trust that you saw the video, though, and realized I was trying to make a funny.
My bad, it was a pretty funny video
  quote
Posting Rules Navigation
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Post Reply

Forum Jump
Thread Tools
Similar Threads
Thread Thread Starter Forum Replies Last Post
Windows Media center edition... I'm impressed Wrao General Discussion 25 2005-08-15 12:07
Tetris on iPod leaks on Apple's own site? VL-Tone Speculation and Rumors 16 2005-06-03 14:44
Reformat drive and change block size alcimedes General Discussion 16 2004-07-04 15:56


« Previous Thread | Next Thread »

All times are GMT -5. The time now is 18:56.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Copyright ©2004 - 2018, AppleNova