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.


Topics - Szedou

Pages: [1]
1
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 * 12] ={
        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, 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, 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, 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, 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, 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.

2
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...


3
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]