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

Pages: [1]
1
General / I need help with colision map
« on: April 10, 2019, 12:36:08 am »
so I need some help seriously and as quickly as possible (deadline this Friday)

 I have created a collision map that doesn't work right
I need some serious help, I'm confused, and tried like 10 different approaches idk what to do anymore


sf::Vector2f pp = Player.GetPlayerPos();
         PtpY = static_cast<int>(pp.y/40+1);
         PtpX = static_cast<int>(pp.x/40+1);
         float Ptop = pp.y;
         float  Pbot =pp.y+Player.PlayerSprite.getGlobalBounds().height ;
         float  Pleft = pp.x;
         float Pright = pp.x + Player.PlayerSprite.getGlobalBounds().width;

int i, j;
            for ( i =1 ; i <= 20; i++)
            {
               for (j = 1; j <=20; j++)
               {
                  float top = static_cast<float>(PtpX);
                  float bot = static_cast<float>(PtpX*20);
                  float right = static_cast<float>(PtpY*20);;
                  float left = static_cast<float>(PtpY);;
                  int mk =( PtpX * 20) + PtpY;
                 
                     




                     if (Ptop > top)Player.PlayerSprite.setPosition(pp.x,pp.y--);
                     else if (Pbot <bot)Player.PlayerSprite.setPosition(pp.x, pp.y++);
                     else if (Pleft >left)Player.PlayerSprite.setPosition(pp.x--, pp.y);
                     else if (Pright <right)Player.PlayerSprite.setPosition(pp.x++, pp.y);

               }
//////////////////////////////////////////////////////////////////////////
int Overlay_Centermap[] = {
       25,25,25,25,10,10,10,10,10,52,10,10,10,10,10,10,25,25,25,25,
       25,25,25,25,25,25,10,10,10,10,10,10,10,10,10,10,25,25,25,25,
       25,25,25,25,25,25,10,10,10,10,10,10,10,10,10,10,25,25,25,25,
       25,25,25,25,10,10,10,10,10,10,10,10,10,10,10,10,10,25,25,25,
       25,25,25,25,10,25,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
       25,25,25,25,10,25,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
       10,10,10,10,10,25,10,10,10,10,10,10,10,10,10,10,10,10,10,50,
       25,25,25,25,25,25,10,10,10,10,10,10,10,10,25,25,10,25,10,10,
       51,10,10,10,10,10,10,10,10,10,10,10,10,10,25,25,10,25,10,10,
       51,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,25,10,10,
       10,10,10,10,10,10,10,10,10,10,10,10,25,25,25,25,25,25,10,10,
       10,10,10,25,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
       10,10,10,25,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
       10,10,25,25,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
       10,25,25,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
       25,25,10,10,10,10,10,10,10,10,10,25,25,25,25,11,10,10,10,10,
       25,10,10,10,10,15+S,10,10,15+S,10,10,25,25,25,25,10,10,10,10,10,
       25,10,10,10,10,13+S,10,10,13+S,10,10,25,25,25,25,10,10,10,10,10,
       47,47,47,47,47,47,10,10,47,47,47,47,47,47,47,47,47,47,47,47,
       10,10,10,10,10,10,53,53,10,10,10,10,10,10,10,10,10,10,10,10,
    };

2
General / I need help with my own class implementation
« on: January 12, 2019, 12:37:54 pm »
Good day, I´m relatively new to using SFML, I watched a ton of diferent videos for class and using it with SFML, I get the idea how it works but for some reason it wont work and I have no idea why, I made 3 classes and all of them I comented out and used meanwhile some copy-paste ones as  replacment.

my header file :
#pragma once
#include <SFML/Graphics.hpp>
class MyMap
{
public:
   MyMap(std::string &MapName, unsigned int width, unsigned int height, const int* tiles,
      unsigned int StartX, unsigned int StartY, unsigned int SizeOfOne, const int NumberofObjects);
   ~MyMap();

   /*void draw(sf::RenderWindow &window);*/
private:
   sf::Sprite sprite;
   
};

My cpp:
#include "MyMap.h"
#include "Resource.h"


MyMap::MyMap(std::string &MapName, unsigned int width, unsigned int height,const int* tiles,
   unsigned int StartX,unsigned int StartY,unsigned int SizeOfOne,const int NumberofObjects)
{
   sf::Sprite Osprite[10],OverlayMapS[2];
   sprite.setTexture(Resource::getTexture(MapName));
   for (int a = 0; a <= NumberofObjects; a++)
   {
      Osprite[a] = sprite;
    Osprite[a].setTextureRect(sf::IntRect(StartX, SizeOfOne, StartY, SizeOfOne));
    Osprite[a].setOrigin(SizeOfOne/2, SizeOfOne/2);
   }

   for (unsigned int i = 0; i < width; i++)
   {
      for (unsigned int j = 0; j < height; j++)
      {
         int curentObject = tiles[i + j * width];

         Osprite[curentObject].setPosition(i*SizeOfOne,j*SizeOfOne);
      
      }
   }

   
   
}


MyMap::~MyMap()
{
}

and my implementation in the main
[/size][/size]
const    int MPC[] =
   {
      0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
      0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 2, 0, 0, 0, 0,
      1, 1, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3,
      0, 1, 0, 0, 2, 0, 3, 3, 3, 0, 1, 1, 1, 0, 0, 0,
      0, 1, 1, 0, 3, 3, 3, 0, 0, 0, 1, 1, 1, 2, 0, 0,
      0, 0, 1, 0, 3, 0, 2, 2, 0, 0, 1, 1, 1, 1, 2, 0,
      2, 0, 1, 0, 3, 0, 2, 2, 2, 0, 1, 1, 1, 1, 1, 1,
      0, 0, 1, 0, 3, 2, 2, 2, 0, 0, 0, 0, 1, 1, 1, 1,
      1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
      2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
      3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
   };

   MyMap map(window,"Map.png", 16, 12, MPC,0,0, 40,4);
It show an Error when i implement window from my own fuction in MyMap class, I just cant get the constructor right, Can somebody help me ?? :'( :'( :'( :-[ :-\



Pages: [1]