Exemplo n.º 1
0
        public void CheckForCollision(Actor actor1, Actor actor2)
        {
            bool collisionHandled = false;
            foreach(Tile tile1 in actor1.Tiles)
            {
                foreach(Tile tile2 in actor2.Tiles)
                {
                    if (tile1.CurrentRectCoords.Intersects(tile2.CurrentRectCoords))
                    {
                        Tuple<ActorMovementType, ActorMovementType> actorMovementTuple = new Tuple<ActorMovementType, ActorMovementType>(tile1.BaseActor.MovementType, tile2.BaseActor.MovementType);

                        if (LudimusGame.ActorCollisionLookup.ContainsKey(actorMovementTuple))
                        {
                            ActorCollisionType actorCollisionType = (ActorCollisionType)LudimusGame.ActorCollisionLookup[actorMovementTuple];
                            System.Console.WriteLine("Found collision Type: " + actorCollisionType.ToString());
                            if (actorCollisionType == ActorCollisionType.Bounce)
                            {
                                tile1.BaseActor.Bounce(tile1, tile2);
                                collisionHandled = true;
                                break;
                            }
                            if (actorCollisionType == ActorCollisionType.BounceBoth)
                            {
                                tile1.BaseActor.Bounce(tile1, tile2);
                                tile2.BaseActor.Bounce(tile2, tile1);
                                collisionHandled = true;
                                break;
                            }
                        }

                        System.Console.WriteLine("Colliding! " + tile1.Type + " hit " + tile2.Type);
                        System.Console.WriteLine("Colliding Actors! " + actor1.MovementType + " hit " + actor2.MovementType);
                    }
                }
                if (collisionHandled)
                    break;
            }
        }
Exemplo n.º 2
0
        public void SetActors()
        {
            //Find tiles neighboring each tile, and add them to Actors
            foreach(Tile tileToCheck in ActiveTiles)
            {
                if (tileToCheck.BaseActor == null)
                {
                    Actor actorToAdd = new Actor();
                    actorToAdd.AddTile(tileToCheck);

                    bool noTilesToAdd = false;

                    while (noTilesToAdd == false)
                    {
                        List<Tile> neighboringTiles = new List<Tile>();
                        foreach (Tile tile in actorToAdd.Tiles)
                        {
                            neighboringTiles.AddRange(FindNeighboringTiles(tile));
                        }

                        if (neighboringTiles.Count == 0)
                        {
                            noTilesToAdd = true;
                        }
                        else
                        {
                            bool addedAnyTile = false;
                            foreach (Tile tile in neighboringTiles)
                            {
                                if (actorToAdd.AddTile(tile))
                                    addedAnyTile = true;
                            }
                            if (!addedAnyTile)
                                noTilesToAdd = true;
                        }
                    }
                    actorToAdd.SetMovementType();
                    actorToAdd.BaseGameBoard = this;

                    Actors.Add(actorToAdd);
                }
            }
        }