// Use this for initialization void Start() { OriginalPosition = PlatformChild.transform.position; PlatformScript = PlatformChild.GetComponent <FallingPlatform>(); RespawnCheck = 0; RespawnCheckBool = false; }
void Start() { player = FindObjectOfType <Player>(); foreach (GameObject sObject in FindGameObjectsWithTags(new string[] { "orangeDestroy", "coin" })) { stateObjects.Add(sObject); } foreach (GameObject dObject in GameObject.FindGameObjectsWithTag("dissPlatform")) { FallingPlatform fPlatform = dObject.GetComponent <FallingPlatform>(); fallingPlatforms.Add(fPlatform); } foreach (GameObject pObject in FindGameObjectsWithTags(new string[] { "movingPlatform", "chaseBoss" })) { PlatformController pController = pObject.GetComponent <PlatformController>(); platforms.Add(pController); } foreach (GameObject lObject in GameObject.FindGameObjectsWithTag("Lever")) { Lever lever = lObject.GetComponent <Lever>(); levers.Add(lever); } }
// Start is called before the first frame update protected override void Start() { base.Start(); originPos = transform.position; rb2D = GetComponent <Rigidbody2D>(); left = CheckSidePlatform(leftPoint.position); right = CheckSidePlatform(rightPoint.position); }
void OnCollisionEnter(Collision col) { m_isJumping = false; Collider coll = col.gameObject.GetComponent <Collider>(); if (coll) { m_material = coll.material; } if (col.collider.tag == "FallingPlat") { FallingPlatform platform = col.gameObject.GetComponent <FallingPlatform>(); if (platform) { m_FallingExtraForce = platform.m_appliedForce; m_onFalling = true; } } else { m_onFalling = false; } if (col.collider.tag == "EndLevel") { if (SceneManager.GetActiveScene().buildIndex + 1 > 3) { SceneManager.LoadScene(0); } else { SceneManager.LoadScene(m_currentScene + 1); } } if (col.collider.tag == "Ramp") { m_rampDirection = col.transform.rotation.eulerAngles; float landingSpot = transform.position.x + desiredRampLaunchDist; m_distance = landingSpot - (transform.position.x); CalculateRampMovement(); m_onRamp = true; } else { m_onRamp = false; } if (col.collider.tag == "Level1" || col.collider.tag == "Level2") { col.gameObject.transform.GetChild(1).gameObject.SetActive(true); StartCoroutine(LoadScene(col.collider.tag)); } }
void Start() { //Find Player_Movement script playerMovement = FindObjectOfType <Player_Movement>(); //find EnvObject script environment = FindObjectOfType <EnvObject>(); //Find sound manager sounds = GameObject.Find("SoundManager").GetComponent <SoundManager>(); //Find FallingPlatform fallingPlatform = FindObjectOfType <FallingPlatform>(); }
void FillLists() { foreach (GameObject oObject in GameObject.FindGameObjectsWithTag("orb")) { PickUpGlobe oOrb = oObject.GetComponent <PickUpGlobe>(); orbs.Add(oOrb); } numberOrbs = orbs.Count; foreach (GameObject seObject in GameObject.FindGameObjectsWithTag("coin")) { PickUpSecret sOrb = seObject.GetComponent <PickUpSecret>(); secrets.Add(sOrb); } foreach (GameObject sObject in FindGameObjectsWithTags(new string[] { "orangeDestroy", "coin" })) { stateObjects.Add(sObject); } foreach (GameObject dObject in GameObject.FindGameObjectsWithTag("dissPlatform")) { FallingPlatform fPlatform = dObject.GetComponent <FallingPlatform>(); fallingPlatforms.Add(fPlatform); } foreach (GameObject pObject in FindGameObjectsWithTags(new string[] { "movingPlatform", "chaseBoss" })) { PlatformController pController = pObject.GetComponent <PlatformController>(); platforms.Add(pController); } foreach (GameObject lObject in GameObject.FindGameObjectsWithTag("Lever")) { Lever lever = lObject.GetComponent <Lever>(); levers.Add(lever); } }
/// <summary> /// Generates a series of platforms with varying frictions and bounciness /// </summary> /// <param name="pos">The X/Y Position to create the platforms at (top left)</param> /// <param name="xWidth">The X width the platforms must be constrained in</param> /// <returns>Array of generated platforms</returns> public Platform[] GeneratePlatforms(Vector2 pos, float xWidth) { //Get our list of platforms to return List <Platform> platforms; float positionY = pos.Y; float screenWidth = xWidth; //Pick a number of platforms, as long as it wasnt one we just had int numOfPlatforms; while ((numOfPlatforms = rand.Next(MinPlatformNumbers, MaxPlatformNumbers)) == prevNumOfPlatforms || prevNumOfPlatforms == 3 && numOfPlatforms == 2) { } prevNumOfPlatforms = numOfPlatforms; platforms = new List <Platform>(); //Console.WriteLine(numOfPlatforms); //Will this row have a dynamic platform in? bool hasDynamicPlatform = rand.Next(1, 11) < DynamicPlatformChance; int dynamicPlatformType; while (specialPlatformPrefabs[dynamicPlatformType = rand.Next(0, specialPlatformPrefabs.Length)].PlatformType == prevDynamicType) { ; } //Decide which platform index it will replace, in the case of a moving platform, it replaces 2 int dynamicPlatformIndex = specialPlatformPrefabs[dynamicPlatformType].PlatformType == Platform.PlatformTypes.DynamicMoving ? rand.Next(0, numOfPlatforms - 1) : rand.Next(0, numOfPlatforms); //Get some size calculations //Total free space we'll have on the row float spaceSize = ((screenWidth / 100) * MaxPlatformSpacePercentOfScreen) / numOfPlatforms; float platformSize = (screenWidth - (spaceSize * numOfPlatforms)) / numOfPlatforms; //Generate all the normal platforms for (int i = 0; i < numOfPlatforms; i++) { platforms.Add(new Platform()); //Randomly decide what kind of platform to use int platformType = rand.Next(0, platformPrefabs.Length); platforms[i].IsStaticHorizontal = true; platforms[i].IsStaticVertical = true; platforms[i].IsIgnoringGravity = true; platforms[i].Friction = platformPrefabs[platformType].FrictionCoefficients; platforms[i].Bounciness = platformPrefabs[platformType].Bounciness; //Set the Texture platforms[i].TextureLeftFile = platformPrefabs[platformType].TextureLeft; platforms[i].TextureMidFile = platformPrefabs[platformType].TextureMid; platforms[i].TextureRightFile = platformPrefabs[platformType].TextureRight; //Calculate the size and positions of each platform platforms[i].Size = new Vector2(platformSize, PlatformYSize); platforms[i].BoxCollider = new Vector2(platformSize, PlatformYSize); //Automatically space out the platforms depending on how many there are //The size of the platform, plus the size needed for a space, //Then add a bit of etxra padding so it ends at the edge of the screen //And if its only 1 platform, we add some extra space at the start so its centered Vector2 newPos = new Vector2(pos.X + ((i * (platformSize + spaceSize + (spaceSize / (numOfPlatforms > 1 ? numOfPlatforms - 1 : 1)))) + (numOfPlatforms == 1 ? spaceSize / 2 : 0)), positionY); platforms[i].Position = newPos; //Set the Scale platforms[i].Scale = new Vector2(0.2f, 0.2f); } //Replace the platform at the given index with our dynamic one if (hasDynamicPlatform && !prevContainsDynamic) { //If so, decide ahead of time which dynamic platform we'll include prevContainsDynamic = true; prevDynamicType = specialPlatformPrefabs[dynamicPlatformType].PlatformType; //Set Type Specific Values switch (specialPlatformPrefabs[dynamicPlatformType].PlatformType) { case Platform.PlatformTypes.DynamicSpring: { //Spring SpringPlatform springPlat = new SpringPlatform(); springPlat.IsStaticHorizontal = false; springPlat.IsStaticVertical = false; springPlat.IsIgnoringGravity = true; //Set Textures springPlat.TextureLeftFile = specialPlatformPrefabs[dynamicPlatformType].TextureLeft; springPlat.TextureMidFile = specialPlatformPrefabs[dynamicPlatformType].TextureMid; springPlat.TextureRightFile = specialPlatformPrefabs[dynamicPlatformType].TextureRight; //Set Properties springPlat.Friction = specialPlatformPrefabs[dynamicPlatformType].FrictionCoefficients; springPlat.Bounciness = specialPlatformPrefabs[dynamicPlatformType].Bounciness; //Set Type springPlat.PlatformType = specialPlatformPrefabs[dynamicPlatformType].PlatformType; //Set Positions and whatnot springPlat.Position = platforms[dynamicPlatformIndex].Position; springPlat.Rotation = platforms[dynamicPlatformIndex].Rotation; springPlat.Scale = platforms[dynamicPlatformIndex].Scale; //Set Scale springPlat.Size = platforms[dynamicPlatformIndex].Size; springPlat.BoxCollider = platforms[dynamicPlatformIndex].BoxCollider; platforms[dynamicPlatformIndex] = (Platform)springPlat; break; } case Platform.PlatformTypes.DynamicFalling: { //If it's a falling platform make sure it isnt in any middle platforms //Or this could destroy the only path up to the next level if (numOfPlatforms % 2 == 1 && (dynamicPlatformIndex != 0 && dynamicPlatformIndex != numOfPlatforms)) { dynamicPlatformIndex--; } //If this is the only platform, dont change it or we could make the level impossible if (numOfPlatforms == 1) { break; } //Falling FallingPlatform fallingPlat = new FallingPlatform(); fallingPlat.IsStaticHorizontal = true; fallingPlat.IsStaticVertical = true; fallingPlat.IsIgnoringGravity = true; //Set Textures fallingPlat.TextureLeftFile = specialPlatformPrefabs[dynamicPlatformType].TextureLeft; fallingPlat.TextureMidFile = specialPlatformPrefabs[dynamicPlatformType].TextureMid; fallingPlat.TextureRightFile = specialPlatformPrefabs[dynamicPlatformType].TextureRight; //Set Properties fallingPlat.Friction = specialPlatformPrefabs[dynamicPlatformType].FrictionCoefficients; fallingPlat.Bounciness = specialPlatformPrefabs[dynamicPlatformType].Bounciness; //Set Type fallingPlat.PlatformType = specialPlatformPrefabs[dynamicPlatformType].PlatformType; //Set Positions and whatnot fallingPlat.Position = platforms[dynamicPlatformIndex].Position; fallingPlat.Rotation = platforms[dynamicPlatformIndex].Rotation; fallingPlat.Scale = platforms[dynamicPlatformIndex].Scale; //Set Scale fallingPlat.Size = platforms[dynamicPlatformIndex].Size; fallingPlat.BoxCollider = platforms[dynamicPlatformIndex].BoxCollider; fallingPlat.EnemyReference = EnemyReference; fallingPlat.AIReference = AIReference; platforms[dynamicPlatformIndex] = (Platform)fallingPlat; break; } case Platform.PlatformTypes.DynamicMoving: { //If this is the only platform, dont change it as it overcomplicates waypoints if (numOfPlatforms <= 2) { break; } //Moving MovingPlatform movPlat = new MovingPlatform(); movPlat.IsStaticHorizontal = true; movPlat.IsStaticVertical = true; movPlat.IsIgnoringGravity = true; //Set Textures movPlat.TextureLeftFile = specialPlatformPrefabs[dynamicPlatformType].TextureLeft; movPlat.TextureMidFile = specialPlatformPrefabs[dynamicPlatformType].TextureMid; movPlat.TextureRightFile = specialPlatformPrefabs[dynamicPlatformType].TextureRight; //Set Properties movPlat.Friction = specialPlatformPrefabs[dynamicPlatformType].FrictionCoefficients; movPlat.Bounciness = specialPlatformPrefabs[dynamicPlatformType].Bounciness; //Set Type movPlat.PlatformType = specialPlatformPrefabs[dynamicPlatformType].PlatformType; //Set Positions and whatnot movPlat.Position = platforms[dynamicPlatformIndex].Position; movPlat.Rotation = platforms[dynamicPlatformIndex].Rotation; movPlat.Scale = platforms[dynamicPlatformIndex].Scale; //Set Scale movPlat.Size = platforms[dynamicPlatformIndex].Size; movPlat.BoxCollider = platforms[dynamicPlatformIndex].BoxCollider; //Left and Right Move Limits movPlat.LeftPos = platforms[dynamicPlatformIndex].Position; movPlat.RightPos = platforms[dynamicPlatformIndex + 1].Position; platforms.RemoveAt(dynamicPlatformIndex + 1); movPlat.EnemyReference = EnemyReference; platforms[dynamicPlatformIndex] = (Platform)movPlat; break; } } } else if (prevContainsDynamic) { prevContainsDynamic = false; } //Return these generated platforms return(platforms.ToArray()); }
public void ActivateFallingPlatform(params object[] parameterContainer) { FallingPlatform fallingPlatform = (FallingPlatform)parameterContainer[0]; fallingPlatform.Activate(); }
public IEnumerator Move(Vector3 target, Action endEvent = null) { //premove AudioManager.instance.PlaySound(walking); target.z = target.y; transform.parent = null; _isMoving = true; //setting tiles if (currentPlate != null) { currentPlate.Release(); currentPlate = null; } if (currenPlatform != null) { currenPlatform.player = null; currenPlatform = null; } if (currenFallingPlatform != null) { currenFallingPlatform.Damage(); currenFallingPlatform = null; } //moving Vector3 start = transform.position; float t = 0; while (transform.position != target) { t += Time.deltaTime; transform.position = Vector3.Lerp(start, target, t * speed); yield return(null); } //promove _isMoving = false; position = new Vector2Int(Mathf.RoundToInt(target.x - 0.5f), Mathf.RoundToInt(target.y - 1f)); animator.Play(Idle); //setting tiles Platform platform = grid.GetPlatform(position); if (platform != null) { transform.parent = platform.transform; currenPlatform = platform; platform.player = this; } FallingPlatform fallingPlatform = grid.GetFallingPlatform(position); if (fallingPlatform != null) { currenFallingPlatform = fallingPlatform; } PressurePlate plate = grid.GetPlate(position); if (plate != null) { currentPlate = plate; currentPlate.Step(); } endEvent?.Invoke(); foreach (Laser laser in grid.lasers) { StartCoroutine(laser.LaserCast()); } }
private void IsOnEdge() { isOnLeftEdge = false; isOnRightEdge = false; bool isOnSolid = base.CollideCheck((int)GameTags.Solid, this.Position + Vector2.UnitY); if (isOnSolid == true) { isOnRightEdge = !base.CollideCheck((int)GameTags.Solid, new Vector2(this.Position.X + this.Width, this.Position.Y + 1)); isOnLeftEdge = !base.CollideCheck((int)GameTags.Solid, new Vector2(this.Position.X - this.Width, this.Position.Y + 1)); } bool isOnOneWay = base.CollideCheck((int)GameTags.Oneway, this.Position + Vector2.UnitY); if (isOnOneWay == true) { isOnRightEdge = !base.CollideCheck((int)GameTags.Oneway, new Vector2(this.Position.X + this.Width, this.Position.Y + 1)); isOnLeftEdge = !base.CollideCheck((int)GameTags.Oneway, new Vector2(this.Position.X - this.Width, this.Position.Y + 1)); } bool isOnFallingPlat = base.CollideCheck((int)GameTags.FallingPlatform, this.Position + Vector2.UnitY); if (isOnFallingPlat == true) { using (List <Entity> .Enumerator enumerator = base.Scene[(int)GameTags.FallingPlatform].GetEnumerator()) { while (enumerator.MoveNext()) { FallingPlatform falling = (FallingPlatform)enumerator.Current; if (this.Right >= falling.Right) { isOnRightEdge = true; } else if (this.Left <= falling.Left) { isOnLeftEdge = true; } } } } bool isOnMovingPlat = base.CollideCheck((int)GameTags.MovingPlatform, this.Position + Vector2.UnitY); if (isOnMovingPlat == true) { using (List <Entity> .Enumerator enumerator = base.Scene[(int)GameTags.MovingPlatform].GetEnumerator()) { while (enumerator.MoveNext()) { MovingPlatform movingPlat = (MovingPlatform)enumerator.Current; if (this.Right >= movingPlat.Right) { isOnRightEdge = true; } else if (this.Left <= movingPlat.Left) { isOnLeftEdge = true; } } } } if (isOnRightEdge == false && isOnLeftEdge == false) { using (List <Entity> .Enumerator enumerator = base.Scene[(int)GameTags.MovingPlatformVert].GetEnumerator()) { while (enumerator.MoveNext()) { MovingPlatformVert one = (MovingPlatformVert)enumerator.Current; if (one.IsPlayerOn == true) { if (this.Right >= one.Right) { isOnRightEdge = true; } else if (this.Left <= one.Left) { isOnLeftEdge = true; } } } } } }
public override void LoadContent() { base.LoadContent(); Tile = new LevelTiler(); levelData = Engine.Instance.Content.Load <LevelData>("TestLevel"); Tile.LoadContent(levelData); collisionInfo = LevelTiler.TileConverison(Tile.CollisionLayer, 2); tiles = new LevelTilesSolid(collisionInfo); this.Add(tiles); stopPointsInfo = LevelTiler.TileConverison(Tile.CollisionLayer, 4); stopPoints = new LevelTilesStopPoints(stopPointsInfo); this.Add(stopPoints); Player = new Player(Tile.PlayerPosition[0]); this.Add(Player); Player.Added(this); onewayInfo = LevelTiler.TileConverison(Tile.CollisionLayer, 3); for (int i = 0; i < onewayInfo.GetLength(0); i++) { for (int j = 0; j < onewayInfo.GetLength(1); j++) { bool tile = onewayInfo[i, j]; if (tile == false) { continue; } Vector2 position = new Vector2(i * TileInformation.TileWidth, j * TileInformation.TileHeight); Oneway platform = new Oneway(position); this.Add(platform); platform.Added(this); } } foreach (Entity entity in Tile.Entites) { if (entity.Type == "Enemy") { BasicEnemy enemy = new BasicEnemy(entity.Position); this.Add(enemy); enemy.Added(this); } if (entity.Type == "FallingPlatform") { FallingPlatform fallingPlatform = new FallingPlatform(entity.Position); this.Add(fallingPlatform); fallingPlatform.Added(this); } if (entity.Type == "MovingPlatform") { MovingPlatform movingPlatform = new MovingPlatform(entity.Position); this.Add(movingPlatform); movingPlatform.Added(this); } if (entity.Type == "MovingPlatformVert") { MovingPlatformVert movingPlatform = new MovingPlatformVert(entity.Position); this.Add(movingPlatform); movingPlatform.Added(this); } } }