public void ShowHorsemanDock(Horseman context, GamePlayer player) { if (_currentDock != null) _currentDock.Hide(); _horsemanDock.UpdateContext(context, player); _currentDock = _horsemanDock; _currentDock.Show(); }
public void ShowCampDock(TrainingCamp context, GamePlayer player) { if (_currentDock != null) _currentDock.Hide(); _campDock.UpdateContext(context, player); _currentDock = _campDock; _currentDock.Show(); }
public GameWorld(ControlManager controlManagerRef) { ControlManagerRef = controlManagerRef; Map = new TileMap(200, 400); MainPlayer = new GamePlayer(this); MainPlayer.Name = "Osama Abulail"; int cloudsCount = (Map.MapWidth*Map.MapHeight)/(20*20); CloudManager = new CloudManager(Map, cloudsCount, CloudDirection.West, 0.5f); MovementManager = new UnitMovementManager(this); SelectionManager = new UnitSelectionManager(this); DockManager = new DockManager(ControlManagerRef); UpperStatusBar = new UpperStatusBar(new Vector2(10, 0), MainPlayer, ControlManagerRef); _trees = new List<Tree>(); // generate random trees. Random r = new Random(); for (int i = 0; i < 4000; i++) { Point treeLoc = new Point(r.Next(0,Map.MapWidth), r.Next(0,Map.MapHeight)); if (Map.MapCellAt(treeLoc).Walkable) { Tree t = new Tree("tree" + r.Next(1, 26), this, treeLoc); _trees.Add(t); } } // border _border = new PictureBox(GameGraphics.GetTexture("gameplay_border").SourceTexture, new Rectangle(0, 0, 1366, 768)); ControlManagerRef.Add(_border); }
public UpperStatusBar(Vector2 Position,GamePlayer context, ControlManager controlManager) { this.ControlManager = controlManager; this.Context = context; this.OriginPosition = Position; #region setting labels resources = new Label(); resources.SpriteFont = GameFonts.GetFont("f5"); resources.Color = LabelColor; resources.SetPosition(GetAbsolutePosition(90,3)); resources.Text = "Resources: "+Context.Resources; ControlManager.Add(resources); score = new Label(); score.SpriteFont = GameFonts.GetFont("f5"); score.Color = LabelColor; score.SetPosition(GetAbsolutePosition(90+160, 3)); score.Text = "Score: " + Context.Score; ControlManager.Add(score); elapsedTime = new Label(); elapsedTime.SpriteFont = GameFonts.GetFont("f5"); elapsedTime.Color = LabelColor; elapsedTime.SetPosition(GetAbsolutePosition(90+160+160, 3)); elapsedTime.Text = "Population: "+Context.Population; ControlManager.Add(elapsedTime); #endregion }
public void ShowFarmerDock(Farmer context, GamePlayer player) { if (_currentDock != null) _currentDock.Hide(); _farmerDock.UpdateContext(context, player); _currentDock = _farmerDock; _currentDock.Show(); }
public Farm(string identifier, GameWorld gameWorldRef, GamePlayer playerRef, Point location) : base(identifier, gameWorldRef, playerRef, location) { SelectionLineTexture = GameGraphics.GetTexture("farm_selection_line"); SelectionGroup = GroupMapper.FarmGroup; MaxFood = 300; Food = MaxFood; }
public ResidentialHouse(GameWorld gameWorldRef, GamePlayer playerRef, Point Location) : base("building1", gameWorldRef, playerRef, Location) { // filling the occupied_cells_locations List // (the purpose is to make these cells not walkable) #region Occupied Cells Work int cells_east = 3, cells_west = 5; Point west_indexer = Location; Point east_indexer = Location; for (int i = 0; i < cells_west; i++) { for (int j = 0; j < cells_east; j++) { OccupiedCellsLocations.Add(east_indexer); east_indexer = east_indexer.WalkTo(Direction.NE); } west_indexer = west_indexer.WalkTo(Direction.NW); east_indexer = west_indexer; } // now set the Mapcells at locations found to be not walkable.. foreach (var location in OccupiedCellsLocations) { MapRef.MapCellAt(location).Walkable = false; } #endregion // making smoke on the roof #region smoke smoke = new SpriteAnimation(GameGraphics.GetTexture("smoke").SourceTexture); smoke.AddAnimation("normal", 0, 0, 30, 64, 16, 0.15f); smoke.Position = Camera.WorldToScreen(new Vector2(this.BuildingOrigin.X + 65, this.BuildingOrigin.Y - 64 + 35)); smoke.CurrentAnimation = "normal"; smoke.DrawDepth = BuildingInfo.SmokeDrawDepth; smoke.IsAnimating = true; #endregion selectionGroup = GroupMapper.HouseGroup; SelectionLineTexture = GameGraphics.GetTexture("residence_selection_line"); #region Setting Entity Properties MaxHealth = 500; MaxDefense = 100; MaxAttack = 0; Health = MaxHealth; Defense = MaxDefense; Attack = MaxAttack; #endregion }
public CarryToHouseAction(Farmer farmer, GamePlayer player) { _farmer = farmer; _player = player; foreach (var building in player.Buildings) { if (building is ResidentialHouse) { _storageHouse = building as ResidentialHouse; break; } } }
public Farmer(GameWorld gameWorldRef, GamePlayer playerRef, Vector2 position) : base("farmer_ss", 48, 48, 8, gameWorldRef, playerRef, position, AnimationSpeed) { CharSelect = GameGraphics.GetTexture("char_select"); Speed = WalkingSpeed; SelectionGroup = GroupMapper.FarmerGroup; Animation.DrawOffset = new Vector2(-24, -38); Animation.AddAnimation("seeding", 0, 8 * 48, 48, 48, 72, 0.1f); Animation.AddAnimation("spreading", 0, 9 * 48, 48, 48, 64, 0.1f); SelectBounds = new Rectangle((int)position.X - -16, (int)position.Y - 40, 50, 50); _capacityStatusLine = new StatusLine(StatusLineType.Yellow); _capacityStatusLineOffset = new Vector2(-13, -45); #region Setting Entity Properties MaxHealth = 50; MaxDefense = 5; MaxAttack = 3; Health = MaxHealth; Defense = MaxDefense; Attack = MaxAttack; #endregion #region Adding Possible Actions IAction action = new GoToFarmAction(this, playerRef); Actions.Add(action); IAction action2 = new SeedAction(this, playerRef); Actions.Add(action2); IAction action3 = new SpreadAction(this, playerRef); Actions.Add(action3); IAction action4 = new GatherAction(this, playerRef); Actions.Add(action4); IAction action5 = new CarryToHouseAction(this, playerRef); Actions.Add(action5); IAction action6 = new ReturnFromBuildingToFarmAction(this, playerRef); Actions.Add(action6); #endregion }
public FarmBase(string identifier, GameWorld gameWorldRef, GamePlayer playerRef, Point location) { Texture = GameGraphics.GetTexture(identifier); Location = location; _gameWorldRef = gameWorldRef; PlayerRef = playerRef; MapRef = _gameWorldRef.Map; _drawDepth = 1.0f - TileEngineInfo.HeightRowDepthMod; _rowOffset = (MapRef.MapCellAt(location).OnOddRow) ? TileInfo.OddRowXOffset : 0; FarmOrigin = new Vector2((Location.X * TileInfo.TileStepX) + _rowOffset + Texture.AlignmentOffset.X, Location.Y * TileInfo.TileStepY - Texture.AlignmentOffset.Y); }
protected CreatureBase(string animationIdentifier, int frameWidth, int frameHeight, int frames, GameWorld gameWorldRef, GamePlayer playerRef, Vector2 position, float animationSpeed) { PlayerRef = playerRef; GameWorldRef = gameWorldRef; _mapRef = gameWorldRef.Map ; // walking animation is unified in all creatures #region setting appropriate walking animation AnimationSet = GameGraphics.GetTexture(animationIdentifier); Animation = new SpriteAnimation(AnimationSet.SourceTexture); Animation.AddAnimation("Walk_E", 0, frameHeight * 0, frameWidth, frameHeight, frames, animationSpeed); Animation.AddAnimation("Walk_N", 0, frameHeight * 1, frameWidth, frameHeight, frames, animationSpeed); Animation.AddAnimation("Walk_NE", 0, frameHeight * 2, frameWidth, frameHeight, frames, animationSpeed); Animation.AddAnimation("Walk_NW", 0, frameHeight * 3, frameWidth, frameHeight, frames, animationSpeed); Animation.AddAnimation("Walk_S", 0, frameHeight * 4, frameWidth, frameHeight, frames, animationSpeed); Animation.AddAnimation("Walk_SE", 0, frameHeight * 5, frameWidth, frameHeight, frames, animationSpeed); Animation.AddAnimation("Walk_SW", 0, frameHeight * 6, frameWidth, frameHeight, frames, animationSpeed); Animation.AddAnimation("Walk_W", 0, frameHeight * 7, frameWidth, frameHeight, frames, animationSpeed); Animation.AddAnimation("Idle_E", 3 * frameWidth, frameHeight * 0, frameWidth, frameHeight, 1, 0.2f); Animation.AddAnimation("Idle_N", 3 * frameWidth, frameHeight * 1, frameWidth, frameHeight, 1, 0.2f); Animation.AddAnimation("Idle_NE", 3 * frameWidth, frameHeight * 2, frameWidth, frameHeight, 1, 0.2f); Animation.AddAnimation("Idle_NW", 3 * frameWidth, frameHeight * 3, frameWidth, frameHeight, 1, 0.2f); Animation.AddAnimation("Idle_S", 3 * frameWidth, frameHeight * 4, frameWidth, frameHeight, 1, 0.2f); Animation.AddAnimation("Idle_SE", 3 * frameWidth, frameHeight * 5, frameWidth, frameHeight, 1, 0.2f); Animation.AddAnimation("Idle_SW", 3 * frameWidth, frameHeight * 6, frameWidth, frameHeight, 1, 0.2f); Animation.AddAnimation("Idle_W", 3 * frameWidth, frameHeight * 7, frameWidth, frameHeight, 1, 0.2f); CurrentAnimation = "Idle_SE"; Animation.IsAnimating = true; #endregion Position = position; _currentMoveDir = Vector2.Zero; _previousMovDir = Vector2.Zero; Distination = position; HealthStatusLine = new StatusLine(StatusLineType.Green); _healthStatusLineOffset = new Vector2(-13, -50); Actions = new ActionManager(); }
public Horseman(GameWorld gameWorldRef, GamePlayer playerRef, Vector2 position) : base("horseman_ss", 86, 86, 12, gameWorldRef, playerRef, position, AnimationSpeed) { CharSelect = GameGraphics.GetTexture("horseman_select"); Speed = WalkingSpeed; SelectionGroup = GroupMapper.HorsemanGroup; Animation.DrawOffset = new Vector2(-45, -60); SelectBounds = new Rectangle((int)position.X - -16, (int)position.Y - 40, 50, 50); #region Setting Entity Properties MaxHealth = 90; MaxDefense = 30; MaxAttack = 6; Health = MaxHealth; Defense = MaxDefense; Attack = MaxAttack; #endregion }
public Swordsman(GameWorld gameWorldRef, GamePlayer playerRef, Vector2 position) : base("swordsman_ss", 48, 48, 8, gameWorldRef, playerRef, position, AnimationSpeed) { CharSelect = GameGraphics.GetTexture("char_select"); Speed = WalkingSpeed; SelectionGroup = GroupMapper.SwordsmanGroup; Animation.DrawOffset = new Vector2(-24, -38); #region More Animation #endregion SelectBounds = new Rectangle((int)position.X - 16, (int)position.Y - 32, 48 - 16, 48 - 16); #region Setting Entity Properties MaxHealth = 120; MaxDefense = 70; MaxAttack = 17; Health = 70; Defense = MaxDefense; Attack = MaxAttack; #endregion }
/// <summary> /// updates the data source and command operator /// </summary> /// <param name="context"></param> /// <param name="player"></param> public virtual void UpdateContext(ResidentialHouse context, GamePlayer player) { Context = context; Player = player; UpdateDisplayText(); }
/// <summary> /// updates the data source and command operator /// </summary> /// <param name="context"></param> /// <param name="player"></param> public virtual void UpdateContext(Stable context, GamePlayer player) { Context = context; Player = player; UpdateDisplayText(); }
public void ShowHouseDock(ResidentialHouse context, GamePlayer player) { if (_currentDock != null) _currentDock.Hide(); _houseDock.UpdateContext(context, player); _currentDock = _houseDock; _currentDock.Show(); }
/// <summary> /// updates the data source and command operator /// </summary> /// <param name="context"></param> /// <param name="player"></param> public virtual void UpdateContext(TrainingCamp context, GamePlayer player) { Context = context; Player = player; UpdateDisplayText(); }
protected BuildingBase(string identifier, GameWorld gameWorldRef, GamePlayer playerRef, Point location) { Texture = GameGraphics.GetTexture(identifier); Location = location; GameWorldRef = gameWorldRef; MapRef = gameWorldRef.Map; PlayerRef = playerRef; var rowOffset = (MapRef.MapCellAt(location).OnOddRow) ? TileInfo.OddRowXOffset : 0; BuildingOrigin = new Vector2((location.X * TileInfo.TileStepX) + rowOffset + Texture.AlignmentOffset.X, location.Y * TileInfo.TileStepY - Texture.AlignmentOffset.Y); #region Build Segments of the texture.. var imgSegmentsF = new List<Rectangle>(); var imgSegmentsB = new List<Rectangle>(); var segWidth = TileInfo.TileWidth / 2; // seg_width = 32 var doubleDivision = (Texture.SourceRectangle.Width / 2.0) / segWidth; var intDivision = (double)((int)doubleDivision); // check if image width not devided by half of tile width (32) const double epsilon = 0.01f; var isOverloaded = (!(Math.Abs(doubleDivision - intDivision) < epsilon)); int height = Texture.SourceRectangle.Height; int mid = Texture.SourceRectangle.Width / 2; int forwardIndexer = mid; int backwardIndexer = mid - segWidth; for (int i = 0; i < intDivision; i++) { var rectForward = new Rectangle(forwardIndexer, Texture.SourceRectangle.Y, segWidth, height); var rectBackward = new Rectangle(backwardIndexer, Texture.SourceRectangle.Y, segWidth, height); imgSegmentsB.Add(rectBackward); imgSegmentsF.Add(rectForward); forwardIndexer += segWidth; backwardIndexer -= segWidth; } // next, using latest value of forward_indexer if (isOverloaded) { var leftSegWidth = mid - (int)intDivision * segWidth; var lastRectRight = new Rectangle(/**/forwardIndexer/**/, Texture.SourceRectangle.Y, leftSegWidth, height); var lastRectLeft = new Rectangle(Texture.SourceRectangle.X, Texture.SourceRectangle.Y, leftSegWidth, height); imgSegmentsB.Add(lastRectLeft); imgSegmentsF.Add(lastRectRight); } // setting depths of segments.. var indexer = location; _imgSegmentsDepths = new List<SegDepth>(); // first forward and backward segments have same depth as cell at this building's Location var depth = MapRef.MapCellAt(location).DrawDepth; _imgSegmentsDepths.Add(new SegDepth(imgSegmentsF[0], depth)); _imgSegmentsDepths.Add(new SegDepth(imgSegmentsB[0], depth)); // moving to the tiles on the right.. for (var i = 1; i < imgSegmentsF.Count; i++) { indexer = indexer.WalkTo(Direction.NE); depth = MapRef.MapCellAt(indexer).DrawDepth; _imgSegmentsDepths.Add(new SegDepth(imgSegmentsF[i], depth)); } //resetting indexer = location; // moving to the tiles on the left.. for (int i = 1; i < imgSegmentsB.Count; i++) { indexer = indexer.WalkTo(Direction.NW); depth = MapRef.MapCellAt(indexer).DrawDepth; _imgSegmentsDepths.Add(new SegDepth(imgSegmentsB[i], depth)); } // constructing an ordered version of the img_segments_depths list.. ImgSegmentsDepthsOrdered = new List<SegDepth>(); for (int i = _imgSegmentsDepths.Count - 1; i >= _imgSegmentsDepths.Count - (imgSegmentsB.Count - 1); i--) { ImgSegmentsDepthsOrdered.Add(_imgSegmentsDepths[i]); } ImgSegmentsDepthsOrdered.Add(_imgSegmentsDepths[1]); ImgSegmentsDepthsOrdered.Add(_imgSegmentsDepths[0]); for (int i = 2; i < (imgSegmentsF.Count - 1) + 2; i++) { ImgSegmentsDepthsOrdered.Add(_imgSegmentsDepths[i]); } /// /// now, img_segments_depths_ordered is constructed properly /// so that it can be used to access and / or modify the segments of /// the building in the child classes of this class /// #endregion #region Generating Built Units Locations and idle animations BuiltUnitsLocations = new List<Vector2>(); var cells = new List<Point>(); var index = Location; index = index.WalkTo(Direction.S).WalkTo(Direction.NE) .WalkTo(Direction.NE).WalkTo(Direction.NE); cells.Add(index); index = index.WalkTo(Direction.SW); cells.Add(index); index = index.WalkTo(Direction.SW); cells.Add(index); index = index.WalkTo(Direction.SW); cells.Add(index); index = index.WalkTo(Direction.NW); cells.Add(index); index = index.WalkTo(Direction.NW); cells.Add(index); index = index.WalkTo(Direction.NW); cells.Add(index); _builtUnitIndex = 0; foreach (var point in cells) { BuiltUnitsLocations.Add(MapRef.MapCellAt(point).CenterPosition); } // setting initial idle animations to look away from building InitialIdleAnimation = new List<string>(); InitialIdleAnimation.Add("Idle_SE"); InitialIdleAnimation.Add("Idle_SE"); InitialIdleAnimation.Add("Idle_SE"); InitialIdleAnimation.Add("Idle_S"); InitialIdleAnimation.Add("Idle_SW"); InitialIdleAnimation.Add("Idle_SW"); InitialIdleAnimation.Add("Idle_S"); InitialIdleAnimation.Add("Idle_SW"); InitialIdleAnimation.Add("Idle_SW"); #endregion }
public void ShowStableDock(Stable context, GamePlayer player) { if (_currentDock != null) _currentDock.Hide(); _stableDock.UpdateContext(context, player); _currentDock = _stableDock; _currentDock.Show(); }
public SeedAction(Farmer farmer, GamePlayer player) { _farmer = farmer; _player = player; }
public void ShowKnightDock(Knight context, GamePlayer player) { if (_currentDock != null) _currentDock.Hide(); _knightDock.UpdateContext(context, player); _currentDock = _knightDock; _currentDock.Show(); }
public GoToFarmAction(Farmer farmer, GamePlayer player) { _farmer = farmer; _player = player; }
public GatherAction(Farmer farmer, GamePlayer player) { _farmer = farmer; _player = player; }
public TrainingCamp(GameWorld gameWorldRef, GamePlayer playerRef, Point Location) : base("building6", gameWorldRef, playerRef, Location) { // filling the occupied_cells_locations List // (the purpose is to make these cells not walkable) #region Occupied Cells Work const int cellsEast = 3; const int cellsWest = 4; Point westIndexer = Location; Point eastIndexer = Location; for (int i = 0; i < cellsWest; i++) { for (int j = 0; j < cellsEast; j++) { OccupiedCellsLocations.Add(eastIndexer); eastIndexer = eastIndexer.WalkTo(Direction.NE); } westIndexer = westIndexer.WalkTo(Direction.NW); eastIndexer = westIndexer; } // add the irregular occupied cells.. Point indexer = Location; indexer = indexer.WalkTo(Direction.SW); indexer = indexer.WalkTo(Direction.NW); indexer = indexer.WalkTo(Direction.NW); OccupiedCellsLocations.Add(indexer); indexer = indexer.WalkTo(Direction.NW); OccupiedCellsLocations.Add(indexer); // now set the Mapcells at locations found to be not walkable.. foreach (var location in OccupiedCellsLocations) { MapRef.MapCellAt(location).Walkable = false; } //setting depths of irregular occupied cells.. float irregularDepth1; float irregularDepth2; indexer = Location.WalkTo(Direction.SW).WalkTo(Direction.NW).WalkTo(Direction.NW); irregularDepth1 = MapRef.MapCellAt(indexer).DrawDepth; indexer = indexer.WalkTo(Direction.NW); irregularDepth2 = MapRef.MapCellAt(indexer).DrawDepth; int segIndexer = (ImgSegmentsDepthsOrdered.Count / 2) - 3; // indexes segment no. 3 counting from middle segment leftwards SegDepth newSegment = new SegDepth(ImgSegmentsDepthsOrdered[segIndexer].SegRect, irregularDepth1); ImgSegmentsDepthsOrdered[segIndexer] = newSegment; segIndexer--; SegDepth newSegment2 = new SegDepth(ImgSegmentsDepthsOrdered[segIndexer].SegRect, irregularDepth1); ImgSegmentsDepthsOrdered[segIndexer] = newSegment2; segIndexer--; SegDepth newSegment3 = new SegDepth(ImgSegmentsDepthsOrdered[segIndexer].SegRect, irregularDepth2); ImgSegmentsDepthsOrdered[segIndexer] = newSegment3; #endregion #region Generating Custom Built Units Locations //remove last location BuiltUnitsLocations.RemoveAt(BuiltUnitsLocations.Count-1); //get the new last location var loc = BuiltUnitsLocations[BuiltUnitsLocations.Count-1]; Vector2 cell = new Vector2(MapRef.WorldToMapCell(loc).X, MapRef.WorldToMapCell(loc).Y); cell = cell.WalkTo(Direction.SW); BuiltUnitsLocations.Add(MapRef.MapCellAt(cell).CenterPosition); cell = cell.WalkTo(Direction.NW); BuiltUnitsLocations.Add(MapRef.MapCellAt(cell).CenterPosition); cell = cell.WalkTo(Direction.NW); BuiltUnitsLocations.Add(MapRef.MapCellAt(cell).CenterPosition); #endregion // making smoke on the roof #region smoke _smoke = new SpriteAnimation(GameGraphics.GetTexture("smoke").SourceTexture); _smoke.AddAnimation("normal", 0, 0, 30, 64, 16, 0.1f); _smoke.Position = Camera.WorldToScreen(new Vector2( this.BuildingOrigin.X+85, this.BuildingOrigin.Y-60)); _smoke.CurrentAnimation = "normal"; _smoke.DrawDepth = BuildingInfo.SmokeDrawDepth; _smoke.IsAnimating = true; #endregion selectionGroup = GroupMapper.CampGroup; SelectionLineTexture = GameGraphics.GetTexture("camp_selection_line"); #region Setting Entity Properties MaxHealth = 800; MaxDefense = 300; MaxAttack = 0; Health = MaxHealth; Defense = MaxDefense; Attack = MaxAttack; #endregion }
/// <summary> /// updates the data source and command operator /// </summary> /// <param name="context"></param> /// <param name="player"></param> public virtual void UpdateContext(Horseman context, GamePlayer player) { Context = context; Player = player; UpdateDisplayText(); }
public ReturnFromBuildingToFarmAction(Farmer farmer, GamePlayer player) { _farmer = farmer; _player = player; }
public void ShowSwordsmanDock(Swordsman context, GamePlayer player) { if (_currentDock != null) _currentDock.Hide(); _swordsmanDock.UpdateContext(context, player); _currentDock = _swordsmanDock; _currentDock.Show(); }