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

Pages: [1]
1
General / Re: Adding shapes to vector
« on: November 07, 2018, 05:05:27 pm »
I don't really know how to do that, nor how to operate with an array like this afterwards. Somebody got an idea how to do it with vectors?  :-\

Or can somebody explain me what is the problem with my stuff above?

2
General / Re: Adding shapes to vector
« on: November 07, 2018, 04:49:37 pm »
Hi,

I'm sure that it works with an array, but I'm not sure if it works with a vector (List<T> in C#)

i.e. (in C#)

Parent[] array = new Parent[] { new Child1(), new Child2(), new Child1(), new Child4() };

Or maybe if you don't make the generic type "const" ... ?  ::)

........

What has happened with your Arkanoid clone project? Remember that Hapax and i tried to help you?  ;D
(sorry for the out of topic)

I abandoned it for now due to the issue I still couldn't solve. Maybe I'll just use a sprite with rounded edges like another project does where this issue doesn't appear.

I'll try to implement your suggestion to my code and gonna see if it works.

3
General / Adding shapes to vector
« on: November 06, 2018, 03:23:19 pm »
Hi, I want to make a class with a vector inside that storages shapes for me (e.g. a rectangle, circle). I know that sf::RectangleShape's and sf::CircleShape's base class is sf::Shape, so I made a class like that (includes are irrelevant here, they are fine):
//header file
class ObjectStorage
{
private:
        std::vector <std::shared_ptr<sf::Shape>>sequence;

public:
         ObjectStorage();
         void add(std::shared_ptr<sf::Shape> const &ob);
         void show();
};
//cpp file
void ObjectStorage::add(std::shared_ptr<sf::Shape> const &ob)
{
        sequence.push_back(ob);
}

As you can see whenever I want to call the method add with a rectangle or circle shape called test1 I do it like that (objectstorage is a pointer that is initialized with the ObjectStorage constructor, no problems with it as well):

objectstorage->add(test1);

Although it gives me this compiler error "no suitable user-defined conversion from "sf::RectangleShape" to "const std::shared_ptr<sf::Shape>" exists".
How can I store rectangle, convex and circle shapes in a single vector?

4
General / Issue with collision
« on: September 17, 2018, 07:02:13 pm »
Hi, I got a strange problem with my Arkanoid clone, whenever the ball hits a corner of the paddle it doesn't bounce off like expected:
https://media.giphy.com/media/vguZfLMc4eyiu3M7ls/giphy.gif

I already tried to fix it on several ways, one of them was:
/*I use the Collision class from Sonar Systems tutorial videos, although it happens with normal getGlobalBounds().intersects (and so on) collision check too.*/

else if (Collision::PixelPerfectTest(ball, paddle.getShape()))
{
   if (!ball.getGlobalBounds().contains(paddle.getShape().getPosition().x, paddle.getShape().getPosition().y))
        {
             y_ballSpeed = -y_ballSpeed;
        }
}

I wanted to check if the ball collides with the top left corner of the paddle (I could check every corner by adding some numbers above), if not it would normally bounce off, but it doesn't have any effect. The problem appears only if the ball hits a corner, except of that it works pretty well.

5
General / Re: Syntax error with identifiers
« on: September 16, 2018, 06:38:10 pm »
Thanks, I fixed it with a forward declaration. Can it be solved without it though? Just being curious.

6
General / Syntax error with identifiers
« on: September 16, 2018, 11:51:23 am »
Hi, I'm struggling with a compile-time error that tells me there's a syntax error with an identifier. It doesn't only appear with 'Ball', but also with other identifiers. I restarted my PC and VS already, but it still doesn't work. I'm already trying to fix it for a week.

//Blocks.h

#pragma once
#include <SFML/Graphics.hpp>
#include "Ball.h"
#include "Variables.h"

class Blocks
{
private:
        sf::RectangleShape blocks[16];
public:
        Blocks();
        sf::RectangleShape getShape(int i);
        bool checkCollision(Ball &ball);        // syntax error: identifier 'Ball'
        void draw(sf::RenderWindow &window);
};


//////////////////////////////////////////////////////////////

//Function checkCollision in Blocks.cpp

bool Blocks::checkCollision(Ball &ball)
{
        for (int i = 0; i < 16; i++)
        {
                if (ball.getShape().getGlobalBounds().intersects(blocks[i].getGlobalBounds()))
                {
                        blocks[i].setPosition(-100.f, -100.f);
                        return true;
                }
        }
        return false;
}

//////////////////////////////////////////////////////////////
//Function call in Game.cpp

if (blocks->checkCollision(*ball))       // 'Blocks::checkCollision': function does not take 1 arguments
{
        ball->moveAfterCollision();
}
 

There's no error with the definition of checkCollision(*ball) in Blocks.cpp, only with the declaration in Blocks.h.
ball->moveAfterCollision(); doesn't cause the problem too.

7
General / Re: Collision by differentiating colors
« on: September 01, 2018, 02:57:25 pm »
It's working well, though it throws an exception once the hits the bottom of the screen. No compiler errors.

(click to show/hide)

bool Player::checkCollision(Level level)
{
        const sf::Color wallcolor(85, 255, 234);
        const sf::Image image = level.getImage();

        int a, b;

        for (a = 0; a < 20; a++)
                for (b = 0; b < 20; b++)
                        if (image.getPixel(player.getPosition().x + a, player.getPosition().y + b) == wallcolor)
                                return true;
        return false;
               
}


8
General / Re: Collision by differentiating colors
« on: September 01, 2018, 01:43:15 pm »
Thanks for help @Hapax @Tigre Pablito, I'll try out what Pablito suggested.

9
General / Re: Collision by differentiating colors
« on: August 29, 2018, 05:14:27 pm »
Assuming that your level doesn't change, you can retrieve the colour of a pixel of an image easily.

The texture loading shortcut step will have to be skipped though like so:
sf::Image image;
if (!image.loadFromFile("image.png"))
    return EXIT_FAILURE;
sf::Texture texture;
if (!texture.loadFromImage(image))
    return EXIT_FAILURE;
sf::Sprite sprite(texture);

Then, you can check any pixel of that image at any time:
const sf::Color colorAtXy = image.getPixel(x, y);
See: https://www.sfml-dev.org/documentation/2.5.0/classsf_1_1Image.php#acf278760458433b2c3626a6980388a95

Thanks for replying, I understand what you mean. The main problem is I don't really know how I can check the collision if the player gets on that certain color (I can't make an if statement if it intersects any of the walls' pixels, it would be very much to check). Normally to check if the player's colliding with one of the walls (in this example rectangles) I'd write it as the following:

bool Player::checkCollision(Level level)
{

        for (int i = 0; i <= 6; i++)
        {
                if (level.getRects(i).getGlobalBounds().intersects(player.getGlobalBounds()))
                {
                        return true;
                }
        }
        return false;
       
}

But now I need to figure out how to check if the player intersects this certain (here turquoise) color.

10
General / [SOLVED] Collision by differentiating colors
« on: August 29, 2018, 03:17:11 pm »
Hi, I'm writing a maze game where you need to go through tight tunnels. Once you touch the wall, you lose and need to start from the beginning. I know that I can basically draw rectangles and iterate through them to check if the player sprite intersects any of them, but it would be very time consuming to make several levels. I made the background (tunnels) in GIMP (picture below), and would like the collision to be detected if the player intersects a pixel with the color of the wall (here it's turquoise). Unfortunately I haven't got an idea what classes, functions and anything like that I could use to do so.

(click to show/hide)

11
General / Re: How can I make a rectangle follow the mouse cursor?
« on: August 29, 2018, 03:07:04 pm »
Thanks for your help, it can be closed and archived.

12
General / [SOLVED] How can I make a rectangle follow the mouse cursor?
« on: August 24, 2018, 06:55:14 pm »
Hi, I'm currently writing a simple game.
I want a rectangle to be at the cursor's position whenever the mouse has been moved. I found a solution on how to do it, but it's not working like it actually should. The rectangle is always located the same distance away, just like in the picture below (yellow dot imitates the cursor, it hasn't been caught on print screen):
(click to show/hide)

Code:
(click to show/hide)
I hope to receive some advice on how to do it, thanks in advance.

13
Code: [Select]
#include <SFML/Graphics.hpp>
#include <iostream>

class Game
{
sf::RenderWindow window(sf::VideoMode(800, 600), "Game");
public:
//void render();
//void update();

};

int main()
{

}

I've done that but the compiler says it expects a ")", identifiers, constant and string. It's just like it wouldn't be recognized within the class.

14
I know what a member variable is, I also don't want to buy a book if there's a documentation and tutorials on how SFML classes work etc. I wanted to know how I can program with SFML by doing it OOP-wise, like a short tutorial that would show some examples of a class that creates a window object or something like that.

15
Hi, I'm new to SFML and I'd like to know how to program something by doing it object oriented. The problem is, when I make a static method for rendering a window for example, the object won't be recognized outside of the method in the class. I'd like to make classes such as Graphics where I can collect all the textures, Render, Player for physics and so on. Down below you can see one of the opportunities I've tried, I'm aware that it cannot work because the object window can be only seen within the method "createWindow". I just need an advice on how it works with SFML so I can get forward. Thanks in advance.

Code: [Select]
#include <SFML/Graphics.hpp>
#include <iostream>

class Game
{
public:
static void createWindow()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "Test");
}
static void render()
{
while (window.isOpen()) //i've also tried Game::window and so on
{
window.clear();
window.display();
}
}
};
int main()
{
Game::createWindow();
Game::render();

}

Pages: [1]