Skip to main content
replaced http://gamedev.stackexchange.com/ with https://gamedev.stackexchange.com/
Source Link

This is how I would do that (pseudo-code):

class Vector {
    var float x;
    var float y;

    function Vector (float angle, float magnitude); // constructor
    function add(Vector);                           // adds new vector to current vector
    function angle(float new_angle);                // returns or sets angle
    function magnitude(float new_magnitude);        // returns or sets magnitude
}

class Ship {
    position = new Vector(0, 0); 
    velocity = new Vector(0, 0); 
    max_speed = 10; 
}

function update() {
    acceleration = impulse_key_pressed ? new Vector (ship.position.angle(), engine_power) : new Vector(0, 0);
    ship.position.add(acceleration);
    ship.position.add(asteroid_collision);
    if (ship.velocity.magnitude() > ship.max_speed)
        ship.velocity.magnitude(ship.velocity.magnitude() - 0.1);
}

Getting hit with an asteroid is just a one time addition of new acceleration to the current position. This acceleration is big enough to influence the current ship's velocity and increase it over its max speed. Afterwards the ship slows down gradually (by 0.1 of magnitude each update).

You can read up more on vectors e.g. in this answerthis answer.

This is how I would do that (pseudo-code):

class Vector {
    var float x;
    var float y;

    function Vector (float angle, float magnitude); // constructor
    function add(Vector);                           // adds new vector to current vector
    function angle(float new_angle);                // returns or sets angle
    function magnitude(float new_magnitude);        // returns or sets magnitude
}

class Ship {
    position = new Vector(0, 0); 
    velocity = new Vector(0, 0); 
    max_speed = 10; 
}

function update() {
    acceleration = impulse_key_pressed ? new Vector (ship.position.angle(), engine_power) : new Vector(0, 0);
    ship.position.add(acceleration);
    ship.position.add(asteroid_collision);
    if (ship.velocity.magnitude() > ship.max_speed)
        ship.velocity.magnitude(ship.velocity.magnitude() - 0.1);
}

Getting hit with an asteroid is just a one time addition of new acceleration to the current position. This acceleration is big enough to influence the current ship's velocity and increase it over its max speed. Afterwards the ship slows down gradually (by 0.1 of magnitude each update).

You can read up more on vectors e.g. in this answer.

This is how I would do that (pseudo-code):

class Vector {
    var float x;
    var float y;

    function Vector (float angle, float magnitude); // constructor
    function add(Vector);                           // adds new vector to current vector
    function angle(float new_angle);                // returns or sets angle
    function magnitude(float new_magnitude);        // returns or sets magnitude
}

class Ship {
    position = new Vector(0, 0); 
    velocity = new Vector(0, 0); 
    max_speed = 10; 
}

function update() {
    acceleration = impulse_key_pressed ? new Vector (ship.position.angle(), engine_power) : new Vector(0, 0);
    ship.position.add(acceleration);
    ship.position.add(asteroid_collision);
    if (ship.velocity.magnitude() > ship.max_speed)
        ship.velocity.magnitude(ship.velocity.magnitude() - 0.1);
}

Getting hit with an asteroid is just a one time addition of new acceleration to the current position. This acceleration is big enough to influence the current ship's velocity and increase it over its max speed. Afterwards the ship slows down gradually (by 0.1 of magnitude each update).

You can read up more on vectors e.g. in this answer.

added vectors reading material
Source Link
cprn
  • 254
  • 1
  • 3
  • 7

This is how I would do that (pseudo-code):

class Vector {
    var float x;
    var float y;

    function Vector (float angle, float magnitude); // constructor
    function add(Vector);                           // adds new vector to current vector
    function angle(float new_angle);                // returns or sets angle
    function magnitude(float new_magnitude);        // returns or sets magnitude
}

class Ship {
    position = new Vector(0, 0); 
    velocity = new Vector(0, 0); 
    max_speed = 10; 
}

function update() {
    acceleration = impulse_key_pressed ? new Vector (ship.position.angle(), engine_power) : new Vector(0, 0);
    ship.position.add(acceleration);
    ship.position.add(asteroid_collision);
    if (ship.velocity.magnitude() > ship.max_speed)
        ship.velocity.magnitude(ship.velocity.magnitude() - 0.1);
}

Getting hit with an asteroid is just a one time addition of new acceleration to the current position. This acceleration is big enough to influence the current ship's velocity and increase it over its max speed. Afterwards the ship slows down gradually (by 0.1 of magnitude each update).

You can read up more on vectors e.g. in this answer.

This is how I would do that (pseudo-code):

class Vector {
    var float x;
    var float y;

    function Vector (float angle, float magnitude); // constructor
    function add(Vector);                           // adds new vector to current vector
    function angle(float new_angle);                // returns or sets angle
    function magnitude(float new_magnitude);        // returns or sets magnitude
}

