public override void Create(GameObject createdObject) { if (createdObject == this) { Solid = false; } }
public override void Create(GameObject createdObject) { if (createdObject == this) { _greenPellet = TextureContainer.ColoredRectangle(Color.Green, 10, 18); _redPellet = TextureContainer.ColoredRectangle(Color.Red, 10, 18); } }
public override void Destroy(GameObject destroyedObject) { if (destroyedObject == this) { ExplodeSound.Play(0.5f, 0.2f, 0.0f); SpaceInvaders.RefScore.AddPoints(_points); } }
public override void Create(GameObject createdObject) { if (createdObject == this) { _mainPosition = Sprite.Position; _current = (Wave)CreateAndReturnObject(typeof(Wave), _mainPosition); } }
public override void Create(GameObject createdObject) { if (createdObject == this) { Visable = false; Solid = false; Alarms.Add("spawn", new Alarm(ObjectManager.Rand.Next(_spawnTimeBottom, _spawnTimeTop))); } }
public override void Create(GameObject createdObject) { if (createdObject == this) { if (_ANSIrepresentations == null || _side == 0 || _spacing == 0 || _squareSide == 0) //This means that the object isnt initialized properly { throw new NullReferenceException(); } Objects = new GameObject[_side, _side]; _positions = new Vector2[_side, _side]; int doubleSpacing = _spacing * 2; //This is used so there is space for lines left #region Calculate square positions float yPosition = Sprite.Position.Y + _spacing; for (int i = 0; i < _side; i++) { for (int j = 0; j < _side; j++) { _positions[i, j] = new Vector2(yPosition, _squareSide * j + Sprite.Position.X + _spacing + doubleSpacing * j); } yPosition += _squareSide + doubleSpacing; } #endregion #region Calculate line positions _verticalLinePoints = new Vector2[2, _side + 1]; _horizontalLinePoints = new Vector2[2, _side + 1]; int lineLenght = _spacing * 2 + _squareSide * _side + doubleSpacing * (_side - 1); int lineSpacing = _spacing * 2 + _squareSide; for (int i = 0; i <= _side; i++) { Vector2 horizontalFirstPoint = new Vector2(Sprite.Position.X, Sprite.Position.Y + lineSpacing * i); Vector2 horizontalSecondPoint = new Vector2(horizontalFirstPoint.X + lineLenght, horizontalFirstPoint.Y); _horizontalLinePoints[0, i] = horizontalFirstPoint; _horizontalLinePoints[1, i] = horizontalSecondPoint; Vector2 verticalFirstPoint = new Vector2(Sprite.Position.X + lineSpacing * i, Sprite.Position.Y); Vector2 verticalSecondPoint = new Vector2(verticalFirstPoint.X, verticalFirstPoint.Y + lineLenght); _verticalLinePoints[0, i] = verticalFirstPoint; _verticalLinePoints[1, i] = verticalSecondPoint; } #endregion } }
public override void Create(GameObject createdObject) { if (createdObject == this) { Alarms.Add("reset canShoot", new Alarm()); _checker = (CheckObject)CreateAndReturnObject(typeof(CheckObject), new Vector2(0, 0)); _checker.Player = this; } }
public override void Create(GameObject createdObject) { if (createdObject == this) { Font = Score.Font; Solid = false; Visable = false; ChangeSpriteTexture(TextureContainer.ColoredRectangle(Color.White, 1, 18)); } }
public void DestroyObject(GameObject obj) { ObjectManager.Destroy(obj); }
public virtual void Destroy(GameObject destroyedObject) { }
public virtual void Create(GameObject createdObject) { }
public override void Create(GameObject createdObject) { if (createdObject == this) { Visable = false; Solid = false; int blockSide = new Block().Sprite.Image.Height; //Since a block is square shaped it dosen't matter wich side you take //Make a thin sprite as tall as an barrier. It is positioned where barriers are. Sprite = new Sprite(TextureContainer.ColoredRectangle(Color.White, 3, blockSide * 3), new Vector2(SpaceInvaders.Device.Viewport.Width / 2, BlockMaker.Position.Y)); //Creates it where the player shoots bullets } }
public static void ImportExisting(GameObject obj) { ObjectsToCreate.Add(obj); //Call the create event: foreach (var i in Objects) //I used 'i' here instead of 'obj' because 'obj' is taken { i.Create(obj); } obj.Create(obj); //the loop above won't do this since it loops trough "Objects" and "obj" isnt in that list yet }
//Destroy all invaders when destroyed public override void Destroy(GameObject destroyedObject) { if (destroyedObject == this) { foreach (var invader in _invaders) { DestroyObject(invader); } } }
public static void Destroy(GameObject obj) { ObjectsToDestroy.Add(obj); //Call the destroy event: foreach (var i in Objects) //I used 'i' here instead of 'obj' because 'obj' is taken { i.Destroy(obj); } }
public override void Create(GameObject createdObject) { Solid = false; Sprite.Scale = 4f; Sprite.Origin = new Vector2(50, 25 / 2); }
//Changes the position of the object to the position in argument public void SetPosition(GameObject obj, Vector2 newPosition) { if (newPosition.X >= _side || newPosition.Y >= _side || newPosition.X < 0 || newPosition.Y < 0) { throw new Exception("Position is outside of the grid"); } Vector2 oldPosition = GetXY(obj); Objects[(int)oldPosition.X, (int)oldPosition.Y] = null; if (Objects[(int)newPosition.X, (int)newPosition.Y] == null) { Objects[(int)newPosition.X, (int)newPosition.Y] = obj; } else { throw new Exception("Space occupied"); } }
//Changes the position of the object by adding and/or subtracting from its coordinates public void RelativeSetPosition(GameObject obj, Vector2 modifier) { Vector2 modifiedPosition = GetXY(obj) + modifier; SetPosition(obj, modifiedPosition); }
public Vector2 GetXY(GameObject obj) { int hashCode = obj.GetHashCode(); for (int i = 0; i < _side; i++) { for (int j = 0; j < _side; j++) { if (Objects[i, j] != null && Objects[i, j].GetHashCode() == hashCode) return new Vector2(i, j); } } throw new Exception("Object isn't in the grid"); }
public float GetDistance(GameObject obj) { return (this.Sprite.Position - obj.Sprite.Position).Length(); }
public static void InstantImportExisting(GameObject obj) { Objects.Add(obj); //Call the create event: foreach (var i in Objects) //I used 'i' here instead of 'obj' because 'obj' is taken { i.Create(obj); } }
public bool IsColliding(GameObject obj) { if (this != obj) // dont check collisions with yourself { if (Sprite.GetRectangle().Intersects(obj.Sprite.GetRectangle())) //check if rectangles collide { if (IntersectPixels(Sprite, obj.Sprite)) //check pixel collision { return true; } else { return false; } } else { return false; } } else { return false; } }
public override void Create(GameObject createdObject) { if (createdObject == this) { _positon = Sprite.Position; Alarms.Add("move", new Alarm(_moveTime)); Alarms.Add("shoot", new Alarm(ObjectManager.Rand.Next(_shootTimeBottom, _shootTimeTop))); _invaderWidth = new InvaderType1().Sprite.GetRectangle().Width; _invaderHeight = new InvaderType1().Sprite.GetRectangle().Height; _rows = _invaders.GetLength(0); _columns = _invaders.GetLength(1); FillInvaders(); } }