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

Pages: [1]
1
Graphics / Setting points in sf::VertexArray relative to sprite
« on: July 27, 2014, 01:49:52 am »
Hi again everybody,

After more experimenting with VertexArrays, I want to set each vertex (2 vertices in the array) to one end of a sprite.  This wouldn't be that bad, except that the sprite rotates.  I might not have done too great of a job explaining what I mean, so here's a visual representation:



How can I set each vertex to stay at that end of the sprite?

Sorry for all the questions about this, I'm still learning more advanced topics of C++ and SFML, but I figured that a good way to learn would be pushing myself with harder projects, so I'm not entirely sure how to solve all the problems I run across.

Thanks for all the help!

2
Graphics / Drawing a line segment with end points set by mouse click
« on: July 24, 2014, 06:35:10 am »
Hi everybody,

I did some quick googling and I think I found how to draw the line successfully, but I have a problem setting the start and end points of the line.  When I use the code that I have now, the start point is the top left corner of the screen, and it ends wherever I click.  How can I get it to start where the first click is and end at the second click? 

This is what I have now:
Player::Player()
        : isPressed(false)
{
        points[0].color = sf::Color::Red;
        points[1].color = sf::Color::Red;
}

void Player::handleInput(sf::Event event)
{
        switch (event.type)
        {
        case sf::Event::MouseButtonPressed:
                pressed = true;
                std::cout << std::to_string(pressed) << std::endl;
                break;
        case sf::Event::MouseButtonReleased:
                pressed = false;
                std::cout << std::to_string(pressed) << std::endl;
                break;
        }
}

void Player::update(sf::RenderWindow& window, sf::Time dt)
{
        mousePos = sf::Mouse::getPosition(window);

        if (isPressed)
                points[0] = sf::Vector2f(static_cast<float>(mousePos.x), static_cast<float>(mousePos.y));

        std::cout << points[0].position.x << std::endl;
}

void Player::render(sf::RenderWindow& window)
{
        window.draw(points, 2, sf::Lines);
}

Thank you for the help!

3
General / Moving the sf::View at the same rate that the player moves
« on: July 06, 2014, 11:27:21 pm »
I want to make a sidescroller, but I ran into the problem where it seems unnecessarily complicated to get the camera to move at the same rate as the player.  If I do this:

view.move(sf::Vector2f(Speed, 0.f));

The camera moves significantly faster than the player, how can I match them up?

4
General / Methods for Collsion Detection
« on: June 19, 2014, 08:37:24 pm »
Hi everybody.

Right now I'm just working on a pong game.  So far I have the ball bouncing off the top and bottom of the screen implemented, along with scoring for the player and opponent.  But I'm having some trouble with the paddle collision.  I tried this:

if (ball.getPosition().x > player.getPosition().x &&
                ball.getPosition().x < (player.getPosition().x + PADDLE_WIDTH) &&
                ball.getPosition().y > player.getPosition().y &&
                ball.getPosition().y < (player.getPosition().y + PADDLE_HEIGHT))
        {
                ballDirX = 1;
                if (ballDirY == 1)
                        ballDirY = -1;
                else
                        ballDirY = 1;
        }

But I realized that this only checks if ONE POINT on the ball is colliding with the player's paddle, which causes problems when the player only hits part of the ball that isn't being checked for collisions.  How could I implement a collision system that doesn't have these problems?

5
General / Running an SFML Game on other computers
« on: April 09, 2014, 02:46:00 am »
Hi everybody!

So I recently finished working on a little game just for learning and all that, and I want to run it on other computers and I remember doing it a long time ago, but it wasn't the best way, since I just copied the .dll files straight into the folder with the .exe.  How should I go about running my game on other computers?

Thanks!  ;D

6
General / Adding states to the game created in the SFML Book
« on: April 06, 2014, 06:59:09 pm »
Hello everybody!

So I followed the SFML book and now I'm just editing it for a personal project, but I've encountered a project.  I'm trying to add a new state that can be accessed by a button the menu.  The code for the state compiles just fine, the button shows up and everything.  But whenever I try to click on the button I get this message (in the attached pics).  The code at Statestack,cpp, line 69 is this:
 
Could somebody please let me know whats going wrong?
Thanks!  ;D

7
General / Curious About Lighting
« on: August 29, 2013, 03:42:07 am »
Hey everybody!

I saw all of the Game Jam entries and had a stroke of inspiration.  I want to get a relatively simple lighting system ready that I might be able to use for some future projects.  I found this tutorial that would be perfect for what I would like, but it's written in an earlier version of SFML (1.6 I think).

(Link) http://www.facepunch.com/threads/showthread.php?t=1011659

Is this a relatively good system for lighting and if so, how would I convert it to SFML 1.6?  The majority of it works, but the stuff like sf::Shape::Line does not.

It doesn't really matter though, any 2D lighting system would be appreciated!

Thank you! :D

8
General / SFML GameDev Book Chapter 3 Problems
« on: August 13, 2013, 05:07:40 am »
So I've been reading the book.  And I ended up just copying the code from https://github.com/SFML/SFML-Game-Development-Book/tree/master/03_World and then I'm going to re-read the chapter so that I know what's going on without having to type everything in.

When I run it the background displays and scrolls, but none of the planes are displayed.
Is there anyway that I can fix this?

