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

Pages: [1]
1
General / Deleting and spawning object
« on: March 29, 2018, 10:58:27 am »
How can i delete object when it passes the player and spawn new in the same time?

#pragma once
#include <vector>
#include <SFML\Graphics.hpp>


class TBlocks:public sf::Drawable
{
public:
        TBlocks(float t_Y);
        TBlocks()=delete;
        ~TBlocks();

        void update_block();
        void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
        sf::Texture block_texture;
        sf::Sprite blockSprite;
        sf::Texture *bTexture = &block_texture;
        sf::FloatRect blockBound();
        sf::Sprite getSprite();
        sf::Vector2f getPosition();




private:
       

       
        std::string blocks[2];


};

 

#include "TBlocks.h"
#include "Collision.h"
#include <iostream>
#include <stdio.h>    
#include <SFML\Graphics.hpp>
#include <stdlib.h>  
#include <algorithm>
#include <random>
#include <time.h>



TBlocks::TBlocks(float t_Y)
{
        //POSITION X
        int position_of_block_X[8] = {100, 200, 300, 400, 500, 600,700,800};

        //ROTATION
        int rotation_of_block[5] = { 30,20,45,90,15 };

        //PATHS TO BLOCKS
        blocks[0] = "blocks/oracle_1.png";
        blocks[1] = "blocks/rectangle_1.png";
       

        //RANDOM BLOCKS
        std::random_device block_rseed;
        std::mt19937 block_rgen(block_rseed());
        std::uniform_int_distribution<int> block_idist(0, 2);

        int B = block_idist(block_rgen);
        //RANDOM BLOCKS END


        //RANDOM POSITION X
        std::random_device position_rseed;
        std::mt19937 position_rgen(position_rseed());
        std::uniform_int_distribution<int> position_idist(0,7);

        int X = position_idist(position_rgen);
        //RANDOM POSITION X END


        //RANDOM ROTATION
        std::random_device rotation_rseed;
        std::mt19937 rotation_rgen(rotation_rseed());
        std::uniform_int_distribution<int> rotation_idist(0, 4);

        int R = rotation_idist(rotation_rgen);
        //RANDOM ROTATION END

       
       
        Collision::CreateTextureAndBitmask(block_texture, blocks[B]);
        blockSprite.setRotation(rotation_of_block[R]);
        blockSprite.setTexture(block_texture);
        blockSprite.setPosition(position_of_block_X[X], t_Y);
        blockSprite.setOrigin(sf::Vector2f(blockSprite.getTexture()->getSize().x * 0.5, blockSprite.getTexture()->getSize().y * 0.8));
}

void TBlocks::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
        target.draw(this->blockSprite, states);
}
void TBlocks::update_block()
{
        blockSprite.move(0, 3);
}

sf::FloatRect TBlocks::blockBound()
{
        return blockSprite.getGlobalBounds();

}


sf::Sprite TBlocks::getSprite()
{
        return blockSprite;
}

sf::Vector2f TBlocks::getPosition()
{
        return blockSprite.getPosition();
}

TBlocks::~TBlocks()
{
        std::cout << "Clean";

}

#include "TGame.h"
#include "TBlocks.h"
#include "Menu.h"
#include <iostream>
#include "Collision.h"
#include <SFML\Graphics.hpp>\

#define WIDTH 900
#define HEIGTH 950


TGame::TGame(TPlayer * player_, TBlocks * block_) : player(player_), block(block_), mWindow(sf::VideoMode(WIDTH, HEIGTH), "GAME")
{
        mWindow.setFramerateLimit(60);
}


void TGame::run()
{
        sf::Clock clock;

        while (mWindow.isOpen())
        {
               
                processEvents();
                sf::Time elapsed = clock.getElapsedTime();
                render();
                update_game();
               
        }
}

void TGame::processEvents()
{
        sf::Event event;
        while (mWindow.pollEvent(event))
        {
                if (event.type == sf::Event::Closed)
                        mWindow.close();
                break;
        }
}


void TGame::render()
{
       
        mWindow.clear();

        mWindow.draw(*block);
        mWindow.draw(*player);
        block->update_block();
        renderBlocks();
        player->update();


        mWindow.display();
}

void TGame::renderBlocks()
{
       
                if (block->getPosition().y > (player->getPosition().y * (5.f/2) ))
                {
                        std::cout << "MNEIJSZE";
                        //block->~TBlocks();
                }

}

void TGame::update_game()
{
       
}


bool TGame::checkCollision()
{
        if (Collision::PixelPerfectTest(player->getSprite(), block->getSprite()))
        {
                std::cout << "Collision!";
                return true;
        }

}

 

2
General / Re: Collision detection
« on: March 25, 2018, 03:37:50 pm »
Oh i didn't realise that thanks

3
General / Re: Collision detection
« on: March 25, 2018, 10:23:38 am »
Quote
sf::FloatRect TBlocks::blockBound()
{
   return blockSprite.getGlobalBounds();

}
Quote
sf::FloatRect TPlayer::playerBound()
{
   return playerSprite.getGlobalBounds();
}
Quote
bool TGame::checkCollision()
{
   if (player->playerBound().instersects(block->blockBound()))
   {
      return true;
   }

}

}

}

