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

Pages: [1]
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 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

4
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

5
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)

6
General / Is there anyway not to have a console window?
« on: January 10, 2011, 01:07:05 pm »
i have been learning sfml for 2 days and i dunno if I'm the only one who gets annoyed by this, is there any option in visual c++ so it wont show a console window or anyway not to have it come using some kind of code in SFML

also does anyone know how to make click able buttons like what u would have in a menu of a game

and finally does anyone know how to make it full screen, the window covering the whole screen with no start bar and stuff.

Thanks, your guys have been so helpful

7
General / Is SFML Good for This type game?
« on: January 09, 2011, 06:05:07 pm »
Hi all, i wanna make a top down game abit like zelda oracles of ages/Seasons (i have the sprites for that and its an awsome game)

Also Would SFML be good for making games like scorched and other side tank games


thanks, Nevets_19

8
Feature requests / How To Do Collisions In SFML
« on: January 09, 2011, 02:44:07 pm »
Hello everyone, i been looking for a tutorial on collisions in sfml as i need it to help with my first game but i can not find any can anything that helps. can anyone help me do some collisions, basically i want it if i hit a object then score changes.

Question one:Anyone Know of a good sfml 'video' tutorial site
Question two:Can anyone help me with my Collisions.


Thanks in Advanced :D

9
General / SFML Wont Run Properly
« on: January 06, 2011, 05:37:10 pm »
Hello, i have recently being trying to install SFML as it looks good and i would like to start programing game i follow the tutorial on this website and the time sample thing works fine but when i try to open a window nothing comes up its just a blank console window and no screen, this is my code

Code: [Select]

#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>

int main ()
{

    sf::RenderWindow Game(sf::VideoMode(800, 600, 32), "Game");

    sf::Event Event;

    while(Game.IsOpened())
    {
        while(Game.GetEvent(Event))
        {
            if(Event.Type == sf::Event::Closed)
                Game.Close();
        }

        Game.Clear();

        Game.Display();

    }

    return EXIT_SUCCESS;


}







thanks to anyone who can help ;D

Pages: [1]