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

Pages: [1]
1
General / Re: Tilemap - check collision from sides
« on: January 10, 2017, 10:38:59 pm »
Thanks for reply!
I made something like this. It works with left/right collision and bottom. Top works as well but , now when my player is on the block the yVelocity is 0(m_Tile = true) and that is ok but the player will stay in the same Y position even when i move out of blocks. How can I get it simple to work?

counter = 0;
            for(wallit = wallGroup.begin(); wallit != wallGroup.end(); wallit++){
                bottom = wallGroup[counter].getPosition().y + 64;
                top = wallGroup[counter].getPosition().y;
                right = wallGroup[counter].getPosition().x + 64;
                left = wallGroup[counter].getPosition().x;
              if(player.getBounds().intersects(wallGroup[counter].getGlobalBounds())){
                   if(!player.m_onTile){
                        if(player.m_velocity.x > 0 && player.getPosition().x < right){
                            player.setPosition(player.getPosition().x - 1, player.getPosition().y);

                        } else if(player.m_velocity.x < 0 && player.getPosition().x > right){
                            player.setPosition(player.getPosition().x + 1, player.getPosition().y);
                        }

                        //top collision
                         else if(player.m_velocity.y > 0 && player.getPosition().y < bottom){
                                player.m_onTile = true;
                               
                        }

                        else if(player.m_velocity.y < 0 && player.getPosition().y > bottom){
                                player.setPosition(player.getPosition().x,player.getPosition().y + 2);

                        }

                   } else {
                       

                  }

              }else {
                   
              }

                counter++;
            }

2
General / Tilemap - check collision from sides
« on: January 09, 2017, 05:51:37 pm »
Hi,
I got problem. I got Tilemap.
Tilemap.h
#pragma once

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

#include "Player.h"

#include "Enemy.h"

using namespace std;
using namespace sf;

class newTiled{
    public:
        newTiled(void);
        ~newTiled(void);

        void draw(RenderWindow &);
        void Update(Player &player, Time &dt);

    private:

        vector <RectangleShape>::const_iterator wallit;
        vector <RectangleShape> wallGroup;

        int map_width = 42;
        int map_height = 12;


        Texture tileset_texture;
        Sprite tileset_sprite;

        Texture bg_txt;
        Sprite bg_sprite;

        RectangleShape t;

        int counter;

    int level[42 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0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
    };


};

 

Tilemap.cpp
#include "newTiled.h"
#include <cmath>

using namespace sf;
using namespace std;

newTiled::newTiled(){
    if(!tileset_texture.loadFromFile("assets/images/tajlmap.png"))
       return;

    if(!bg_txt.loadFromFile("assets/images/bg2.png"))
       return;


    tileset_sprite.setTexture(tileset_texture);
    bg_sprite.setTexture(bg_txt);


}

newTiled::~newTiled(){

}

void newTiled::draw(RenderWindow &window){
      window.draw(bg_sprite);

    t = RectangleShape(Vector2f(64, 64));
    t.setFillColor(sf::Color::Transparent);

    for(int y = 0; y < map_height; ++y){
        for(int x = 0; x < map_width; ++x){
            int tilecount = x + y * map_width;

            tileset_sprite.setPosition(x * 64, y * 64);
            tileset_sprite.setTextureRect(IntRect(level[tilecount] * 64, 0, 64, 64));

            if(level[tilecount] == 2){
                t.setPosition(x*64, y*64);
                wallGroup.push_back(t);
            }

            window.draw(tileset_sprite);


        }
    }

            counter = 0;
            for(wallit = wallGroup.begin(); wallit != wallGroup.end(); wallit++){
                window.draw(wallGroup[counter]);

                counter++;
            }
}

void newTiled::Update(Player &player, Time &dt){
            float bottom, top, left, right;


            int posX = floor((int)(player.getPosition().x / 64));
            int posY = floor((int)(player.getPosition().y / 64));

            int tilecount = posX + posY * map_width;

            if(level[tilecount] == 1)
                player.m_onGround = true;
            else
                player.m_onGround = false;


            counter = 0;
            for(wallit = wallGroup.begin(); wallit != wallGroup.end(); wallit++){
                bottom = wallGroup[counter].getPosition().y + 64;
                top = wallGroup[counter].getPosition().y;
                right = wallGroup[counter].getPosition().x + 66;
                left = wallGroup[counter].getPosition().x;
              if(player.getBounds().intersects(wallGroup[counter].getGlobalBounds())){
                    if(player.right > left && player.right > right){
                        player.setPosition(player.getPosition().x - 1, player.getPosition().y);
                    }
                    else if (player.left < right && player.left < left){
                           player.setPosition(right + player.left, player.getPosition().y);
                    }

                    //top tile collision
                    else if(player.bottom > top && player.bottom > bottom){

                    }  else if (player.top < bottom && player.top < top){

                        }





              }else {
                //  player.m_onTile = false;
                   // player.setColor(sf::Color::Red);
              }

                counter++;
            }

}
 

