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

Pages: [1]
1
Graphics / [SFML 2.0] Spawn projectiles to mouse pointer problem
« on: May 19, 2013, 01:18:39 pm »
Basically, I have a function that has a spaceship follow the mouse pointer, which works perfectly.

        void lookAtMouse(sf::RenderWindow &app)
        {
                sf::Vector2f curPos = sprite.getPosition();
                sf::Vector2i position = sf::Mouse::getPosition(app);

                const float PI = 3.14159265;

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

                float rotation = (atan2(dY, dX)) * 180 / PI;

                sprite.setRotation(rotation - 180);
        }
 

I've tried to modify this to work for the projectiles it shoots, however it doesn't work and causes all kinds of graphical glitches, which I think I know why.

void MoveBullet(int numOfBullets)
{
        for (int i = 0; i < numOfBullets; i++)
        {
                                        sf::Vector2f curPos = bullet[i].getPosition();
                                        sf::Vector2i position = sf::Mouse::getPosition(app.window);

                                        const float PI = 3.14159265;

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

                                        float rotation = (atan2(dY, dX)) * 180 / PI;

                                    if (bullet[i].exists) bullet[i].Move(dX, dY);
        }
}
 
How would I approach having the projectiles fire to wherever the mouse pointer is? I can provide full source if required.

2
Window / [SFML 2.0] 2D diagonal movement problem
« on: May 17, 2013, 06:52:15 pm »
Minor question that is probably me being a huge derp, but nevertheless I am momentarily stumped.

Basically, I'm trying to implement 2D movement, which works fine, however when I try to move diagonally, the sprite faces the right direction, but its coords don't change and it doesn't move.

if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up)&&sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
{
   Ship_s.setRotation(135.f);
   Ship_s.move(7, 7);
}
 

3
Graphics / SFML 2.0 - Move in direction faced
« on: May 12, 2013, 04:42:47 pm »
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))  
              Ship_s.rotate(7.f);
      if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
              Ship_s.rotate(-7.f);
      if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))    
             Ship_s.move(cos(Ship_s.getRotation()*3.14159265/180)*3.f,sin(Ship_s.getRotation()*3.14159265/180)*-3.f);
      if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))  
             Ship_s.move(cos(Ship_s.getRotation()*3.14159265/180)*-3.f,sin(Ship_s.getRotation()*3.14159265/180)*3.f);

 

The above code works, however when I try to move the ship around the screen, it only moves in the correct direction in one of the compass directions.

What do?

EDIT: https://www.youtube.com/watch?v=0SRkzad7sVw&feature=youtu.be Here's a video of what happens.

4
Graphics / SFML 2.0 - Movement lag issue
« on: May 10, 2013, 08:51:17 pm »
I'm fairly new to SFML 2.0, used SFML 1.6 for a while so not completely new to SFML.

Basically, since 2.0 was released I figured I'd rewrite the game I'm working on to use SFML 2.0. The process went smoother than I thought it would do, but I've hit a snag. It's not exactly a big error, but the movement in all directions is fairly jittery, even with VSync/framelimits.

#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
//#include "projectile.h"
#include <iostream>

int main()
{
   sf::RenderWindow App(sf::VideoMode(800, 600, 32), "Asteroids");
   sf::Texture Ship;
   sf::Texture Space;
   if(!Ship.loadFromFile("ship.png"))
           return EXIT_FAILURE;
   if(!Space.loadFromFile("space-1.png"))
           return EXIT_FAILURE;

   sf::Sprite Ship_s;
   Ship_s.setTexture(Ship);
   sf::Sprite Space_s(Space);
   Ship_s.setPosition(200.f, 100.f);
   Ship_s.setScale(1.f, 1.f);

   sf::Clock clock;
   App.setFramerateLimit(120);
   //App.setVerticalSyncEnabled(true);
   while (App.isOpen())
   {
      sf::Time dt=clock.restart();
      sf::Event Event;
      while (App.pollEvent(Event))
      {
         if (Event.type == sf::Event::Closed)
            App.close();
      }

     
      if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))  
              Ship_s.move(-1 * 100 *dt.asSeconds(), 0);
      if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
              Ship_s.move( 1 * 50 * dt.asSeconds(), 0);
      if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))    
              Ship_s.move( 0,-1 * 50 * dt.asSeconds());
      if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))  
              Ship_s.move( 0, 1 * 50 * dt.asSeconds());

      App.clear();
      App.draw(Space_s);
      App.draw(Ship_s);
      App.display();
   }
   return EXIT_SUCCESS;
}

 

If needed, I can post a video of what it looks like. Currently running this on the latest version of Fedora 18 x86_64 on an Acer Aspire 7730. Is there anything I can do to reduce the lag?

Pages: [1]
anything