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

Pages: [1]
1
General / Game Speed Consistency
« on: April 14, 2014, 10:53:46 am »
How do I make sure that my game runs at the same speed on all computers? The problem occurred when i transferred my game project from my old laptop to my new one. The game runs too fast and is unplayable.

Game background: Its a small top-down car game with three ai's trying to shoot you down. Game ends when a bullet collides.

If any more information is required I'll be more than happy to share.

int main()
{      
        sf::Clock clock;
        bool end_game= false;
        initialize_cars();
        initialize_bullets();
        initialize_explosion_sprite();
    while (window.isOpen())
    {  
        sf::Event event;
        if (window.pollEvent(event))
        {
            if (event.type== sf::Event::Closed || (event.type== sf::Event::KeyReleased) && (event.key.code== sf::Keyboard::Escape))
                window.close();
        }
                       
        move_cars();
        set_bullet_timer(&clock);
        move_bullets();
       
                end_game= bullet_collision(&clock, &black_car, &blue_bullet);
                if(end_game== true)
                break;
               
                end_game= bullet_collision(&clock, &black_car, &red_bullet);
                if(end_game== true)
                break;
               
                for(int i=0; i<2; i++)
        {
                end_game= bullet_collision(&clock, &black_car, &green_bullet[i]);
                if(end_game== true)
                        break;
        }
        if(end_game== true)
                break;
       
                window.clear(sf::Color::White);
                display_cars();
                display_bullets();
        window.display();
    }
    return 0;
}

2
General / Re: How to Delete/Remove Sprite?
« on: February 26, 2014, 11:13:25 am »
Sorry to be unclear. Its my first attempt making a game and coding on sfml.

I have a "car sprite" which on collision with a "bullet sprite" should, well, for now disappear/get removed/get deleted.
 
Any help on how to achieve that?

3
General / How to Delete/Remove Sprite?
« on: February 26, 2014, 11:02:24 am »
mySprite.setTexture(NULL) gives syntax error.

Any alternatives?

4
General / Re: Changing from dev c++ to visual studio 2012
« on: September 13, 2013, 03:41:35 pm »
Im sorry I didn't get you...

This is the part of the code till it runs.

Quote
#include<SFML/Graphics.hpp>
#include<iostream>
#include<cmath>

#define PI 3.14159265

using namespace std;

