private void moveShip() { // Check if ship has enough fuel to move // Check that it is not going to be out of bounds // Readjust velocity if (petrol > 0 && shipState == EShipState.wandering) { // This code not quite right, ships will travel slightly too far right. Fix later? * 1.25 = hacky way of fixing this if (shipLocation.X >= (boundsRectangle.Width - shipSize * 1.25) || (shipLocation.X <= 0)) // if outside bounds rectangle { shipVelocity.X *= -1; // invert our velocity - repeat below } else if (shipLocation.Y >= (boundsRectangle.Height - shipSize) || (shipLocation.Y <= 0)) { shipVelocity.Y *= -1; } shipLocation.X += shipVelocity.X; // adjust ship velocity shipLocation.Y += shipVelocity.Y; usePetrol(); // decrement our gas } else { shipState = EShipState.refueling; } }
//TODO randomize the position/delta/size here?(will need rng) public Ship(Point startPosition, Point world_size, int size, Point delta, Graphics g) : base(startPosition, world_size, size, g) { this.delta = delta; this.fuel = 100; this.shipState = EShipState.WANDERING; }
//Constructor public Ship(Graphics shipCanvas, Random rGen) { this.shipCanvas = shipCanvas; this.rGen = rGen; // Set default state shipState = EShipState.wandering; // Set petrol value pRand = rGen.Next(50, 101); Petrol = pRand; // Set ship location // set fix position for now shipLocation = new Point(100 + rGen.Next(50), 100 + rGen.Next(50)); // Set ship color as black shipColor = Color.FromArgb(0, 0, 0); // Set ship velocity // Make sure the no zero number gets generated int randNum = rGen.Next(MIN_SPEED, MAX_SPEED); shipVelocity = new Point(MIN_SPEED + rGen.Next(-randNum, randNum), MIN_SPEED + rGen.Next(-randNum, randNum)); }
public Ship(Graphics ShipCanvas, int ShipSize, Rectangle Rectangle, Random Rand) { rgen = Rand; boundsRectangle = Rectangle; shipCanvas = ShipCanvas; shipSize = ShipSize; shipColour = Color.Red; shipXVelocity = rgen.Next(MAX_SHIP_VELOCITY) + MIN_SHIP_VELOCITY; shipYVelocity = rgen.Next(MAX_SHIP_VELOCITY) + MIN_SHIP_VELOCITY; Petrol = 100; shipState = EShipState.wandering; shipLocation = new Point(rgen.Next(boundsRectangle.Width), rgen.Next(boundsRectangle.Height)); if( shipLocation.X + shipSize > boundsRectangle.Right) { shipLocation.X -= shipSize; } else if (shipLocation.X < boundsRectangle.Left) { shipLocation.X += shipSize; } else if (shipLocation.Y + shipSize > boundsRectangle.Bottom) { shipLocation.Y -= shipSize; } else if (shipLocation.Y < boundsRectangle.Top) { shipLocation.Y += shipSize; } }
private void refuel() { OnOutOfFuelEvent(shipLocation); if (petrolBotState == EPetrolBotState.refuelling) { petrolBot.botCurrentLocation = shipLocation; if (petrol < 300) { shipState = EShipState.refueling; //shipVelocity = new Point(0, 0); petrol += 10; } else // we have finished refueling { //shipVelocity = oldVelocity; shipState = EShipState.wandering; petrolBotState = EPetrolBotState.docked; OnFullOfFuelEvent(); } } else { checkIfPetrolBotHasArrived(); } }
public void ChangeState(EShipState state, params object[] constructorArgs) { if (_state != null) { _state.Stop(); } _state = _stateFactory.Create(state, constructorArgs); _state.Start(); }
public void usePetrol() { petrol--; if (petrol <= 0) { OnOutOfFuelEvent(); shipState = EShipState.refueling; } }
public Ship(Graphics shipCanvas, Rectangle boundaryRectangle, int shipSize, Random rGen) { MaxPetrol = rGen.Next(50,100); Petrol = MaxPetrol; this.shipCanvas = shipCanvas; this.boundaryRectangle = boundaryRectangle; shipLocation = new Point(rGen.Next(boundaryRectangle.Width - shipSize), rGen.Next(boundaryRectangle.Height - shipSize)); this.shipSize = shipSize; shipState = EShipState.WANDERING; shipVelocity = new Point(rGen.Next(10), rGen.Next(10)); }
public Ship(Graphics shipCanvas, Color shipColour, Point shipLocation, int shipSize) { this.shipCanvas = shipCanvas; this.shipColour = shipColour; this.shipSize = shipSize; ShipLocation = shipLocation; shipState = EShipState.Wandering; rGen = new Random(); ShipBrush = new SolidBrush(shipColour); }
public Ship(Graphics shipCanvas, int shipSize, Random rGen) { this.shipCanvas = shipCanvas; this.rGen = rGen; petrol = rGen.Next(100); shipColour = Color.Red; shipLocation = new Point(rGen.Next(400), rGen.Next(400)); this.shipSize = shipSize; shipState = EShipState.wandering; shipVelocity = new Point(rGen.Next(-5, 5)); }
private void checkFuelLevel() { if (currentFuel == 0) { // Change our state State = EShipState.REFUELING; // Fire the Out Of Fuel event if (OnOutOfFuelEvent != null) { OnOutOfFuelEvent(this, new ShipEventArgs(currentLocation)); } } }
public void refuel() { if (petrol != 100) { petrol++; shipColor = Color.FromArgb(255 / 100 * petrol, 0, 0); drawShip(); } else { OnFullOfFuelEvent(); shipState = EShipState.wandering; } }
public Ship(int xPos, int yPos, Graphics shipCanvas, Random rGen) { this.xPos = xPos; this.yPos = yPos; this.shipCanvas = shipCanvas; this.rGen = rGen; xVel = rGen.Next(10); yVel = rGen.Next(10); shipSize = 30; petrol = 99; shipState = EShipState.WANDERING; shipColour = Color.Red; shipBrush = new SolidBrush(shipColour); }
public Ship(Graphics canvas, Rectangle harbour, Random rand) { this.rand = rand; this.canvas = canvas; this.harbour = harbour; brush = new SolidBrush(generateColour()); currentLocation = new Point(rand.Next(0, harbour.Width - SIZE), rand.Next(0, harbour.Height - SIZE)); State = EShipState.WANDERING; size = new Size(SIZE, SIZE); currentFuel = FUEL; fuelUsage = FUEL_USE; }
private void refuel() { // Refill currentFuel += FUEL_REFILL_RATE; if (currentFuel >= FUEL) { // Make sure we don't have more than MAX_FUEL currentFuel = FUEL; // Change state State = EShipState.WANDERING; // Fire the Full Of Fuel event if (OnFullOfFuelEvent != null) { OnFullOfFuelEvent(this, new EventArgs()); } } }
public Ship(int shipSize, Graphics parentCanvas, Random r) { //Pass in random from the form to ensure proper seed generation this.r = r; //put ship into wanderer state on create state = EShipState.WANDERING; this.shipSize = shipSize; this.parentCanvas = parentCanvas; //Give initial amount of fuel (at least half full) petrol = r.Next(50, 100); //Give position shipLocation = new Point(r.Next(0, 395), r.Next(0, 300)); //Give black as starting colour shipColour = Color.FromArgb(0, 0, 0); //Set ship velocity shipVelocity = new Point(r.Next(-3,3), r.Next(-3,3)); }
public void ShipCycle() { if (petrol == 100) { shipState = EShipState.wandering; OnFullOfFuelEvent(); } if (petrol == 0) { shipState = EShipState.refueling; } if (shipState == EShipState.wandering) { drawShip(); moveShip(); } else { drawShip(); OnOutOfFuelEvent(); } }
//Method that is run when petrol bot arrives public void WaitingForShip(object o, EventArgs e) { shipState = EShipState.refueling; }
private void setShipToHook() { float newHookDestination = (float)(200/3*(rseed.Next(0,4)+200)); //select 3 locations //this.hookDestination = new Vector2((float)(newHookDestination), this.Pos.Y); //this.hookVel = this.shipState = EShipState.HOOKING; }
public void usePetrol() { petrol--; if(petrol <= 0) { OnOutOfFuelEvent(); shipState = EShipState.refueling; } }
public IsShipState(EShipState state) { this.state = state; }
void refuel() { Petrol += 5; if(Petrol == 100) { OnFullOfFuelEvent(); shipState = EShipState.wandering; } }
private void moveShip() { // Check if ship has enough fuel to move // Check that it is not going to be out of bounds // Readjust velocity if (petrol > 0 && shipState == EShipState.wandering) { // This code not quite right, ships will travel slightly too far right. Fix later? * 1.25 = hacky way of fixing this if (shipLocation.X >= (boundsRectangle.Width - shipSize * 1.25) || (shipLocation.X <= 0)) // if outside bounds rectangle shipVelocity.X *= -1; // invert our velocity - repeat below else if (shipLocation.Y >= (boundsRectangle.Height - shipSize) || (shipLocation.Y <= 0)) shipVelocity.Y *= -1; shipLocation.X += shipVelocity.X; // adjust ship velocity shipLocation.Y += shipVelocity.Y; usePetrol(); // decrement our gas } else { shipState = EShipState.refueling; } }
private void checkFuelLevel() { if (amountOfFuel == 0) { // Change our state State = EShipState.REFUELING; // Fire the Out Of Fuel event if (OnOutOfFuel != null) OnOutOfFuel(this, new ShipEventArgs(location)); } }
public SetShipState(EShipState state) { this.state = state; }
private void wander() { //Check we actually have fuel left to use! if (fuel <= 0) { shipState = EShipState.REFUELING; } else { //Calculate speed so that faster ships run out of fuel quicker int speed = (int)Math.Sqrt((Math.Abs(delta.X) + Math.Abs(delta.Y))); //Burn that fuel efficently fuel = fuel - speed / 2; //Move ship Point newLocation = new Point(location.X + delta.X, location.Y + delta.Y); //Checks bounds and reverses direction if needed if ((location.X < size) || (location.X > world_size.X)) { delta.X = -delta.X; } if ((location.Y < size) || (location.Y > (world_size.Y - size))) { delta.Y = -delta.Y; } //Add new co-ords location.X += delta.X; location.Y += delta.Y; } }
private void raiseOutOfFuelEvent() { //Sit and wait shipState = EShipState.REFUELING; //Check someone is listening before raising event or system will crash if (OutOfFuelEvent != null) { OutOfFuelEvent(this, new EventArgs()); } }
private void setShipToWait(GameTime gameTime) { this.Vel = new Vector2(0.0f, 0.0f); this.shipState = EShipState.WAITING; this.timeToNextHook = (int)gameTime.TotalGameTime.TotalMilliseconds + 1000; //set the time to send the hook down! }
//need gameTime to reset timeToNextHook private void setShipToSeek() { float newDestination = (rseed.Next(0, 4) * 300 + 200); //select 4 locaons (includes min value) while (Math.Abs(newDestination - this.Pos.X) < 10) { newDestination = (rseed.Next(0, 4) * 300 + 200); } //Debug.WriteLine("Destination " + newDestination); //determine ships destination if (newDestination < this.Pos.X) { //FLIP THE SHIP TO FACE LEFT if (FacingLeft) { //ACTUALLY FACING RIGHT FacingLeft = false; } } else { if (!FacingLeft) { FacingLeft = true; } } if (newDestination < this.Pos.X) { //SET VELOCITY this.Vel = new Vector2(-movingVel, 0.0f); } else { this.Vel = new Vector2(movingVel, 0.0f); } this.shipDestination = new Vector2((float)(newDestination), this.Pos.Y); //SET DESTINATION this.shipState = EShipState.SEEKING; }
public void ShipCycle() { if (petrol == 100) { shipState = EShipState.wandering; OnFullOfFuelEvent(); } if (petrol == 0) shipState = EShipState.refueling; if(shipState == EShipState.wandering) { drawShip(); moveShip(); } else { drawShip(); OnOutOfFuelEvent(); } }
//Constructor public ShipEventArgs(EShipState state) { this.state = state; }
public ShipEventArgs(EShipState currentShipState) { shipState = currentShipState; }
private void usePetrol() { if (Petrol > 0) Petrol --; else shipState = EShipState.REFUELING; OnFullOfFuelEvent(); }
private void refuel() { // Refill amountOfFuel += FUEL_REFILL_RATE; if (amountOfFuel >= MAX_FUEL_AMOUNT) { // Make sure we don't have more than MAX_FUEL amountOfFuel = MAX_FUEL_AMOUNT; // Change state State = EShipState.WANDERING; // Fire the Full Of Fuel event if (OnFullOfFuel != null) OnFullOfFuel(this, new EventArgs()); } }
private void refuel() { if (Petrol < MaxPetrol) Petrol++; else shipState = EShipState.WANDERING; OnOutOfFuelEvent(); }
private void refuel() { OnOutOfFuelEvent(shipLocation); if (petrolBotState == EPetrolBotState.refuelling) { petrolBot.botCurrentLocation = shipLocation; if (petrol < 300) { shipState = EShipState.refueling; //shipVelocity = new Point(0, 0); petrol += 10; } else // we have finished refueling { //shipVelocity = oldVelocity; shipState = EShipState.wandering; petrolBotState = EPetrolBotState.docked; OnFullOfFuelEvent(); } } else checkIfPetrolBotHasArrived(); }
public ShipState Create(EShipState state, params object[] constructorArgs) { return _factories[(int)state].Create(constructorArgs); }
void usePetrol() { int usePetrolRate = 0; if(shipXVelocity < 0) { usePetrolRate = shipXVelocity * -1; }else{ usePetrolRate = shipXVelocity; } Petrol -= usePetrolRate; if(Petrol < 0) { Petrol = 0; OnOutOfFuelEvent(shipLocation); shipState = EShipState.refueling; } }
public void ShipCycle() { if (shipState == EShipState.REFUELING) { if (petrol >= 90) { OnFullOfFuelEvent(); shipState = EShipState.WANDERING; } else { OnOutOfFuelEvent(); DrawShip(); Refuel(); } } else { if (petrol <= 0) { shipState = EShipState.REFUELING; } else { UsePetrol(); MoveShip(); DrawShip(); } } }
//ctor public ShipEventArgs(EShipState state) { this.state = state; }
private void raiseFullOfFuelEvent() { //Go back to wandering around shipState = EShipState.WANDERING; //Check someone is listening before raising event or system will crash if (FullOfFuelEvent != null) { FullOfFuelEvent(this, new EventArgs()); } }
private void refuel() { // Refill currentFuel += FUEL_REFILL_RATE; if (currentFuel >= FUEL) { // Make sure we don't have more than MAX_FUEL currentFuel = FUEL; // Change state State = EShipState.WANDERING; // Fire the Full Of Fuel event if (OnFullOfFuelEvent != null) OnFullOfFuelEvent(this, new EventArgs()); } }