void Start() { System.Random prng = new System.Random(); MeshRenderer mesh_Renderer = GetComponent <MeshRenderer>(); MeshFilter mesh_Filter = GetComponent <MeshFilter>(); map = new Map(52, 52); level = map.generateLevel(prng.Next()); mesh_Filter.mesh = level.mesh; transform.position = map.position; float scale = 2; int octaves = 6; float persistance = 0.6f; float lacunarity = 3.41f; var mapData = map.generateObjects(prng.Next(), new Map.Range[0], scale, octaves, persistance, lacunarity); for (int y = 0; y < mapData.YN; ++y) { for (int x = 0; x < mapData.XN; ++x) { var section = (int)level.data.grid[x, y]; var obstaclesLength = sections[section].obstacles.Length; var obstacles = sections[section].obstacles; int obstacleIndex = Random.Range(0, obstaclesLength); var obstacle = obstacles[obstacleIndex]; if (mapData.grid[x, y] == 1) { var collider = obstacle.GetComponent <BoxCollider2D>(); var offset = new Vector3(collider.offset.x, collider.offset.y - collider.size.y, 0); var pos = new Vector3(x + 0.5f, y + 0.5f, 0) + map.position - offset; var obj = Instantiate(obstacle, pos, Quaternion.identity); var renderer = obj.GetComponentInChildren <SpriteRenderer>(); renderer.sortingOrder = Mathf.RoundToInt(5200 - ((obj.transform.position.y + offset.y) * 100)); } } } StartCoroutine("spawnBoosters"); }
public void RestartGame() { projectiles.Clear(); entities.Clear(); gameObjects.Clear(); clouds.Clear(); bool checkpoint = level.CheckpointReached; Vector2 spawnPos = level.PlayerSpawn; level = new Map.Level(); level.CheckpointReached = checkpoint; level.PlayerSpawn = spawnPos; Entities.Player player = new Entities.Player(level.PlayerSpawn, 1); player.LoadContent(ScreenManager.Content); player.Health.Add(1); AddEntity(player); }
public override void LoadContent(ContentManager Content) { Graphics.Textures.LoadContent(Content); base.LoadContent(Content); Engine.Paused = false; APEngine.SoundManager.SoundManager.LoadContent(Content); SoundManager = new APEngine.SoundManager.SoundManager(); SoundManager.Volume = GameSettings.SFXVol; GossipManager = new Entities.Gossip.GossipManager(); EditorMode = false; paused = Content.Load<Texture2D>("Data\\GFX\\Paused"); Congrats = Content.Load<Texture2D>("Data\\GFX\\Congratz"); lifeCounter = Content.Load<Texture2D>("Data\\GFX\\LivesIcon"); ammoCounter = Content.Load<Texture2D>("Data\\GFX\\AmmoIcon"); starPowerCounter = Content.Load<Texture2D>("Data\\GFX\\StarPowerBar"); level = new Map.Level(); level.CheckpointReached = false; EditUI = new Map.Editor.EditorUI(UIScale); EditUI.LoadContent(Content); lifeCountTimer = new UITimer(6000f); ammoTimer = new UITimer(6000f); starPowerTimer = new UITimer(6000f); uiBackgroundTimer = new UITimer(6500f); uiBackgroundPos = new Vector2(0, 0); projectiles = new List<Entities.Projectile>(); entities = new List<Entities.Entity>(); gameObjects = new List<GameObjects.GameObject>(); mapGameObjects = new List<GameObjects.GameObject>(); waterObjects = new List<GameObjects.Water>(); clouds = new List<Map.Cloud>(); powerUpsWindow = new UI.InfoBox(new Rectangle((int)(Engine.Monitor.VirtualWidth / 2) - 200, (int)(Engine.Monitor.VirtualHeight / 2) - 100, 400, 200)); powerUpsWindow.LoadContent(Content); powerUpsWindow.Visible = false; projectiles.Clear(); entities.Clear(); gameObjects.Clear(); backgroundFront = Content.Load<Texture2D>("Data\\GFX\\Forest\\backgroundFront"); backgroundSky = Content.Load<Texture2D>("Data\\GFX\\Forest\\backgroundSkyNight"); uiBackgroundTexture = Content.Load<Texture2D>("Data\\GFX\\UIBackground"); FillClouds(10, Map.CloudType.Dark); Entities.Player player = new Entities.Player(level.PlayerSpawn, 1); player.Ability.HasDoubleJump = true; AddEntity(player); camera.LevelHeight = level.Height * Map.Tile.HEIGHT; camera.LevelWidth = level.Width * Map.Tile.WIDTH; healthText = Content.Load<Texture2D>("Data\\GFX\\healthText"); healthBar = Content.Load<Texture2D>("Data\\GFX\\healthBar"); textBox = new UI.GameFont(new Rectangle(100, Engine.Monitor.Height - 20, 800, 20), 800f); textBox.LoadContent(Content); textBox.Text = "Twitch: www.twitch.tv/corpseloleu | Twitter: @corpsegrindr"; lifePos = new Vector2(10, 10); ammoPos = new Vector2(10, 15 + lifeCounter.Height * UIScale); starPowerPos = new Vector2(Engine.Monitor.VirtualWidth - 80 * UIScale, 12); lives = new UI.GameFont(new Rectangle((int)(lifePos.X + lifeCounter.Width * UIScale), (int)(lifePos.Y + 12 * UIScale), 200, 18), 200); lives.LoadContent(Content); lives.Text = player.Lives.ToString(); ammo = new UI.GameFont(new Rectangle((int)(ammoPos.X + ammoCounter.Width * UIScale), (int)(ammoPos.Y + 8 * UIScale), 200, 18), 200); ammo.LoadContent(Content); ammo.Text = player.Clip.ToString(); starPowerFont = new UI.GameFont(new Rectangle((int)(starPowerPos.X + starPowerCounter.Width * UIScale), (int)(starPowerPos.Y + 10 * UIScale), 100, 18), 100); starPowerFont.LoadContent(Content); starPowerFont.Text = player.Lives.ToString(); AddGameObject(new GameObjects.DoubleJump(new Vector2(level.PlayerSpawn.X + 32 * 25, level.PlayerSpawn.Y + 16 - (32 * 5)))); //level.CreateNewLevel(Map.Theme.JungleForest, 40, 40, "Empty Level"); level.LoadMap("Empty Level"); }