Beispiel #1
0
        public CharacterBase(int x, int y, Level level)
            : this()
        {
            if (level != null)
            {
                Level = level;

                Location = new Point2(x, y);

                Type = (CharacterType)level.Map.Planes[(int)Level.Planes.Objects][y, x];

                SetAxisLock(PhysicsServer.BodyAxis.AngularX, true);
                SetAxisLock(PhysicsServer.BodyAxis.AngularY, true);
                SetAxisLock(PhysicsServer.BodyAxis.AngularZ, true);

                MoveLockY = true;

                CollisionShape colShape = new CollisionShape();
                CylinderShape  cylShape = new CylinderShape();

                cylShape.Height = Level.CellSize;
                cylShape.Radius = Level.CellSize * 0.25f;

                colShape.Shape = cylShape;

                AddChild(colShape);

                CollisionLayer = (uint)Level.CollisionLayers.Characters;
                CollisionMask  = (uint)(
                    Level.CollisionLayers.Characters |
                    Level.CollisionLayers.Static |
                    Level.CollisionLayers.Doors |
                    Level.CollisionLayers.Walls |
                    Level.CollisionLayers.Floor |
                    Level.CollisionLayers.Pickups |
                    Level.CollisionLayers.Projectiles);

                Level.AddChild(this);

                Transform tform = this.Transform;

                tform.origin = level.MapToWorld(x, y);

                this.Transform = tform;

                SetPhysicsProcess(true);
            }
        }
Beispiel #2
0
        protected PropBase(int x, int y, Level level)
            : this()
        {
            if (level != null)
            {
                Level    = level;
                Type     = (PropType)Level.Map.Planes[(int)Level.Planes.Objects][y, x];
                Location = new Point2(x, y);

                Billboard = SpatialMaterial.BillboardMode.FixedY;
                Texture   = (Assets.GetSprite(PropSpriteIndices[Type]) as SpatialMaterial).AlbedoTexture;
                PixelSize = Level.CellSize / (float)Assets.VSWAP.SpriteSize.Height;

                Level.AddChild(this);

                Transform tform = this.Transform;

                tform.origin = level.MapToWorld(x, y);

                this.Transform = tform;
            }
        }
Beispiel #3
0
        public DoorSecret(int x, int y, Level level)
        {
            if (level != null)
            {
                Location = new Point2(x, y);
                Level    = level;

                Type = level.Map.Planes[(int)Level.Planes.Walls][y, x];

                // This will be the physical body for the door itself.

                BoxShape box = new BoxShape();
                box.Extents = new Vector3(Level.CellSize * 0.5f, Level.CellSize * 0.5f, Level.CellSize * 0.5f);

                _wallShape       = new CollisionShape();
                _wallShape.Shape = box;

                _wallBody                = new RigidBody();
                _wallBody.Mode           = RigidBody.ModeEnum.Static;
                _wallBody.CollisionLayer = (uint)Level.CollisionLayers.Walls;
                _wallBody.CollisionMask  = (uint)(Level.CollisionLayers.Characters | Level.CollisionLayers.Projectiles);
                _wallBody.AddChild(_wallShape);

                AddChild(_wallBody);

                // Create the actual mesh for the door

                _mesh      = new MeshInstance();
                _mesh.Mesh = GetMeshForDoor(Type);

                _wallBody.AddChild(_mesh);

                // Add an audio player to play the "pushing" sound when the door
                // is activated.

                _audioPlayer = new AudioStreamPlayer3D();

                _wallBody.AddChild(_audioPlayer);

                _activateSound = Assets.GetSoundClip(Assets.DigitalSoundList.PushWallActivation);

                // Add the tween that will be used to animate the door.

                _tween = new Tween();
                _tween.Connect("tween_all_completed", this, "OnTweenCompleted");

                AddChild(_tween);

                // Add myself to the world and set my position.

                level.AddChild(this);

                Transform tform = this.Transform;
                tform.origin   = level.MapToWorld(x, y);
                this.Transform = tform;

                // Set my default state.

                State   = DoorState.Stopped;
                Enabled = true;

                SetProcess(true);
                SetPhysicsProcess(true);
            }
        }
