public override void Draw(SpriteBatch spriteBatch) { spriteBatch.End(); // to get some crispy pixels <e're gonna call the spritebatch with new parameters spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null, null, null); background.TopLeftDraw(spriteBatch, new Vector2(0, 0)); CurrentSprite.DrawFromFeet(spriteBatch, PlayerPosition); foreach (Vector2 v in PizzaPositions) { pizza.DrawFromFeet(spriteBatch, v + new Vector2(0, pizza_height)); } foreach (Tuple <Vector2, Vector2, Sprite> o in DisplayObjects) { o.Item3.DrawFromFeet(spriteBatch, o.Item1); } spriteBatch.End(); spriteBatch.Begin(); base.Draw(spriteBatch); }
public void AfterAllDetection() { if (CollidedList.Count > 0) { foreach (Entity one in CollidedList) { Intersection = Rectangle.Intersect(FutureBox, one.BoundBox); if (one.EntityCollision.FirstContact < min.EntityCollision.FirstContact) { third = two; two = min; min = one; } one.EntityCollision.Response(this); CurrentSprite.CollisionResponse(true); //tint sprite one.Sprite.CollisionResponse(true); //tint sprite } Intersection = Rectangle.Intersect(FutureBox, min.BoundBox); Response(min.EntityCollision); if (two != null && FutureBox.Intersects(two.BoundBox) && two != min) { Intersection = Rectangle.Intersect(FutureBox, two.BoundBox); Response(two.EntityCollision); } if (third != null && FutureBox.Intersects(third.BoundBox) && third != two && third != min) { Intersection = Rectangle.Intersect(FutureBox, third.BoundBox); Response(third.EntityCollision); } CollidedList.Clear(); } }
private async void ApplicationBarMenuItem_Texture(object sender, EventArgs e) { if (!IsSpriteSelected) { return; } var img = await ChoosePhotoAndInteropIsLoaded(); if (img != null) { switch ((sender as ApplicationBarMenuItem).Text) { case "main texture": CurrentSprite.SetMainTexture(img); break; case "blend texture": CurrentSprite.SetBlendTexture(img); break; case "mask texture": CurrentSprite.SetMaskTexture(img); break; } } }
public override void Update(GameTime gameTime, World world, Player player) { if (!world.Bounds.Contains(Hurtbox)) { ApplyForce(-2 * Vector2.Normalize(Hurtbox.Center.ToVector2() - world.Bounds.Center.ToVector2())); } else { foreach (PhysicalObject p in world.Stuff) { Vector2 distance = FeetPosition - p.FeetPosition; if (p != this && p is Bee && distance.Length() <= 50 && Velocity.Length() < 5) { //Console.WriteLine("collision between two bees"); if (distance.Length() <= 0.0001f) { distance = new Vector2(random.Next(0, 2) * 2 - 1, random.Next(0, 2) * 2 - 1); } Vector2 bounce = BeeBounceFactor * distance / (distance.Length() * distance.Length()); ApplyForce(bounce); p.ApplyForce(-bounce); } } } Velocity.Y *= AirFriction; CurrentSprite.UpdateFrame(gameTime); // mouvement brownien brownianVelocity += new Vector2((float)random.Next(-5, 5) / 200, (float)random.Next(-5, 5) / 200) - 0.002f * brownianPosition; brownianPosition += brownianVelocity; base.Update(gameTime, world, player); }
internal override void OnDraw(GraphicInfoList graphic, float fadeTime) { //テクスチャが同じなら、変化なし if (this.CurrentSprite != null && this.CurrentSprite.GraphicInfo == graphic.Main) { return; } //フェードアウト中のスプライトは消す if (FadeOutSprite != null) { FadeOutSprite.FadeOut(0, true); FadeOutSprite = null; } if (CurrentSprite != null) { //既にスプライトがあるならフェードアウトさせる FadeOutSprite = CurrentSprite; ///表示順は手前にする FadeOutSprite.LocalOrderInLayer = FadeOutSprite.LocalOrderInLayer + 1; FadeOutSprite.FadeOut(fadeTime, true); //テクスチャからスプライト作成 CurrentSprite = CreateSprite(graphic); } else { //新規スプライトがあるならフェードインさせる //テクスチャからスプライト作成 CurrentSprite = CreateSprite(graphic); CurrentSprite.FadeIn(fadeTime); } }
public void Draw(SpriteBatch sb) { #if DEBUG hitboxTexture = new Texture2D(sb.GraphicsDevice, 1, 1); // à terme, rendre la texture de hitbox générale? hitboxTexture.SetData(new[] { Color.Red }); sb.Draw(hitboxTexture, HitBox, Color.White * 0.5f); #endif CurrentSprite.Draw(sb, HorizontalFlip); }
//フェードアウト処理 internal override void OnFadeOut(float fadeTime) { CurrentSprite.FadeOut(fadeTime, true); if (FadeOutSprite) { FadeOutSprite.FadeOut(0, true); FadeOutSprite = null; } }
internal void SetCurrentSprite(TKey spriteKey, bool restartAnim) { if (Locked) { return; } CurrentSpriteKey = spriteKey; CurrentSprite.StartAnimation(); }
public void FlyUp() { CurrentSprite.Top -= 10; CurrentSprite.Left += 30; var resolution = Screen.PrimaryScreen.Bounds.Size; if (CurrentSprite.Left < 0 || CurrentSprite.Left > resolution.Width || CurrentSprite.Top < 10 || CurrentSprite.Top > resolution.Width) { CurrentSprite.Dispose(); } }
public virtual void Update(GameTime gameTime) { CurrentSprite.SetBoundingBox(); BoundingBox = CurrentSprite.BoundingBox; CurrentSprite.Origin = new Vector2(CurrentSprite.width / 2, CurrentSprite.height / 2); if (Life <= 0) { Console.WriteLine("Mob die"); Delete = true; } }
void UpdateSpriteRenderer() { if (CurrentSprite != null && CurrentSprite.uvs.Length > 0 && CurrentSprite.boundsData.Length > 1) { Sprite newSprite = null; if (spritesCache.ContainsKey(CurrentSprite) && (spritesCache[CurrentSprite] != null) && ((Sprite)spritesCache[CurrentSprite]) && Application.isPlaying) { newSprite = spritesCache[CurrentSprite] as Sprite; } else { Texture2D mainTexture = CurrentSprite.materialInst.mainTexture as Texture2D; Rect spriteRect = new Rect(mainTexture.width * CurrentSprite.uvs[0].x, mainTexture.height * CurrentSprite.uvs[0].y, CurrentSprite.boundsData[1].x, CurrentSprite.boundsData[1].y ); Bounds ub = CurrentSprite.GetUntrimmedBounds(); Bounds tb = CurrentSprite.GetBounds(); float shiftX = ub.size.x * 0.5f - ub.center.x + tb.center.x - tb.size.x * 0.5f; float shiftY = ub.size.y * 0.5f - ub.center.y + tb.center.y - tb.size.y * 0.5f; Vector2 shift = new Vector2(shiftX, shiftY); Vector2 anchorInPixels = new Vector2(AnchorPointVect2.x * ub.size.x, AnchorPointVect2.y * ub.size.y) - shift; Vector2 newAnchor = new Vector2(anchorInPixels.x / tb.size.x, anchorInPixels.y / tb.size.y); newSprite = Sprite.Create(mainTexture, spriteRect, newAnchor, PixelsPerMeter, 0, SpriteMeshType.FullRect, Vector4.zero); spritesCache.Remove(CurrentSprite); spritesCache.Add(CurrentSprite, newSprite); } if (SpriteRenderer != null) { SpriteRenderer.sprite = newSprite; } /* * if (UIImage != null) * { * UIImage.sprite = newSprite; * } */ } else { SpriteRenderer.sprite = null; } }
/// <summary> /// Finds a declaration (excluding methods) with the specified name /// </summary> /// <param name="name">The name of the declaration to search for.</param> /// <returns>The declaration with the specified name or null if not found.</returns> public IDeclaration GetDeclaration(string name) { // Project if (Project == null) { return(null); } IDeclaration superGlobalDeclaration = Project.GetDeclaration(name); if (superGlobalDeclaration != null) { return(superGlobalDeclaration); } // Sprite if (CurrentSprite == null) { return(null); } ITypedDeclaration globalDeclaration = CurrentSprite.GetDeclaration(name); if (globalDeclaration != null) { return(globalDeclaration); } // Methods if (CurrentScope == null) { return(null); } // Method params ParamDeclaration methodParam = (CurrentScope.Method as MethodDeclaration)?.FindParam(name); if (methodParam != null) { return(methodParam); } // Scoped variables return(CurrentScope.Search(name)); }
public override void Update(GameTime gameTime, World world, Player player) { WindBox = new Rectangle((int)FeetPosition.X + (direction - 1) * 400, (int)FeetPosition.Y - 200, 800, 200); CurrentSprite.UpdateFrame(gameTime); foreach (PhysicalObject p in world.Stuff) { if (WindBox.Contains(p.Hurtbox.Center)) { p.ApplyForce(new Vector2(direction * 0.1f, 0)); } } if (player.Hurtbox.Intersects(WindBox)) { player.ApplyForce(new Vector2(direction * 4.2f, 0)); } base.Update(gameTime, world, player); }
public void Update(List <InputType> playerInputs, float deltaTime, List <ICollidable> levelActors) { CurrentSprite.Update(deltaTime);//avant ou après ApplyPhysics? //Movement = Vector2.Zero; //this.deltaTime = deltaTime; //qu'est ce qui est le mieux entre stocker le dT ou le passer de méthode en méthode? //if (playerInputs.Count > 0) //{ // SortAndExecuteInput(playerInputs); //} //CurrentPosition += Movement; //currentSprite.CurrentPosition = CurrentPosition; //currentSprite.Update(deltaTime); SortAndExecuteInput(playerInputs, deltaTime); ApplyPhysics(playerInputs, deltaTime, levelActors); CurrentSprite.CurrentPosition = Position; XMovement = 0; }
public virtual void Detection(GameTime gameTime, ICollision collideObject) //detect IF it will collide. { if (FutureBox.Intersects(collideObject.CurrentEntity.BoundBox) && !collideObject.CurrentEntity.Dead) { third = two; two = min; collideObject.FirstContact = gameTime.ElapsedGameTime.Milliseconds; min = collideObject.CurrentEntity; CollidedList.Add(min); Intersection = Rectangle.Intersect(FutureBox, collideObject.CurrentSprite.BoundBox); } _elapsed += gameTime.ElapsedGameTime.Milliseconds; if (_elapsed >= Delay)//To show a black color for collision response. { CurrentSprite.CollisionResponse(false); collideObject.CurrentSprite.CollisionResponse(false); _elapsed = 0; } }
/// <summary> /// Override of Character Draw. Drawing a hero may need an offset due to attacking state. /// </summary> /// <param name="gameTime"></param> public override void Draw(GameTime gameTime) { if (this.State == CharacterState.Attacking) { SpriteContainer.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend); CurrentSprite.Draw(SpriteContainer, this.Position); SpriteContainer.End(); } else if (this.State == CharacterState.Hit) { float pulsate = GetPulsingValue(gameTime); //float pulsate = (float)Math.Sin(gameTime.TotalGameTime.TotalSeconds * 6) + 1; SpriteContainer.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend); CurrentSprite.Draw(SpriteContainer, this.Position, Color.Red, pulsate); SpriteContainer.End(); } else { base.Draw(gameTime); } }
public override void Update(GameTime gameTime) { movement_direction = 0; if (Input.keyboard.IsKeyDown(Keys.Left) && !Input.keyboard.IsKeyDown(Keys.Right)) { movement_direction = -1; } else if (!Input.keyboard.IsKeyDown(Keys.Left) && Input.keyboard.IsKeyDown(Keys.Right)) { movement_direction = 1; } if (PlayerPosition.Y >= GROUND_LEVEL) // ground or below ground { if (game_status == GameStatus.Win) { CurrentSprite = win; PlayerPosition.Y = GROUND_LEVEL; PlayerVelocity.Y = 0; PlayerVelocity.X = 0; } else { if (Input.keyboard.IsKeyDown(Keys.Up) || Input.keyboard.IsKeyDown(Keys.Z)) { PlayerVelocity.Y = -35; CurrentSprite = jump; jump_sound.Play(); } else { PlayerPosition.Y = GROUND_LEVEL; PlayerVelocity.Y = 0; CurrentSprite = idle; } if (movement_direction != 0) { CurrentSprite = walk; int speed = 11; // if(MiniGameManager.GetScore() > 9) speed = MiniGameManager.GetScore(); PlayerVelocity.X = movement_direction * speed; } } } else { CurrentSprite = jump; PlayerVelocity.Y += 2.9f; // gravity if (movement_direction != 0) { PlayerVelocity.X = movement_direction * 5; } } if (movement_direction == 0) { PlayerVelocity.X *= 0.8f; } else { direction = movement_direction; } if (game_status == GameStatus.Pending) { player_hitbox = new Rectangle((int)PlayerPosition.X - 100, (int)PlayerPosition.Y - 300, 200, 300); Vector2 pizza_to_remove = Vector2.Zero; foreach (Vector2 v in PizzaPositions) { if (player_hitbox.Contains(v)) { PizzaPositions.Remove(v); pizza_count++; if (pizza_count == total_pizza_count) { Win(); yay.Play(); } pizza_to_remove = v; pizza_collected.Play(); break; } } if (pizza_to_remove != Vector2.Zero) { PizzaPositions.Remove(pizza_to_remove); } } else if (game_status == GameStatus.Lose) { if (PizzaPositions.Count > 0) { foreach (Vector2 v in PizzaPositions) { DisplayObjects.Add(new Tuple <Vector2, Vector2, Sprite>(v, new Vector2(r.Next(-5, 5), -10), dark_pizza)); } PizzaPositions.Clear(); } } pizza_height = 10 * (float)Math.Cos(timer / 200); PlayerPosition += PlayerVelocity; CurrentSprite.direction = direction; List <Tuple <Vector2, Vector2, Sprite> > // this is dirty I'm sorry if you're reading this UpdatedObjects = new List <Tuple <Vector2, Vector2, Sprite> >() { }; foreach (Tuple <Vector2, Vector2, Sprite> o in DisplayObjects) { Vector2 NewPosition = o.Item1 + o.Item2; Vector2 NewVelocity = o.Item2 + new Vector2(0, 1); // Gravity Tuple <Vector2, Vector2, Sprite> UpdatedObject = new Tuple <Vector2, Vector2, Sprite>(NewPosition, NewVelocity, o.Item3); UpdatedObjects.Add(UpdatedObject); } DisplayObjects.Clear(); DisplayObjects.AddRange(UpdatedObjects); CurrentSprite.UpdateFrame(gameTime); background.UpdateFrame(gameTime); base.Update(gameTime); }
public override void Update(GameTime gameTime) { switch (CurrentState) { case eState.idle: inMovement = false; if (util.getDistance(Position, Player.Position) < RadiusVisionLength && basicAI.CanSeePlayer) { CurrentState = eState.walkTo; } break; case eState.walkTo: inMovement = true; if (util.getDistance(Position, spawnPosition) > 400) { CurrentState = eState.comeBack; } else if (util.getDistance(Position, Player.Position) > 20) { Vector2 pos = TileMap.GetTilePosAt((int)Position.X, (int)Position.Y, 0); Vector2 playerPos = TileMap.GetTilePosAt((int)Player.Position.X, (int)Player.Position.Y, 0); float angle = util.getAngle(Player.Position, Position); Direction = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)); if (util.getDistance(Position, Player.Position) > 200) { CurrentSpeed = SprintSpeed; } else { CurrentSpeed = Speed; } Position += Direction * CurrentSpeed; } else if (attackReady && CurrentSprite.count == 0) { CurrentSprite = AnimationList["attack"]; CurrentSprite.count = 0; CurrentState = eState.attack; } break; case eState.attack: inMovement = true; attackTimer += (float)gameTime.ElapsedGameTime.TotalSeconds; Console.WriteLine("test"); if (attackTimer > attackTime) { attackTimer = 0; Console.WriteLine("Attack"); CurrentSprite = AnimationList["walk"]; attackReady = false; CurrentState = eState.walkTo; } break; case eState.comeBack: inMovement = true; if (!(Position.X > spawnPosition.X - 1 && Position.X < spawnPosition.X + 1) && !(Position.Y > spawnPosition.Y - 1 && Position.Y < spawnPosition.Y + 1)) { float angle = util.getAngle(spawnPosition, Position); Direction = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)); Position += Direction * Speed; inMovement = true; } else { CurrentSprite.count = 0; CurrentState = eState.idle; } break; default: break; } if (!attackReady) { attackCooldownTimer += (float)gameTime.ElapsedGameTime.TotalSeconds;; if (attackCooldownTimer > attackCooldown) { attackReady = true; attackCooldownTimer = 0; } } if (inMovement) { CurrentSprite.Update(gameTime); } for (int i = 0; i < SceneGameplay.enemieManager.lstEnemies.Count; i++) { Enemie friend = SceneGameplay.enemieManager.lstEnemies[i]; if (util.getDistance(Position, friend.Position) < 100) { if ((friend.CurrentState == Enemie.eState.attack || friend.CurrentState == Enemie.eState.walkTo) && (CurrentState == eState.idle) && friend != this && basicAI.CanSeePlayer) { Aggro(); } } } if (util.getDistance(Position, Player.Position) < MainGame.ScreenWidth) { basicAI.Update(gameTime); } base.Update(gameTime); }
public override void Update(GameTime gameTime, World world, Player player) { this.world = world; KeyboardState KbState = Keyboard.GetState(); if (PreviousState == CurrentState) { state_frames += 1; } else { state_frames = 0; } PreviousState = CurrentState; switch (CurrentState) { case PlayerState.idle: /*if (KbState.IsKeyDown(Input.Left) && KbState.IsKeyUp(Input.Right)) * { * if (Velocity.X > -MaxSpeed) * ApplyForce(new Vector2(-2f, 0)); * CurrentState = PlayerState.walk; * } else if (KbState.IsKeyDown(Input.Right)) * { * if (Velocity.X < MaxSpeed) * ApplyForce(new Vector2(2f, 0)); * CurrentState = PlayerState.walk; * }*/ if (!IsOnGround(world)) { CurrentState = PlayerState.jump; } else if (Input.direction != 0) { CurrentState = PlayerState.walk; } else if (KbState.IsKeyDown(Input.Jump)) { ApplyForce(new Vector2(0, -15f)); SoundEffectPlayer.Play(jump, 1f, 0f); if (Input.direction != 0) { PlayerDirection = Input.direction; } CurrentState = PlayerState.jump; } break; case PlayerState.walk: if (KbState.IsKeyDown(Input.Jump)) { // Velocity = 0; if (Input.direction != 0) { PlayerDirection = Input.direction; } ApplyForce(new Vector2(0, -15f)); SoundEffectPlayer.Play(jump, 1f, 0f); CurrentState = PlayerState.jump; } else if (!IsOnGround(world)) { CurrentState = PlayerState.jump; } else if (Input.direction != 0) // player is inputing a direction (either left or right) { PlayerDirection = Input.direction; if (Math.Sign(Velocity.X) * Math.Sign(Input.direction) >= 0) // if inputed direction is the same as current movement direction { if (Velocity.X * Velocity.X < MaxSpeed * MaxSpeed) // if norm of velocity below max speed { ApplyForce(new Vector2(Input.direction * 5f, 0)); } } else // if player is inputing the direction against the current movement (brake) { ApplyForce(new Vector2(Input.direction * 5f, 0)); } } else { CurrentState = PlayerState.idle; } break; case PlayerState.jump: if (Velocity.Y < 0 && Velocity.X != 0) { PlayerDirection = Math.Sign(Velocity.X); // raising } if (KbState.IsKeyDown(Input.Jump) && !prevKbState.IsKeyDown(Input.Jump)) { Velocity.Y = 0; //if (Input.direction == 0) SoundEffectPlayer.Play(jump, 1f, 0.5f); ApplyForce(new Vector2(0, -15)); //else //{ // PlayerDirection = Input.direction; // ApplyForce(new Vector2(Input.direction * 50, -8)); // } CurrentState = PlayerState.doublejump; } else if (Input.direction != 0) // player is inputing a direction (either left or right) { if ((Velocity.X + Input.direction) * Math.Sign(Velocity.X) <= MaxSpeed) { ApplyForce(new Vector2(Input.direction * 5f, 0)); } } if (IsOnGround(world)) { CurrentState = PlayerState.idle; } break; case (PlayerState.doublejump): { if (Velocity.Y < 0 && Velocity.X != 0) { PlayerDirection = Math.Sign(Velocity.X); // raising } if (IsOnGround(world)) { CurrentState = PlayerState.idle; } else if (Input.direction != 0) // player is inputing a direction (either left or right) { if ((Velocity.X + Input.direction) * Math.Sign(Velocity.X) <= MaxSpeed) { ApplyForce(new Vector2(Input.direction * 5f, 0)); } } break; } case (PlayerState.flip): { if (CurrentSprite.isOver && state_frames > 200) { world.NextLevel(this); //do something like next level; CurrentState = PlayerState.idle; } break; } } // // SPRITE DETERMINATION // PreviousSprite = CurrentSprite; switch (CurrentState) { case (PlayerState.idle): { if (Velocity.X * Velocity.X < 1) { CurrentSprite = idle; } else { CurrentSprite = brake; } break; } case (PlayerState.walk): { CurrentSprite = run; break; } case (PlayerState.jump): { if (Velocity.Y < -1) { CurrentSprite = rise; } else if (Velocity.Y > 1) { CurrentSprite = fall; } else { CurrentSprite = top; } break; } case (PlayerState.doublejump): { if (Velocity.Y < 3) { CurrentSprite = roll; } else { CurrentSprite = fall; } break; } case (PlayerState.flip): { CurrentSprite = flip; break; } } /*if (Input.double_tap_waiting && IsOnGround(world) && CurrentSprite != slug_walk) * { * CurrentSprite = slug_charge_attack; * PlayerDirection = Input.direction; * }*/ if (CurrentSprite != PreviousSprite) { CurrentSprite.ResetAnimation(); //Console.WriteLine("Switched to sprite " + CurrentSprite.Texture.Name); } CurrentSprite.direction = PlayerDirection; CurrentSprite.UpdateFrame(gameTime); foreach (PhysicalObject o in world.Stuff) { if (o is Bee b) { b.AttractFromPlayer(this); if (Hurtbox.Intersects(b.Hurtbox)) { //Console.WriteLine("collision between bee and player"); world.RemovedStuff.Add(b); SoundEffectPlayer.Play(bee_collected, 0.08f, (float)(r.NextDouble() * 0.2)); } } // do something; } prevKbState = KbState; base.Update(gameTime, world, this); }
public override void Draw(SpriteBatch spriteBatch) { CurrentSprite.DrawFromFeet(spriteBatch, FeetPosition + brownianPosition); }
public virtual void Draw(SpriteBatch spriteBatch) { CurrentSprite.Position = Position; CurrentSprite.Draw(spriteBatch); }
public virtual void Draw(SpriteBatch spriteBatch) { CurrentSprite.DrawFromFeet(spriteBatch, new Vector2(FeetPosition.X, FeetPosition.Y + 1)); }
/// <summary> /// Octorok Drawing rotates based on direction /// </summary> /// <param name="gameTime"></param> public override void Draw(GameTime gameTime) { SpriteContainer.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend); CurrentSprite.Draw(SpriteContainer, this.Position, this.ObjectDirection); SpriteContainer.End(); }
public override void Draw(SpriteBatch spriteBatch) { CurrentSprite.DrawFromFeet(spriteBatch, FeetPosition + new Vector2(0, 8)); //base.Draw(spriteBatch); }
public void Update(GameTime time) { CurrentSprite.Update(time); }