Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (480)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (546)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Validation of a rotated Block  (Read 1152 times)
0 Members and 1 Guest are viewing this topic.
Offline stef569

Junior Member





« Posted 2007-08-27 16:02:03 »

Hi, i'm trying to make a Tetris close

I have blocks that fall, and they aren't allowed to walk out of the array.
Then i wanted to flip one Block with following code:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
  public void rotateClockwise() {
    if (canRotate) {
      for (int i = 0; i < 4; i++) {
        final int temp = blocks[i].x;

        blocks[i].x = -blocks[i].y;
        blocks[i].y = temp;
      }
    }
    else
      System.out.println("You are not allowed to Rotate here...");
  }



But I have no idee how to start, to write a function that validates the flip?
I was thinking if i made a copy of the field and put the block in, that would give an exception but that stops my code all together, i only want to validate it.

For moving Left I used:
1  
blockFits(centrePoint.x, centrePoint.y-1)

and i was abit amazed that the figure 4 blocks on top of eachther didn't got out of bounds(Because the center is the Second Block?) but that's another story  Cool
Offline kaosnkorruption

Senior Newbie





« Reply #1 - Posted 2007-08-27 19:31:35 »

I developed a tetris clone for a class project.  this is how I handled that.  Everything was based off arrays of single blocks; both the tetris shapes and the dead blocks (the ones that stack at the bottom).  When a tetris piece moved or rotated, before it actually moved/rotated, I would move/rotate a mock shape, to determine if any of the blocks making up the shape breached the playing grid or intersected the dead blocks.  If the mock shape moved/rotated successfully, then I would rotate the actual shape, otherwise the tetris piece either landed or did not rotate.
Offline broumbroum

Junior Member





« Reply #2 - Posted 2007-08-27 23:53:46 »

see that a tetris piece of blocks has a 2Dimensional area covered by the blocks. if you want to rotate and check for the intersect, do as following ; first calculate the rotation within the game area and then intersect with Rectangle.intersect between you game area and the piece of blocks area. That be quite easy, wouldn't it uh?
A validate() meth' must impl these 2 processes and calculate the results (that be the piece graphics bounds) while the painting process waits for a short time to get the validation completed.
sheme graphic looks like :    PIECE < -----  validate(AffineTransform rotationTX, Rectangle intersect) --------> GameAREA.graphics
                                                       |                                                            ^                                                                                                        ^
                                                       drawImage(Rectangle bounds) ---| ------------------------------------------------------------------------------|


 Cheesy

::::... :..... :::::: ;;;:::™ b23:production 2006 GNU/GPL @ http://b23prodtm.webhop.info
on sf.net: /projects/sf3jswing
Java (1.6u10 plz) Web Start pool
dev' VODcast[/ur
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline keldon85

Senior Member


Medals: 1



« Reply #3 - Posted 2007-08-28 09:08:40 »

(Note) tetris concept wikipage: must read tetris wiki

lol, I did something similar (ish) once. I am working on a secret Tetris clone (that only a few privileged people have seen) and this is how I handle it:
 - a PieceTemplate class that stores an array of the block arrangement at all rotations (so that you could handle any of the many rotation systems)
 - a Piece class with a final PieceTemplate object, direction and position
 - a Tetrion class with a collides(x,y):boolean method that checks whether the piece collides at the given offset (i.e. if you tried to move at this position relative to where it is now). It could be rewritten to take the direction as an argument too

It allows me to have a really flexible Tetris back end, and the general structure has not changed for a long time. Just about every time I knock together a Tetris clone it has that sort of structure.

Offline stef569

Junior Member





« Reply #4 - Posted 2007-08-28 17:24:38 »

Thx, I got it sorted Grin

Tetris clones seem to be very popular... I already found 3 sources from other people who made the same thing.

btw You might remember that I was here a while ago asking about tile games etc... It's not possible to create a game like that after you got the intro of classes....
I learnt a lesson  Grin After I'm 100% done with this i will do some more basic games and then i'll try again.

I'll be back for my next question  Wink
Offline keldon85

Senior Member


Medals: 1



« Reply #5 - Posted 2007-08-29 06:27:46 »

 A path to games development: guide to your route into game development! Not sure what you mean about "not possible to create a game like that", do you mean tile games?

Offline stef569

Junior Member





« Reply #6 - Posted 2007-08-29 11:36:16 »

I already read that page,

I ment that you first need to finish a smaller project until you do bigger things as explained on the website you gave.
tile games was just an example of what was (is) too high for me.
Offline keldon85

Senior Member


Medals: 1



« Reply #7 - Posted 2007-08-29 15:22:58 »

Oh, lol; well any link I give comes from a sort of bookmark so that would explain why I gave you the exact same link Smiley

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

atombrot (20 views)
2014-08-19 09:29:53

Tekkerue (21 views)
2014-08-16 06:45:27

Tekkerue (21 views)
2014-08-16 06:22:17

Tekkerue (12 views)
2014-08-16 06:20:21

Tekkerue (19 views)
2014-08-16 06:12:11

Rayexar (55 views)
2014-08-11 02:49:23

BurntPizza (37 views)
2014-08-09 21:09:32

BurntPizza (27 views)
2014-08-08 02:01:56

Norakomi (35 views)
2014-08-06 19:49:38

BurntPizza (64 views)
2014-08-03 02:57:17
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!