int main()
{
   const int xRes= 1300;
   const int yRes= 700;
   
   sf::RenderWindow window(sf::VideoMode(xRes, yRes), "Window");
   
   float carLength= 35, carBreadth= 15, bulletLength= 20, bulletBreadth= 10;
   
   float xCar= 100, yCar= 100;
   sf::Texture car_texture, bullet_texture;
   if(!car_texture.loadFromFile("black_car.png"))
      cout<<"Could not load image file"<<endl;

Then it breaks saying...

Quote
First-chance exception at 0x748EDCF8 (msvcr110.dll) in sfml_prac.exe: 0xC0000005: Access violation reading location 0x00511000.
Unhandled exception at 0x748EDCF8 (msvcr110.dll) in sfml_prac.exe: 0xC0000005: Access violation reading location 0x00511000.

5
General / Re: Changing from dev c++ to visual studio 2012
« on: September 13, 2013, 03:08:07 pm »
Problem occurs when the image is being loaded in the texture variable. Where exactly do i need to save the '.png' files? Or do i have the give the full path name? Right now there are in the debug folder along with the sfml dlls and project application/run file

6
General / Changing from dev c++ to visual studio 2012
« on: September 13, 2013, 02:42:30 pm »
I first got sfml up and running perfectly in visual studio 2012(got the green circle and everything).

Then I copy-pasted the code, since it was a small project containing only a main file.
Next I pasted a few sprites which I'm using in the code in the debug folder of my project in visual studio.

The project compiles and builds fine. When I run it, I get an unhandled exception with msvcr110.dll in braces.

Help will be really appreciated. 

7
General / Re: Simultaneous input
« on: July 19, 2013, 03:16:38 pm »
It took me while to realize the difference. xD Really dumb of me.

Thanks a lot.

8
General / Simultaneous input
« on: July 19, 2013, 02:37:26 pm »
How do I go about moving and turning the rectangle at the same time. He is my code..

#include<SFML/Graphics.hpp>
#include<iostream>
#include<cmath>

#define PI 3.14159265

using namespace std;

void displace(sf::RectangleShape *shape, float angle)
{

}

int main()
{
        const int xRes= 800;
        const int yRes= 600;
       
        sf::RenderWindow window(sf::VideoMode(xRes, yRes), "Window");
       
        float rectLength= 20, rectBreadth= 10;
        sf::RectangleShape rectangle(sf::Vector2f(rectLength, rectBreadth));
       
        float xCod= 100, yCod= 100;
        rectangle.setPosition(xCod, yCod);
        rectangle.setFillColor(sf::Color::Black);
        rectangle.setOrigin(rectLength/2, rectBreadth/2);
       
        float direction, speed= 0.5;
       
        while(window.isOpen())
        {
                sf::Event event;
                while(window.pollEvent(event))
                {
                        if(event.type== sf::Event::Closed || (event.type== sf::Event::KeyReleased) && (event.key.code== sf::Keyboard::Escape))
                                window.close();
                }
               
                if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
                {
                        direction= rectangle.getRotation();
                        rectangle.move(speed*cos(direction*PI/180), speed*sin(direction*PI/180));
                }
               
                else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
                {
                        direction= rectangle.getRotation();
                        rectangle.move(-speed*cos(direction*PI/180), -speed*sin(direction*PI/180));
                }
               
                else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
                {
                        rectangle.rotate(-0.5);
                        direction= rectangle.getRotation();
                }
                else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
                {
                        rectangle.rotate(0.5);
                        direction= rectangle.getRotation();
                }
               
                window.clear(sf::Color::White);
                window.draw(rectangle);
                window.display();
        }
        return 0;
}

9
Thanks. I did read it, ill try again. Maybe look for more examples.

10
I've created basic shapes like rectangles, triangles and lines but they all rotate from one end of the object. I want to uniformly rotate it from the center of the object. Intention is to create a car(top down) driving on the screen.

11
General / Re: Basic collision detection
« on: July 17, 2013, 02:19:02 pm »
Thanks a lot. It worked. :)

12
General / Re: Basic collision detection
« on: July 17, 2013, 01:38:00 pm »
if(x<0)
           {
              x= 0;
              rectangle.setPosition(x, y);
           }


I changed it into the above, still no difference.

13
General / Basic collision detection
« on: July 17, 2013, 12:15:52 pm »
I'm really sorry of asking such a basic question, but I tried fixing it with searches and the sfml documents and couldn't get it. Also, it's my first sfml/graphics program.

All i want to is for my rectangle to not go out of the screen.

Here's my code.   

#include <SFML/Graphics.hpp>

int main()
{
   float x= 50, y= 50, width= 20, height= 10, xVid= 800, yVid=600;
   float mov= 0.5;
   
    sf::RenderWindow window(sf::VideoMode(xVid, yVid), "SFML works!");
   
    sf::RectangleShape rectangle(sf::Vector2f(width, height));
    rectangle.setFillColor(sf::Color::White);
    rectangle.setPosition(x, y);

    while (window.isOpen())
    {   
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
           
            if(event.type== sf::Event::KeyReleased)
            {
               if(event.key.code== sf::Keyboard:: Escape)
                  window.close();
            }
        }      
       
        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
        {
           
           if(x<0)
              x= 0;
           else
              rectangle.move(-mov,0);
        }   
           
        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
        {
           if(x+width>600)
              x= 600- width;
           else
              rectangle.move(mov,0);
        }
       
        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
        {
           if(y<0)
              y= 0;
           else
              rectangle.move(0, -mov);
        }
       
        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
        {
           if(y+height> 800)
              y= 800- height;
           else
              rectangle.move(0, mov);
        }
       
        window.clear();
        window.draw(rectangle);
        window.display();
    }
    return 0;
}

Pages: [1]