Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added creature scattering code

  • Loading branch information...
commit 49aebb6cf7f4e5a5a9e45770b66aa949f8c5ed96 1 parent 0271068
@muraliavarma authored
View
6 murali_varma_hw2/Creature.pde
@@ -20,13 +20,17 @@ class Creature {
Creature(int i) {
idx = i;
+ init();
+ }
+
+ void init() {
posX = random(1);
posY = random(1);
velX = WANDERING_WEIGHT * (1 - random(2));
velY = WANDERING_WEIGHT * (1 - random(2));
neighborsFC = new ArrayList();
- neighborsCA = new ArrayList();
+ neighborsCA = new ArrayList();
}
void draw() {
View
BIN  murali_varma_hw2/build-tmp/murali_varma_hw2$Creature.class
Binary file not shown
View
BIN  murali_varma_hw2/build-tmp/murali_varma_hw2.class
Binary file not shown
View
13 murali_varma_hw2/build-tmp/source/murali_varma_hw2.java
@@ -99,6 +99,13 @@ else if(key == 'w') {
loop();
}
+ //commands
+ if (key == 's') {
+ for (int i = 0; i < NUM_CREATURES; i++) {
+ creatures[i].init();
+ }
+ }
+
//forces
if (key == '1') {
flockCenteringForce = !flockCenteringForce;
@@ -135,13 +142,17 @@ else if(key == 'w') {
Creature(int i) {
idx = i;
+ init();
+ }
+
+ public void init() {
posX = random(1);
posY = random(1);
velX = WANDERING_WEIGHT * (1 - random(2));
velY = WANDERING_WEIGHT * (1 - random(2));
neighborsFC = new ArrayList();
- neighborsCA = new ArrayList();
+ neighborsCA = new ArrayList();
}
public void draw() {
View
7 murali_varma_hw2/murali_varma_hw2.pde
@@ -84,6 +84,13 @@ void keyPressed() {
loop();
}
+ //commands
+ if (key == 's') {
+ for (int i = 0; i < NUM_CREATURES; i++) {
+ creatures[i].init();
+ }
+ }
+
//forces
if (key == '1') {
flockCenteringForce = !flockCenteringForce;
Please sign in to comment.
Something went wrong with that request. Please try again.