I am making a Tetris game and am making the different shapes but the problem is I create the shapes with an array and do not know how I would go about rotating it.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class world2 here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class world2 extends World
{
int BlockY = 10;
int BlockX = 6;
boolean addWall = false;
private int [] x = {10,11,12,10}; //J piece
private int [] y = {10,10,10,10,11};//J piece
boolean Jpiece = false;
/**
* Constructor for objects of class world2.
*
*/
public world2()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(30, 30, 30);
prepare();
}
public void act()
{
Addwall();
setPaintOrder(Wall.class,block.class);
addBlock();
}
public void Addwall()
{
if (!addWall)
{
Greenfoot.setSpeed(70);
Wall wall = new Wall();
addObject(wall,BlockY,BlockX);
BlockY++;
if (BlockY == 20)
{
BlockX = BlockX + 1;
BlockY = 10;
if (BlockX > 29 && BlockY == 10)
{
addWall = true;
Greenfoot.setSpeed(50);
}
}
}
}
private void addBlock()
{
if (!Jpiece)
{
for (int r = 0; r< x.length; r++)
{
addObject(new block(), x[r], y[r]);
}
Jpiece = true;
}
}
/**
* Prepare the world for the start of the program.
* That is: create the initial objects and add them to the world.
*/
private void prepare()
{
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class block here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class block extends Actor
{
public block()
{
GreenfootImage image = getImage();
image.scale(30, 30);
image.setColor(Color.BLACK);
setImage(image);
}
/**
* Act - do whatever the block wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
setLocation(getX(), getY() +1);
if (isTouching(block.class)) setLocation(getX(), getY()-1);
if (Greenfoot.isKeyDown ("A"))
{setRotation(90); //Move left
}
}
}