Beispiel #4
0
        public DoorSliding(int x, int y, Level level)
        {
            if (level != null)
            {
                Location = new Point2(x, y);
                Level    = level;

                Type = (DoorType)level.Map.Planes[(int)Level.Planes.Walls][y, x];

                level.Cells[y, x] = Level.Cell.Default();

                // Adjust neighboring walls to show the door excavation.

                if (!IsVertical)
                {
                    if ((x - 1) > -1 &&
                        level.Cells[y, x - 1].East != Level.Cell.NoWall)
                    {
                        level.Cells[y, x - 1].East = DoorWestEastWall;
                    }

                    if ((x + 1) < level.Map.Width &&
                        level.Cells[y, x + 1].West != Level.Cell.NoWall)
                    {
                        level.Cells[y, x + 1].West = DoorWestEastWall;
                    }
                }
                else
                {
                    if ((y + 1) < level.Map.Height &&
                        level.Cells[y + 1, x].North != Level.Cell.NoWall)
                    {
                        level.Cells[y + 1, x].North = DoorNorthSouthWall;
                    }

                    if ((y - 1) > -1 &&
                        level.Cells[y - 1, x].South != Level.Cell.NoWall)
                    {
                        level.Cells[y - 1, x].South = DoorNorthSouthWall;
                    }
                }

                // Create a static body for the cell so that
                // we can block the player from entering or exiting the cell
                // when the door is closed or moving.

                _cellShape = new CollisionShape();
                BoxShape box = new BoxShape();
                box.Extents = new Vector3(Level.CellSize * 0.5f, Level.CellSize * 0.5f, Level.CellSize * 0.5f);

                _cellShape.Shape = box;
                _cellShape.Name  = "CollisionShape";

                _cellBody = new StaticBody();
                _cellBody.CollisionLayer = (uint)Level.CollisionLayers.Static;
                _cellBody.CollisionMask  = (uint)(Level.CollisionLayers.Characters);
                _cellBody.AddChild(_cellShape);

                AddChild(_cellBody);

                // Create the actual mesh for the door and set it up for
                // this particular instance.

                BuildDoorMesh();

                _mesh                  = new MeshInstance();
                _mesh.Mesh             = _doorMesh;
                _mesh.MaterialOverride = Assets.GetTexture(_doorTexture[Type]);

                if (IsVertical)
                {
                    _mesh.Transform = Transform.Identity.Rotated(Vector3.Up, Mathf.Pi * 0.5f);
                }
                else
                {
                    _mesh.Transform = Transform.Identity.Rotated(Vector3.Up, Mathf.Pi);
                }

                // Setup a physics body for the door itself for the purposes
                // of detecting collisions with projectiles since projectiles shouldn't
                // be blocked by the cell's static body that is normally only used for
                // ensuring characters can't enter or exit the cell if the door is closed
                // or moving.

                _doorShape  = new CollisionShape();
                box         = new BoxShape();
                box.Extents = new Vector3(Level.CellSize * 0.5f, Level.CellSize * 0.5f, Mathf.Epsilon);

                _doorShape.Shape = box;
                _doorShape.Name  = "CollisionShape";

                _doorBody = new RigidBody();
                _doorBody.CollisionLayer = (uint)Level.CollisionLayers.Doors;
                _doorBody.CollisionMask  = (uint)Level.CollisionLayers.Projectiles;
                _doorBody.AddChild(_doorShape);
                _doorBody.Mode = RigidBody.ModeEnum.Static;

                _mesh.AddChild(_doorBody);

                AddChild(_mesh);

                // Add myself to the world and set my position
                // along with some default state variables.

                level.AddChild(this);

                Transform tform = this.Transform;
                tform.origin   = level.MapToWorld(x, y);
                this.Transform = tform;

                State = DoorState.Closed;

                _openCloseDuration = 0.75f;
                _canClose          = true;

                _openSound  = Assets.GetSoundClip(Assets.DigitalSoundList.DoorOpening);
                _closeSound = Assets.GetSoundClip(Assets.DigitalSoundList.DoorClosing);

                // Add a tween node for controlling the animation of the
                // door opening and closing.

                _tween = new Tween();
                _tween.Connect("tween_all_completed", this, "OnTweenCompleted");

                _mesh.AddChild(_tween);

                // Add an audio player so we can emit a sound
                // when the door opens and closes.

                _audioPlayer      = new AudioStreamPlayer3D();
                _audioPlayer.Name = "AudioPlayer";

                AddChild(_audioPlayer);

                SetProcess(true);
                SetPhysicsProcess(true);
            }
        }