public static int getScorePercent(List <Score> scores) { LevelLibrary.loadLevelsOnce(); int percent = 0; int stars = 0; int total = 3 * LevelLibrary.allLevels.Count; foreach (Score scr in scores) { foreach (Level lvl in LevelLibrary.allLevels) { if (scr.levelName == lvl.levelName) { foreach (int threshold in lvl.starThresholds) { if (scr.score >= threshold && scr.score != 0) { stars++; } } } } } if (total != 0) { percent = (int)(stars / (float)total * 100); } return(percent); }
/* Create map * To do: * Create a way to load in maps from outside the function * Random maps * As you can tell, it is currently hardcoded! */ public TileMap(Texture2D mouseMap, LevelLibrary.Level level) { this.mouseMap = mouseMap; // Find Width and height from level file MapWidth = level.Rows; MapHeight = level.Columns; for (int y = 0; y < MapHeight; y++) { MapRow thisRow = new MapRow(); for (int x = 0; x < MapWidth; x++) { thisRow.Columns.Add(new MapCell(0)); } Rows.Add(thisRow); } // Render level by setting the base, height, and topper tile of each tile // to being those defined by the appropriate block in the level object for (int row = 0; row < level.Rows; row++) { for (int column = 0; column < level.Columns; column++) { LevelLibrary.Block block = level.GetBlock(row, column, 0); Rows[row].Columns[column].AddBaseTile(block.BaseTile); Rows[row].Columns[column].AddHeightTile(block.HeightTile); Rows[row].Columns[column].AddTopperTile(block.TopperTile); } } }
public void Update(LevelLibrary.Directions direction) { // Update the positions of the background for (int i = 0; i < positions.Length; i++) { #if MODULE_DEBUG Console.Write("Position[" + i + "].X = " + positions[i].X); Console.WriteLine(); #endif // Update the position of the screen by adding the speed if (direction == LevelLibrary.Directions.left) { positions[i].X -= speed; // Check the texture is out of view then put that texture at the end of the screen if (positions[i].X <= -texture.Width) { positions[i].X = texture.Width * (positions.Length - 1); } } else if (direction == LevelLibrary.Directions.right) { positions[i].X += speed; // Check if the texture is out of view then position it to the start of the screen if (positions[i].X >= texture.Width * (positions.Length - 1)) { positions[i].X = -texture.Width; } } } }
public void adoptSave(PlayerAccount newSave) { save = newSave; Text[] items = GetComponentsInChildren <Text> (); foreach (Text item in items) { if (item.gameObject.name == "SaveName") { item.text = save.accountInfo.username; } if (item.gameObject.name == "CampaignPercent") { item.text = LevelLibrary.getScorePercent(save.accountInfo.scores.highScores) + "%"; } } }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Initialise method // animation - texture atlas of all the animation frames ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public void Initialize(LevelLibrary.SpriteAnimator animation, Vector2 startPosition, int xSize, int ySize) { PlayerAnimation = animation; // Set the starting position of the player around the middle of the screen and to the back position = startPosition; direction = LevelLibrary.Directions.none; currentSpeed = 1f; gravity = new LevelLibrary.Gravity(); gravity.windowHeight = ySize; gravity.objectHeight = PlayerAnimation.FrameHeight; // Set the player health Health = 100; Lives = 3; // Can I hover hoverAbility = false; PlayerAnimation.Active = true; PlayerAnimation.Position = Position; }
public void ConStruct() { LevelLibrary = Resources.Load <LevelLibrary>("Libraries/LevelLibrary"); }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Handles ; // - collisions with platforms // - applying gravity to the player // - resetting the player position if needed. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// private void UpdatePlayerGravityAndPlatforms(GameTime gameTime, LevelLibrary.LevelRenderer levelRenderer) { bool clashing; gravity.Apply(ref position, gameTime, isOnGround); // Update the level positions and enemies levelRenderer.Update(gameTime, ref position, this.Width, this.Height, this); // Check for clashes clashing = levelRenderer.HandleClash(ref position, Width, Height, ref isOnGround); // If we clash with the square below and we're falling STOP if (clashing) { if (gravity.direction == LevelLibrary.Directions.down) { gravity.direction = LevelLibrary.Directions.none; } else if (gravity.direction == LevelLibrary.Directions.up) { gravity.SetVelocity(1, LevelLibrary.Directions.down); } } // If we have landed back on earth, we can jump again. if (isOnGround || hoverAbility == true) { jumping = false; } }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Update the position, animation frame etc ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public void Update(LevelLibrary.LevelRenderer levelRenderer, GameTime gameTime, bool jumpKey, bool leftKey, bool rightKey) { UpdatePlayerSpeedAndDirection(jumpKey, leftKey, rightKey); UpdateAnimationMovementState(); UpdatePlayerGravityAndPlatforms(gameTime, levelRenderer); UpdatePlayerAnimation(gameTime); }
public void Update(GameTime gameTime, LevelLibrary.LevelRenderer levelRenderer ) { // Store our old position in case we need to reset // because we're clashing with something oldPosition = position; // Different guys have different movement patterns //direction.X = 1f; switch (EnemyMode) { case enemyMode.LeftRight: ModeLeftRight(levelRenderer); break; case enemyMode.UpDown: ModeLeftRight(levelRenderer); break; case enemyMode.Chase: ModeChase(levelRenderer); break; } // Update the sprite animators position enemyAnimation.Position = position; enemyAnimation.Update(gameTime); }
public void SetVelocity(float v, LevelLibrary.Directions dir) { vi = v; direction = dir; }
private void ModeUpDown(LevelLibrary.LevelRenderer levelRenderer) { bool clash = false; bool isOnGround = false; position += direction; clash = levelRenderer.HandleClash(ref position, enemyAnimation.FrameWidth, enemyAnimation.FrameHeight, ref isOnGround); // Clash on left ? // Clash on right ? if ((clash) || (position.Y <= 0) || (position.Y >= screenLimits.Y)) { //position = oldPosition; // Reverse the direction by multiplying by -1 // e.g. 1 * -1 = -1 // and -1 * -1 = 1 // Nice huh? direction.Y = direction.Y * -1.0f; if (enemyAnimation.direction == Directions.up) { enemyAnimation.direction = Directions.down; } else { enemyAnimation.direction = Directions.up; } } }
private void ModeLeftRight(LevelLibrary.LevelRenderer levelRenderer) { //LevelLibrary.LevelRenderer.Sides clashingWith; bool clash = false; bool isOnGround = false; position += direction; clash = levelRenderer.HandleClash(ref position, enemyAnimation.FrameWidth, enemyAnimation.FrameHeight, ref isOnGround); // Clash on left ? // Clash on right ? if ((clash) || (position.X <= 0) || (position.X >= screenLimits.X)) { //position = oldPosition; // Reverse the direction by multiplying by -1 // e.g. 1 * -1 = -1 // and -1 * -1 = 1 // Nice huh? direction.X = direction.X * -1.0f; if (enemyAnimation.direction == Directions.right) { enemyAnimation.direction = Directions.left; } else { enemyAnimation.direction = Directions.right; } } }
private void ModeChase(LevelLibrary.LevelRenderer levelRenderer) { bool clash = false; bool isOnGround = false; if (playerPosition.X < position.X) { direction.X = -1f; } else { direction.X = 1f; } position += direction; clash = levelRenderer.HandleClash(ref position, enemyAnimation.FrameWidth, enemyAnimation.FrameHeight, ref isOnGround); // Clash on left ? // Clash on right ? if ((clash) || (position.X <= 0) || (position.X >= screenLimits.X)) { direction.Y = 0f; } }
private void Start() { instance = instance ?? this; }
public void LoadLevel(LevelLibrary.Level level) { collectedCount = 0; rows = level.Rows; cols = level.Columns; tiles = new Tile[rows, cols]; int jewelcount = 0; for (int r = 0; r < rows; r++) { for (int c = 0; c < cols; c++) { int symbol = level.GetValue(r, c); switch (symbol) { case 0: tiles[r, c] = new Tile(0); tiles[r, c].Position = new Vector2(r * tileHeight, c * tileWidth); break; case 1: tiles[r, c] = new Tile(1); tiles[r, c].Position = new Vector2(r * tileHeight, c * tileWidth); break; case 2: tiles[r, c] = new Tile(2); tiles[r, c].Position = new Vector2(r * tileHeight, c * tileWidth); break; case 3: tiles[r, c] = new Tile(3); tiles[r, c].Position = new Vector2(r * tileHeight, c * tileWidth); break; case 4: tiles[r, c] = new Tile(4); tiles[r, c].Position = new Vector2(r * tileHeight, c * tileWidth); break; case 5: //Spawnpoint spawn = new Vector2(r, c); tiles[r, c] = new Tile(7); tiles[r, c].Position = new Vector2(r * tileHeight, c * tileWidth); spawnRow = r; spawnCol = c; spawn = new Vector2(r * tileHeight, c * tileWidth); camera.Position=getCameraCenter(); currentPlayer.Position=spawn; currentPlayer.setPosition(r,c); break; case 6: //Jewel jewels[jewelcount].Position = new Vector2(r * tileHeight, c * tileWidth); jewels[jewelcount].setCol(c); jewels[jewelcount].setRow(r); tiles[r, c] = new Tile(7); tiles[r, c].Position = new Vector2(r * tileHeight, c * tileWidth); jewelcount++; break; case 7: //Bird birds.Add(new Bird(TextureRefs.bird,new Vector2(r * tileHeight, c * tileWidth),c,r)); tiles[r, c] = new Tile(7); tiles[r, c].Position = new Vector2(r * tileHeight, c * tileWidth); break; case 8: break; case 9: break; } /*char cType = symbol[0]; if (cType != '-') { LoadCritter(cType, Convert.ToInt32(symbol[1].ToString()), r, c); }*/ } } }
private void Awake() { instance = instance ?? this; }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> public void Update(GameTime gameTime, LevelLibrary.GameObject player) { health = player.Health; lives = player.Lives; }