public override void update(GameObject gameObject, QuadTree quadTree, SceneManager sceneManager) { // Debug.Write(gameObject.position + "\n"); //Debug.Write(quadTree.getObjects(gameObject).Count); // nearby objects... quadTree.getObjects(gameObject).ForEach((returnObject) => { if (!(returnObject is MoronGameObject) && !(returnObject.ComponentContainer.GetPhysicsComponent() is GrassPhysicsComponent)) // DUNNO why this happens, check getObjects method.. { Rectangle bla1 = new Rectangle((int)gameObject.position.X + 59, (int)gameObject.position.Y + 105, 10, 2); // player movement box, imagine rectangle at the bottom of the character Rectangle bla2 = new Rectangle((int)returnObject.position.X, (int)returnObject.position.Y + 64 /* HEIGHT */, 128, 64); if (CollisionDetection.AreRectanglesColliding(bla1, bla2)) { gameObject.Color = Color.Red; gameObject.GameObjectStateContainer.GetPrevious().Reverse(gameObject); // if (null != returnObject.ComponentContainer.GetHealthComponent()) // returnObject.ComponentContainer.GetHealthComponent().update(gameObject, returnObject); } else { gameObject.Color = Color.White; } } }); }
public override void update(GameObject gameObject, QuadTree quadTree, SceneManager sceneManager) { gameObject.GameObjectStateContainer.Change(new StateStanding()); // hm return state with easing somehow if (defaultPosition == default(Vector2)) { defaultPosition = gameObject.position; } gameObject.position = defaultPosition; quadTree.getObjects(gameObject).ForEach((returnObject) => { // if gameObject->GetCollideBox().Position.. Rectangle bla1 = new Rectangle((int)returnObject.position.X + 59, (int)returnObject.position.Y + 105, 10, 2); // player movement box, imagine rectangle at the bottom of the character Rectangle bla2 = new Rectangle((int)gameObject.position.X, (int)gameObject.position.Y + 64 /* HEIGHT */, 128, 64); if (CollisionDetection.AreRectanglesColliding(bla1, bla2)) { if (returnObject is MoronGameObject && returnObject.GameObjectStateContainer.GetPrevious() is StateWalking) { gameObject.GameObjectStateContainer.Change(new StateWaving()); } } }); }
public override void update(GameObject gameObject, QuadTree quadTree, SceneManager sceneManager) { quadTree.getObjects(gameObject).ForEach((returnObject) => { Rectangle rect1 = new Rectangle((int)gameObject.position.X, (int)gameObject.position.Y, 128, 128); Rectangle rect2 = new Rectangle((int)returnObject.position.X, (int)returnObject.position.Y, 128, 128); if (CollisionDetection.AreRectanglesColliding(rect1, rect2)) { if (null != gameObject.ComponentContainer.GetScriptComponent() && returnObject is MoronGameObject) { gameObject.ComponentContainer.GetScriptComponent().update(gameObject, quadTree, sceneManager); } } }); }
public override void update(GameObject arrow, QuadTree quadTree, SceneManager sceneManager) { MouseState mouseState = Mouse.GetState(); targetIsHit = false; float mousePositionX = mouseState.Position.X; float mousePositionY = mouseState.Position.Y; Vector2 mousePosition = new Vector2(mousePositionX, mousePositionY); if (targetPosition == default(Vector2)) // if removed, some cool stuff will happen :D { targetPosition = mousePosition; } float distance = Vector2.Distance(arrow.position, targetPosition); Vector2 direction = Vector2.Normalize(targetPosition - arrow.position); arrow.position += direction * 50; quadTree.getObjects(arrow).ForEach((returnObject) => { if (!(returnObject is DamageGameObject) && !(returnObject is MoronGameObject)) // FIIIIIIIX { Rectangle arrowRectangle = new Rectangle((int)arrow.position.X, (int)arrow.position.Y, 128, 128); Rectangle targetObjectRectangle = new Rectangle((int)returnObject.position.X, (int)returnObject.position.Y, 128, 64); if (CollisionDetection.AreRectanglesColliding(arrowRectangle, targetObjectRectangle) && null != returnObject.ComponentContainer.GetHealthComponent() ) { returnObject.Damaged = true; returnObject.ComponentContainer.GetHealthComponent().update(arrow, returnObject); targetIsHit = true; } } }); if (Vector2.Distance(targetPosition, arrow.position) >= distance || targetIsHit) { arrow.Destroyed = true; } }