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 - nevets_19

Pages: [1] 2 3
1
General / Need help with collisions with player that moves towards mouse
« on: November 11, 2014, 02:45:41 pm »
Hello everyone,

I just finished my first year at uni and am now on a 4 month break, so i thought, what great time to learn SFML and more c++ (have been doing it for about 7 months).

I made a space invaders style game no problem so i thought i would try something a little more challenging and make a top down zombie survival type game.  So far it is going quiet well except i am having issues with making the character stop move in a particular direction if they collide with another sprite/shape.

the character moves towards the mouse when the W key is pressed and away from the mouse when the S key is pressed.

i tried this for my collisions:

void Player::restrictMovement(sf::RectangleShape & shape){
        sf::FloatRect bb1 = playerSprite.getGlobalBounds();
        sf::FloatRect bb2 = shape.getGlobalBounds();

        if (bb1.intersects(bb2)){
                if (rotationAngle >= 0 && rotationAngle < 90){
                        canMoveForward = false;
                        playerSprite.move(-8.5, -8.5);
                }
                else if (rotationAngle > 90 && rotationAngle < 180){
                        canMoveForward = false;
                        playerSprite.move(8.5, -8.5);
                }
                else if (rotationAngle > 180 && rotationAngle < 270){
                        canMoveForward = false;
                        playerSprite.move(8.5f, 0.0f);
                }
                else if (rotationAngle > 270 && rotationAngle < 360){
                        canMoveForward = false;
                        playerSprite.move(-8.5, 8.5);
                }
        }
}
 

That code works to an extent, but when the player turns close to the object and the back corner of the player hit the object, they go shooting straight through it as the rotation angle is not correct any more.

this is my movement code and how i set the roation angle

void Player::setRotation(sf::RenderWindow & w){
        sf::Vector2f playerPos = playerSprite.getPosition();
        curPos = sf::Mouse::getPosition(w);

        float dX = playerPos.x - curPos.x;
        float dY = playerPos.y - curPos.y;

        rotationAngle = (atan2(dY, dX)) * 180 / PI + 180;
}
 

And my movement code

if (canMoveForward == true){
                playerSprite.move(-cos(val) * movementSpeed, sin(val) *-movementSpeed);
        }
        if (canMoveBackward == true){
                playerSprite.move(cos(val) * movementSpeed / 2, -sin(val) *-movementSpeed / 2);
        }
 


and the code where the above function is called (this is from the player.update())

        float angle = (playerSprite.getRotation() + 180) * PI / 180;
        playerSprite.setRotation(rotationAngle);
        movement(angle);
 


if anyone could help guide me in the right direction of how i would go about doing a better collision so the character can't pass through and object no matter what, it would be greatly appreciated

2
General / Need help making a shape move automatically
« on: May 19, 2011, 10:52:13 am »
Hello, i am new to SFML and i wanna just do a simple program where u press an arrow key and the ball moves in the direction until you press space bar, i know in visual basic you can get timers which do this very easily (shape.left = shape.left + 1) can u make a timer function in SFML and it constantly does the action like in Visual Basic

3
Graphics / How to load multiple images while key is being pressed
« on: April 06, 2011, 09:51:27 am »
thats a better idea

thank you all for your help

4
Graphics / How to load multiple images while key is being pressed
« on: April 06, 2011, 08:55:17 am »
oh, right so i just need to put the pictures in the same folder as my exe?

5
General / New to SFML
« on: April 05, 2011, 11:43:33 pm »
Hello, i am basically the exact same as u, new to SFMl and new to C++, but with your linker problems are you linking sfml-graphics.lib, sfml-system.lib. etc?

make sure you go into your project properties and go to linker then input, then additional dependencies and link the appropriate files, watch the tutorials on this website to find out which files you need to link

and the difference between SFML 1.6 and SFML 2 is SFMl 2 has a few more features and less bugs


P.S that youtube video does work fine if you have it set up properly i used that one =D.

also i had alot of trouble setting it up but now i know how

6
Graphics / How to load multiple images while key is being pressed
« on: April 05, 2011, 11:25:03 pm »
how do i do realitive paths XD
thanks for you help btw

7
Graphics / How to load multiple images while key is being pressed
« on: April 05, 2011, 03:17:00 pm »
Hello i have been worknig on a zelda like game and i have run into a problem, i have got a bunch of images names linkeast1 linkeast2, etc up to 10,  i want it to load them while i am holding down the right key to represent walking, however when i do this i get an output in the console window saying cannot load image unable to open file. I am using .PNG images and this is my code

Code: [Select]