And my Player is sf::RectangleShape. I check his sides with :
    bottom = m_rect.getPosition().y + m_rect.getSize().y;
    left = m_rect.getPosition().x;
    right = m_rect.getPosition().x + m_rect.getSize().x;
    top = m_rect.getPosition().y;

And I got problem with wall collision from left/right/top/bottom just to stop player from moving etc.

3
General / Re: Problem with debuging VisualStudio 2012 AGAIN
« on: July 08, 2013, 05:48:53 pm »
Oh, now it works!!!!

I just deleted SFML_STATIC to change to static version and it is working now!

Thanks a lot all of You guys! You are great! and sorry for problems...

4
General / Re: Problem with debuging VisualStudio 2012 AGAIN
« on: July 08, 2013, 08:33:29 am »
Ok i rebuilt my code with tutorial one:

Quote
#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear();
        window.draw(shape);
        window.display();
    }

    return 0;
}

and Its not works anyway...

Quote
Error   3   error LNK1120: 2 unresolved externals   D:\VisualProjects\SFML Project_1\Debug\SFML Project_1.exe   1   1   SFML Project_1

Error   1   error LNK2001: unresolved external symbol "public: static class sf::Color const sf::Color::Green" (?Green@Color@sf@@2V12@B)   D:\VisualProjects\SFML Project_1\SFML Project_1\main.obj   SFML Project_1

Error   2   error LNK2001: unresolved external symbol "public: static class sf::RenderStates const sf::RenderStates::Default" (?Default@RenderStates@sf@@2V12@B)   D:\VisualProjects\SFML Project_1\SFML Project_1\main.obj   SFML Project_1


Arghhhh!

5
General / Re: Problem with debuging VisualStudio 2012 AGAIN
« on: July 07, 2013, 07:49:47 pm »
Here it is:

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


using namespace sf;
using namespace std;

int main()
{
    RenderWindow window(VideoMode(800, 600), "SFML works!");
   cout << "-----SFML2.0 is working!-----" << endl;

   Time _czas;
   Clock _zegar;

   Sprite   playerSprite;
   Texture player_txt;
   if(!player_txt.loadFromFile("spritesheet.png", IntRect(0,0,30,65))){ //wyswietlanie czesci obrazka a-startingPos(X),b-startingPos(Y),c-width,d-height
      cout<< "Error, could not load player image" << endl;
   }
   playerSprite.setTexture(player_txt);
   playerSprite.setPosition(0,0);

   int attack = 0; //przyklad definiowania przyciskow w grze
   //cout << _czas.asSeconds() << endl;

    while (window.isOpen())
    {

        sf::Event zdarzenie;
        while (window.pollEvent(zdarzenie))
        {
            switch(zdarzenie.type){
         case Event::Closed:
               window.close();
               break;
         case Event::MouseEntered:
               cout<<"Mouse within screen bounds."<<endl;
               break;
         case Event::MouseLeft:
               cout<< "Mouse out of screen bounds."<< endl;
         case Event::MouseMoved:
               //cout<<"X: " << zdarzenie.mouseMove.x << "Y: " << zdarzenie.mouseMove.y<<endl;
               break;
         case Event::MouseButtonPressed:
            if(zdarzenie.mouseButton.button == Mouse::Left){
               //cout<< "Left mouse button pressed at: " << " X: "<< zdarzenie.mouseButton.x << "Y "<< zdarzenie.mouseButton.y << endl;
            }
               break;
         case Event::MouseWheelMoved:
               cout<< "delta: " << zdarzenie.mouseWheel.delta << endl;
               break;
         case Event::GainedFocus:
               cout << "Window Active" << endl;
               break;
         case Event::LostFocus:
               cout << "Window not Active" << endl;
               break;
         case Event::Resized:
               cout<< "X: "<< zdarzenie.size.width << " Y: " << zdarzenie.size.height << endl;
               break;
         case Event::TextEntered:
            if(zdarzenie.text.unicode >= 33 && zdarzenie.text.unicode <=126)
               cout << (char)zdarzenie.text.unicode;
               break;
         case Event::JoystickConnected:
               cout << " GAMEPAD " << zdarzenie.joystickConnect.joystickId + 1 << " is Connected" << endl;
               break;
         case Event::JoystickDisconnected:
               cout << "GAMEPAD " << zdarzenie.joystickConnect.joystickId + 1 << " is Disconnected" <<endl;
               break;
         case Event::JoystickButtonPressed:
               cout << "Button: " << zdarzenie.joystickButton.button << endl;
               attack = zdarzenie.joystickButton.button; // odczytywanie wcisnietego przycisku do attacku..
               break;
         case Event::JoystickMoved:
               if(zdarzenie.joystickMove.axis == sf::Joystick::X){
                  cout<< "position: " << zdarzenie.joystickMove.position << endl;
               }
               
         }
        }
      _czas = _zegar.getElapsedTime();
      //cout << _czas.asSeconds() << endl;
      //_zegar.restart();
        window.clear();
      window.draw(playerSprite);
        window.display();
    }

    return 0;
}

