MCPcopy Create free account
hub / github.com/candybox2/candybox2.github.io / addBird

Method addBird

code/main/Desert.ts:127–152  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

125
126 // Private methods
127 private addBird(): void{
128 // We create the variable which will contain our bird
129 var bird: DesertBird;
130
131 // We choose the y position of our bird
132 var yPos: number = Random.upTo(14);
133
134 // We check if we could collide with another bird using this y position
135 for(var i = 0; i < this.getEntities().length; i++){
136 if(this.getEntities()[i].getCbc() != null && this.getEntities()[i].getCbc().collidesWith(new CollisionBoxCollection(new CollisionBox(new QuestEntity(this, new Pos(0, 0)), new Pos(0, yPos), new Pos(149, 4)))))
137 return;
138 }
139
140 // We add a bird going right
141 if(Random.flipACoin()){
142 bird = new DesertBird(this, new Pos(-9, yPos), true);
143 }
144 // Or a bird going left
145 else{
146 bird = new DesertBird(this, new Pos(149, yPos), false);
147 }
148
149 // We add the health bar and finally add the bird to the entities
150 bird.setHealthBar(new QuestEntityHealthBar(bird, new Pos(9, 1)));
151 this.addEntity(bird);
152 }
153
154 private addCamel(pos: Pos): void{
155 var camel: QuestEntity;

Callers 1

updateMethod · 0.95

Calls 5

getEntitiesMethod · 0.80
getCbcMethod · 0.80
setHealthBarMethod · 0.80
addEntityMethod · 0.80
collidesWithMethod · 0.45

Tested by

no test coverage detected