1.1.2 Super Mario Advance 4: Super Mario Bros.1.1.1 Super Mario World / Super Mario World: Super Mario Advance 2.Snake Blocks most likely get their name from the classic arcade game Snake, in which the player controls a sequence of dots that resembles the snake animal. Mario must continue to move and follow it when on these blocks, otherwise they keep moving under Mario's feet, and he may possibly fall off. Snake Blocks can turn left, right, up, or down as they follow a predetermined course over obstacles such as a wide pool of lava, a bed of spikes, or a bottomless pit. They consist of a set of blocks that start out as a normal platform and begin to move like a snake when stepped on by Mario or Luigi. They first appear in Super Mario World, and reappear in Super Mario Advance 4: Super Mario Bros. Snake Blocks, originally named snake platforms and also named Caterpillar Blocks or simply Platforms, are blocks usually found in castle-type levels. “We're working on new and novel ways to use Snake Blocks at our new Snake Block testing facility! Just jump onto a Snake Block and it'll start moving.” - Snake Block Enthusiast, Super Mario Maker 2 Moves in straight lines, helping the player traverse otherwise impossible-to-reach areas. If (other.tag = "Wall" || (other.tag = "SnakePart" & invulnerabilityTime <= Time.Not to be confused with Platform. If (other.tag = "SnakePart" & invulnerabilityTime <= Time.time)Ĭould be written with a single if statement: private void OnTriggerEnter2D(Collider2D other) Private void SetDirection(Direction direction) If (snake.Count = 1 || moveDirection != d.Opposite) If (keycodeToDirection.TryGetValue(ke圜ode, out d) Private Direction GetDirectionForKe圜ode(Ke圜ode ke圜ode) Var direction = GetDirectionForKe圜ode(Input.GetKeyDown) edit: Just realised this wouldn't compile due to not being able to set the property values here, but that's not the point of the example. GameObject food = ObjectPoolers.GetPooledObject() If (Snake.GetComponent().IsMoving & Time.time >= nextSpawn) SnakeSize = Snake.GetComponent().bounds.size īackground = GameObject.Find("Background") Private static readonly System.Random rnd = new System.Random() This class is attached to a GameObject which also have some image on it and by changing those 2 values a new food type is created.Īnd of course the FoodSpawner class which creates the food during the game public class FoodSpawner : MonoBehaviour The invulnerability is being set to 200ms (probably can down that a bit) whenever a food is eaten to prevent this effect. It helps preventing the snake from crashing in itself when a food is eaten, there is a possibility that the blocks will spawn in front of the snake depending on the direction it's moving, even tho as a user you wont be able to notice that since it's a matter of milliseconds the program will "see" it and will cause invalid collision. ScoreText.text = : " + (snake.Count - 1)/5 Īn interesting field here is private float invulnerabilityTime. SnakePart.GetComponent().sortingOrder = orderInLayer If (other.tag = "SnakePart" & invulnerabilityTime ().sortingOrder - 1 Private void OnTriggerEnter2D(Collider2D other) New Vector3((moveSize.x*moveDirection.x)*Speed, (moveSize.y*moveDirection.y)*Speed) Transform.position = transform.position + If (snake.Count = 1 || moveDirection != oppositeDirection)įor (int i = snake.Count - 1 i > 0 i-) Private void SetDirection(Vector3 direction, Vector3 oppositeDirection, params Ke圜ode triggers) SetDirection(Vector3.down, Vector3.up, Ke圜ode.DownArrow, Ke圜ode.S) SetDirection(Vector3.up, Vector3.down, Ke圜ode.UpArrow, Ke圜ode.W) SetDirection(Vector3.right, Vector3.left, Ke圜ode.RightArrow, Ke圜ode.D) SetDirection(Vector3.left, Vector3.right, Ke圜ode.LeftArrow, Ke圜ode.A) Private readonly List snake = new List() Public ObjectPooler snakePartsObjectPooler The snake is controlled by the SnakeHead script public class SnakeHead : MonoBehaviour As you can see the snake has a highlighted head (the light green block) and it consists of quite a lot smaller blocks and there are those outlines on the body of the snake they are created on each 10 blocks you get This is a screenshot from the game here I'm colliding with myself and the game is restarted after that. I've made a simple snake game in Unity and it has 3 different types of foods.
0 Comments
Leave a Reply. |