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

Pages: [1]
1
Graphics / [solved]Collision counter, count increses 1 time per collision
« on: January 09, 2015, 01:35:45 pm »
Hello fellas!

I'm woundering how can I make a collision counter that only increses 1 time per collision. I want to know how to get around the game loop because everytime I hit an object the counter looks like this
0
110
110
110
110
220
220
220
330
...

All the spam is ofcourse the game loop but how can I controll it to only increse one time, I've been tring to use a bool.

game.cpp
                        cout << handler.showHighScore() << endl;
                        handler.update();
                        window.draw(handler);
                        window.display();
show function
int gameHandler::showHighScore()
{
        if (this->collided == true)
        {
                this->collided = false;
                this->score.addScore();
        }
        return this->score.showHighScore();
}
When the collision is true I'm setting a bool to not increse the score any more THE COLLISION FUNCTION IS CALLED IN THE UPDATE FUNCTION
bool gameHandler::collisionCoin(Obstacle &o)
{
       
        if (player.getSprite().getGlobalBounds().intersects(o.getSprite().getGlobalBounds()))
        {
                this->show = false;
                this->collided = true;
                return true;
        }
        return false;
}

Regards Stolle

2
Can anyone tell me what a executable is, do you mean the .exe from the debug?  :o

Because this is my debug folder

3
Quote
I have copyed the graphics,system,window -d-2.dll files to the folder where all my .cpp and .h files exists, in my case C:\temp\projekt\projekt.
Copy them where your executable is.

Well ain't that where the executable are? :O


4
Hello!

I'm having some issues with my SFML, I'm getting a error message that the sfml-graphics-d-2.dll is missing but I can run the program perfect with not debugging.

I have copyed the graphics,system,window -d-2.dll files to the folder where all my .cpp and .h files exists, in my case C:\temp\projekt\projekt.

Because it's asking for -d-2.dll and if you check the image on the linker/input I haven written -2.dll

image:

http://i.imgur.com/uzycEoP.png

running
win 7
vs 2013 ultimate 2013


Regards Stolle!

5
Graphics / Re: White texture while loading textures from array(beginner)
« on: December 21, 2014, 05:45:21 pm »
Okej so I have to overload the =operator or is there a easier way?

6
Graphics / White texture while loading textures from array(beginner)
« on: December 21, 2014, 02:25:13 pm »
Hello!

So I'm getting a stange error when I'm creating a array from something I call "Obstacle", the problem I'm having is when I'm trying to load the array(sprites) they are all turning white. Now to the strange everything works perfectly when I'm not having the array (only loading one object).

I think that I'm loading the array too many times so that everything get overwriten.

I'm not going to post the Object and the Obstacle code tho I known thats right beacuse it works when I'm creating only one obejct in gameHandler.

gameHandler.h(creating the objects here and calling to load the sprites)

#pragma once
#include "Player.h"
#include "Obstacle.h"
#include "Background.h"

class gameHandler :public sf::Drawable
{
private:
        static const int CAP = 3;
        Player player = ("img/playerSheet.png");
        Obstacle obstacles[CAP];
        //Obstacle obstacles = ("img/obstacle.png");
        Background bg = ("img/cloud.png");
        void draw(sf::RenderTarget &target, sf::RenderStates states)const;

gameHandler.cpp

calling for the constructor to load the image
gameHandler::gameHandler()
{
        for (int i = 0; i < this->CAP; i++)
        {
                this->obstacles[i] = Obstacle("img/obstacle.png");
        }
}

drawing the sprites
void gameHandler::draw(sf::RenderTarget &target, sf::RenderStates states)const
{
        target.draw(this->bg, states);
        target.draw(this->player, states);
        target.draw(this->obstacles[0], states);
        target.draw(this->obstacles[1], states);
       
}

update function
void gameHandler::update()
{
        this->player.jump();

        for (int i = 0; i < this->CAP; i++)
        {
                this->collision(this->obstacles[i]);
        }
        int yPos = rand() % 690+200;
        int xPos = rand() % 200 + 1;;

        this->obstacles[0].moveObstacle(1000, -yPos);
        this->obstacles[1].moveObstacle(1000, 1050 - yPos);

}


game.cpp (main)

#include <sfml/Graphics.hpp>
#include "gameHandler.h"
#include <iostream>
using namespace std;

int main()
{

        gameHandler handler;
        sf::RenderWindow window(sf::VideoMode(1000, 900), "Flappy bird <<Fist14>> Edition");
        srand(int(time(0)));
        sf::Clock clock;
        window.setFramerateLimit(900);
        while (window.isOpen())
        {
                sf::Event event;
                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                                window.close();

                }
                sf::Time time = clock.getElapsedTime();
                //cout << 1.0f/time.asSeconds() << endl;
                clock.restart().asSeconds();
               
                window.clear();
                handler.update();
                window.draw(handler);
                window.display();

        }

        return 0;
}


Thanks Stolle

Pages: [1]