finally managed to create a crazy collision lol.
#include "GameScreen.h"
#include "Collision.h"
#include <iostream>
GameScreen::GameScreen()
{
}
GameScreen::~GameScreen()
{
}
void GameScreen::LoadContent() {
if (!font.loadFromFile("Font4.ttf"))
std::cout << " no font found" << std::endl;
text.setString("Press F1 To go to back");
text.setFont(font);
PlayerTexture.loadFromFile("player.png");
PlayerSprite.setTexture(PlayerTexture);
PlayerSprite.setPosition(sf::Vector2f(500, 275));
PlayerSprite.setScale(sf::Vector2f(2, 2));
//camera ?
//sf::View Camera(sf::Vector2f(400.f, 300.f), sf::Vector2f(400.f, 300.f));
//sf::Sprite* follow = &PlayerSprite;
Tile001Texture.loadFromFile("tile001.png");
//Tile001Sprite.setTextureRect(sf::IntRect(33, 30, 30, 30));
Tile001Sprite.setTexture(Tile001Texture);
//Tile001Rect.intersects
Tile001Sprite.setPosition(sf::Vector2f(445,600));
Tile001Sprite.setScale(sf::Vector2f(2,2));
if (playpos == true) {
PlayerSprite.setPosition(sf::Vector2f(33, 33));
}
}
void GameScreen::UnloadContent() {
}
void GameScreen::Update() {
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
{
// left key is pressed: move our character
//std::cout << "Player right" << std::endl;
PlayerSprite.setTextureRect(sf::IntRect(52, 0, -53, 98));
PlayerSprite.move(3.1, 0.0);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
{
// left key is pressed: move our character
//std::cout << "Player left" << std::endl;
PlayerSprite.setTextureRect(sf::IntRect(0, 0, 53, 98));
PlayerSprite.move(-3.1, 0.0);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::LAlt))
{
//playpos = true;
//PlayerSprite.setTextureRect(sf::IntRect(0, 0, 53, 98));
//if (playpos == true)
PlayerSprite.move(sf::Vector2f(0, -10));
//comment teleport
//if (PlayerSprite.getPosition().y) {
// PlayerSprite.setPosition(0, 0);
// PlayerSprite.move(sf::Vector2f(0,-1));
// }
//comment no out fly y+
//else PlayerSprite.move(sf::Vector2f(0, 1));
//if (PlayerSprite.getPosition().y) {
//PlayerSprite.setPosition(PlayerSprite);
//}
}
// gravity
if (gravity == true) {
for (int t = 0;t <= 5;t++) {
PlayerSprite.move(sf::Vector2f(0, 0.3));
}
}
else
PlayerSprite.move(sf::Vector2f(0, 0));
xposplayer = PlayerSprite.getPosition().x;
yposplayer = PlayerSprite.getPosition().y;
xpostile001 = Tile001Sprite.getPosition().x;
ypostile001 = Tile001Sprite.getPosition().y;
xvel = 0;
yvel = 0;
//if (xsetposplayer == true) {
// PlayerSprite.setPosition(PlayerSprite.getPosition());
//}
if (PlayerSprite.getGlobalBounds().intersects(Tile001Sprite.getGlobalBounds())) {
std::cout << "good job fool" << std::endl;
PlayerSprite.move(sf::Vector2f(0,0));
gravity = false;
//if (xpostile001&&xposplayer) {
// PlayerSprite.move() = Tile001Sprite.move();
// std::cout << "1" << std::endl;
// xsetposplayer = true;
// if (sf::Keyboard::isKeyPressed(sf::Keyboard::End)) {
//xposplayer = 66;
// }
//}
//else if (!xpostile001 && xposplayer) {
// xsetposplayer = false;
// std::cout << "2" << std::endl;
//}
}
else
{
gravity = true;
std::cout << "no" << std::endl;
}
// coll 2 with bug
//if (Collision::PixelPerfectTest(PlayerSprite,Tile001Sprite)) {
// std::cout << "im idiot" << std::endl;
//}
//else
//{
// std::cout << "no col" << std::endl;
//}
}
void GameScreen::Draw(sf::RenderWindow& Window) {
Window.draw(text);
Window.draw(PlayerSprite);
Window.draw(Tile001Sprite);
Window.setFramerateLimit(60);
}