public bool BuildingInRange(float range) { float distance = Mathf.Sqrt(Mathf.Pow(PlayerMouvements.GetX() - location.x, 2) + Mathf.Pow(PlayerMouvements.GetY() - location.y, 2)); return(distance <= range); }
public void _on_Area2D_area_shape_entered(int id, Area2D area, int areaShape, int selfShape) { /* REcuperation des loots*/ if (area.GetGroups().Contains("loot")) { /*On a un loot*/ Loot loot = area.GetNode <Loot>(".."); bool canAdd = Player.inventoryItems.CanAdd(loot.GetLootType(), loot.GetLootAmount()); Player.inventoryItems.Add(loot.GetLootType(), Player.inventoryItems.GetAmountCanAdd(loot.GetLootType(), loot.GetLootAmount())); area.RemoveFromGroup("loot"); if (canAdd) { PlayerMouvements.PlaySound(Sounds.Type.PlayerGetloot); loot.QueueFree(); } else { loot.Explosion(); loot.dead = true; loot.GetNode <Sprite>("img").Visible = false; Delay.StartDelay(loot, 0.3f, () => loot.QueueFree()); } } }
public override void _Process(float delta) { if (PlayerState.Is(PlayerState.State.Pause)) { return; } Vector2 playerPosition = new Vector2(PlayerMouvements.GetX(), PlayerMouvements.GetY()); List <Building> buildingsNear = new List <Building>(); int x = (int)(playerPosition.x - radius); x = Chunk.size * Mathf.FloorToInt(x / (float)Chunk.size); for (; x <= (int)(playerPosition.x + radius); x += Chunk.size) { Chunk c = World.GetChunk(x); List <Building> l = World.placedBuildingByChunk[c]; foreach (var b in l) { buildingsNear.Add(b); } } RemoveLine(); foreach (var b in buildingsNear) { if (isInRange(b, playerPosition)) { if (Building.buildingGiveEnergy2Player.Contains(b.type)) { TransfereEnergy(b, delta); } } } }
/// Enleve de la vie au joueur. public static void RemoveHealth(float amount) { PlayerMouvements.PlaySound(Sounds.Type.PlayerHurt); health -= amount; if (health < 0) { health = 0; } }
public override void _Process(float delta) { if (PlayerState.GetState() != PlayerState.State.Normal || Player.UsableSelected != Usable.Type.Laser) { Visible = false; return; } Visible = true; LookAt(GetGlobalMousePosition()); if (GlobalRotation < -Mathf.Pi / 2 || GlobalRotation > Mathf.Pi / 2) { anSprite.FlipV = true; } else { anSprite.FlipV = false; } Vector2 mouse_position = GetLocalMousePosition(); Vector2 max_cast_to = mouse_position.Normalized() * RADIUS; raycast.CastTo = max_cast_to; if (Input.IsActionPressed("mouse1")) { if (Player.energy > 0) { shoot(delta); particule.Emitting = true; Player.RemoveEnergy(POWERENERGY * delta); if (!isalreadyshooting) { PlayerMouvements.PlaySound(Sounds.Type.PlayerLaser); isalreadyshooting = true; } } else { begin.Visible = false; beam.Visible = false; particule.Emitting = false; } } if (Input.IsActionJustReleased("mouse1")) { begin.Visible = false; beam.Visible = false; particule.Emitting = false; isalreadyshooting = false; } }
public override void _EnterTree() { HasPlayer = true; depopos = Position; instance = this; Teleport(initialPosition.x, initialPosition.y); if (!World.IsInit) { GD.Print("Player : Warning, le monde n'est pas initialisé"); } audioStream = GetNode <AudioStreamPlayer2D>("Stream"); }
public static void Spawn_Enemy_Randomly() { r = rand.Next(0, 2); positionPlayer = new Vector2(PlayerMouvements.GetX(), PlayerMouvements.GetY()); positionPlayer = Convertion.World2Location(positionPlayer); if (r == 1) { Spawn_Enemy(PlayerMouvements.GetX() + 10, PlayerMouvements.GetY() + 50); } else { Spawn_Enemy(PlayerMouvements.GetX() - 10, PlayerMouvements.GetY() + 50); } }
public static void Revive() { if (health <= 0) { FillHealth(); FillOxygene(); FillEnergy(); inventoryUsables = new StorageUsables(inventoryUsablesSize); inventoryItems = new StorageItems(inventoryItemsSize); inventoryLiquids = new StorageLiquids(inventoryLiquidsSize); inventoryBuildings = new StorageBuildings(inventoryBuildingsSize); UsableSelected = Usable.Type.Laser; BuildingSelected = Building.Type.SolarPanel; PlayerMouvements.Teleport(World.spawn.x, World.spawn.y); PlayerMouvements.canMove = true; } }
private void Get_To_Player() { Position_Player = new Vector2(PlayerMouvements.GetX(), PlayerMouvements.GetY()); Position_Player = Convertion.World2Location(Position_Player); Vector2 direction = (-this.GlobalPosition + Position_Player).Normalized(); vel = direction * Speed; if (vel.x >= 0) { Enemy_fly.FlipH = true; } else { Enemy_fly.FlipH = false; } MoveAndSlide(vel, up); }
public void Damage(float damage) { if (durabilities[type] == -1) { return; } health -= damage; if (health <= 0) { UI_breakingBlocks.RemoveUI(this); PlayerMouvements.PlaySound(Sounds.Type.BlockBreak); SpawnDrop(); Remove(); } else if (health < durabilities[type]) { UI_breakingBlocks.AddUI(this); } }
private void JUMP(float delta) { AnimationPlayer bond = GetNode <AnimationPlayer>("AnimationPlayer"); Sprite image = GetNode <Sprite>("Image"); if (on_ground) { vel.y = 0; } if (plouf && !on_ground && LiquidCoefMove != 1.0f) { PlayerMouvements.PlaySound(Sounds.Type.PlayerPlouf); plouf = false; } if (LiquidCoefMove == 1.0f) { plouf = true; } if (LiquidCoefMove != 1.0f && Input.IsActionPressed("ui_up")) { vel.y += JUMP_POWER * 0.1f * LiquidCoefMove * delta; vel.y = vel.y < -YLIMITESPEED ? -YLIMITESPEED : vel.y; } else if (on_ground && Input.IsActionPressed("ui_up") && LiquidCoefMove == 1.0f) { bond.Play("Start_Jump"); vel.y += JUMP_POWER * LiquidCoefMove * delta; on_ground = false; } else if (vel.y != 0 && (!bond.IsPlaying() || bond.CurrentAnimation == "Run")) { bond.Play("Jump"); } }
public static float GetScreenMaxX() => PlayerMouvements.GetX() + (Convertion.Location2World(new Vector2(Game.WorldScreenSizeX / 2, 0))).x;
private void HorizontalMouvement(float delta) { AnimationPlayer bond = GetNode <AnimationPlayer>("AnimationPlayer"); Sprite image = GetNode <Sprite>("Image"); /////////Move Right if (Input.IsActionJustPressed("ui_right") && move_left == false) { image.FlipH = false; if (IsOnFloor()) { bond.Play("Turn"); } } ///Cannot input Turn because it wont be seen and will be replace by run if (Input.IsActionPressed("ui_right")) { if (move_left == false) { move_right = true; image.FlipH = false; if (IsOnFloor()) { bond.Play("Run"); } } vel.x = SPEED * LiquidCoefMove; } else if (Input.IsActionJustReleased("ui_right") && move_left == false) { move_right = false; if (IsOnFloor()) { bond.Play("Turn_Back"); } } /////////Move Left if (Input.IsActionJustPressed("ui_left") && move_right == false) { image.FlipH = true; if (IsOnFloor()) { bond.Play("Turn"); } } if (Input.IsActionPressed("ui_left")) { if (move_right == false) { move_left = true; image.FlipH = true; if (IsOnFloor()) { bond.Play("Run"); } } vel.x = -SPEED * LiquidCoefMove; } else if (Input.IsActionJustReleased("ui_left") && move_right == false) { move_left = false; if (IsOnFloor()) { bond.Play("Turn_Back"); } } if ((move_left || move_right) && IsOnFloor()) { if (timer % 15 == 0) { PlayerMouvements.PlaySound(Sounds.Type.PlayerStep); } } }
public override void _PhysicsProcess(float delta) { if (PlayerState.Is(PlayerState.State.Pause)) { return; } AnimationPlayer bond = GetNode <AnimationPlayer>("AnimationPlayer"); Sprite image = GetNode <Sprite>("Image"); if (!isplaying) { InitSound("res://Assets/Ressources/Sounds/background sound/Gravity.res"); } bool isOnWater = IsInWater(); if (isOnWater && LiquidCoefMove == 1.0f && Mathf.Abs(vel.y) > 80) { vel.y *= Liquid.density[Liquid.Type.Water]; } if (isOnWater) { LiquidCoefMove = Liquid.density[Liquid.Type.Water]; } else { LiquidCoefMove = 1.0f; } vel.x = 0; if (Player.health <= 0 && PlayerState.GetState() != PlayerState.State.Dead) ///////// Death { bond.Play("Death"); canMove = false; PlaySound(Sounds.Type.PlayerDeath); Player.Die(); vel = new Vector2(); } if (!on_ground && IsOnFloor()) { on_ground = true; PlayerMouvements.PlaySound(Sounds.Type.PlayerLanding); if (vel.y >= FALLSPEEDDAMAGE1 && LiquidCoefMove == 1.0f) { float a = (100.0f - 5.0f) / (FALLSPEEDDAMAGE2 - FALLSPEEDDAMAGE1); float b = 5 - FALLSPEEDDAMAGE1 * a; Player.RemoveHealth(a * vel.y + b); } } else if (!IsOnFloor()) { on_ground = false; } if (canMove && (PlayerState.GetState() == PlayerState.State.Normal || PlayerState.GetState() == PlayerState.State.Build || PlayerState.GetState() == PlayerState.State.Link)) { GD.Print("eoooe"); HorizontalMouvement(delta); JUMP(delta); if (vel.x == 0) ////////// Idle { if (!bond.IsPlaying()) { image.FlipH = false; bond.Play("Idle"); } } } vel.y += GRAVITY * LiquidCoefMove * delta; MoveAndSlide(vel, UP); }
public override void _PhysicsProcess(float delta) { if (PlayerState.Is(PlayerState.State.Pause)) { return; } if (dead) { return; } if (t >= lifeTime) { QueueFree(); Enemies.enemiesCount--; } if (!verifground) { if (IsOnFloor()) { verifground = true; } vel.x = 0; if (!verifdie) { vel.y = 300; } else { vel.y = 10; } MoveAndSlide(vel, up); } if (verifground) { this.delta = delta; if (!verifattack) { if (!Player_Near()) { if (!veriftime) { time.Start(); veriftime = true; } t += delta; Random_moves(); } else { t = 0; time.Stop(); veriftime = false; Get_To_Player(); } } else { Position_Player = new Vector2(PlayerMouvements.GetX(), PlayerMouvements.GetY()); Position_Player = Convertion.World2Location(Position_Player); Vector2 direction = (-this.GlobalPosition + Position_Player).Normalized(); vel = direction * (-Speed / 5); MoveAndSlide(vel, up); } } Vector2 p = GetViewportTransform().origin *CurrentCamera.GetXZoom(); int viewportSizeX = Mathf.FloorToInt(GetViewport().Size.x *CurrentCamera.GetXZoom()); Vector2 vecMin = Convertion.Location2World(p) * -1; Vector2 vecMax = Convertion.Location2World(new Vector2(p.x * -1 + viewportSizeX, p.y)); if (vecMin.x < 0) { if (!mirrored) { int i = (int)Mathf.Abs(vecMin.x / Chunk.size) + 1; if (Convertion.Location2World(Position).x >= (World.size - i) * Chunk.size) { Position = Position - new Vector2(World.size * Chunk.size * World.BlockTilemap.CellSize.x, 0); mirrored = true; } } else if (-vecMin.x + prev_x_viewport >= 0.90f * World.size * Chunk.size) { int i = (int)Mathf.Abs(vecMin.x / Chunk.size) + 1; if (Convertion.Location2World(Position).x >= (World.size - i) * Chunk.size) { Position = Position - new Vector2(World.size * Chunk.size * World.BlockTilemap.CellSize.x, 0); mirrored = false; } } } else if (vecMax.x >= World.size * Chunk.size) { if (!mirrored) { int i = (int)Mathf.Abs((vecMax.x - World.size * Chunk.size) / Chunk.size) + 1; if (Convertion.Location2World(Position).x <= i * Chunk.size) { Position = Position + new Vector2(World.size * Chunk.size * World.BlockTilemap.CellSize.x, 0); mirrored = true; } } else if (vecMin.x - prev_x_viewport >= 0.90f * World.size * Chunk.size) { int i = (int)Mathf.Abs((vecMax.x - World.size * Chunk.size) / Chunk.size) + 1; if (Convertion.Location2World(Position).x <= i * Chunk.size) { Position = Position + new Vector2(World.size * Chunk.size * World.BlockTilemap.CellSize.x, 0); mirrored = false; } } } else if (vecMax.x < World.size * Chunk.size && vecMin.x >= 0) { if (mirrored) { if (Convertion.Location2World(Position).x < 0) { Position = Position + new Vector2(World.size * Chunk.size * World.BlockTilemap.CellSize.x, 0); } else { Position = Position - new Vector2(World.size * Chunk.size * World.BlockTilemap.CellSize.x, 0); } mirrored = false; } } prev_x_viewport = vecMin.x; }
private bool PositionInRange(int range, Vector2 pos) { float distance = Mathf.Sqrt(Mathf.Pow((pos.x - PlayerMouvements.GetX()), 2) + Mathf.Pow((pos.y - PlayerMouvements.GetY()), 2)); return(distance <= range); }