Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (788)
Games in Android Showcase (234)
games submitted by our members
Games in WIP (860)
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 3020 times)
0 Members and 1 Guest are viewing this topic.
Offline stef569

Junior Devvie

« 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:

  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;
      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:
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 Devvie

« 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) -------->
                                                       |                                                            ^                                                                                                        ^
                                                       drawImage(Rectangle bounds) ---| ------------------------------------------------------------------------------|


::::... :..... :::::: ;;;:::™ b23:production 2006 GNU/GPL @
on /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 Devvie

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 Devvie

« 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 Devvie

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 Devvie

« 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 Devvie

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  

hadezbladez (2081 views)
2018-11-16 13:46:03

hadezbladez (799 views)
2018-11-16 13:41:33

hadezbladez (2050 views)
2018-11-16 13:35:35

hadezbladez (414 views)
2018-11-16 13:32:03

EgonOlsen (3444 views)
2018-06-10 19:43:48

EgonOlsen (3666 views)
2018-06-10 19:43:44

EgonOlsen (2271 views)
2018-06-10 19:43:20

DesertCoockie (2993 views)
2018-05-13 18:23:11

nelsongames (3070 views)
2018-04-24 18:15:36

nelsongames (3786 views)
2018-04-24 18:14:32
Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20 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‑
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!