Skip to content

Commit d31969c

Browse files
committed
Added random direction selection to DirectedPix
1 parent cbb739b commit d31969c

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

DirectedPix.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,27 @@
77

88
public class DirectedPix extends Pix
99
{
10-
private static int direction; // (N E S W)
10+
private int direction; // (N E S W)
1111

1212
/**
1313
* Constructs a DirectedPix with a random direction
1414
*/
1515
public DirectedPix()
1616
{
1717
super();
18-
direction = 0;
18+
// direction = 0;
19+
direction = (int)(Math.random()*4);
1920
}
2021
public DirectedPix(int r, int g, int b, int direction)
2122
{
2223
super(r,g,b);
2324
this.direction = direction;
2425
}
2526

27+
/**
28+
* Sets the direction integer
29+
* @param dir direction
30+
*/
2631
public void setDir(int dir)
2732
{
2833
direction = dir;
@@ -69,6 +74,7 @@ public void movePixel(Pix[][] grid, int ix, int iy, int x, int y)
6974
// Moves it along
7075
Spawner.spawnXY( grid[ix][iy].getClass(), x, y );
7176
grid[x][y].setPix(grid[ix][iy]);
77+
((DirectedPix)grid[x][y]).setDir(direction);
7278

7379
// Duplicates upward and downward
7480
//Spawner.spawnXY( grid[ix][iy].getClass(), x, y-1 );

Pixelife.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void run()
6868
{
6969
myGrid.update();
7070
//line_spawner.update();
71-
//spawner.update();
71+
spawner.update();
7272

7373
draw();
7474

Spawner.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public Spawner()
3838
respawnCounter = 0;
3939
respawnMax = 200;
4040
numSpawn = 5;
41-
numSpawnMax = 10;
41+
numSpawnMax = 20;
4242
defaultX = -1;
4343
defaultY = -1;
4444
spawnClass = Pix.class;

0 commit comments

Comments
 (0)