private void HandleWeaponShooting() { switch (_currentWeaponType) { case WeaponType.SingleShot: float currentRotation = _playerRoot.GetRotation(); float xVelocity = Mathf.Cos(currentRotation); float yVelocity = Mathf.Sin(currentRotation); ShootSingleShotBullet(new Vector2(xVelocity, yVelocity)); break; case WeaponType.Shotgun: ShootShotGunBullet(); break; case WeaponType.ChargeGun: { _chargeWeaponCurrentScale = 1; _chargedShotBullet = (ChargedBullet)playerChargedBulletPrefab.Instance(); _playerChargedShotShootingPosition.AddChild(_chargedShotBullet); _chargedShotBullet.SetGlobalPosition(_playerChargedShotShootingPosition.GetGlobalPosition()); _chargedShotBullet.SetAsStaticBullet(); _chargedShotBullet.SetMode(RigidBody2D.ModeEnum.Kinematic); } break; default: throw new ArgumentOutOfRangeException(nameof(_currentWeaponType), _currentWeaponType, null); } }
private void CreateChargedAttack() { // Charged Bullet _chargedBullet = (BossBullet)chargedBulletPrefab.Instance(); _dualArmAttackPosition.AddChild(_chargedBullet); _chargedBullet.SetMode(RigidBody2D.ModeEnum.Kinematic); _chargedBullet.SetGlobalPosition(_dualArmAttackPosition.GetGlobalPosition()); _chargedBullet.SetAsStaticBullet(); // Charged Bullet Effect _chargedEffectDestroy = (DestroyNodeForced)chargingEffectPrefab.Instance(); _dualArmAttackPosition.AddChild(_chargedEffectDestroy); }
public override void _Process(float delta) { _cameraPosition = _target.GetGlobalPosition(); if (useCameraLocking) { if (_cameraPosition.x < lockBottomLeftCorner.x) { _cameraPosition.x = lockBottomLeftCorner.x; } else if (_cameraPosition.x > lockTopRightCorner.x) { _cameraPosition.x = lockTopRightCorner.x; } if (_cameraPosition.y > lockBottomLeftCorner.y) { _cameraPosition.y = lockBottomLeftCorner.y; } else if (_cameraPosition.y < lockTopRightCorner.y) { _cameraPosition.y = lockTopRightCorner.y; } } SetGlobalPosition(_cameraPosition); }
void SpawnEnemy(string enemyType) { PackedScene scene = enemyScenes[enemyType]; Node2D enemy = scene.Instance() as Node2D; enemy.SetPosition(spawn.GetGlobalPosition()); AddChild(enemy); }
public override void _Process(float delta) { if (bottomright.GetGlobalPosition().x <= (camera.Position.x + camera.Offset.x)) { QueueFree(); if (GroundDestroyed != null) { GroundDestroyed(this, null); } //DEPRECATED //EmitSignal(nameof(Destroyed)); } }
private void UpdateFirstArmAttack(float delta) { _attackTimer -= delta; if (_attackTimer <= 0) { SetArmAttackState(ArmAttackState.IdleState); } _attackVariable_2 -= delta; if (_attackVariable_2 <= 0) { _attackVariable_2 = timeBetweenSingleArmAttacks; LaunchSingleArmAttack(_firstArmAttackPosition.GetGlobalPosition()); } }
private void SpawnEnemy() { Individuals.Enemy enemyInstance = (Individuals.Enemy)enemyTypes[_currentEnemyTypeIndex].Instance(); AddChild(enemyInstance); _groupEnemies.Add(enemyInstance); Node2D spawnPoint = _spawnPoints[(int)(GD.Randi() % _spawnPoints.Count)]; enemyInstance.SetGlobalPosition(spawnPoint.GetGlobalPosition()); enemyInstance.SetEnemyColors( enemyColors[GD.Randi() % enemyColors.Length], enemyColors[GD.Randi() % enemyColors.Length] ); enemyInstance.SetParentEnemyGroup(this); }
protected override void EnemyLaunchSingleShotAttack() { BombBullet bombBulletInstance = (BombBullet)bombPrefab.Instance(); GetParent().AddChild(bombBulletInstance); Node2D launchPoint = _launchPoints[0]; bombBulletInstance.SetGlobalPosition(launchPoint.GetGlobalPosition()); float rotation = _rotationNode.GetGlobalRotation(); float xVelocity = Mathf.Cos(rotation); float yVelocity = Mathf.Sin(rotation); Vector2 launchVector = new Vector2(xVelocity, yVelocity); bombBulletInstance.LaunchBullet(launchVector.Normalized()); }
public override void _Process(float delta) { base._Process(delta); if (targetToFollow == null) { Logger.Warning("Call init first."); return; } if (!IsInstanceValid(targetToFollow)) { SetGlobalPosition(Vector2.Zero); return; } SetGlobalPosition(targetToFollow.GetGlobalPosition()); }
private void ShootSingleShotBullet(Vector2 forwardVectorNormalized) { Bullet bulletInstance = (Bullet)playerBulletPrefab.Instance(); _playerBulletHolder.AddChild(bulletInstance); if (_currentDamageDiffPercent != 0) { float damageChange = bulletInstance.GetBulletDamage() * _currentDamageDiffPercent / 100; _currentDamageDiff += damageChange; _currentDamageDiffPercent = 0; } bulletInstance.SetBulletDamage(bulletInstance.GetBulletDamage() + _currentDamageDiff); bulletInstance.SetGlobalPosition(_playerBulletShootingPosition.GetGlobalPosition()); bulletInstance.LaunchBullet(forwardVectorNormalized); bulletInstance.SetFreezingBulletState(_freezingBulletBought); }
private void CheckAndLaunchLaserAttack() { if (_laserLaunched) { return; } EnemyLaser enemyLaserInstance = (EnemyLaser)laserPrefab.Instance(); GetParent().AddChild(enemyLaserInstance); Node2D launchPoint = _launchPoints[0]; enemyLaserInstance.SetGlobalPosition(launchPoint.GetGlobalPosition()); enemyLaserInstance.SetGlobalRotationDegrees(_rotationNode.GetGlobalRotationDegrees()); _currentLaser = enemyLaserInstance; _laserLaunched = true; }
private void LaunchBullets() { _isOffsetUsed = !_isOffsetUsed; for (int i = 0; i < bulletsInEachRow; i++) { BossBullet bossBulletInstance = (BossBullet)bulletPrefab.Instance(); _bulletHolder.AddChild(bossBulletInstance); float indexRatio = (float)i / bulletsInEachRow; Vector2 finalPosition = _spawnLeftMostPoint.GetGlobalPosition().LinearInterpolate(_spawnRightMostPoint.GetGlobalPosition(), indexRatio); if (_isOffsetUsed) { finalPosition.x += bulletGapOffset; } bossBulletInstance.SetGlobalPosition(finalPosition); bossBulletInstance.LaunchBullet(bulletDefaultVelocity.Normalized()); } }
public override void _Ready() { //Viewport. wavePauseTimer = GetNode <Timer>("WavePauseTimer"); wave = LoadWave(waveCount - 1); //ASSIGN WORLD GRID worldGrid = FindNode("WorldGrid") as TileMap; //LOAD TOWER SCENE towerScenes.Add("Tower", (PackedScene)ResourceLoader.Load("res://Scenes/Towers/Tower.tscn")); towerCosts.Add("Tower", 40); towerScenes.Add("Shoot", (PackedScene)ResourceLoader.Load("res://Scenes/Towers/Shoot.tscn")); towerCosts.Add("Shoot", 40); towerScenes.Add("Mortar", (PackedScene)ResourceLoader.Load("res://Scenes/Towers/Mortar.tscn")); towerCosts.Add("Mortar", 50); towerScenes.Add("Shotgun", (PackedScene)ResourceLoader.Load("res://Scenes/Towers/Shotgun.tscn")); towerCosts.Add("Shotgun", 60); //LOAD ENEMY SCENE enemyScenes.Add("Enemy", (PackedScene)ResourceLoader.Load("res://Scenes/Enemies/Enemy.tscn")); enemyScenes.Add("EnemyBig", (PackedScene)ResourceLoader.Load("res://Scenes/Enemies/EnemyBig.tscn")); enemyScenes.Add("Goblin", (PackedScene)ResourceLoader.Load("res://Scenes/Enemies/Goblin.tscn")); enemyScenes.Add("Elephant", (PackedScene)ResourceLoader.Load("res://Scenes/Enemies/Elephant.tscn")); enemyScenes.Add("Fast", (PackedScene)ResourceLoader.Load("res://Scenes/Enemies/Fast.tscn")); enemyScenes.Add("Carriage", (PackedScene)ResourceLoader.Load("res://Scenes/Enemies/Carriage.tscn")); //PATH FINDING debugLine = FindNode("DebugLine") as Line2D; debugLineSnapped = FindNode("DebugLineSnapped") as Line2D; nav2d = GetNode <Navigation2D>("Navigation2D"); spawn = GetNode <Node2D>("Spawn"); goal = GetNode <Node2D>("ParasitNiklas"); path = nav2d.GetSimplePath(spawn.GetGlobalPosition(), goal.GetGlobalPosition(), false); debugLine.Points = path; bDL = FindNode("bDL") as Line2D; //ALIGN PATH TO GRID GD.Print(path.Length); path = PathSnapToGrid(path); GD.Print(path.Length); debugLineSnapped.Points = path; money = GetTree().GetRoot().GetNode("World").FindNode("Money") as Label; GD.Print(money.GetName()); health = GetTree().GetRoot().GetNode("World").FindNode("Health") as Label; GD.Print(health.GetName()); EarnMoney(100); UpdateHealth(1000); Tuple <Vector2, int> tuple = BackTrackPath(path, worldGrid.MapToWorld(new Vector2(8, 6)), 24, 3); GD.Print("btpi: ", tuple.Item2); }