Quote
error C2039: 'instersects': is not a member of 'sf::Rect<float>'
How can i correct this?

4
General / Re: Collision detection
« on: March 24, 2018, 09:49:51 pm »
eXpl0it3r I will appreciate if you will show me how to do it

5
General / Re: Collision detection
« on: March 24, 2018, 03:05:23 pm »
I dont now how to do this
My classes:
Quote
#pragma once
#include <vector>
#include <SFML\Graphics.hpp>


class TBlocks:public sf::Drawable
{
public:
   TBlocks(float t_Y);
   TBlocks()=delete;
   virtual ~TBlocks() = default;

   void update_block();
   void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
   sf::Texture block_texture;
   sf::Sprite blockSprite;
   sf::Texture *bTexture = &block_texture;

private:
   

   
   std::string blocks[3];


};


Quote
#ifndef TPLAYER_H
#define TPLAYER_H
#include <SFML/Graphics.hpp>


class TPlayer : public sf::Drawable
{
public:

   TPlayer(float t_X, float t_Y);
   TPlayer() = delete;
   virtual ~TPlayer() = default;
   void update();

   float moveRight();
   float moveLeft();

   void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
   sf::Texture playerTexture;
   sf::Sprite playerSprite;
   sf::Texture *pTexture = &playerTexture;


private:
   
   


   const double playerVelocity{4};
   sf::Vector2f velocity{ playerVelocity, 0.f };




};

#endif // TPLAYER_H


and i want to use this fuction from third class:
Quote
bool TGame::checkCollision()
{
   if (SPRITE.getGlobalBounds().intersects(SPRITE2.getGlobalBounds())

}



6
General / Collision detection
« on: March 24, 2018, 01:54:27 pm »
How can i get two sprites from different classes to put them to function which is created in third class?

7
General / SFML PixelPerfectTest function
« on: March 18, 2018, 10:05:45 pm »
I want to use this function:
 
Quote
bool TGame::PixelPerfectTest( )
{
   sf::FloatRect Intersection;
   if (Object1.getGlobalBounds().intersects(Object2.getGlobalBounds(), Intersection)) {
      sf::IntRect O1SubRect = Object1.getTextureRect();
      sf::IntRect O2SubRect = Object2.getTextureRect();

      sf::Uint8* mask1 = Bitmasks.GetMask(Object1.getTexture());
      sf::Uint8* mask2 = Bitmasks.GetMask(Object2.getTexture());

      for (int i = Intersection.left; i < Intersection.left + Intersection.width; i++) {
         for (int j = Intersection.top; j < Intersection.top + Intersection.height; j++) {

            sf::Vector2f o1v = Object1.getInverseTransform().transformPoint(i, j);
            sf::Vector2f o2v = Object2.getInverseTransform().transformPoint(i, j);

            if (o1v.x > 0 && o1v.y > 0 && o2v.x > 0 && o2v.y > 0 &&
               o1v.x < O1SubRect.width && o1v.y < O1SubRect.height &&
               o2v.x < O2SubRect.width && o2v.y < O2SubRect.height) {

               if (Bitmasks.GetPixel(mask1, Object1.getTexture(), (int)(o1v.x) + O1SubRect.left, (int)(o1v.y) + O1SubRect.top) > AlphaLimit &&
                  Bitmasks.GetPixel(mask2, Object2.getTexture(), (int)(o2v.x) + O2SubRect.left, (int)(o2v.y) + O2SubRect.top) > AlphaLimit)
                  return true;

            }
         }
      }
   }
   return false;
}
this function is from there https://github.com/SFML/SFML/wiki/Source:-Simple-Collision-Detection-for-SFML-2
I want to check collision beetwen:
Quote
#ifndef TPLAYER_H
#define TPLAYER_H
#include <SFML/Graphics.hpp>


class TPlayer : public sf::Drawable
{
public:

   TPlayer(float t_X, float t_Y);
   TPlayer() = delete;
   virtual ~TPlayer() = default;
   void update();

   float moveRight();
   float moveLeft();

   void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
   sf::Texture playerTexture;
   sf::Sprite playerSprite;
   sf::Texture *pTexture = &playerTexture;


private:
   
   


   const double playerVelocity{4};
   sf::Vector2f velocity{ playerVelocity, 0.f };




};

#endif // TPLAYER_H
and:
Quote
#pragma once
#include <SFML\Graphics.hpp>


class TBlocks:public sf::Drawable
{
public:
   TBlocks(float t_X, float t_Y);
   TBlocks()=delete;
   virtual ~TBlocks() = default;

   void update_block();
   void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
   sf::Texture block_texture;
   sf::Sprite blockSprite;
   sf::Texture *bTexture = &block_texture;

private:
   

   
   std::string blocks[3];


};

how to get sprites from this classes into function?

Pages: [1]