protected override void CollisionWithLine(int asteroidIndex) { for (int index = lazerList.Count - 1; index > -1; index--) { // om skott krockar med astroid if (Raylib.CheckCollisionCircleRec(asteroidList[asteroidIndex].GetCirclePos, asteroidList[asteroidIndex].GetAsteroidHitboxSize, lazerList[index].GetRect)) { // - skott dmg && ta bort skott && + score för spaceship asteroidList[asteroidIndex].Hp -= lazerList[index].GetDamage; Spaceship.AddToScore(lazerList[index].GetID, lazerList[index].GetDamage); Lazer.RemoceInstanceOfLine(index); // om hp efter -dmg >=0 ta bort astroid också if (asteroidList[asteroidIndex].Hp <= 0) { for (int i = 0; i < 3 * ButtonSeries.GetSelectedMultiplier(2); i++) { ScatterAsteroidSubMissile scatterAsteroidSubMissile = new ScatterAsteroidSubMissile(asteroidList[asteroidIndex].GetCirclePos, Color.PINK, 100); } asteroidList.Remove(asteroidList[asteroidIndex]); } } } }
public void Update() { foreach (var s in springs) { s.Update(); } foreach (var p in points) { if (Raylib.CheckCollisionCircleRec(p.position, 5, ground) && p.velocity.Y > 0) { p.position.Y = ground.y; p.velocity.Y = 0; } } foreach (var p1 in points) { foreach (var p2 in points) { if (p1 != p2 && Raylib.CheckCollisionCircles(p1.position, springLength / collapseFactor, p2.position, springLength / collapseFactor)) { var dir = p2.position - p1.position; p1.velocity -= dir * Raylib.GetFrameTime(); } } } }
public void SelectInRect(Rectangle rec) { foreach (Component c in this.AllComponents) { if (Raylib.CheckCollisionRecs(rec, c.GetRectangle())) { this.Select(c); } } foreach (Wire wire in this.AllWires) { List <WireNode> wireNodes = wire.Graph.Vertices.ToList(); foreach (WireNode wn in wireNodes) { if (wn is JunctionWireNode) { if (Raylib.CheckCollisionCircleRec(wn.GetPosition(), 5, rec)) { this.Select(wn); } } } } }
//Draw/move objects and handle collisions static void HandleObjects(List <Bullet> bulletList, List <Obstacle> obstacleList, Game game) { //Draw/move bullets foreach (Bullet shot in bulletList) { Raylib.DrawCircle((int)shot.pos.X, (int)shot.pos.Y, 15, Color.GREEN); shot.pos.X += shot.xSpeed / 6; shot.pos.Y -= shot.ySpeed / 6; } //Draw/move obstacles and check all possible collisions //To remove objects from these lists using loops, it is required to go through for-loops in reverse for (int i = obstacleList.Count - 1; i >= 0; i--) { Obstacle enemy = obstacleList[i]; int sizeX = 80; int sizeY = 120; enemy.color = new Color(255, enemy.red, enemy.red, 255); enemy.box = new Rectangle(enemy.pos.X + 20, enemy.pos.Y, sizeX, sizeY); Raylib.DrawTexture(enemy.image, (int)enemy.pos.X, (int)enemy.pos.Y, enemy.color); enemy.pos.X += enemy.xSpeed; enemy.pos.Y += enemy.ySpeed; //If collision is detected, remove bullet and damage obstacle. for (int x = bulletList.Count - 1; x >= 0; x--) { if (Raylib.CheckCollisionCircleRec(bulletList[x].pos, 15, enemy.box)) { bulletList.RemoveAt(x); enemy.hp -= 1; enemy.red = 155; } } //Make obstacle less red by increasing green and blue. If more green/blue than 255, make it 255. enemy.red += 15; if (enemy.red > 255) { enemy.red = 255; } //Make obstacle bounce at borders if (enemy.pos.X > 900 || enemy.pos.X < 0) { enemy.xSpeed = -enemy.xSpeed; } //Remove obstacle if its HP is 0 if (enemy.hp < 1) { obstacleList.Remove(enemy); game.money += 100; } } }
private void CollisionWithLine(int asteroidIndex) { for (int index = lineList.Count - 1; index > 0; index--) { // om skott krockar med astroid if (Raylib.CheckCollisionCircleRec(asteroids[asteroidIndex].circlePos, 60, lineList[index].GetRect)) { // - skott dmg && ta bort skott asteroids[asteroidIndex].hp -= lineList[index].GetDamage; Line2.RemoceInstanceOfLine(index); // om hp efter -dmg >=0 ta bort astroid också if (asteroids[asteroidIndex].hp <= 0) { asteroids.Remove(asteroids[asteroidIndex]); } } } }
// hämtar in lista med skott // syftet med metoden är att checka om ett skott(Line) kolliderar med en asteroid protected virtual void CollisionWithLine(int asteroidIndex) { // för varje instans av Lazer tittar om kollision med astroid; for (int index = lazerList.Count - 1; index > -1; index--) { // om skott krockar med astroid if (Raylib.CheckCollisionCircleRec(asteroidList[asteroidIndex].GetCirclePos, asteroidList[asteroidIndex].GetAsteroidHitboxSize, lazerList[index].GetRect)) { // - skott dmg && ta bort skott && + score för spaceship asteroidList[asteroidIndex].Hp -= lazerList[index].GetDamage; // om hp efter -dmg >=0 ta bort astroid också if (asteroidList[asteroidIndex].Hp <= 0) { // lägger till poäng för asteroid Spaceship.AddToScore(lazerList[index].GetID, asteroidList[asteroidIndex].worth); // tar bort instans av astroid asteroidList.Remove(asteroidList[asteroidIndex]); } // tar bort skott(index) Lazer.RemoceInstanceOfLine(index); } } }