mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-07-04 14:43:01 +02:00
fixme: it compiles and shows the world with 4 textures which are in ther place where there should be but it does not move
This commit is contained in:
parent
f886ba36b8
commit
6c591f2ef2
@ -3,6 +3,7 @@
|
||||
|
||||
#include <cstddef> // std::size_t
|
||||
#include "../SceneNodeDerrivatives/SpriteNode.hpp"
|
||||
#include "../SceneNodeDerrivatives/entity.hpp"
|
||||
|
||||
World::World(sf::RenderWindow& window)
|
||||
: mWindow(window)
|
||||
@ -56,7 +57,7 @@ void World::buildScene()
|
||||
std::unique_ptr<Aircraft> leader(new Aircraft(Aircraft::Eagle, mTextures)); // we create the player's airplane
|
||||
mPlayerAircraft = leader.get();
|
||||
mPlayerAircraft -> setPosition(mSpawnPosition); // Set player position
|
||||
mPlayerAircraft -> setVelocity(PLAYER_SIDEWARD_VELOCITY, mScrollSpeed); // forward velocity equals scroll speed, sideward velocity equals PLAYER_SIDEWARD_VELOCITY
|
||||
mPlayerAircraft -> SetVelocity(PLAYER_SIDEWARD_VELOCITY, mScrollSpeed); // forward velocity equals scroll speed, sideward velocity equals PLAYER_SIDEWARD_VELOCITY
|
||||
mSceneLayers[Air] -> attachChild(std::move(leader)); // we attach the plane to the Air scene layer
|
||||
|
||||
std::unique_ptr<Aircraft> leftEscort(new Aircraft(Aircraft::Raptor, mTextures)); // create new airplane
|
||||
@ -66,7 +67,28 @@ void World::buildScene()
|
||||
std::unique_ptr<Aircraft> rightEscort(new Aircraft(Aircraft::Raptor, mTextures)); // create new airplane
|
||||
rightEscort -> setPosition(RIGHT_ESCORT_X_POSITION, RIGHT_ESCORT_Y_POSITION); // Set new airplane position
|
||||
mPlayerAircraft -> attachChild(std::move(rightEscort)); // leftEscort is now a child of player aircraft and it will folow it!
|
||||
}
|
||||
|
||||
void World::draw()
|
||||
{
|
||||
mWindow.setView(mWorldView);
|
||||
mWindow.draw(mSceneGraph);
|
||||
}
|
||||
|
||||
void World::update(sf::Time deltaTime) // controls world scrolling and entity movement
|
||||
{
|
||||
mWorldView.move(0.f, mScrollSpeed * deltaTime.asSeconds());
|
||||
|
||||
sf::Vector2f position = mPlayerAircraft -> getPosition();
|
||||
sf::Vector2f velocity = mPlayerAircraft -> getVelocity();
|
||||
|
||||
if(position.x <= mWorldBounds.left + WORLD_MAX_DISTANCE_FROM_BOUNDARY || position.x >= mWorldBounds.left + mWorldBounds.width - WORLD_MAX_DISTANCE_FROM_BOUNDARY) // if the player gets too close to world bounds make its velocity negative so it comes back
|
||||
{
|
||||
velocity.x = -velocity.x;
|
||||
mPlayerAircraft -> SetVelocity(velocity);
|
||||
}
|
||||
|
||||
mSceneGraph.update(deltaTime); // mSceneGraph actaully applies these velocities
|
||||
}
|
||||
|
||||
#endif // WORLD_CPP
|
||||
|
||||
@ -6,7 +6,7 @@ void Entity::SetVelocity(sf::Vector2f velocity)
|
||||
mVelocity = velocity;
|
||||
}
|
||||
|
||||
void Entity::setVelocity(float velocityX, float velocityY)
|
||||
void Entity::SetVelocity(float velocityX, float velocityY)
|
||||
{
|
||||
mVelocity.x = velocityX;
|
||||
mVelocity.y = velocityY;
|
||||
|
||||
@ -7,7 +7,7 @@ class Entity : public SceneNode
|
||||
{
|
||||
public:
|
||||
void SetVelocity(sf::Vector2f velocity);
|
||||
void setVelocity(float velocityX, float velocityY);
|
||||
void SetVelocity(float velocityX, float velocityY);
|
||||
sf::Vector2f getVelocity() const;
|
||||
|
||||
private:
|
||||
|
||||
Binary file not shown.
@ -42,5 +42,6 @@ const float WORLD_TOP_Y_POSITION = 0;
|
||||
// const float WORLD_WIDTH = 0; by default mWorldView.getSize().x
|
||||
const float WORLD_HEIGHT = 2000;
|
||||
const float WORLD_SCROLL_SPEED = -1;
|
||||
const float WORLD_MAX_DISTANCE_FROM_BOUNDARY = 150;
|
||||
|
||||
#endif // CONSTANTS_HPP
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
|
||||
|
||||
|
||||
class Game
|
||||
class Game : private sf::NonCopyable
|
||||
{
|
||||
public:
|
||||
Game(); // Sets up player radius, position and fill color
|
||||
@ -35,15 +35,27 @@ class Game
|
||||
sf::RenderWindow mWindow;
|
||||
TextureHolder mTexture;
|
||||
sf::Sprite mPlayer;
|
||||
World mWorld;
|
||||
};
|
||||
|
||||
Game::Game() : mWindow(sf::VideoMode(640, 480), "SFML Application"), mTexture(), mPlayer()
|
||||
Game::Game()
|
||||
: mWindow(sf::VideoMode(640, 480), "World", sf::Style::Close)
|
||||
, mWorld(mWindow)
|
||||
/* , mFont()
|
||||
, mStatisticsText()
|
||||
, mStatisticsUpdateTime()
|
||||
, mStatisticsNumFrames(0)
|
||||
*/
|
||||
{
|
||||
mTexture.load(Textures::Eagle, PATH_TO_PLAYER_TEXTURE);
|
||||
mPlayer.setTexture(mTexture.get(Textures::Eagle));
|
||||
mPlayer.setPosition(PLAYER_X_POSITION, PLAYER_Y_POSITION);
|
||||
/* mFont.loadFromFile("Media/Sansation.ttf");
|
||||
mStatisticsText.setFont(mFont);
|
||||
mStatisticsText.setPosition(5.f, 5.f);
|
||||
mStatisticsText.setCharacterSize(10);
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
// Resposible for managing game loop - fetching input form the window system, updating the world, and ordering the rendering of the game
|
||||
void Game::run()
|
||||
{
|
||||
/* Other useful frame rate related tecnhiques:
|
||||
@ -126,7 +138,10 @@ void Game::update(sf::Time deltaTime)
|
||||
void Game::render()
|
||||
{
|
||||
mWindow.clear();
|
||||
mWindow.draw(mPlayer);
|
||||
mWorld.draw();
|
||||
|
||||
mWindow.setView(mWindow.getDefaultView());
|
||||
// mWindow.draw(mStatisticsText);
|
||||
mWindow.display();
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
Loading…
Reference in New Issue
Block a user