200 lines
4.7 KiB
C++
200 lines
4.7 KiB
C++
#include "../include/core.h"
|
|
#include <SFML/System/Vector2.hpp>
|
|
#include <SFML/Window/WindowStyle.hpp>
|
|
#include <cstdlib>
|
|
#include <SFML/Audio/SoundBuffer.hpp>
|
|
#include <SFML/Graphics.hpp>
|
|
#include <SFML/Graphics/Rect.hpp>
|
|
#include <SFML/Audio.hpp>
|
|
#include <SFML/Window/Keyboard.hpp>
|
|
#include <SFML/Window/VideoMode.hpp>
|
|
|
|
const int MAX_ENTITIES = 2;
|
|
Entity *entities[MAX_ENTITIES];
|
|
|
|
int main() {
|
|
// sf::Text hud;
|
|
// sf::Font font;
|
|
// font.loadFromFile("assets/fonts/Rajdhani/Rajdhani-Regular.ttf");
|
|
// hud.setFont(font);
|
|
// hud.setCharacterSize(75);
|
|
// hud.setFillColor(sf::Color::White);
|
|
// hud.setPosition(20, 20);
|
|
|
|
enum State { PAUSED, LEVELING_UP, GAME_OVER, PLAYING };
|
|
|
|
State state = State::GAME_OVER;
|
|
|
|
sf::Vector2f resolution;
|
|
resolution.x = sf::VideoMode::getDesktopMode().width;
|
|
resolution.y = sf::VideoMode::getDesktopMode().height;
|
|
|
|
sf::VideoMode vm(resolution.x, resolution.y);
|
|
sf::RenderWindow window(vm, "Zombie Shooter", sf::Style::Fullscreen);
|
|
|
|
sf::View main_view(sf::FloatRect(0, 0, resolution.x, resolution.y));
|
|
|
|
sf::Clock clock;
|
|
sf::Time game_time_total;
|
|
sf::Vector2f mouse_world_position;
|
|
sf::Vector2i mouse_screen_position;
|
|
|
|
Player player;
|
|
|
|
sf::IntRect arena;
|
|
|
|
|
|
while (window.isOpen()) {
|
|
// INPUT
|
|
{
|
|
sf::Event event;
|
|
while (window.pollEvent(event)) {
|
|
// if (event.type == sf::Event::Closed) {
|
|
// window.close();
|
|
// }
|
|
|
|
if (event.type == sf::Event::KeyPressed) {
|
|
if (event.key.code == sf::Keyboard::Return && state == State::PLAYING) {
|
|
state = State::PAUSED;
|
|
} else if (event.key.code == sf::Keyboard::Return && state == State::PAUSED) {
|
|
state = State::PLAYING;
|
|
// Restart clock so there isn't a frame jump
|
|
clock.restart();
|
|
} else if (event.key.code == sf::Keyboard::Return && state == State::GAME_OVER) {
|
|
state = State::LEVELING_UP;
|
|
}
|
|
|
|
if (state == State::PLAYING) {
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) {
|
|
window.close();
|
|
}
|
|
|
|
// Player movement
|
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::W)) {
|
|
player.up_pressed = true;
|
|
} else {
|
|
player.up_pressed = false;
|
|
}
|
|
|
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::A)) {
|
|
player.left_pressed = true;
|
|
} else {
|
|
player.left_pressed = false;
|
|
}
|
|
|
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::S)) {
|
|
player.down_pressed = true;
|
|
} else {
|
|
player.down_pressed = false;
|
|
}
|
|
|
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::D)) {
|
|
player.right_pressed = true;
|
|
} else {
|
|
player.right_pressed = false;
|
|
}
|
|
|
|
// LEVELING_UP
|
|
if (state == State::LEVELING_UP) {
|
|
if (event.key.code == sf::Keyboard::Num1) {
|
|
state = State::PLAYING;
|
|
}
|
|
|
|
if (event.key.code == sf::Keyboard::Num2) {
|
|
state = State::PLAYING;
|
|
}
|
|
|
|
if (event.key.code == sf::Keyboard::Num3) {
|
|
state = State::PLAYING;
|
|
}
|
|
|
|
if (event.key.code == sf::Keyboard::Num4) {
|
|
state = State::PLAYING;
|
|
}
|
|
|
|
if (event.key.code == sf::Keyboard::Num5) {
|
|
state = State::PLAYING;
|
|
}
|
|
|
|
if (event.key.code == sf::Keyboard::Num6) {
|
|
state = State::PLAYING;
|
|
}
|
|
|
|
if (state == State::PLAYING) {
|
|
arena.width = 500;
|
|
arena.height = 500;
|
|
arena.left = 0;
|
|
arena.top = 0;
|
|
int tile_size = 50;
|
|
player.spawn(arena, resolution, tile_size);
|
|
|
|
// Restart to avoid frame jump
|
|
clock.restart();
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// UPDATE
|
|
{
|
|
if (state == State::PLAYING) {
|
|
sf::Time delta = clock.restart();
|
|
|
|
game_time_total += delta;
|
|
|
|
float delta_as_seconds = delta.asSeconds();
|
|
|
|
mouse_screen_position = sf::Mouse::getPosition();
|
|
mouse_world_position = window.mapPixelToCoords(mouse_screen_position, main_view);
|
|
|
|
player.update(delta_as_seconds, mouse_screen_position);
|
|
|
|
// sf::Vector2f player_position(player.position);
|
|
|
|
main_view.setCenter(player.position);
|
|
}
|
|
|
|
// for (int i = 0; i < MAX_ENTITIES; i++) {
|
|
// entities[i]->update(delta);
|
|
// }
|
|
|
|
}
|
|
|
|
|
|
// DRAW
|
|
{
|
|
if (state == State::PLAYING) {
|
|
window.clear();
|
|
window.setView(main_view);
|
|
window.draw(player.sprite);
|
|
}
|
|
|
|
if (state == State::LEVELING_UP) {
|
|
}
|
|
|
|
if (state == State::PAUSED) {
|
|
}
|
|
|
|
if (state == State::GAME_OVER) {
|
|
}
|
|
|
|
// for (int i = 0; i < MAX_ENTITIES; i++) {
|
|
// window.draw(entities[i]->shape);
|
|
// }
|
|
|
|
window.display();
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
}
|