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

Pages: [1]
1
Graphics / Re: Problem using sf::Rect
« on: January 08, 2013, 04:05:26 pm »
Thanks for the help, binary. Everything seems to be working now that I've moved the sfml headers to the top of the stdafx.h.

2
Graphics / Re: Problem using sf::Rect
« on: January 08, 2013, 02:00:26 am »
Nope, min and max seem to work outside of that method.

3
Graphics / Re: Problem using sf::Rect
« on: January 08, 2013, 01:38:53 am »
It does not seem to work, no.
Everything works fine just up until the intersect method is called.

4
Graphics / Re: Problem using sf::Rect
« on: January 08, 2013, 01:06:19 am »
It is probably me as I'm still trying to get the hang of things and I have no doubt I'm writing awful code. I'll post the header file as well in the mean time.

#ifndef BALL_H
#define BALL_H

#pragma once

#include "Player.h"
class Ball
{
        sf::Vector2f * position;
        sf::Texture texture;
        sf::Sprite sprite;
        sf::Vector2u sprite_size;
        sf::Vector2f screen_size;
        bool is_moving;
        float * moveX;
        float * moveY;
        float * speed;

public:
        Ball(sf::VideoMode *video);
        ~Ball(void);
        void Update(sf::VideoMode&,Player&);
        void Draw(sf::RenderWindow *window);
        void Collision(float *, float *,Player&);

        sf::FloatRect bRect;
};

#endif

5
Graphics / Re: Problem using sf::Rect
« on: January 08, 2013, 12:48:04 am »
Guess I'll just paste the whole file then:

#include "stdafx.h"
#include "Ball.h"
//#include "BrickBreak.h"

Ball::Ball(sf::VideoMode *video)
{
        Player * player = new Player(video);

        position = new sf::Vector2f();
       
        if(!texture.loadFromFile("ball.png"))
                std::cout << "ERROR";

        sprite.setTexture(texture);

        sprite_size = texture.getSize();

        screen_size.x = video->width;
        screen_size.y = video->height;

        position->x = player->position->x + player->sprite_size.x / 2;
        position->y = player->position->y - sprite_size.y;

        sprite.setPosition(unsigned int(position->x),unsigned int(position->y));

        is_moving = false;

        moveX = new float(1.0f);
        moveY = new float(-1.0f);

        speed = new float(1.0f);

}


Ball::~Ball(void)
{
}

void Ball::Update(sf::VideoMode &video,Player &player)
{
        if(is_moving == true)
        {
                Collision(moveX,moveY,player);
               
        }
        else
        {
                sprite.setPosition(player.position->x + sprite_size.x / 2, player.position->y - sprite_size.y);
        }

        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Space))
        {
                is_moving = true;
        }
        bRect = sprite.getGlobalBounds();
}

void Ball::Draw(sf::RenderWindow *window)
{
        window->draw(sprite);
}

void Ball::Collision(float * moveX, float * moveY,Player &player)
{
        float pos_move = 1.0f;
        float neg_move = -1.0f;
        position->x = sprite.getPosition().x;
        position->y = sprite.getPosition().y;
        sprite.setPosition(position->x + (*moveX * *speed),position->y + (*moveY * *speed));
        if(position->x <= 0)
        {
                *moveX = pos_move;
                //*speed += 0.05f;
        }
        if(position->x >= screen_size.x + 32)
        {
                *moveX = neg_move;
                //*speed += 0.05f;
        }
        if(position->y <= 0)
        {
                *moveY = pos_move;
                //*speed += 0.05f;
        }
        if(position->y >= screen_size.y - 8)
        {
                *moveY = neg_move;
                //*speed += 0.05f;
        }
        if(bRect.intersects(player.pRect) == true)
        {
                std::cout << "Hello";
        }
}

6
Graphics / Problem using sf::Rect
« on: January 08, 2013, 12:38:15 am »
Hey, I'm attempting to use the sf::Rect class to check for intersections between two sprites. The problem appears when I actually call the intersects method for the class in that I get this error:

c:\sfml\include\sfml\graphics\rect.inl(104): error C2589: '(' : illegal token on right side of '::'
1>          c:\sfml\include\sfml\graphics\rect.inl(102) : while compiling class template member function 'bool sf::Rect<T>::intersects(const sf::Rect<T> &,sf::Rect<T> &) const'
1>          with
1>          [
1>              T=float
1>          ]
1>          c:\sfml\include\sfml\graphics\rect.inl(95) : see reference to function template instantiation 'bool sf::Rect<T>::intersects(const sf::Rect<T> &,sf::Rect<T> &) const' being compiled
1>          with
1>          [
1>              T=float
1>          ]
1>          c:\sfml\include\sfml\graphics\rect.inl(28) : while compiling class template member function 'sf::Rect<T>::Rect(void)'
1>          with
1>          [
1>              T=float
1>          ]
1>          c:\users\username\documents\visual studio 2012\projects\brickbreak\brickbreak\ball.cpp(6) : see reference to function template instantiation 'sf::Rect<T>::Rect(void)' being compiled
1>          with
1>          [
1>              T=float
1>          ]
1>c:\sfml\include\sfml\graphics\rect.inl(104): error C2059: syntax error : '::'
1>c:\sfml\include\sfml\graphics\rect.inl(105): error C2589: '(' : illegal token on right side of '::'
1>c:\sfml\include\sfml\graphics\rect.inl(105): error C2059: syntax error : '::'
1>c:\sfml\include\sfml\graphics\rect.inl(106): error C2589: '(' : illegal token on right side of '::'
1>c:\sfml\include\sfml\graphics\rect.inl(106): error C2059: syntax error : '::'
1>c:\sfml\include\sfml\graphics\rect.inl(107): error C2589: '(' : illegal token on right side of '::'
1>c:\sfml\include\sfml\graphics\rect.inl(107): error C2059: syntax error : '::'

Here's the code to create the rectangles:
bRect = sprite.getGlobalBounds();
pRect = sprite.getGlobalBounds();

And here's the actual call to the intersects method:
if(bRect.intersects(player.pRect) == true)
        {
                std::cout << "Hello";
        }

Anybody able to help me out on this one?

Pages: [1]
anything