// TODO: extract 9 element scaling into separate class, use it also for bars public GUIBox(Vector2 pos, Vector2 size, Func <bool> shouldShow = null) : base(pos, size, Game.guiResourceLoader.GetResource(GUI_SHEET) as Texture, size / REGION_SIZE, shouldShow) { Texture tex = Game.guiResourceLoader.GetResource(GUI_SHEET) as Texture; for (int x = 0; x < 3; ++x) { for (int y = 0; y < 3; ++y) { Sprite s = (x == 1 && y == 1) ? sprite : new Sprite(); s.Texture = tex; s.RegionEnabled = true; s.RegionRect = new Rect2(x * REGION_SIZE, y * REGION_SIZE, REGION_SIZE, REGION_SIZE); if (!(x == 1 && y == 1)) { s.SetPosition(size / 2 * new Vector2(x - 1, y - 1)); if (x == 1 && y != 1) { s.SetScale(new Vector2(size.x / REGION_SIZE, 1)); } else if (y == 1 && x != 1) { s.SetScale(new Vector2(1, size.y / REGION_SIZE)); } AddChild(s); } } } }
private void HandleMovement() { if (Input.IsActionPressed("dpad_left")) { moveVelocity.x = Utils.Approach(moveVelocity.x, -moveSpeed, moveAcceleration); sprite.SetScale(new Vector2(-1.0f, 1.0f)); if (animationPlayback.IsPlaying()) { animationPlayback.Travel("run"); } } else if (Input.IsActionPressed("dpad_right")) { moveVelocity.x = Utils.Approach(moveVelocity.x, moveSpeed, moveAcceleration); sprite.SetScale(new Vector2(1.0f, 1.0f)); if (animationPlayback.IsPlaying()) { animationPlayback.Travel("run"); } } else { moveVelocity.x = Utils.Approach(moveVelocity.x, 0.0f, moveFriction); if (animationPlayback.IsPlaying()) { animationPlayback.Travel("stand"); } } }
protected void SetIconAnimation() { if (myActiveAnimation != EIconActiveAnimation.None) { // do active animation stuff } else { switch (myPassiveAnimation) { case EIconPassiveAnimation.Squeeze: myIcon.SetScale(new Vector2(1.1f, 0.8f)); myIcon.SetPosition(myIcon.GetPosition() + new Vector2(-GetTileSize() * 0.05f, GetTileSize() * 0.2f)); break; case EIconPassiveAnimation.Jump: const float FramesBetweenJumps = 10.0f; float wrappedFrames = FrameCounter.GetCurrentFrame() / FramesBetweenJumps; float jumpProgress = (float)Math.Abs(Math.Sin(wrappedFrames)); const float JumpHeightPercent = 0.05f; //float extraXScale = (1f - jumpProgress) * 0.1f; //myIcon.SetScale(new Vector2(1f + extraXScale, 1f)); myIcon.SetPosition(myIcon.GetPosition() + new Vector2(0.0f, -JumpHeightPercent * GetTileSize() * jumpProgress)); // + new Vector2(-extraXScale / 2f, 0.0f)); break; case EIconPassiveAnimation.None: myIcon.SetScale(new Vector2(1.0f, 1.0f)); break; default: break; } } }
public override void _PhysicsProcess(float delta) { string newAnimation = "idle"; if (_state == StateWalking) { _linearVelocity += GravityVec * delta; _linearVelocity.x = _direction * WalkSpeed; _linearVelocity = MoveAndSlide(_linearVelocity, FloorNormal); if ((!_detectFloorLeft.IsColliding()) || (_detectWallLeft.IsColliding())) { _direction = 1; } if ((!_detectFloorRight.IsColliding()) || (_detectWallRight.IsColliding())) { _direction = -1; } _sprite.SetScale(new Vector2(_direction, 1)); newAnimation = "walk"; } else { newAnimation = "explode"; } if (_anim != newAnimation) { _anim = newAnimation; ((AnimationPlayer)GetNode("anim")).Play(_anim); } }
public void UpdateSprite() { if (Owner.AlongVelocity) { Vector3 zero = Vector3.zero; if (!(LastWorldPos != Vector3.zero)) { return; } zero = CurWorldPos - LastWorldPos; if (zero != Vector3.zero) { CurDirection = zero; Sprite.SetRotationTo(CurDirection); } } Sprite.SetScale(Scale.x * OriScaleX, Scale.y * OriScaleY); if (Owner.ColorAffectorEnable) { Sprite.SetColor(Color); } if (Owner.UVAffectorEnable) { Sprite.SetUVCoord(LowerLeftUV, UVDimensions); } Sprite.SetRotation((float)OriRotateAngle + RotateAngle); Sprite.SetPosition(CurWorldPos); Sprite.Update(force: false); }
public Enemy(TextureManager textureManager) { _spaceship.Texture = textureManager.Get("enemy_ship"); _spaceship.SetScale(_scale, _scale); _spaceship.SetRotation(Math.PI); // make it face the player _spaceship.SetPosition(200, 0); // put it somewhere easy to see }
public void UpdateSprite() { ////set direction if (Owner.AlongVelocity) { Vector3 curDir = Vector3.zero; if (LastWorldPos != Vector3.zero) { curDir = CurWorldPos - LastWorldPos; } else {//LastWorldPos = zero means first update. return; } if (curDir != Vector3.zero) { CurDirection = curDir; Sprite.SetRotationTo(CurDirection); } } Sprite.SetScale(Scale.x * OriScaleX, Scale.y * OriScaleY); if (Owner.ColorAffectorEnable) { Sprite.SetColor(Color); } if (Owner.UVAffectorEnable) { Sprite.SetUVCoord(LowerLeftUV, UVDimensions); } Sprite.SetRotation((float)OriRotateAngle + RotateAngle); Sprite.SetPosition(CurWorldPos); Sprite.Update(false); }
public PulsateEffect(Sprite sprite, Func <bool> whenToInvoke = null, float lastScale = 1f, float pulsateSpeed = 6f, float range = 0.08f, string toUpperOrLower = "Upper") : base(sprite, true) { SetWhenToInvoke(whenToInvoke); SetOriginalScale(lastScale); SetPulsateSpeed(pulsateSpeed); SetPulsateRange(range); SetToUpperOrLower(toUpperOrLower); SetTask(() => { if (WhenToInvoke == null) { return; } if (WhenToInvoke()) { Sprite.SetScale(Pulsate(OriginalScale, Speed, Range, ToUpperOrLower)); Sprite.IsPulsating = true; } else { if (Sprite.Scale.ToString("0.0") != OriginalScale.ToString("0.0")) { var difference = Math.Abs(Sprite.Scale - OriginalScale); if (Sprite.Scale > OriginalScale) { Sprite.SetScale(Sprite.Scale - (difference > Range ? Range : difference)); // Sprite.Scale = MathHelper.Clamp(Sprite.Scale, OriginalScale, Sprite.Scale); } else { Sprite.SetScale(Sprite.Scale + (difference > Range ? Range : difference)); // Sprite.Scale = MathHelper.Clamp(Sprite.Scale, Sprite.Scale, OriginalScale); } //Sprite.Scale = OriginalScale > Sprite.Scale ? Sprite.Scale + (MathHelper.Clamp(Range,Range,OriginalScale - Range)) : Sprite.Scale - (Sprite.Scale - OriginalScale); return; } else { Sprite.SetScale(OriginalScale); } Sprite.IsPulsating = false; } }); }
private void numericUpDown1_ValueChanged(object sender, EventArgs e) { if (mSprite == null) { return; } mSprite.SetScale((double)nudScale.Value, (double)nudScale.Value); }
public void Main(string[] args) { using (AgateSetup setup = new AgateSetup(args)) { setup.Initialize(true, false, false); if (setup.WasCanceled) { return; } DisplayWindow wind = DisplayWindow.CreateWindowed("Rotating sprite", 300, 300); Sprite sp = new Sprite("spike.png", 16, 16); sp.RotationCenter = OriginAlignment.Center; sp.DisplayAlignment = OriginAlignment.Center; sp.RotationAngleDegrees = 90; sp.SetScale(2, 2); Point location = new Point(150, 100); while (wind.IsClosed == false) { Display.BeginFrame(); Display.Clear(Color.DarkRed); sp.RotationAngleDegrees += 180 * Display.DeltaTime / 1000.0; sp.Draw(location); Display.DrawRect(location.X, location.Y, 1, 1, Color.YellowGreen); Display.EndFrame(); Core.KeepAlive(); if (Keyboard.Keys[KeyCode.F5]) { if (wind.IsFullScreen) { wind.SetWindowed(); wind.Size = new Size(500, 500); } else { wind.SetFullScreen(800, 600, 32); } Keyboard.ReleaseKey(KeyCode.F5); } if (Keyboard.Keys[KeyCode.Escape]) { return; } } } }
protected override void OnSceneStart() { sp = new Sprite("Images/spike.png", 16, 16) { RotationCenter = OriginAlignment.Center, DisplayAlignment = OriginAlignment.Center, RotationAngleDegrees = 90 }; sp.SetScale(2, 2); }
public virtual void SetSprite(string aTextureName, Point aPosition, Point aSize, bool aSetScale) // todo default args pls { SetSprite(aTextureName, aPosition); myHotspot.Width = (int)mySprite.GetSize().X; myHotspot.Height = (int)mySprite.GetSize().Y; if (aSetScale) { mySprite.SetScale(new Vector2(aSize.X, aSize.Y)); myHotspot.Width *= aSize.X; myHotspot.Height *= aSize.Y; } }
private void UpdatePowerupTimer(GameTime gameTime) { if (powerUpInSlot != null && _powerupTimer > 0) { _timerText.CenterText(new Rectangle((int)powerUpInSlot.position.X, (int)powerUpInSlot.position.Y, 32, 32), true, true); _powerupTimer -= gameTime.ElapsedGameTime.Milliseconds; if (_powerupTimer <= 0) { switch (powerUpInSlot.Type) { case Powerup.PowerupType.Speed: _movementSpeed = 3f; break; case Powerup.PowerupType.BigAmmo: _hasBigAmmo = false; if (_chargeLevel == 1) { _scale = 1f; cannon.SetScale(1f); } break; case Powerup.PowerupType.AttackSpeed: _hasFastAttack = false; coolDownTime = 300; break; } powerUpInSlot = null; } } }
private void SetupGorgon() { Gorgon.Initialize(true, false); Gorgon.SetMode(this); //Gorgon.AllowBackgroundRendering = true; //Gorgon.Screen.BackgroundColor = Color.FromArgb(50, 50, 50); //Gorgon.CurrentClippingViewport = new Viewport(0, 20, Gorgon.Screen.Width, Gorgon.Screen.Height - 20); //PreciseTimer preciseTimer = new PreciseTimer(); //Gorgon.MinimumFrameTime = PreciseTimer.FpsToMilliseconds(66); Gorgon.Idle += new FrameEventHandler(Gorgon_Idle); Gorgon.FrameStatsVisible = true; bouncesprite = new Sprite("bouncey", GorgonLibrary.Graphics.Image.FromFile(mediadir + @"\textures\0_Items.png"), new Vector2D(0, 0), new Vector2D(22, 20)); bouncesprite.SetScale(3, 3); decalsprite = new Sprite("decal", GorgonLibrary.Graphics.Image.FromFile(mediadir + @"\textures\0_Decals.png"), new Vector2D(56, 0), new Vector2D(103, 29)); decalsprite.SetScale(1, 1); decalShader = FXShader.FromFile(mediadir + @"\shaders\decalshader.fx", ShaderCompileOptions.Debug); decalShader.Parameters["tex1"].SetValue(decalsprite.Image); baseTarget = new RenderImage("baseTarget", 32, 32, ImageBufferFormats.BufferRGB888A8); baseTargetSprite = new Sprite("baseTargetSprite", baseTarget); bounceysprites = new BounceySprite[10]; for (int i = 0; i < 10; i++) { bounceysprites[i] = new BounceySprite(bouncesprite, new Vector2D(random.Next(0, Gorgon.Screen.Width), random.Next(0, Gorgon.Screen.Height)), new Vector2D((float)random.Next(-100000, 100000) / 100000, (float)random.Next(-100000, 100000) / 100000), decalsprite, new Vector2D(random.Next(-10, 15), random.Next(-10, 15)), decalShader, this); } //Calculate decal texcoord offsets /*Vector2D decalBToffset = new Vector2D(10,5); * float BTXDTL_x = decalBToffset.X / bouncesprite.Image.Width; * float BTXDTL_y = decalBToffset.Y / bouncesprite.Image.Height; * float BTXDBR_x = (decalBToffset.X + decalsprite.Width)/bouncesprite.Image.Width; * float BTXDBR_y = (decalBToffset.Y + decalsprite.Height)/bouncesprite.Image.Height; * float CFx = (float)decalsprite.Image.Width/(float)bouncesprite.Image.Width; * float CFy = (float)decalsprite.Image.Height / (float)bouncesprite.Image.Height; * float DOtc_xtl = (float)decalsprite.ImageOffset.X / (float)decalsprite.Image.Width; * float DOtc_ytl = (float)decalsprite.ImageOffset.Y / (float)decalsprite.Image.Height; * * Vector4D decalParms1 = new Vector4D(BTXDTL_x, BTXDTL_y, BTXDBR_x, BTXDBR_y); * Vector4D decalParms2 = new Vector4D(CFx, CFy, DOtc_xtl, DOtc_ytl);*/ }
private void SetupGorgon() { Gorgon.Initialize(true, false); Gorgon.SetMode(this); //Gorgon.AllowBackgroundRendering = true; //Gorgon.Screen.BackgroundColor = Color.FromArgb(50, 50, 50); //Gorgon.CurrentClippingViewport = new Viewport(0, 20, Gorgon.Screen.Width, Gorgon.Screen.Height - 20); //PreciseTimer preciseTimer = new PreciseTimer(); //Gorgon.MinimumFrameTime = PreciseTimer.FpsToMilliseconds(66); Gorgon.Idle += new FrameEventHandler(Gorgon_Idle); Gorgon.FrameStatsVisible = true; bouncesprite = new Sprite("bouncey", GorgonLibrary.Graphics.Image.FromFile(mediadir + @"\textures\0_Items.png"), new Vector2D(0,0), new Vector2D(22,20)); bouncesprite.SetScale(3, 3); decalsprite = new Sprite("decal", GorgonLibrary.Graphics.Image.FromFile(mediadir + @"\textures\0_Decals.png"), new Vector2D(56,0), new Vector2D(103,29)); decalsprite.SetScale(1, 1); decalShader = FXShader.FromFile(mediadir + @"\shaders\decalshader.fx", ShaderCompileOptions.Debug); decalShader.Parameters["tex1"].SetValue(decalsprite.Image); baseTarget = new RenderImage("baseTarget", 32, 32, ImageBufferFormats.BufferRGB888A8); baseTargetSprite = new Sprite("baseTargetSprite", baseTarget); bounceysprites = new BounceySprite[10]; for (int i = 0; i < 10; i++) { bounceysprites[i] = new BounceySprite(bouncesprite, new Vector2D(random.Next(0, Gorgon.Screen.Width), random.Next(0, Gorgon.Screen.Height)), new Vector2D((float)random.Next(-100000,100000) / 100000, (float)random.Next(-100000,100000) / 100000), decalsprite, new Vector2D(random.Next(-10,15), random.Next(-10,15)), decalShader, this); } //Calculate decal texcoord offsets /*Vector2D decalBToffset = new Vector2D(10,5); float BTXDTL_x = decalBToffset.X / bouncesprite.Image.Width; float BTXDTL_y = decalBToffset.Y / bouncesprite.Image.Height; float BTXDBR_x = (decalBToffset.X + decalsprite.Width)/bouncesprite.Image.Width; float BTXDBR_y = (decalBToffset.Y + decalsprite.Height)/bouncesprite.Image.Height; float CFx = (float)decalsprite.Image.Width/(float)bouncesprite.Image.Width; float CFy = (float)decalsprite.Image.Height / (float)bouncesprite.Image.Height; float DOtc_xtl = (float)decalsprite.ImageOffset.X / (float)decalsprite.Image.Width; float DOtc_ytl = (float)decalsprite.ImageOffset.Y / (float)decalsprite.Image.Height; Vector4D decalParms1 = new Vector4D(BTXDTL_x, BTXDTL_y, BTXDBR_x, BTXDBR_y); Vector4D decalParms2 = new Vector4D(CFx, CFy, DOtc_xtl, DOtc_ytl);*/ }
public override void _Process(float delta) { Vector2 newPos = (GetPosition() + dir * speed * delta); float dist = GetPosition().DistanceTo(newPos); SetPosition(newPos); float progress = origin.DistanceTo(GetPosition()) / origin.DistanceTo(targetPos); pellet.SetPosition(QuadraticBezier(new Vector2(0, 0), new Vector2(50 * -dir.y, 50 * -dir.x), new Vector2(0, 0), progress)); pellet.SetScale(QuadraticBezier(new Vector2(1, 1), new Vector2(1.5f, 1.5f), new Vector2(1, 1), progress)); if (origin.DistanceTo(targetPos) <= origin.DistanceTo(GetPosition())) { Hit(); } }
void CreateLogo() { // Get logo texture ResourceCache cache = GetSubsystem <ResourceCache>(); Texture2D logoTexture = cache.GetResource <Texture2D>("Textures/FishBoneLogo.png"); if (!logoTexture) { return; } // Create logo sprite and add to the UI layout UI ui = GetSubsystem <UI>(); logoSprite_ = ui.GetRoot().CreateChild <Sprite>(); // Set logo sprite texture logoSprite_.SetTexture(logoTexture); int textureWidth = logoTexture.GetWidth(); int textureHeight = logoTexture.GetHeight(); // Set logo sprite scale logoSprite_.SetScale(256.0f / textureWidth); // Set logo sprite size logoSprite_.SetSize(textureWidth, textureHeight); // Set logo sprite hot spot logoSprite_.SetHotSpot(textureWidth, textureHeight); // Set logo sprite alignment logoSprite_.SetAlignment(HorizontalAlignment.HA_RIGHT, VerticalAlignment.VA_BOTTOM); // Make logo not fully opaque to show the scene underneath logoSprite_.SetOpacity(0.9f); // Set a low priority for the logo so that other UI elements can be drawn on top logoSprite_.SetPriority(-100); }
private void UpdateScale() { if (_scaleSettings is not null) { if (Sprite.Position.Y < _scaleSettings.StartAtY) { Sprite.SetScale(_scaleSettings.MinScale / 100); } else if (Sprite.Position.Y > _scaleSettings.StartAtY && Sprite.Position.Y < _scaleSettings.EndAtY) { var scaleAreaHeight = _scaleSettings.EndAtY - _scaleSettings.StartAtY; var scaleDiff = _scaleSettings.MaxScale - _scaleSettings.MinScale; var percentageInArea = (Sprite.Position.Y - _scaleSettings.StartAtY) / scaleAreaHeight; var scale = scaleDiff * percentageInArea + _scaleSettings.MinScale; Sprite.SetScale(scale / 100); } else { Sprite.SetScale(_scaleSettings.MaxScale / 100); } } }
void CreateLogo() { cache = ResourceCache; var logoTexture = cache.GetTexture2D("Textures/LogoLarge.png"); if (logoTexture == null) { return; } ui = UI; logoSprite = ui.Root.CreateSprite(); logoSprite.Texture = logoTexture; int w = logoTexture.Width; int h = logoTexture.Height; logoSprite.SetScale(256.0f / w); logoSprite.SetSize(w, h); logoSprite.SetHotSpot(0, h); logoSprite.SetAlignment(HorizontalAlignment.Left, VerticalAlignment.Bottom); logoSprite.Opacity = 0.75f; logoSprite.Priority = -100; }
public override void _Process(float delta) { // Called every frame. Delta is time since last frame. // Update game logic here. //update timer spawnTimer += delta; //if timer >= spawn time, spawn a candy at a random position if (spawnTimer >= spawnTime) { spawnCandy(); spawnTimer = 0; } //update score text with score scoreText.Text = "Score: " + score.ToString(); //update life bar scale width with the life of the dragon lifeBar.SetScale(new Vector2(Dragon.life, 1)); //reduce game time gameTime -= delta; //if game time <= 0 game over if (gameTime <= 0) { GetTree().ChangeScene("GameOver.scn"); } //if dragon life <= 0 game over if (Dragon.life <= 0) { GetTree().ChangeScene("GameOver.scn"); } }
void CreateSprites() { var cache = ResourceCache; var graphics = Graphics; UI ui = UI; // Get the Urho3D fish texture Texture2D decalTex = cache.GetTexture2D("Textures/UrhoDecal.dds"); for (uint i = 0; i < NumSprites; ++i) { // Create a new sprite, set it to use the texture Sprite sprite = new Sprite(); sprite.Texture = decalTex; // The UI root element is as big as the rendering window, set random position within it sprite.Position = new IntVector2((int) (NextRandom()*graphics.Width), (int) (NextRandom()*graphics.Height)); // Set sprite size & hotspot in its center sprite.Size = new IntVector2(128, 128); sprite.HotSpot = new IntVector2(64, 64); // Set random rotation in degrees and random scale sprite.Rotation = NextRandom()*360.0f; sprite.SetScale(NextRandom(1.0f) + 0.5f); // Set random color and additive blending mode sprite.SetColor(new Color(NextRandom(0.5f) + 0.5f, NextRandom(0.5f) + 0.5f, NextRandom(0.5f) + 0.5f)); sprite.BlendMode = BlendMode.Add; // Add as a child of the root UI element ui.Root.AddChild(sprite); // Store sprites to our own container for easy movement update iteration spritesWithVelocities[sprite] = new Vector2(NextRandom(200.0f) - 100.0f, NextRandom(200.0f) - 100.0f); } }
void CreateSprites() { var cache = ResourceCache; var graphics = Graphics; UI ui = UI; // Get the Urho3D fish texture Texture2D decalTex = cache.GetTexture2D("Textures/UrhoDecal.dds"); for (uint i = 0; i < NumSprites; ++i) { // Create a new sprite, set it to use the texture Sprite sprite = new Sprite(); sprite.Texture = decalTex; // The UI root element is as big as the rendering window, set random position within it sprite.Position = new IntVector2((int)(NextRandom() * graphics.Width), (int)(NextRandom() * graphics.Height)); // Set sprite size & hotspot in its center sprite.Size = new IntVector2(128, 128); sprite.HotSpot = new IntVector2(64, 64); // Set random rotation in degrees and random scale sprite.Rotation = NextRandom() * 360.0f; sprite.SetScale(NextRandom(1.0f) + 0.5f); // Set random color and additive blending mode sprite.SetColor(new Color(NextRandom(0.5f) + 0.5f, NextRandom(0.5f) + 0.5f, NextRandom(0.5f) + 0.5f)); sprite.BlendMode = BlendMode.Add; // Add as a child of the root UI element ui.Root.AddChild(sprite); // Store sprites to our own container for easy movement update iteration spritesWithVelocities[sprite] = new Vector2(NextRandom(200.0f) - 100.0f, NextRandom(200.0f) - 100.0f); } }
private void AnimateBlendIn(float delta) { _iconSprite.Rotation = MathHelper.SmoothStep(0.0f, 1.0f, delta) * MathHelper.TwoPi; _iconSprite.SetScale(MathHelper.SmoothStep(0.0f, 1.0f, delta)); _iconSprite.Alpha = delta; }
public SpriteTile(string file, Vector3 pos, float scalex, float scaley) { Sprite = SpriteManager.AddSprite(file); Sprite.Position = pos; Sprite.SetScale(scalex, scaley); }
public void SetScale(double x, double y) { _background.SetScale(x, y); }
double _speed = 512; // pixels per second public PlayerCharacter(TextureManager textureManager) { _spaceship.Texture = textureManager.Get("player_ship"); _spaceship.SetScale(0.5, 0.5); // spaceship is quite big, scale it down. }
void CreateLogo() { cache = ResourceCache; var logoTexture = cache.GetTexture2D("Textures/LogoLarge.png"); if (logoTexture == null) return; ui = UI; logoSprite = ui.Root.CreateSprite(); logoSprite.Texture = logoTexture; int w = logoTexture.Width; int h = logoTexture.Height; logoSprite.SetScale(256.0f / w); logoSprite.SetSize(w, h); logoSprite.SetHotSpot(0, h); logoSprite.SetAlignment(HorizontalAlignment.Left, VerticalAlignment.Bottom); logoSprite.Opacity = 0.75f; logoSprite.Priority = -100; }
public override void _PhysicsProcess(float delta) { // increment counters _onAirTime += delta; _shootTime += delta; // MOVEMENT // apply gravity _linearVelocity += delta * GravityVec; // Move and Slide _linearVelocity = MoveAndSlide(_linearVelocity, FloorNormal, SlopeSlideStop); // Detect floor if (IsOnFloor()) { _onAirTime = 0; } _onFloor = _onAirTime < MinOnAirTime; // CONTROL // Horizontal Movement float targetSpeed = 0f; if (Input.IsActionPressed("move_left")) { targetSpeed += -1; } if (Input.IsActionPressed("move_right")) { targetSpeed += 1; } targetSpeed *= WalkSpeed; _linearVelocity.x = Mathf.Lerp(_linearVelocity.x, targetSpeed, 0.1f); // Jumping if (_onFloor && Input.IsActionJustPressed("jump")) { _linearVelocity.y = -JumpSpeed; _jumpSound.Play(); } // Shooting if (Input.IsActionJustPressed("shoot")) { // Preload is currently not available in c# //auto bullet = Preload RigidBody2D bullet = (RigidBody2D)_bulletScene.Instance(); bullet.Position = ((Position2D)GetNode("sprite/bullet_shoot")).GlobalPosition; bullet.LinearVelocity = new Vector2(_sprite.Scale.x * BulletVelocity, 0); bullet.AddCollisionExceptionWith(this); GetParent().AddChild(bullet); _shootSound.Play(); _shootTime = 0; } // ANIMATION string newAnimation = "idle"; if (_onFloor) { if (_linearVelocity.x < -SidingChangeSpeed) { _sprite.SetScale(new Vector2(-1, 1)); newAnimation = "run"; } if (_linearVelocity.x > SidingChangeSpeed) { _sprite.SetScale(new Vector2(1, 1)); newAnimation = "run"; } } else { // We want the character to immediately change facing side when the player // tries to change direction, during air control. // This allows for example the player to shoot quickly left then right. if (Input.IsActionPressed("move_left") && !Input.IsActionPressed("move_right")) { _sprite.SetScale(new Vector2(-1, 1)); } if (Input.IsActionPressed("move_right") && !Input.IsActionPressed("move_left")) { _sprite.SetScale(new Vector2(1, 1)); } if (_linearVelocity.y < 0) { newAnimation = "jumping"; } else { newAnimation = "falling"; } } if (_shootTime < ShootTimeShowWeapon) { newAnimation += "_weapon"; } if (newAnimation != _anim) { _anim = newAnimation; ((AnimationPlayer)GetNode("anim")).Play(_anim); } }