Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - JasonMcG

Pages: [1]
1
General / SetPosition and delta-time
« on: October 04, 2017, 07:49:43 pm »
Hi,

If I am using move(x, y), I know yo should multiply by delta-time to ensure the frame rate is correct.

If I am using setPosition(x, y), do I still need to use delta time?
If so, how would I use delta-time?

2
General / Scaling
« on: September 20, 2017, 10:36:09 pm »
How do I scale an object?

I have an object at the edge of the screen. As it moves towards the center, how do I scale it down in size?

Tried
Code: [Select]
setScale and
Code: [Select]
scale in my move function and update function but did not work.

3
General / Re: Populate vector every few seconds
« on: September 20, 2017, 12:18:39 pm »
I have tried that as well. Giving a small range, 4.5 - 5.5.
Should this work?
Code: [Select]
if(clock.getElapsedTime().asSeconds() > x-0.5 && clock.getElapsedTime().asSeconds() < x+0.5)

4
General / Populate vector every few seconds
« on: September 20, 2017, 11:44:24 am »
Hi,

I have a Rock class with rock constructor that sets the initial position of the rock.
There should be multiple rocks in the game that appear periodically.

I created a vector,
Code: [Select]
vector<*Rock> _rock;
I want to push_back a new rock every few seconds. How do I do this?
I Tried:
Code: [Select]
sf::Clock clock;
int x = 5;
if (clock.getElapsedTime().asSeconds() == x) {
   _asteroids.push_back(new Asteroid(*_player));
}
x = x +5;

This does not work. Am I on the correct track? What should I do?

5
General / Enemy movement to Player
« on: September 19, 2017, 09:42:07 pm »
I have a Player class that houses my player.
I have an Enemy class that houses my enemy.

I want an enemy to appear at the center of the screen and then get the position if the player and move in that direction, in a straight line.
It must not follow but rather get the position of the player at a point in time and move in a straight line to that position and off the screen.
I can get it to move to the player using vector maths, but how do I make it continue to go off the screen in that straight line?
I do I get the player's position? I get the position but it's the live position that the player is moving in which is constantly updated.
How do I store these enemies? Using a vector, but how to go about it?

6
General / Passing arguments in classes - Error: no function to call
« on: September 19, 2017, 10:55:10 am »
I have a class called Rock and I'm passing in my player class.

Code: [Select]
Rock::Rock(Player& player){
    _rock.setTexture(_rockTexture);
    _rock.setOrigin(650,500);
    _rock.setPosition(X, Y); 

   _player = &player;
}

In my Game glass, which is the game engine, I get an error

Code: [Select]
Game::Game():
    _window(sf::VideoMode(WIDTH, HEIGHT), "ROCK"){

}

Error: no function to call Rock::Rock()

I assume this is because rock is taking a parameter.
But in Game:Game, how am I supposed to define something here to satisfy this error?
I tried making the Rock object in Game a pointer by that crashes the program.

If I had to pass any argument into the Rock constructor, how do I satisfy it in the Game class?

7
General / Passing Class by Reference
« on: September 18, 2017, 08:58:51 pm »
I have a player class which house my player move function.

I have a second class, a rock class. In this rock class, I need to pass the position of the player at its current time. How do I go about doing that? Do I pass the entire class by reference? since I always need the new and current value of player.

8
General / Re: Moving in radial lines.
« on: September 17, 2017, 10:13:17 pm »
Code: [Select]
void Player::move(){
    angle = 0.5;
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right) || sf::Keyboard::isKeyPressed(sf::Keyboard::D)){
        transform.rotate(angle, {600, 350});
    }

I have defined the center as (600, 350).
An object will appear at the center and should fly radially outwards in a straight line to the players position.
I'm thinking,
Code: [Select]
player->getPosition() ? and take the difference between the player and object.
But then how to make the object fly past the player?

9
General / Moving in radial lines.
« on: September 17, 2017, 09:43:19 pm »
Hi,

I have a player that is confined to move around along a circle of set radius.
I want an object that should appear from the center of this circle to fly out at the player in a straight line and continue pass him. How do I go about doing this?

I can understand to get the players position and take the difference and use vector maths, but that would mean the object would stop flying once it reaches the players position at that time. How do I make it continue flying, until it goes off screen?

10
General / SFML - Moving to distinct point
« on: September 15, 2017, 11:35:18 pm »
HI

I have a player that moves in a circle. I used sf::transform and rotate which takes in the angle in degrees and the center to rotate about. I want to fire bullets from this circle to the center. The center point is predefined.
How do I go about doing this? I am trying to use vector maths but it is not working out. It moves but not to the correct location.
And also how do I map the bullet to the player each time the player shoots?
I've added some of my code for reference.

  void Player::turn(){
    float angle = 0.5;
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)){
        transform.rotate(angle, {1920/2.f, 1080/2.f });
    }
}

void Shoot::update(sf::RenderWindow& window){
    float bulletX = _bullet.getPosition().x;
    float bulletY = _bullet.getPosition().y;
   
    float disX = _center.getPosition().x - bulletX;
    float disY = _center.getPosition().y - bulletY;
    float shot_RotationAngle = (atan2(disX, disY));
    _bullet.setRotation( (shot_RotationAngle * 180 / 3.14159265) );
   
    // Distance formula
    float length= sqrt(disX*disX + disY*disY);
       
    float newX = disX;
    float newX = disY;
   
    // Normalize the value
    newX/= length;
    newX/= length;

    bulletX += ((newX*0.1));
    bulletY += ((newX*0.1));

    _bullet.setPosition(bulletX, bulletY);
}
 

Pages: [1]