Thank you!

9
General / Some Bounding Box Help
« on: July 29, 2013, 11:48:26 pm »
Hello again everybody!

So right now I'm just trying to add some collision.  I have a tiled map ( a .txt file with different values for different textures) I'm just going to try for some bounding box collision at the moment.  This is what I have so far, but when I move the player into the enemy box, it just gets stuck.  How can I fix that, or is there a better way to implement collision with a tiled map?  Actually, a better system of implementing collision would be greatly appreciated! :D

#include <SFML/Graphics.hpp>
#include <iostream>
#include <fstream>
#include <cctype>
#include <string>
#include <vector>

const int TILE_SIZE = 32;

class Player
{
public:
        sf::RectangleShape rect;
        float top, bottom, left, right;

        Player(sf::Vector2f position, sf::Vector2f size, sf::Color color)
        {
                rect.setPosition(position);
                rect.setSize(size);
                rect.setFillColor(color);
        }

        void Update(void)
        {
                top = rect.getPosition().y;
                bottom = rect.getPosition().y + rect.getSize().y;
                left = rect.getPosition().x;
                right = rect.getPosition().x + rect.getSize().x;
        }

        bool VertCollision(Player p)
        {
                if (top > p.bottom || bottom < p.top || left > p.right || right < p.left)
                        return false;

                return true;
        }

        bool HorzCollision(Player p)
        {
                if (top > p.bottom || bottom < p.top || left > p.right || right < p.left)
                        return false;

                return true;
        }
};

int main()
{
        sf::RenderWindow window(sf::VideoMode(640, 480, 32), "Bounding Box Collision");

        Player p1(Player(sf::Vector2f(10, 10), sf::Vector2f(20, 20), sf::Color::Green)),
                p2(Player(sf::Vector2f(100, 100), sf::Vector2f(20, 20), sf::Color::Red));

        while (window.isOpen())
        {
                sf::Event event;

                while (window.pollEvent(event))
                {
                        switch (event.type)
                        {
                        case::sf::Event::Closed:
                                window.close();
                                break;
                        default:
                                break;
                        }
                }

                p1.Update();
                p2.Update();

                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
                {
                        p1.rect.move(0, -1.0f);
                        if (p1.VertCollision(p2))
                                p1.rect.move(0, 1.0f);
                }
                else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
                {
                        p1.rect.move(0, 1.0f);
                        if (p1.VertCollision(p2))
                                p1.rect.move(0, -1.0f);
                }      
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
                {
                        p1.rect.move(-1.0f, 0);
                        if (p1.HorzCollision(p2))
                                p1.rect.move(1.0f, 0);
                }
                else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
                {
                        p1.rect.move(1.0f, 0);
                        if (p1.HorzCollision(p2))
                                p1.rect.move(-1.0f, 0);
                }

                window.clear();

                window.draw(p1.rect);
                window.draw(p2.rect);

                window.display();
        }

        return 0;
}

Thanks!

10
Window / Render Function in the Player Class
« on: July 18, 2013, 02:00:56 am »
Hello everybody,

So I had a working program before but it only consisted of a header file and a cpp file.  It basically created a player sprite that moved using the arrow keys.

But now I'm splitting things up into different classes and I've encountered a problem.  In my game loop I can call:
window.draw(playerImage);
but I can't do that in the player class (at least I don't know how to).

What's giving me trouble is that I can't access the window variable from another class. I've tried adding this in my setup class and calling it from the player class, but it doesn't work:
//Setup class:
void CSetup::Render(sf::Texture texture, sf::Sprite sprite, std::string path, float x, float y)
{
        if (!texture.loadFromFile(path))
                std::cout << "Could not find " << path << std::endl;

        sprite.setTexture(texture);
        sprite.setPosition(x, y);

        window.draw(sprite);
}

//Player class
void CPlayer::RenderPlayer(void)
{
        setup -> Render(pTexture, pImage, "player.png", 384, 284);
}

When I try to do this, the screen just appears white and I can't exit the window except by closing the debug console.

How can I draw a Sprite from the player class?

Thanks for your time!

11
General / Writing Good Code
« on: July 16, 2013, 08:07:51 pm »
Hello everybody!

I'm relatively new with C++ (I have a basic understanding and so far I really like it) and I'm pretty proficient with Java.  Learning Java really helped learning C++ but the structures within cpp files and java classes is TOTALLY different.  I've just been following CodingMadeEasy's tutorials and have my code has just gotten bigger and bigger.  However, it's really ugly and sometimes hard to follow, so I split everything into different functions and I call those functions in the constructor.  Then I call the constructor in the main method.  Here's my code.

https://github.com/ChaoticCactus/SFMLProject

You can ignore the first 2 files. 

I'm just curious how I can improve my coding.

Thanks!


12
General / SFML Project for VS 2012
« on: July 14, 2013, 11:50:07 pm »
Hello everybody!

First time poster here.  I've been looking at using SFML for a while but have never had any luck at setting it up.  I've tried time and time again to use it, but for whatever reason, it never works.  I've been using SDL for a little while now (not really that long though) and at this point I'm just curious about SFML.  Is there a project for Visual Studio 2012 Express that already has SFML set up that I can download?  Because this is just driving me crazy.
 
Thanks! :D
Clockwork

Pages: [1]