public static void Drag(AnimatedGameObject animatedGameObject, BaseTrack track, TrackEvent trackEvent, int framesDif, int minFrame, int maxFrame) { if (Mathf.Abs(framesDif) > 0) { var newStartFrame = trackEvent.StartFrame + framesDif; var newEndFrame = trackEvent.EndFrame + framesDif; if (trackEvent.IsDragged) { var eventLenth = trackEvent.Length; trackEvent.StartFrame = Mathf.Clamp(newStartFrame, minFrame, maxFrame - eventLenth); trackEvent.EndFrame = Mathf.Clamp(newEndFrame, trackEvent.StartFrame + eventLenth, maxFrame); } if (OnEventDragged != null) { OnEventDragged(new EventSelectionHolder() { AnimatedGameObject = animatedGameObject, Event = trackEvent, Track = track }); } } }
/// <summary> /// Attack logic for Characters, makes the Character use abilities, attacks and retargets if the target it was attacking died; /// </summary> private void CharacterAttackLogic() { // cast both the owner and target so we can access the Character / Monster properties Character owner_cast = owner as Character; Monster target_cast = targetedObject as Monster; owner_cast.CurrentWeapon.IsAttacking = true; GameObjectList monsterList = currentLevel.GameWorld.Find("monsterLIST") as GameObjectList; // if our ability is not on cooldown we use it. if (!owner_cast.CurrentWeapon.AbilityMain.IsOnCooldown) { owner_cast.CurrentWeapon.UseMainAbility(monsterList, currentLevel.TileField); owner_cast.PlaySFX("basic_ability"); } // otherwise perform a normal strike else { owner_cast.CurrentWeapon.Attack(monsterList, currentLevel.TileField); owner_cast.PlaySFX("attack_hit"); } // if the target is dead we set the targetedobject to null and wait for another monster to enter our LOS again if (target_cast.IsDead) { targetedObject = null; } }
public static void DrawTrackSection(AnimatedGameObject animatedGameObject, BaseTrack track, Rect trackRect, TimeLineParameters parameters) { EditorGUILayout.LabelField(track.TrackName); DrawTrackMenu(animatedGameObject, track); var eventsRect = new Rect(185f, 0, trackRect.width - 205f, RowHeight); GUILayout.BeginArea(eventsRect); var events = track.Events.Where(evt => evt.StartFrame <parameters.MaxFrame && evt.EndFrame> parameters.MinFrame).OrderBy(evt => evt.StartFrame).ToList(); var lastEndFrame = parameters.MinFrame; for (int i = 0; i < events.Count; i++) { var trackEvent = events[i]; if (trackEvent.StartFrame > lastEndFrame) { DrawEmptyEvent(animatedGameObject, track, eventsRect, lastEndFrame, trackEvent.StartFrame, parameters); } var minFrame = i == 0 ? parameters.MinFrame : events[i - 1].EndFrame; var maxFrame = i == events.Count - 1 ? parameters.MaxFrame : events[i + 1].StartFrame; DrawTrackEvent(animatedGameObject, track, trackEvent, eventsRect, parameters, minFrame, maxFrame, i); lastEndFrame = trackEvent.EndFrame; if (i == events.Count - 1 && trackEvent.EndFrame < parameters.MaxFrame) { DrawEmptyEvent(animatedGameObject, track, eventsRect, lastEndFrame, parameters.MaxFrame, parameters); } } GUILayout.EndArea(); Handles.color = Color.black; Handles.DrawLine(new Vector3(0, trackRect.height - 1f), new Vector3(trackRect.width, trackRect.height - 1f)); }
public GetBallOverlay() : base() { giftBox = new AnimatedGameObject(Depth.GiftBox); giftBox.LoadAnimation("Sprites/Animations/spr_animation_getball@4x3", "box", false, 0.05f); giftBox.PlayAnimation("box", true); giftBox.SetOriginToCenter(); giftBox.LocalPosition = new Vector2(320, 600); AddChild(giftBox); glowing = new AnimatedGameObject(Depth.OverlayButton2); glowing.LoadAnimation("Sprites/Animations/spr_animation_glowing@5x2", "glowing", true, 0.1f); glowing.PlayAnimation("glowing", true); glowing.SetOriginToCenter(); glowing.LocalPosition = new Vector2(350, 500); AddChild(glowing); background = new SpriteGameObject("Sprites/Backgrounds/spr_getball", Depth.OverlayBackground2); AddChild(background); message = new TextGameObject("Fonts/GetBall", Depth.OverlayMessage, Color.White, TextGameObject.HorizontalAlignment.Center, TextGameObject.VerticalAlignment.Center); AddChild(message); message.Visible = false; message.Text = "Click to get ball"; message.LocalPosition = new Vector2(350, 900); fireWorkMaker = new ListStar(Depth.RandomBall + 0.001f); AddChild(fireWorkMaker); Reset(); }
public void readMouseToAim(AnimatedGameObject gameObject) { float rel = MOUSE.SC.X - Screen.width / 2; float percentage = rel / Screen.width * 100; percentage = percentage * percentage * (percentage * 0.001f); gameObject.rotation += percentage / sensitivity; }
public void Init(EditorParameters parameters, EventParameters eventParameters, Sequence selectedSequence = null, AnimatedGameObject animatedGameObject = null, BaseTrack track = null, TrackEvent trackEvent = null) { _eventParameters = eventParameters; _sequenceName = selectedSequence == null ? string.Empty : selectedSequence.name; _animatedGameObject = animatedGameObject; _track = track; _trackEvent = trackEvent; _lastEditorParameters = parameters; }
public static void OnDraw(TimeLineParameters parameters, AnimatedGameObject animatedGameObject, Rect controlRect) { Handles.color = new Color(153f / 256f, 153f / 256f, 153f / 256, 1f); var ctrRect1 = new Rect(0, 0, controlRect.width - 10f, RowHeight); var ctrRect2 = new Rect(0, 0, 10f, controlRect.height); Handles.DrawSolidRectangleWithOutline(ctrRect1, Color.white, new Color(0, 0, 0, 0)); Handles.DrawSolidRectangleWithOutline(ctrRect2, Color.white, new Color(0, 0, 0, 0)); Handles.color = Color.black; Handles.DrawLine(new Vector3(0, 0), new Vector3(controlRect.width - 10f, 0)); Handles.DrawLine(new Vector3(10f, RowHeight), new Vector3(controlRect.width - 10f, RowHeight)); EditorGUILayout.BeginHorizontal(GUILayout.Width(190), GUILayout.Height(RowHeight)); EditorGUI.BeginChangeCheck(); animatedGameObject.Toggled = EditorGUILayout.Foldout(animatedGameObject.Toggled, animatedGameObject.GameObject.name); if (EditorGUI.EndChangeCheck()) { //ToggleChanged(animatedGameObject.Toggled); } if (GUILayout.Button("Add", EditorStyles.toolbarDropDown, GUILayout.Width(40), GUILayout.Height(RowHeight))) { var mPos = Event.current.mousePosition; GenericMenu toolsMenu = new GenericMenu(); toolsMenu.AddItem(new GUIContent("Add animation track"), false, OnAddAnimationTrack, animatedGameObject); toolsMenu.DropDown(new Rect(mPos.x, mPos.y, 0, 0)); } var rect = new Rect(0, 0, 190, RowHeight); if (EditorHelper.GetMouseDownRect(rect, 1)) { var mousePos = Event.current.mousePosition; GenericMenu toolsMenu = new GenericMenu(); toolsMenu.AddItem(new GUIContent("Remove GameObject"), false, RemoveGameObject, animatedGameObject); toolsMenu.DropDown(new Rect(mousePos.x, mousePos.y, 0, 0)); GUIUtility.ExitGUI(); } EditorGUILayout.EndHorizontal(); if (animatedGameObject.Toggled) { var lastTrackPosition = RowHeight; foreach (var track in animatedGameObject.Tracks) { var trackRect = new Rect(10f, lastTrackPosition, controlRect.width, RowHeight); GUILayout.BeginArea(trackRect); DrawTrackSection(animatedGameObject, track, trackRect, parameters); GUILayout.EndArea(); lastTrackPosition += RowHeight; } } Handles.color = Color.black; Handles.DrawAAPolyLine(2f, new Vector3(195f, 0), new Vector3(195f, controlRect.height)); }
private AnimatedGameObject CreateClearRowEffect() { AnimatedGameObject newObject = new AnimatedGameObject(Depth.Effect); newObject.LoadAnimation("Sprites/Animations/spr_animation_item_break_horizontal@1x11", "row", false, 0.01f); newObject.PlayAnimation("row", true); newObject.SetOriginToCenter(); newObject.LocalPosition = new Vector2(350, 200 + Row * 100); return(newObject); }
private AnimatedGameObject CreateClearColumnEffect() { AnimatedGameObject newObject = new AnimatedGameObject(Depth.Effect); newObject.LoadAnimation("Sprites/Animations/spr_animation_item_break_vertical@9", "col", false, 0.01f); newObject.PlayAnimation("col", true); newObject.SetOriginToCenter(); newObject.LocalPosition = new Vector2(50 + column * 100, 600); return(newObject); }
public void spawnBackground(int count) { for (int i = 0; i < count; i++) { float x = RANDOM.random.Next(0, 5000); float y = RANDOM.random.Next(0, 5000); Vector2 position = new Vector2(x, y); AnimatedGameObject gameObject = new AnimatedGameObject(position, Res.treeAnim); background.Add(gameObject); } }
public void rotateObject(AnimatedGameObject gameObject) { if (KEYBOARD.KeyDown(rotateAntiClockwise)) { gameObject.rotation -= rotationSpeed; } if (KEYBOARD.KeyDown(rotateClockwise)) { gameObject.rotation += rotationSpeed; } }
//scrolling left through the selection is -1 public void ChangeSpriteLeft(AnimatedGameObject obj, int animationIndex, int index) { if (animationIndex == 1) { characterSelectIndex[index] = 4; } else { characterSelectIndex[index] -= 1; } obj.PlayAnimation("maiden" + characterSelectIndex[index].ToString()); borderSprites[index].GetColor = lockInColor[(characterSelectIndex[index] - 1) * 2]; }
public void JoinPlayer(int controlsnr) { //make and load in the animations characterSprites[playersjoined] = new AnimatedGameObject(2); characterSprites[playersjoined].LoadAnimation("Assets/Sprites/Character selection/shieldmaiden_default", "maiden1", true); characterSprites[playersjoined].LoadAnimation("Assets/Sprites/Character selection/shieldmaiden_blue", "maiden2", true); characterSprites[playersjoined].LoadAnimation("Assets/Sprites/Character selection/shieldmaiden_green", "maiden3", true); characterSprites[playersjoined].LoadAnimation("Assets/Sprites/Character selection/shieldmaiden_orange", "maiden4", true); //position of the sprites characterSprites[playersjoined].Position = new Vector2(borderSprites[playersjoined].Position.X + borderSprites[playersjoined].Width / 2, borderSprites[playersjoined].Position.Y + 100); Add(characterSprites[playersjoined]); //play all the different animations characterSprites[playersjoined].PlayAnimation("maiden" + (playersjoined + 1)); //Add the index number of the selected animation characterSelectIndex[playersjoined] = playersjoined + 1; //Change color of background accordingly to the playing animation borderSprites[playersjoined].GetColor = lockInColor[(characterSelectIndex[playersjoined] - 1) * 2]; //Place the ready sprite readySprite[playersjoined] = new AnimatedGameObject(2); readySprite[playersjoined].Position = new Vector2(borderSprites[playersjoined].Position.X + borderSprites[playersjoined].Width / 2, borderSprites[playersjoined].Position.Y + borderSprites[playersjoined].Height / 7 * 6); readySprite[playersjoined].LoadAnimation("Assets/Sprites/Character selection/Ready-not", "notReady", true); readySprite[playersjoined].LoadAnimation("Assets/Sprites/Character selection/Ready!", "Ready", true); readySprite[playersjoined].PlayAnimation("notReady"); Add(readySprite[playersjoined]); //link the controlnumber to the bordernumber playerborder.Add(controlsnr, playersjoined); //playersjoined is the same as the border number in this method //load in Controls Sprite if (controlsnr <= 1) //0 and 1 is keyboard { controlSprites[playersjoined] = new SpriteGameObject("Assets/Sprites/Character selection/ControllerParchment/KeyboardControls2-2long400", 2); } if (controlsnr >= 2) //2 to 5 is xbox { controlSprites[playersjoined] = new SpriteGameObject("Assets/Sprites/Character selection/ControllerParchment/XboxControlled1long3-400", 2); } controlSprites[playersjoined].Position = new Vector2(GameEnvironment.Screen.X / 4 * playersjoined + 40, 450); Add(controlSprites[playersjoined]); playersjoined++; }
//scrolling right through the selection is +1 public void ChangeSpriteRight(AnimatedGameObject obj, int animationIndex, int index) { //Check if the index is not at max, if so change the index number to the lowest number (=1) if (animationIndex == 4) { characterSelectIndex[index] = 1; } else { characterSelectIndex[index] += 1; } obj.PlayAnimation("maiden" + characterSelectIndex[index].ToString()); borderSprites[index].GetColor = lockInColor[(characterSelectIndex[index] - 1) * 2]; }
public Bar(int t, string id, int layer = 9, int sheetIndex = 1) : base("Sprites/bar2", layer, id, sheetIndex) { playsound = true; type = t; this.Position = new Vector2(20, 30 * t); if (type == 4) { this.position += new Vector2(0, 20); } barPart = WifiWars.AssetManager.Content.Load <Texture2D>("Sprites/bar"); car = new AnimatedGameObject(); car.LoadAnimation("Sprites/Police@2", "car", true); resource = 0; totalResource = 1000; car.PlayAnimation("car"); }
public void searchForTarget() { // TODO Perform this search over a few frames for (int i = 0; i < character.team.enemyTeams.Count; i++) { for (int j = 0; j < character.team.enemyTeams[i].characters.Count; j++) { AnimatedGameObject enemyChar = character.team.enemyTeams[i].characters[j] as AnimatedGameObject; float distanceToEnemy = Vector2.Distance(character._position, enemyChar._position); if (distanceToEnemy < visionRange) { spotTarget(enemyChar as GenericCharacter); } } } }
public void chaseCam(AnimatedGameObject gameObject) { position = gameObject.position; float difference = gameObject.rotation - this.rotation; if (Math.Abs(difference) > Trig.PI) { if (rotation < Trig.PI) { difference = -(Trig.PI_Two - Math.Abs(difference)); } else { difference = (Trig.PI_Two - Math.Abs(difference)); } } rotation += ((difference) / sensitivity); position = Trig.MoveToCurrentDirection(position, rotation, -distanceBehind); }
/// <summary> /// Method that sets the targetedobject to the closest target currently from the owner /// </summary> /// <param name="targets">list with the potential targets to attack</param> public void TargetClosest(List <AnimatedGameObject> targets) { float closestTargetDistance = 0; foreach (AnimatedGameObject target in targets) { Vector2 positionDifference = owner.Position - target.Position; float targetDistance = (float)Math.Sqrt(Math.Pow(positionDifference.X, 2) + Math.Pow(positionDifference.Y, 2)); if (targetDistance > sightRange) { continue; } if (closestTargetDistance == 0 || targetDistance < closestTargetDistance) { closestTargetDistance = targetDistance; targetedObject = target; } } }
private static void DrawTrackMenu(AnimatedGameObject animatedGameObject, BaseTrack track) { var rect = new Rect(0, 0, 185f, RowHeight); if (EditorHelper.GetMouseDownRect(rect, 1)) { var mousePos = Event.current.mousePosition; GenericMenu toolsMenu = new GenericMenu(); toolsMenu.AddItem(new GUIContent("Remove Track"), false, OnRemoveTrack, new RemoveTrackHolder() { Track = track, AnimatedGameObject = animatedGameObject }); var animationTrack = track as AnimationTrack; if (animationTrack != null) { toolsMenu.AddItem(new GUIContent("Generate State Machine"), false, OnGenerateTrack, animationTrack); } toolsMenu.DropDown(new Rect(mousePos.x, mousePos.y, 0, 0)); GUIUtility.ExitGUI(); } }
private static void DrawEmptyEvent(AnimatedGameObject animatedGameObject, BaseTrack track, Rect eventsRect, int startFrame, int endFrame, TimeLineParameters parameters) { var frameLength = parameters.MaxFrame - parameters.MinFrame; var x_dif = eventsRect.width / frameLength; var startFr = startFrame - parameters.MinFrame; var start = Mathf.Clamp(startFr, 0, frameLength); var end = Mathf.Clamp(endFrame - startFr - parameters.MinFrame, 0, frameLength); var rect = new Rect(start * x_dif, 0, end * x_dif, RowHeight); if (EditorHelper.GetMouseDownRect(rect, 1)) { var mousePos = Event.current.mousePosition; GenericMenu toolsMenu = new GenericMenu(); toolsMenu.AddItem(new GUIContent("Add new event"), false, OnAddEvent, new AddEventHolder() { StartFrame = startFrame, EndFrame = endFrame, Track = track, AnimatedGameObject = animatedGameObject }); toolsMenu.DropDown(new Rect(mousePos.x, mousePos.y, 0, 0)); GUIUtility.ExitGUI(); } }
public void controlObject(AnimatedGameObject gameObject) { if (KEYBOARD.KeyDown(forwardKey)) { gameObject._position = Trig.MoveToCurrentDirection(gameObject._position, gameObject.rotation, movementSpeed); } if (KEYBOARD.KeyDown(backwardKey)) { gameObject._position = Trig.MoveToCurrentDirection(gameObject._position, gameObject.rotation, -movementSpeed); } if (KEYBOARD.KeyDown(leftKey)) { gameObject._position = Trig.MoveToCurrentDirection(gameObject._position, gameObject.rotation - Trig.PI_Half, movementSpeed); } if (KEYBOARD.KeyDown(rightKey)) { gameObject._position = Trig.MoveToCurrentDirection(gameObject._position, gameObject.rotation + Trig.PI_Half, movementSpeed); } }
public void Animate(GameTime gameTime, AnimatedGameObject animatedObject) { if (!this.IsActive) { return; } this.Time += gameTime.ElapsedGameTime.Milliseconds; var speed = animatedObject.AnimationSpeed; var objectAsAttackObject = animatedObject as AttackingGameObject; if (objectAsAttackObject != null) { if (objectAsAttackObject.AttackAnimation == this && this.IsActive) { speed = objectAsAttackObject.AttackSpeed; } } if (this.Time > (Constant.TimeForFrameInMilliSeconds * this.Rectangles.Length) / speed) { this.Time = 0f; this.FrameIndex++; if (this.FrameIndex == this.Rectangles.Length) { this.FrameIndex = 0; if (!this.IsLoop) { this.IsActive = false; if ((animatedObject as AttackingGameObject) != null) { if ((animatedObject as AttackingGameObject).Health > 0) { animatedObject.IddleAnimation.IsActive = true; } } } } } }
/// <summary> /// Class that defines a Basic AI for the Dungeon Crawler game. Both for Characters and Monsters. /// </summary> /// <param name="owner">The owner of this AI (and the thing that the AI perfoms it's operations on)</param> /// <param name="movementSpeed">Variable that determines how fast the AI moves</param> /// <param name="currentLevel">The current level the owner of the AI is currently in</param> /// <param name="isMonster">Bool that determines whether this AI follows monster or player logic</param> /// <param name="idleTime">Amount of time an AI waits after attacking</param> /// <param name="sightRange">Distance of the LOS of the AI</param> public BaseAI(AnimatedGameObject owner, float movementSpeed, Level currentLevel, bool isMonster = true, float sightRange = 200, float idleTime = 1.4F) { idleTimer = new Timer(idleTime) { IsExpired = true }; // assign the given variables to the local variables this.currentLevel = currentLevel; this.isMonster = isMonster; this.owner = owner; this.movementSpeed = movementSpeed; this.sightRange = sightRange; levelGrid = currentLevel.TileField; // Find the potential targets of this AI if (isMonster) { targetList = currentLevel.GameWorld.Find("playerLIST") as GameObjectList; } else { targetList = currentLevel.GameWorld.Find("monsterLIST") as GameObjectList; } }
public void Animate(GameTime gameTime, AnimatedGameObject animatedObject) { if(!this.IsActive) { return; } this.Time += gameTime.ElapsedGameTime.Milliseconds; var speed = animatedObject.AnimationSpeed; var objectAsAttackObject = animatedObject as AttackingGameObject; if(objectAsAttackObject != null) { if(objectAsAttackObject.AttackAnimation == this && this.IsActive) { speed = objectAsAttackObject.AttackSpeed; } } if (this.Time > (Constant.TimeForFrameInMilliSeconds * this.Rectangles.Length) / speed) { this.Time = 0f; this.FrameIndex++; if (this.FrameIndex == this.Rectangles.Length) { this.FrameIndex = 0; if(!this.IsLoop) { this.IsActive = false; if ((animatedObject as AttackingGameObject) != null) { if ((animatedObject as AttackingGameObject).Health > 0) { animatedObject.IddleAnimation.IsActive = true; } } } } } }
/// <summary> /// Attack Logic method for monsters, attacks the character and finds a new target if the character it waas attacking got downed /// </summary> private void MonsterAttackLogic() { // cast both the owner and target so we can access the Character / Monster properties Monster owner_cast = owner as Monster; Character target_cast = targetedObject as Character; owner_cast.Attack(); // The Character is downed so we want to target a new Character if (target_cast.IsDowned) { foreach (Character target in targetList.Children) { // If the target is down, we do not want to target it so we continue to the next iteration in the loop. if (target.IsDowned) { continue; } else { targetedObject = target; } } } }
public FrameAnimation(string path, int frames, AnimatedGameObject animatedGameObject) : base(path, frames, animatedGameObject) { }
public SpellContainer(AnimatedGameObject owner) : base(new SpellDef("container", 0, "container"), Vector2.Zero) { State = Active; }
public override void Update(GameTime gameTime) { foreach (Enemy enemy in enemySpawner.Objects) { if(enemy.CollidesWith(castle.mainCastle) || (enemy.Position.X - castle.mainCastle.Position.X) <= 150) { if (enemy.Health > 0) { enemy.Idle(); if (enemy.GetType().Equals(typeof(Bat))) { castle.Health -= enemy.AttackDamage; enemy.Health = 0; } } } if (enemy.Health <= 0) { if(!enemy.IsDead) player.Money += enemy.MoneyDrop; enemy.Dead(); } //Als de enemy verwijderd moet worden, wordt de sprite onzichtbaar gemaakt. Hierna wordt deze verwijderd in de EnemySpawner class. if (enemy.ShouldDeleteEnemy()) enemy.Visible = false; if (enemy.Attack) { castle.Health -= enemy.AttackDamage; enemy.Attack = false; } for (int i = arrows.Objects.Count-1; i > 0; i--) { if (enemy.CollidesWith(arrows.Objects[i] as Arrow)) { InsaneKillerArcher.AssetManager.PlaySound("hit_enemy2"); arrows.Remove(arrows.Objects[i]); enemy.Health -= player.Weapon.Damage; } } for (int i = archerArrows.Objects.Count - 1; i > 0; i--) { if (enemy.CollidesWith(archerArrows.Objects[i] as Arrow)) { enemy.Health -= (archerArrows.Objects[i] as Arrow).damage; archerArrows.Remove(archerArrows.Objects[i]); } } if (boulder != null && IsOutsideRoomRight(boulder.Position.X, -30)) { animatedProjectiles.Remove(boulder); boulder.Visible = false; } if (boulder != null && boulder.CollidesWith(enemy)) { enemy.Health = 0; } } foreach (ClickableSpriteGameObject icon in statusBar.ClickableObjects.Objects) { if (icon.Type == IconType.OverheadArrowsIcon && icon.Clickable && icon.Clicked) { // Tweak values; int intervalXMin = 50; int intervalXMax = 75; int arrowDirectionXMin = 1; int arrowDirectionXMax = 2; int arrowDirectionYMin = 8; int arrowDirectionYMax = 12; int arrowSpawnYMin = -25; int arrowSpawnYMax = -5; int interval = random.Next(intervalXMin, intervalXMax); for (int i = 100; i < InsaneKillerArcher.Screen.X - 100; i += interval) { Vector2 normalizedArrowDirection = new Vector2(random.Next(arrowDirectionXMin, arrowDirectionXMax), random.Next(arrowDirectionYMin, arrowDirectionYMax)); normalizedArrowDirection.Normalize(); arrows.Add(new Arrow(new Vector2(i, random.Next(arrowSpawnYMin, arrowSpawnYMax)), normalizedArrowDirection, 100)); } icon.SetInactive(); } if (icon.Type == IconType.RollingBoulderIcon && icon.Clickable && icon.Clicked) { int boulderStartPosX = 0; int boulderStartPosY = InsaneKillerArcher.Screen.Y - 15; int boulderVelX = 100; int boulderVelY = 0; boulder = new Boulder(new Vector2(boulderStartPosX, boulderStartPosY), new Vector2(boulderVelX, boulderVelY)); animatedProjectiles.Add(boulder); icon.SetInactive(); } if (icon.Type == IconType.BoilingOilIcon && icon.Clickable && icon.Clicked) { // do stuff if Boiling Oil is activated. } } foreach (BuyableGameObject upgrade in Store.upgrades) { if (upgrade.Type == UpgradeType.CastleUpgrade && upgrade.IsActive) { castle.CastleLevel++; castle.CheckForUpgrades(); upgrade.IsActive = false; } if (upgrade.Type == UpgradeType.ArcherUpgrade && upgrade.IsActive) { int archerSpace = castle.CheckForArcherSpace(); if (!upgrade.Claimed) { castle.AskForArchers += 1; upgrade.Claimed = true; } if (archerSpace != 0 && castle.AskForArchers != 0) { for (int i = 0; i < castle.AskForArchers; i++) { archerSpace--; Vector2 newArcherPosition = castle.GetNewArcherPosition(); if (newArcherPosition != Vector2.Zero) { castle.makeArcherVisible(newArcherPosition); castle.AskForArchers--; } } upgrade.IsActive = false; } } if (upgrade.Type == UpgradeType.CatapultUpgrade && upgrade.IsActive) { int catapultSpace = castle.CheckForCatapultSpace(); castle.AskForCatapults += upgrade.Level; if (catapultSpace != 0 && castle.AskForCatapults != 0) { for (int i = 0; i < castle.AskForCatapults; i++) { catapultSpace--; Vector2 newCatapultPosition = castle.GetNewCatapultPosition(); if (newCatapultPosition != Vector2.Zero) { castle.makeCatapultVisible(newCatapultPosition); } } upgrade.IsActive = false; } } } foreach (Arrow arrow in arrows.Objects) { if (IsOutsideRoomLeft(arrow.Position.X, arrow.Width) || IsOutsideRoomRight(arrow.Position.X, arrow.Width)) { arrow.Visible = false; } foreach (SpriteGameObject ground in groundList.Objects) { if (arrow.CollidesWith(ground)) { if (arrow.Active) { InsaneKillerArcher.AssetManager.PlaySound("hit_enemy"); arrow.Velocity = Vector2.Zero; arrow.Gravity = 0; arrow.Active = false; } else if (arrow.deleteTimer > 120) { arrow.Visible = false; } else { arrow.deleteTimer ++; } } } } foreach (CatapultBoulder boulder in catapultBoulders.Objects) { foreach (SpriteGameObject ground in groundList.Objects) { if (ground.CollidesWith(boulder)) { boulder.Bounce(ground.Position.Y); } } foreach (Enemy enemy in enemySpawner.Objects) { if (boulder.CollidesWith(enemy)) { enemy.Health -= 100; boulder.Visible = false; } } } // cooldown voor het schieten staat hier. if (!canShoot) { shootCooldownTimer += (float)gameTime.ElapsedGameTime.Milliseconds; if (shootCooldownTimer >= shootCooldown) { shootCooldownTimer = 0; canShoot = true; } } for (int i = gameObjects.Count - 1; i > 0; i--) if (!gameObjects[i].Visible) Remove(gameObjects[i]); statusBar.MoneyCount = player.Money; base.Update(gameTime); }
public FrameAnimation(string path, int frames, AnimatedGameObject animatedGameObject) : base(path, frames, animatedGameObject) { }
public void faceMouse(AnimatedGameObject gameObject) { gameObject.rotation = Trig.GetRadionsBetween(gameObject._position, mouseWC); }
private static void DrawTrackEvent(AnimatedGameObject animatedGameObject, BaseTrack track, TrackEvent trackEvent, Rect eventsRect, TimeLineParameters parameters, int minFrame, int maxFrame, int index) { var frameLength = parameters.MaxFrame - parameters.MinFrame; var x_dif = eventsRect.width / frameLength; var backgroundColor = GUI.backgroundColor; GUI.backgroundColor = trackEvent.EventInnerColor; var evtStyle = FreeSequencerUtility.GetEventStyle(); var startFr = trackEvent.StartFrame - parameters.MinFrame; var start = Mathf.Clamp(startFr, 0, frameLength); var endFr = trackEvent.EndFrame - parameters.MinFrame; var end = endFr > 0 && frameLength > endFr ? endFr : frameLength; var rect = new Rect(start * x_dif, 0, (end - start) * x_dif, RowHeight); if (Event.current.type == EventType.Repaint) { evtStyle.Draw(rect, false, trackEvent.IsActive, false, false); } if (trackEvent.IsActive) { var color = Handles.color; Handles.color = new Color(1, 1, 1, 0.3f); Handles.DrawSolidRectangleWithOutline(rect, new Color(1, 1, 1, 0.3f), new Color(0, 0, 0, 0)); Handles.color = color; } GUILayout.BeginArea(rect); GUILayout.Label(trackEvent.EventTitle); GUILayout.EndArea(); var minRect = new Rect(start * x_dif, 0, 5f, RowHeight); var maxRect = new Rect(start * x_dif + (end - start) * x_dif - 5f, 0, 5f, RowHeight); if (EditorHelper.GetMouseDown()) { var wasDrag = false; if (EditorHelper.GetMouseDownRect(minRect) && !trackEvent.IsDragged) { wasDrag = trackEvent.IsMinDragged = true; } if (EditorHelper.GetMouseDownRect(maxRect) && !trackEvent.IsDragged) { wasDrag = trackEvent.IsMaxDragged = true; } if (EditorHelper.GetMouseDownRect(rect)) { if (OnEventSelection != null) { var holder = new EventSelectionHolder() { AnimatedGameObject = animatedGameObject, Event = trackEvent, Track = track }; holder.ResetSelection = !Event.current.shift; OnEventSelection(holder); } trackEvent.InitialDraggedPosition = Event.current.mousePosition; if (!trackEvent.IsMinDragged && !trackEvent.IsMaxDragged) { wasDrag = trackEvent.IsDragged = true; } } if (!wasDrag) { trackEvent.IsDragged = false; trackEvent.IsMinDragged = false; trackEvent.IsMaxDragged = false; } } if (EditorHelper.GetMouseUp()) { trackEvent.IsDragged = false; trackEvent.IsMinDragged = false; trackEvent.IsMaxDragged = false; } if (trackEvent.IsMinDragged || trackEvent.IsMaxDragged || trackEvent.IsDragged) { if (EditorHelper.GetMouseDrag()) { var position = Event.current.mousePosition; var initialPosition = trackEvent.InitialDraggedPosition; var difX = initialPosition.x - position.x; int framesDif = (int)(difX / x_dif) * -1; if (Mathf.Abs(framesDif) > 0) { var newStartFrame = trackEvent.StartFrame + framesDif; var newEndFrame = trackEvent.EndFrame + framesDif; if (trackEvent.IsMinDragged) { trackEvent.StartFrame = Mathf.Clamp(newStartFrame, minFrame, trackEvent.EndFrame - 1); } if (trackEvent.IsMaxDragged) { trackEvent.EndFrame = Mathf.Clamp(newEndFrame, trackEvent.StartFrame + 1, maxFrame); } if (trackEvent.IsDragged) { if (DraggedEvent != null) { DraggedEvent(new TrackEventDragHolder() { AnimatedGameObject = animatedGameObject, TrackEvent = trackEvent, Track = track, Step = framesDif }); } /*var eventLenth = trackEvent.Length; * trackEvent.StartFrame = Mathf.Clamp(newStartFrame, minFrame, maxFrame - eventLenth); * trackEvent.EndFrame = Mathf.Clamp(newEndFrame, trackEvent.StartFrame + eventLenth, maxFrame);*/ } if (OnEventDragged != null) { OnEventDragged(new EventSelectionHolder() { AnimatedGameObject = animatedGameObject, Event = trackEvent, Track = track }); } trackEvent.InitialDraggedPosition = position; } } var holder = new EventSelectionHolder() { AnimatedGameObject = animatedGameObject, Event = trackEvent, Track = track }; if (OnEventSelection != null) { OnEventSelection(holder); } } if (EditorHelper.GetMouseDownRect(rect, 1)) { var mousePos = Event.current.mousePosition; GenericMenu toolsMenu = new GenericMenu(); toolsMenu.AddItem(new GUIContent("Remove event"), false, OnRemoveEvent, new RemoveEventHolder() { Event = trackEvent, Track = track, AnimatedGameObject = animatedGameObject }); if (index > 0) { var moveLeftHolder = new MoveHolder() { AnimatedGameObject = animatedGameObject, Track = track, Event = trackEvent, MoveRight = false }; toolsMenu.AddSeparator(string.Empty); toolsMenu.AddItem(new GUIContent("Move left"), false, OnMove, moveLeftHolder); } if (index < track.Events.Count - 1) { var moveRightHolder = new MoveHolder() { AnimatedGameObject = animatedGameObject, Track = track, Event = trackEvent, MoveRight = true }; toolsMenu.AddSeparator(string.Empty); toolsMenu.AddItem(new GUIContent("Move right"), false, OnMove, moveRightHolder); } toolsMenu.DropDown(new Rect(mousePos.x, mousePos.y, 0, 0)); GUIUtility.ExitGUI(); } GUI.backgroundColor = backgroundColor; }
public Sprite(string path, int frames, AnimatedGameObject animatedGameObject) : this(path, frames) { this.Position = animatedGameObject.Position; }