-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
275 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import '../game_objects/game_object.dart'; | ||
import '../game_objects/sheep/sheep.dart'; | ||
import '../game_objects/sheep/i_sheep_herder.dart'; | ||
|
||
const _creator_num_of_sheep = 15; | ||
const _creator_sheep_in_row = 5; | ||
const _creator_sheep0_x = -5.0; | ||
const _creator_sheep0_z = -10.0; | ||
const _creator_distance = 2.0; | ||
|
||
const walking_plane_y = 1.1; | ||
|
||
class HerdController { | ||
final GameObject rootObject; | ||
final ISheepHerder sheepHerder; | ||
|
||
List<Sheep> _herdMembers = <Sheep>[]; | ||
|
||
HerdController(this.rootObject, this.sheepHerder){ | ||
_createHerdMembers(); | ||
} | ||
|
||
void moveHerdMembers(){ | ||
for (Sheep sheep in _herdMembers){ | ||
sheep.move(); | ||
} | ||
} | ||
|
||
void _createHerdMembers(){ | ||
int row = 0; | ||
int column = 0; | ||
for (int i = 0; i < _creator_num_of_sheep; i++){ | ||
Sheep sheep = new Sheep(sheepHerder); | ||
// sets inital position | ||
double z = _creator_sheep0_z; | ||
z += row * _creator_distance; | ||
sheep.z = z; | ||
|
||
double x = _creator_sheep0_x; | ||
x += column * _creator_distance; | ||
sheep.x = x; | ||
|
||
rootObject.addChild(sheep); | ||
_herdMembers.add(sheep); | ||
|
||
column++; | ||
if (column == _creator_sheep_in_row){ | ||
row++; | ||
column = 0; | ||
} | ||
} | ||
|
||
// for (int i = 0; i < _initial_num_of_sheep; i++){ | ||
// Sheep sheep = new Sheep(sheepHerder); | ||
// sheep.translateY(walking_plane_y); | ||
// sheep.z = -10.0; | ||
|
||
// if (i == 0){ | ||
// sheep.x = -5.0; | ||
// } | ||
|
||
// if (i == 2){ | ||
// sheep.x = 5.0; | ||
// } | ||
|
||
// rootObject.addChild(sheep); | ||
// _herdMembers.add(sheep); | ||
// } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import '../../math_util.dart' as math_util; | ||
|
||
abstract class ISheepHerder { | ||
double get x; | ||
double get y; | ||
double get z; | ||
|
||
double get rotation; | ||
|
||
math_util.Point3D get point3D; | ||
|
||
math_util.Point2D get point2D_birdView; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
library Sheep; | ||
|
||
import '../game_object.dart'; | ||
import '../../math_util.dart' as math_util; | ||
|
||
import 'i_sheep_herder.dart'; | ||
part 'sheep_body.dart'; | ||
|
||
class Sheep extends GameObject { | ||
// [herder] must be less than [attention_distance] away from Sheep in order for sheep to respond to it | ||
static const attention_distance = 20.0; | ||
|
||
static const movement_speed = 0.02; | ||
|
||
// Shomehing that herds sheep (sheep run away from this object) | ||
ISheepHerder herder; | ||
|
||
SheepBody body; | ||
|
||
Sheep(this.herder) { | ||
body = new SheepBody(this); | ||
addChild(body); | ||
} | ||
|
||
void move() { | ||
// rotates away from player | ||
rotationY = | ||
math_util.angle2D(herder.point2D_birdView, this.point2D_birdView); | ||
rotateY(90.0); | ||
|
||
// if herder away enough it doesn't move | ||
if (math_util.distance3D(herder.point3D, point3D) > attention_distance) { | ||
return; | ||
} | ||
|
||
translateZ(movement_speed); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
part of Sheep; | ||
|
||
class SheepBody extends GameObject { | ||
SheepBody(GameObject parent) { | ||
this.parent = parent; | ||
|
||
List<double> vertices = <double>[ | ||
// Front face | ||
0.0, 1.0, 0.0, | ||
-1.0, -1.0, 1.0, | ||
1.0, -1.0, 1.0, | ||
|
||
// Right face | ||
0.0, 1.0, 0.0, | ||
1.0, -1.0, 1.0, | ||
1.0, -1.0, -1.0, | ||
|
||
// Back face | ||
0.0, 1.0, 0.0, | ||
1.0, -1.0, -1.0, | ||
-1.0, -1.0, -1.0, | ||
|
||
// Left face | ||
0.0, 1.0, 0.0, | ||
-1.0, -1.0, -1.0, | ||
-1.0, -1.0, 1.0, | ||
|
||
// NOTE: Missing the bottom triangles :) | ||
-1.0, -1.0, -1.0, | ||
1.0, -1.0, -1.0, | ||
1.0, -1.0, 1.0, | ||
-1.0, -1.0, -1.0, | ||
1.0, -1.0, 1.0, | ||
-1.0, -1.0, 1.0, | ||
]; | ||
super.setVertexBuffer(vertices); | ||
|
||
var colors = [ | ||
// Front face | ||
1.0, 0.0, 0.0, 1.0, | ||
1.0, 0.0, 0.0, 1.0, | ||
1.0, 0.0, 0.0, 1.0, | ||
|
||
// Right face | ||
0.0, 0.0, 1.0, 1.0, | ||
0.0, 0.0, 1.0, 1.0, | ||
0.0, 0.0, 1.0, 1.0, | ||
|
||
// Back face | ||
0.0, 0.0, 1.0, 1.0, | ||
0.0, 0.0, 1.0, 1.0, | ||
0.0, 0.0, 1.0, 1.0, | ||
|
||
// Left face | ||
0.0, 0.0, 1.0, 1.0, | ||
0.0, 0.0, 1.0, 1.0, | ||
0.0, 0.0, 1.0, 1.0, | ||
|
||
// Bottom face | ||
0.0, 0.0, 1.0, 1.0, | ||
0.0, 0.0, 1.0, 1.0, | ||
0.0, 0.0, 1.0, 1.0, | ||
0.0, 0.0, 1.0, 1.0, | ||
0.0, 0.0, 1.0, 1.0, | ||
0.0, 0.0, 1.0, 1.0 | ||
]; | ||
super.setColorBuffer(colors); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.