Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #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);
- /*int level[] ={
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 2, 0, 0, 2, 0, 2, 2, 2, 0, 2, 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, 2, 0, 0, 2, 0, 2, 0, 0, 2, 0, 2, 0, 2, 0, 2, 0, 0, 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, 2, 0, 0, 2, 0, 2, 0, 0, 2, 0, 2, 2, 2, 0, 2, 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, 2, 0, 0, 2, 0, 2, 0, 0, 2, 0, 2, 0, 0, 0, 2, 0, 0, 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, 2, 0, 0, 2, 0, 2, 0, 0, 2, 0, 2, 0, 0, 0, 2, 0, 0, 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, 2, 2, 2, 0, 0, 2, 2, 2, 2, 0, 2, 0, 0, 0, 2, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
- };*/
- 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));
- window.draw(tileset_sprite);
- }
- }
- }
- void newTiled::Update(Player &player){
- int playerTileX = floor((int)(player.getRect().getPosition().x / 64));
- int playerTileY = floor((int)(player.getRect().getPosition().y / 64));
- // int enemyTileX = floor((int)(snail.getRect().getPosition().x / 64));
- //int enemyTileY = floor((int)(snail.getRect().getPosition().y / 64));
- for (int i = 0; i < map_height; i++){
- for (int j = 0; j < map_width; j++){
- int tilecount = playerTileX + playerTileY * map_width;
- //
- if (level[tilecount] == 1){
- player.m_onGround = true;
- }else {
- player.m_onGround = false;
- }
- /* int tilecount2 = enemyTileX + enemyTileY * map_width;
- if (level[tilecount2] == 1){
- snail.m_onGround = true;
- } else {
- snail.m_onGround = false;
- }
- if (level[tilecount2] == 2){
- snail.FlipX(1);
- } else {
- // snail.FlipX(-1);
- }*/
- }
- }
- }
Add Comment
Please, Sign In to add comment