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.


Topics - anoynlk

Pages: [1]
1
General / Inverting velocity to bounce an object (along x-axis)
« on: April 14, 2017, 02:57:25 pm »
Hey guys,

I'm programming a small game and apart from a few issues it's coming along nicley.

One problem I have is one of the enemies will move from left to right across the screen, he will also be affected by negative gravity to increase his velocity to travel upwards aswell.

For this i'm using:

Code: [Select]
move(velocity * dt);

The full code for inside it's update(dt); is as follows:

Code: [Select]
void Enemy3::update(float dt)
{
// moving from left to right of the screen and having negative gravity effecting the y movement
if (position.x >= 800)
{
velocity.x= -velocity.x;
}
if (position.x <= 0)
{
velocity.x = -velocity.x;
}
move(velocity * dt);
updateAABB(); // updating AABB collision
}

At the moment it will just keep traveling past the screen x edge untill it reaches the max y (800) and will respawn at the bottom of the screen - still traveling at a positive x velocity.

As far as i'm aware this is just inverting the velocity when it reaches the side of the screen? or have I missed somthing.

**I should note its Y velocity is being effected by a manager class which is setting its velocity by taking the players current velocity and matching it through the game.update();

Thanks

2
General / Collision with enemies being managed by a 'manager' class
« on: April 03, 2017, 09:06:53 pm »
Hey guys,

Programming my first game using SFML here and encounter a problem when testing collision between the player and an enemy.

Too add some context, the player is falling past enemies and is using A + D to avoid them, when he collides with an enemy it will kill the enemy or move it off screen (thus killing it) and for testing purposes is moving the player to the top left of the screen aswell. The enemies are being managed by a manager class and the player is not.

code as follows for the collision check in game.update();
Code: [Select]
for (int i = 0; i < enemy1M.getEnemies().size(); i++)
{
if (enemy1M.getEnemies()[i].isAlive()) // check if alive first
{
// call the slow enemies function if they collide
player.collisionResponse();
enemy1M.getEnemies()[i].collisionResponse();
//enemy1M.getEnemies()[i].setPosition(850, 850); <-- this does not work either
}
}

if you need to see any other code let me know and i'll post asap (i'll be monitoring this thread) - didn't want to spam the page with unnecessary code!

Thanks for any time you contribute!   :)

Pages: [1]