mirror of
https://github.com/dylanbenzi/pacmen-sfml.git
synced 2026-11-27 08:26:59 +00:00
add font and basic tile positions
This commit is contained in:
Binary file not shown.
+29
-1
@@ -1,8 +1,11 @@
|
|||||||
#include <SFML/Graphics.hpp>
|
#include <SFML/Graphics.hpp>
|
||||||
#include <SFML/Graphics/CircleShape.hpp>
|
#include <SFML/Graphics/CircleShape.hpp>
|
||||||
|
#include <SFML/Graphics/Font.hpp>
|
||||||
|
#include <SFML/Graphics/Text.hpp>
|
||||||
#include <SFML/System/Vector2.hpp>
|
#include <SFML/System/Vector2.hpp>
|
||||||
#include <SFML/Window/Keyboard.hpp>
|
#include <SFML/Window/Keyboard.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
#include "TileMapLoader.h"
|
#include "TileMapLoader.h"
|
||||||
#include "TileMap.h"
|
#include "TileMap.h"
|
||||||
|
|
||||||
@@ -28,8 +31,23 @@ int main()
|
|||||||
auto window = sf::RenderWindow(sf::VideoMode({1920u, 1080u}), "Pacmen");
|
auto window = sf::RenderWindow(sf::VideoMode({1920u, 1080u}), "Pacmen");
|
||||||
window.setFramerateLimit(144);
|
window.setFramerateLimit(144);
|
||||||
|
|
||||||
sf::CircleShape pacman(16.0f);
|
const sf::Font bitFont("assets/PressStart2P.ttf");
|
||||||
|
|
||||||
|
sf::Text currTile(bitFont, "Current Tile: ");
|
||||||
|
currTile.move({1000, 50});
|
||||||
|
|
||||||
|
sf::CircleShape pacman(20.0f);
|
||||||
pacman.setFillColor(sf::Color(255, 255, 0));
|
pacman.setFillColor(sf::Color(255, 255, 0));
|
||||||
|
pacman.move({32, 32});
|
||||||
|
|
||||||
|
int x = 0;
|
||||||
|
int y = 0;
|
||||||
|
|
||||||
|
sf::Text tileX(bitFont, "0");
|
||||||
|
tileX.move({1000, 100});
|
||||||
|
|
||||||
|
sf::Text tileY(bitFont, "0");
|
||||||
|
tileY.move({1100, 100});
|
||||||
|
|
||||||
while (window.isOpen())
|
while (window.isOpen())
|
||||||
{
|
{
|
||||||
@@ -44,25 +62,35 @@ int main()
|
|||||||
window.clear();
|
window.clear();
|
||||||
|
|
||||||
window.draw(map);
|
window.draw(map);
|
||||||
|
window.draw(currTile);
|
||||||
|
window.draw(tileX);
|
||||||
|
window.draw(tileY);
|
||||||
|
|
||||||
window.draw(pacman);
|
window.draw(pacman);
|
||||||
|
|
||||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::W)) {
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::W)) {
|
||||||
pacman.move({0, -5.0f});
|
pacman.move({0, -5.0f});
|
||||||
|
y--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::A)) {
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::A)) {
|
||||||
pacman.move({-5.0f, 0});
|
pacman.move({-5.0f, 0});
|
||||||
|
x--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::S)) {
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::S)) {
|
||||||
pacman.move({0, 5.0f});
|
pacman.move({0, 5.0f});
|
||||||
|
y++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::D)) {
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::D)) {
|
||||||
pacman.move({5.0f, 0});
|
pacman.move({5.0f, 0});
|
||||||
|
x++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tileX.setString(std::to_string(x));
|
||||||
|
tileY.setString(std::to_string(y));
|
||||||
|
|
||||||
window.display();
|
window.display();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user