class Ship {
    position = new Vector(0, 0); 
    velocity = new Vector(0, 0); 
    max_speed = 10; 
}

function update() {
    acceleration = impulse_key_pressed ? new Vector (ship.position.angle(), engine_power) : new Vector(0, 0);
    ship.position.add(acceleration);
    ship.position.add(asteroid_collision);
    if (ship.velocity.magnitude() > ship.max_speed)
        ship.velocity.magnitude(ship.velocity.magnitude() - 0.1);
}

Getting hit with an asteroid is just a one time addition of new acceleration to the current position. This acceleration is big enough to influence the current ship's velocity and increase it over its max speed. Afterwards the ship slows down gradually (by 0.1 of magnitude each update).

This is how I would do that (pseudo-code):

class Vector {
    var float x;
    var float y;

    function Vector (float angle, float magnitude); // constructor
    function add(Vector);                           // adds new vector to current vector
    function angle(float new_angle);                // returns or sets angle
    function magnitude(float new_magnitude);        // returns or sets magnitude
}

class Ship {
    position = new Vector(0, 0); 
    velocity = new Vector(0, 0); 
    max_speed = 10; 
}

function update() {
    acceleration = impulse_key_pressed ? new Vector (ship.position.angle(), engine_power) : new Vector(0, 0);
    ship.position.add(acceleration);
    ship.position.add(asteroid_collision);
    if (ship.velocity.magnitude() > ship.max_speed)
        ship.velocity.magnitude(ship.velocity.magnitude() - 0.1);
}

Getting hit with an asteroid is just a one time addition of new acceleration to the current position. This acceleration is big enough to influence the current ship's velocity and increase it over its max speed. Afterwards the ship slows down gradually (by 0.1 of magnitude each update).

You can read up more on vectors e.g. in this answer.

added explanation
Source Link
cprn
  • 254
  • 1
  • 3
  • 7

This is how I would do that (pseudo-code):

class Vector {
    var float x;
    var float y;

    function Vector (float angle, float magnitude); // constructor
    function add(Vector);                           // adds new vector to current vector
    function angle(float new_angle);                // returns or sets angle
    function magnitude(float new_magnitude);        // returns or sets magnitude
}

class Ship {
    position = new Vector(0, 0); 
    velocity = new Vector(0, 0); 
    max_speed = 10; 
}

function update() {
    acceleration = impulse_key_pressed ? new Vector (ship.position.angle(), engine_power) : new Vector(0, 0);
    ship.position.add(acceleration);
    ship.position.add(asteroid_collision);
    if (ship.velocity.magnitude() > ship.max_speed)
        ship.velocity.magnitude(ship.velocity.magnitude() - 0.1);
}

Getting hit with an asteroid is just a one time addition of new acceleration to the current position. This acceleration is big enough to influence the current ship's velocity and increase it over its max speed. Afterwards the ship slows down gradually (by 0.1 of magnitude each update).

This is how I would do that (pseudo-code):

class Vector {
    var float x;
    var float y;

    function Vector (float angle, float magnitude); // constructor
    function add(Vector);                           // adds new vector to current vector
    function angle(float new_angle);                // returns or sets angle
    function magnitude(float new_magnitude);        // returns or sets magnitude
}

class Ship {
    position = new Vector(0, 0); 
    velocity = new Vector(0, 0); 
    max_speed = 10; 
}

function update() {
    acceleration = impulse_key_pressed ? new Vector (ship.position.angle(), engine_power) : new Vector(0, 0);
    ship.position.add(acceleration);
    ship.position.add(asteroid_collision);
    if (ship.velocity.magnitude() > ship.max_speed)
        ship.velocity.magnitude(ship.velocity.magnitude() - 0.1);
}

This is how I would do that (pseudo-code):

class Vector {
    var float x;
    var float y;

    function Vector (float angle, float magnitude); // constructor
    function add(Vector);                           // adds new vector to current vector
    function angle(float new_angle);                // returns or sets angle
    function magnitude(float new_magnitude);        // returns or sets magnitude
}

class Ship {
    position = new Vector(0, 0); 
    velocity = new Vector(0, 0); 
    max_speed = 10; 
}

function update() {
    acceleration = impulse_key_pressed ? new Vector (ship.position.angle(), engine_power) : new Vector(0, 0);
    ship.position.add(acceleration);
    ship.position.add(asteroid_collision);
    if (ship.velocity.magnitude() > ship.max_speed)
        ship.velocity.magnitude(ship.velocity.magnitude() - 0.1);
}

Getting hit with an asteroid is just a one time addition of new acceleration to the current position. This acceleration is big enough to influence the current ship's velocity and increase it over its max speed. Afterwards the ship slows down gradually (by 0.1 of magnitude each update).

added an asteroid collision acceleration to the code
Source Link
cprn
  • 254
  • 1
  • 3
  • 7
Loading
Source Link
cprn
  • 254
  • 1
  • 3
  • 7
Loading