6
General / Re: Problem with debuging VisualStudio 2012 AGAIN
« on: July 07, 2013, 05:16:19 pm »
I have D:\SFML-2.0\lib path there.

7
General / Re: Problem with debuging VisualStudio 2012 AGAIN
« on: July 07, 2013, 10:05:50 am »
eh.. I have (sfml-audio-d-2 , sfml-graphics-d-2, sfml-network-d-2, sfml-system-d-2,sfml-window-d-2) in my Debug folder and (sfml-audio-2 , sfml-graphics-2, sfml-network-2, sfml-system-2,sfml-window-2) in my Release folder.

8
General / Re: Problem with debuging VisualStudio 2012 AGAIN
« on: July 06, 2013, 10:10:46 pm »
Yes, look:



Do I need to copy something else than audio-d-2.dll, graphics-d-2.dll, network-d-2.dll, system-d-2.dll, window-d-2.dll files into Release folder(.exe directory)?

9
General / [SOLVED]Problem with debuging VisualStudio 2012 AGAIN
« on: July 06, 2013, 11:26:57 am »
Hi! I have problems with debuging with visualstudio2012 again...

I set up SFML2.0 with VisualStudio2012 as same as in tutorial and errors appear:

Error   2   error LNK1120: 1 unresolved externals   D:\VisualProjects\SFML Project_1\Debug\SFML Project_1.exe   SFML Project_1

and

Error   1   error LNK2001: unresolved external symbol "public: static class sf::RenderStates const sf::RenderStates::Default" (?Default@RenderStates@sf@@2V12@B)   D:\VisualProjects\SFML Project_1\SFML Project_1\main.obj   SFML Project_1

I think I linked files good and have audio-2.dll,graphics-2.dll,network-2.dll,system-2.dll,window-2.dll,openal32.ddll and libsndfile-1.dll in same folder as my .exe file ( Release folder ).

And in my Debug folder I have files like: audio-d-2.dll, graphics-d-2.dll, network-d-2.dll, system-d-2.dll, window-d-2.dll.

And I don't know what am I doing wrong, please help...


10
General / Re: Problem with debuging VisualStudio 2012
« on: July 03, 2013, 09:52:49 pm »
Thank You so much! Forgot to copy that files...

11
General / Problem with debuging VisualStudio 2012
« on: July 03, 2013, 05:36:52 pm »
Hi!
I have SFML2.0 set-up with VisualStudioExpress2012 for Windows Desktop.
When I release my project everything is fine, but when i try to debug, it shows error:

Error   2   error LNK2001: unresolved external symbol "public: static class sf::RenderStates const sf::RenderStates::Default" (?Default@RenderStates@sf@@2V12@B)   D:\VisualProjects\SFML Project_1\SFML Project_1\main.obj   SFML Project_1

and

Error   1   error LNK2001: unresolved external symbol "public: static class sf::Color const sf::Color::Green" (?Green@Color@sf@@2V12@B)   D:\VisualProjects\SFML Project_1\SFML Project_1\main.obj   SFML Project_1

Error   3   error LNK1120: 2 unresolved externals   D:\VisualProjects\SFML Project_1\Debug\SFML Project_1.exe   1   1   SFML Project_1

Thanks for help.

Pages: [1]
anything