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

Pages: [1]
1
Graphics / Creating a circle of circles
« on: September 08, 2014, 05:31:49 am »
Hey guys, I'm working on a small project. I'm wanting to create a circle of circles (weird right? :P) Anyway I know the trig formulas of using cos and sin for creating the circle, but when doing this I either get just one circle placed at an offset, or I get a continuous circle (I know the reasioning for that) Anyway here is what I have for my code:
#include <SFML/Graphics.hpp>
#include <cmath>

#define PI 3.14159265

int main()
{
    // create the window
    sf::RenderWindow window(sf::VideoMode(800, 600), "woot");

    // run the program as long as the window is open
    while (window.isOpen())
    {
        // check all the window's events that were triggered since the last iteration of the loop
        sf::Event event;
        while (window.pollEvent(event))
        {
            // "close requested" event: we close the window
            if (event.type == sf::Event::Closed)
                window.close();
        }

        // clear the window with black color
        window.clear();

        sf::CircleShape shape(10.f);
        shape.setFillColor(sf::Color::Green);
        shape.setOrigin(shape.getLocalBounds().width/2,
                        shape.getLocalBounds().height/2);
        shape.setPosition(window.getSize().x/2, window.getSize().y/2);
        for(int i = 0; i < 360; i++)
        {
          shape.move(cos(i*PI/180), sin(i*PI/180));
          window.draw(shape);
        }

        // end the current frame
        window.display();
    }
}
 

This draws the continuous circle. If I want a circle placed every 20 degrees or so I should be able to change the i to increase by 20 each time or so I thought. Attached is an example of what I'm wanting to draw. Anyway, does anyone have any advice? I'd really appreciate it! Thanks!

2
Window / Input manager help (SFML2.0)
« on: August 08, 2012, 06:37:35 pm »
I've been working on an input manager for a day or two. For some reason it isn't working like it should be. It works fine when using the arrow keys, but when using the wasd keys it acts like it isn't getting any input.

InputManager.hpp
#ifndef INPUTMANAGER_H
#define INPUTMANAGER_H

#include <SFML/Graphics.hpp>

class InputManager
{
        private:
                sf::Event inputEvent;
        public:
                InputManager(sf::Event);
                bool IsKeyPressed(sf::Keyboard::Key);
};

#endif
 

InputManager.cpp
#include "InputManager.hpp"
#include <SFML/Graphics.hpp>
#include <iostream>

InputManager::InputManager(sf::Event event)
{
        inputEvent = event;
}

bool InputManager::IsKeyPressed(sf::Keyboard::Key key)
{
        if(inputEvent.type == sf::Event::KeyPressed)
        {
                if(inputEvent.key.code == key)
                {
                        return true;
                }
        }
        return false;
}
 

Main loop code
while(window.isOpen())
    {
        sf::Event Event;
        InputManager *input = new InputManager(Event);
        while(window.pollEvent(Event))
        {
            //if(Event.Type == sf::Event::Closed || Event.Key.Code == sf::Key::Escape)
            if(Event.type == sf::Event::Closed || input->IsKeyPressed(sf::Keyboard::Escape))
                window.close();
        }

        //if(Window.GetInput().IsKeyDown(sf::Key::Right))
        if(input->IsKeyPressed(sf::Keyboard::D))
            playerVelocity.x = moveSpeed;
        else if(input->IsKeyPressed(sf::Keyboard::A))
            playerVelocity.x = -moveSpeed;
        else
            playerVelocity.x = 0;

        if(input->IsKeyPressed(sf::Keyboard::W) && jump)
        {
            playerVelocity.y = -jumpSpeed;
            jump = false;
        }
       
        if(input->IsKeyPressed(sf::Keyboard::Space))
        {
                        rect.setFillColor(sf::Color::Red);
        }

        if(!jump)
            playerVelocity.y += gravity;
        else
            playerVelocity.y = 0;

        playerPosition += playerVelocity;

        jump = playerPosition.y + 10 >= groundHeight;

        if(jump)
            playerPosition.y = groundHeight - 10;

        rect.setPosition(playerPosition);

        window.clear();
        level->DrawMap(window);
        window.draw(rect);
        window.display();
        delete input;
    }
 

I'm using Xubuntu 12.04 if that matters and everything is being linked dynamically.
Any help on this will be appreciated. Thanks!

Pages: [1]