if(Main.GetInput().IsKeyDown(sf::Key::Right)){
player.LoadFromFile ("C:/Users/Gaming/Documents/Visual Studio 2008/Projects/Programing/SFML/Steven Games/Zelda/Link/LinkEast.png");
player.CreateMaskFromColor(sf::Color(255, 0, 255, 255));
Player.Move (3.0, 0);
player.LoadFromFile ("C:/Users/Gaming/Documents/Visual Studio 2008/Projects/Programing/SFML/Steven Games/Zelda/Link/LinkEast1.png");
player.CreateMaskFromColor(sf::Color(255, 0, 255, 255));
Player.Move (3.0, 0);
player.LoadFromFile ("C:/Users/Gaming/Documents/Visual Studio 2008/Projects/Programing/SFML/Steven Games/Zelda/Link/LinkEast2.png");
player.CreateMaskFromColor(sf::Color(255, 0, 255, 255));
Player.Move (3.0, 0)
player.LoadFromFile ("C:/Users/Gaming/Documents/Visual Studio 2008/Projects/Programing/SFML/Steven Games/Zelda/Link/LinkEast3.png");
player.CreateMaskFromColor(sf::Color(255, 0, 255, 255));
Player.Move (3.0, 0)
player.LoadFromFile ("C:/Users/Gaming/Documents/Visual Studio 2008/Projects/Programing/SFML/Steven Games/Zelda/Link/LinkEast4.png");
player.CreateMaskFromColor(sf::Color(255, 0, 255, 255));
Player.Move (3.0, 0)
player.LoadFromFile ("C:/Users/Gaming/Documents/Visual Studio 2008/Projects/Programing/SFML/Steven Games/Zelda/Link/LinkEast5.png");
player.CreateMaskFromColor(sf::Color(255, 0, 255, 255));
Player.Move (3.0, 0)
player.LoadFromFile ("C:/Users/Gaming/Documents/Visual Studio 2008/Projects/Programing/SFML/Steven Games/Zelda/Link/LinkEast6.png");
player.CreateMaskFromColor(sf::Color(255, 0, 255, 255));
Player.Move (3.0, 0)
player.LoadFromFile ("C:/Users/Gaming/Documents/Visual Studio 2008/Projects/Programing/SFML/Steven Games/Zelda/Link/LinkEast7.png");
player.CreateMaskFromColor(sf::Color(255, 0, 255, 255));
Player.Move (3.0, 0)
player.LoadFromFile ("C:/Users/Gaming/Documents/Visual Studio 2008/Projects/Programing/SFML/Steven Games/Zelda/Link/LinkEast8.png");
player.CreateMaskFromColor(sf::Color(255, 0, 255, 255));
Player.Move (3.0, 0)
player.LoadFromFile ("C:/Users/Gaming/Documents/Visual Studio 2008/Projects/Programing/SFML/Steven Games/Zelda/Link/LinkEast9.png");
player.CreateMaskFromColor(sf::Color(255, 0, 255, 255));
Player.Move (3.0, 0)

}







Thank you for any help, this was just a guess on how to do this so it might be wrong =D i am pretty bad at SFML

8
Graphics / How Can i Draw a Map??
« on: March 18, 2011, 12:05:16 pm »
duh... how do i do this

9
Graphics / How Can i Draw a Map??
« on: March 17, 2011, 09:59:01 am »
ok thank you, i was wondering if you could do it like in game maker, you make one tree object and you can use it everywhere rather than making many

10
Graphics / How Can i Draw a Map??
« on: March 17, 2011, 06:22:54 am »
Hello i have been trying to make a zelda like game in sfml and i want to know if there is an easier way to make multiple objects and still be able to use them for collisions, e.g. make a image named tree and a sprite named tree and draw a long line of trees instead of making like 10 sprites called tree1, tree2, tree3, etc.

thanks

also does anone know a good easy way to make maps in sfml

thanks for your help

11
General / Make Shapes Dissappear when a object hits it.
« on: January 30, 2011, 11:23:08 am »
thanks for the reply and sorry for my late reply i was away but that is a good idea and i will try the bool = true then draw the shape and vice versa

12
General / Make Shapes Dissappear when a object hits it.
« on: January 22, 2011, 03:02:16 am »
okay, thank you, i have one more question, if i have a paddle how to i make its x co-ordinate folow the mouse so if i move the mouse up the paddle moves up and vice versa.

do i just do like sprite.x = mouse.x or something similar because that how u do it in visual basic :D

13
General / Make Shapes Dissappear when a object hits it.
« on: January 21, 2011, 12:55:28 pm »
hi, at first i was gonna try to make a RPG game in sfml but then a friend suggest to start small as i just started learning it.

 so i'm trying to make a bricks type game where u bounce a ball off a paddle to hit a brick, and i want it so if i hit a brick it dissappears how would i do this? also i have no idea how to do a collision could somebody show me a bounding box collision if the ball is called ball and the brick is call brick.

thanks
XD 8)

14
Feature requests / How To Do Collisions In SFML
« on: January 13, 2011, 07:41:18 am »
got them, gonna take a look thanks for recommending them to me

15
Feature requests / How To Do Collisions In SFML
« on: January 12, 2011, 04:18:39 pm »
hmmm, i'll looks for some tutorials then

Pages: [1] 2 3
anything