//methods public Firecracker[] GenerateFirecrackers(int size) { Firecracker[] LocalFirecrackerArray = new Firecracker[size];//allows any size game up to an arbitrary limit set by me (20) for (int i = 0; i < size; i++) { LocalFirecrackerArray[i] = new Firecracker(this);//every firecracker made as part of the game gets passed the parent } return(LocalFirecrackerArray); }
public int ChangePicture(Firecracker theSender) //doesn't actually change the picture, { // returns the index position in the array int ID = 0; // of the cracker, so you know which picture to change foreach (var cracker in FirecrackersArray) { if (Equals(cracker, theSender)) //I was pleasantly surprised when this worked, then again, why wouldn't it? { return(ID); //the loop cycles through the array, checking if the sender is the object it is looking at } ID += 1; //if it's not, then clearly it must be in a later position } return(-1); //will never happen (famous last words...) }// above line required, as 'not all code paths return a value' otherwise
protected override bool OnBurn(Vec2 firePosition, Thing litBy) { for (int index = 0; index < this.ammo; ++index) { Firecracker firecracker = new Firecracker(this.barrelPosition.x, this.barrelPosition.y); firecracker.hSpeed = Rando.Float(-4f, 4f); firecracker.vSpeed = Rando.Float(-1f, -6f); Level.Add((Thing)firecracker); } Level.Remove((Thing)this); if (this.owner is Duck owner) { owner.ThrowItem(); } return(true); }
public override void OnPressAction() { if (this.ammo <= 0) { return; } --this.ammo; SFX.Play("lightMatch", 0.5f, Rando.Float(0.2f) - 0.4f); if (!(this.owner is Duck owner)) { return; } float num1 = 0.0f; float num2 = 0.0f; if (owner.inputProfile.Down("LEFT")) { num1 -= 2f; } if (owner.inputProfile.Down("RIGHT")) { num1 += 2f; } if (owner.inputProfile.Down("UP")) { num2 -= 2f; } if (owner.inputProfile.Down("DOWN")) { num2 += 2f; } Firecracker firecracker = new Firecracker(this.barrelPosition.x, this.barrelPosition.y); if (!owner.crouch) { firecracker.hSpeed = (float)this.offDir * Rando.Float(2f, 2.5f) + num1; firecracker.vSpeed = num2 - 1f + Rando.Float(-0.2f, 0.8f); } else { firecracker.spinAngle = 90f; } Level.Add((Thing)firecracker); }
void Launch() { // check if firecracker would collide with obstacles at instantiation point LayerMask walls = LayerMask.GetMask("Obstacles"); Vector3 spawnLocation = rBody2d.position + Vector2.up * 0.5f; if (Physics2D.OverlapCircle(spawnLocation, 0.3f, walls) != null) { spawnLocation = rBody2d.position; } // instantiate projectile and launch it GameObject projectileObject = Instantiate(noiseMakerPrefab, spawnLocation, Quaternion.identity); Firecracker projectile = projectileObject.GetComponent <Firecracker>(); projectile.Launch(lookDirection, 300); // Trigger player animation animator.SetTrigger("Launch"); }
private Vector2 processInput() { var movement = Vector2.Zero; if (Input.isKeyDown(Keys.A)) { movement.X = -1f; } else if (Input.isKeyDown(Keys.D)) { movement.X = 1f; } if (Input.isKeyDown(Keys.W)) { movement.Y = -1f; } else if (Input.isKeyDown(Keys.S)) { movement.Y = 1f; } if (Input.isKeyPressed(Keys.Escape)) { #if __MonoCS__ Process.GetCurrentProcess().Kill(); // HACK: Linux and escape keypress doesn't work right. #else Core.exit(); #endif } // TEMP if (Input.isKeyPressed(Keys.Space)) { var firecracker = new Firecracker() { duration = 5f, delay = 2f, propagationTime = 0.25f, alertRadius = 200f }; firecracker.transform.position = Input.mousePosition; entity.scene.addEntity(firecracker); } // TEMP if (Input.isKeyPressed(Keys.V)) { var decoyVelocity = new Vector2(2, 0); if (animation.flipX) { decoyVelocity.X = -decoyVelocity.X; } var decoy = new Decoy() { duration = 5f, delay = 2f, velocity = decoyVelocity }; decoy.transform.position = entity.transform.position + new Vector2(animation.width * 0.75f * (decoyVelocity.X < 0 ? -1 : 1), 0); entity.scene.addEntity(decoy); } return(movement); }