commit 80f77c1f1472fb1db971e031f8c18deea1ac3601 Author: Nathan Chapman Date: Tue Jul 29 19:24:01 2025 -0600 Regroup games into one repo diff --git a/ping_pong/.gitattributes b/ping_pong/.gitattributes new file mode 100644 index 0000000..b333f8b --- /dev/null +++ b/ping_pong/.gitattributes @@ -0,0 +1 @@ +assets/fonts/Rajdhani/*.ttf filter=lfs diff=lfs merge=lfs -text diff --git a/ping_pong/.gitignore b/ping_pong/.gitignore new file mode 100644 index 0000000..259148f --- /dev/null +++ b/ping_pong/.gitignore @@ -0,0 +1,32 @@ +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app diff --git a/ping_pong/Makefile b/ping_pong/Makefile new file mode 100644 index 0000000..7a2abf1 --- /dev/null +++ b/ping_pong/Makefile @@ -0,0 +1,14 @@ +CXX=g++ +CXXFLAGS=-Wall -g -std=c++11 +SFML_LIBS=-lsfml-graphics -lsfml-window -lsfml-system -lsfml-audio + +all: ping_pong + +ping_pong: src/main.o src/core.o + $(CXX) $(CXXFLAGS) -o $@ $^ $(SFML_LIBS) + +%.o: %.cpp %.hpp + $(CXX) $(CXXFLAGS) -c $< -o $@ + +clean: + rm -f ping_pong *.o diff --git a/ping_pong/assets/fonts/Rajdhani/Rajdhani-Bold.ttf b/ping_pong/assets/fonts/Rajdhani/Rajdhani-Bold.ttf new file mode 100644 index 0000000..7d5e046 --- /dev/null +++ b/ping_pong/assets/fonts/Rajdhani/Rajdhani-Bold.ttf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0e2754864bf70da4f279189b713026551927c0c10258ff6dd431ff71fd6c8dd0 +size 373192 diff --git a/ping_pong/assets/fonts/Rajdhani/Rajdhani-Light.ttf b/ping_pong/assets/fonts/Rajdhani/Rajdhani-Light.ttf new file mode 100644 index 0000000..106d0dd --- /dev/null +++ b/ping_pong/assets/fonts/Rajdhani/Rajdhani-Light.ttf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9ee65da3e003d283571920f845141c3f3615f34c685357a13f8982a0b5754fea +size 357516 diff --git a/ping_pong/assets/fonts/Rajdhani/Rajdhani-Medium.ttf b/ping_pong/assets/fonts/Rajdhani/Rajdhani-Medium.ttf new file mode 100644 index 0000000..f259934 --- /dev/null +++ b/ping_pong/assets/fonts/Rajdhani/Rajdhani-Medium.ttf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:88a3937dc5d0d96d6b1a313b82802b78541bfdb5c004a208dfeab56192938538 +size 357884 diff --git a/ping_pong/assets/fonts/Rajdhani/Rajdhani-Regular.ttf b/ping_pong/assets/fonts/Rajdhani/Rajdhani-Regular.ttf new file mode 100644 index 0000000..9f054a5 --- /dev/null +++ b/ping_pong/assets/fonts/Rajdhani/Rajdhani-Regular.ttf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f0ba67d6ef91bcff8b0e43a051f7483dd83ebfcade19880cd15df29890234d2e +size 352088 diff --git a/ping_pong/assets/fonts/Rajdhani/Rajdhani-SemiBold.ttf b/ping_pong/assets/fonts/Rajdhani/Rajdhani-SemiBold.ttf new file mode 100644 index 0000000..6e00212 --- /dev/null +++ b/ping_pong/assets/fonts/Rajdhani/Rajdhani-SemiBold.ttf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5fd51c1334cafd3654059b0ee61aa470088a70e4637a9cfc0274557c751eb0cd +size 363500 diff --git a/ping_pong/include/core.hpp b/ping_pong/include/core.hpp new file mode 100644 index 0000000..2deed96 --- /dev/null +++ b/ping_pong/include/core.hpp @@ -0,0 +1,41 @@ +#pragma once +#include +#include + +struct Vector2 { + float x; + float y; +}; + +struct Entity { + Vector2 position; + sf::RectangleShape shape; + float speed; + Vector2 direction; + Vector2 velocity; + + virtual void update(sf::Time delta) = 0; + void set_position(Vector2 new_pos); + void set_size(Vector2 new_size); +}; + +struct Bat : public Entity { + bool moving_right = false; + bool moving_left = false; + + void update(sf::Time delta) override; +}; + + +enum Rebounds { + Sides, + Bat_Or_Top, + Bottom +}; + +struct Ball : public Entity { + void update(sf::Time delta) override; + + void rebound(Rebounds rb); +}; + diff --git a/ping_pong/src/core.cpp b/ping_pong/src/core.cpp new file mode 100644 index 0000000..bd10cda --- /dev/null +++ b/ping_pong/src/core.cpp @@ -0,0 +1,50 @@ +#include "../include/core.hpp" +#include +#include +#include + +void Entity::set_position(Vector2 new_pos) { + position = new_pos; + shape.setPosition(position.x, position.y); +} + +void Entity::set_size(Vector2 new_size) { + shape.setSize(sf::Vector2f{new_size.x, new_size.y}); +} + +void Bat::update(sf::Time delta) { + if (moving_left) { + position.x -= speed * delta.asSeconds(); + } + + if (moving_right) { + position.x += speed * delta.asSeconds(); + } + + set_position(position); +} + + +void Ball::update(sf::Time delta) { + position.y += direction.y * speed * delta.asSeconds(); + position.x += direction.x * speed * delta.asSeconds(); + set_position(position); +} + +void Ball::rebound(Rebounds rb) { + switch (rb) { + case Rebounds::Sides: + direction.x = -direction.x; + break; + + case Rebounds::Bat_Or_Top: + direction.y = -direction.y; + break; + + case Rebounds::Bottom: + position.y = 0; + position.x = 500; + direction.y = -direction.y; + break; + } +} diff --git a/ping_pong/src/main.cpp b/ping_pong/src/main.cpp new file mode 100644 index 0000000..9d4e9b4 --- /dev/null +++ b/ping_pong/src/main.cpp @@ -0,0 +1,133 @@ +#include "../include/core.hpp" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +Vector2 aspect_ratio = Vector2{1920, 1080}; + +const int MAX_ENTITIES = 2; +Entity *entities[MAX_ENTITIES]; + +int main() { + sf::VideoMode vm(aspect_ratio.x, aspect_ratio.y); + sf::RenderWindow window(vm, "Pong", sf::Style::Default); + int score = 0; + int lives = 3; + + // Bottom center of the screen + Bat bat; + bat.set_size(Vector2{50, 5}); + bat.set_position(Vector2{aspect_ratio.x / 2, aspect_ratio.y - 20}); + bat.speed = 300.0f; + + Ball ball; + ball.set_size(Vector2{10, 10}); + ball.set_position(Vector2{aspect_ratio.x / 2, 0}); + ball.direction = Vector2{0.2f, 0.2f}; + ball.speed = 1000.0f; + + entities[0] = &bat; + entities[1] = &ball; + + 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); + + sf::Clock clock; + + + while (window.isOpen()) { + // INPUT + { + sf::Event event; + while (window.pollEvent(event)) { + if (event.type == sf::Event::Closed) { + window.close(); + } + } + + if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) { + window.close(); + } + + if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) { + bat.moving_left = true; + } else { + bat.moving_left = false; + } + + if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) { + bat.moving_right = true; + } else { + bat.moving_right = false; + } + } + + + // UPDATE + { + sf::Time delta = clock.restart(); + + for (int i = 0; i < MAX_ENTITIES; i++) { + entities[i]->update(delta); + } + + std::stringstream ss; + ss << "Score: " << score << " Lives: " << lives; + hud.setString(ss.str()); + + { + sf::FloatRect bounds = ball.shape.getGlobalBounds(); + + if (bounds.top > window.getSize().y) { + ball.rebound(Rebounds::Bottom); + lives--; + + if (lives < 1) { + score = 0; + lives = 3; + } + } + + if (bounds.top < 0) { + ball.rebound(Rebounds::Bat_Or_Top); + score++; + } + + if (bounds.left < 0 || bounds.left + bounds.width > window.getSize().x) { + ball.rebound(Rebounds::Sides); + } + + if (bounds.intersects(bat.shape.getGlobalBounds())) { + ball.rebound(Rebounds::Bat_Or_Top); + } + } + } + + + // DRAW + { + window.clear(); + window.draw(hud); + + for (int i = 0; i < MAX_ENTITIES; i++) { + window.draw(entities[i]->shape); + } + + window.display(); + } + + } + + return 0; +} diff --git a/timber/.gitignore b/timber/.gitignore new file mode 100644 index 0000000..259148f --- /dev/null +++ b/timber/.gitignore @@ -0,0 +1,32 @@ +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app diff --git a/timber/Makefile b/timber/Makefile new file mode 100644 index 0000000..a87ab34 --- /dev/null +++ b/timber/Makefile @@ -0,0 +1,14 @@ +CXX=g++ +CXXFLAGS=-Wall -g -std=c++11 +SFML_LIBS=-lsfml-graphics -lsfml-window -lsfml-system -lsfml-audio + +all: timber + +timber: src/main.o src/core.o + $(CXX) $(CXXFLAGS) -o $@ $^ $(SFML_LIBS) + +%.o: %.cpp %.hpp + $(CXX) $(CXXFLAGS) -c $< -o $@ + +clean: + rm -f timber *.o diff --git a/timber/assets/fonts/KOMIKAP_.ttf b/timber/assets/fonts/KOMIKAP_.ttf new file mode 100644 index 0000000..01317e1 Binary files /dev/null and b/timber/assets/fonts/KOMIKAP_.ttf differ diff --git a/timber/assets/graphics/axe.png b/timber/assets/graphics/axe.png new file mode 100644 index 0000000..104f7a3 Binary files /dev/null and b/timber/assets/graphics/axe.png differ diff --git a/timber/assets/graphics/background.png b/timber/assets/graphics/background.png new file mode 100644 index 0000000..c63ab72 Binary files /dev/null and b/timber/assets/graphics/background.png differ diff --git a/timber/assets/graphics/bee.png b/timber/assets/graphics/bee.png new file mode 100644 index 0000000..8651ddd Binary files /dev/null and b/timber/assets/graphics/bee.png differ diff --git a/timber/assets/graphics/branch.png b/timber/assets/graphics/branch.png new file mode 100644 index 0000000..d3f48cd Binary files /dev/null and b/timber/assets/graphics/branch.png differ diff --git a/timber/assets/graphics/cloud.png b/timber/assets/graphics/cloud.png new file mode 100644 index 0000000..cf78311 Binary files /dev/null and b/timber/assets/graphics/cloud.png differ diff --git a/timber/assets/graphics/log.png b/timber/assets/graphics/log.png new file mode 100644 index 0000000..8cf3aaa Binary files /dev/null and b/timber/assets/graphics/log.png differ diff --git a/timber/assets/graphics/player.png b/timber/assets/graphics/player.png new file mode 100644 index 0000000..591501d Binary files /dev/null and b/timber/assets/graphics/player.png differ diff --git a/timber/assets/graphics/rip.png b/timber/assets/graphics/rip.png new file mode 100644 index 0000000..cbc172a Binary files /dev/null and b/timber/assets/graphics/rip.png differ diff --git a/timber/assets/graphics/tree.png b/timber/assets/graphics/tree.png new file mode 100644 index 0000000..d2ba1b9 Binary files /dev/null and b/timber/assets/graphics/tree.png differ diff --git a/timber/assets/graphics/tree2.png b/timber/assets/graphics/tree2.png new file mode 100644 index 0000000..644a769 Binary files /dev/null and b/timber/assets/graphics/tree2.png differ diff --git a/timber/assets/sound/chop.wav b/timber/assets/sound/chop.wav new file mode 100644 index 0000000..b7d27c2 Binary files /dev/null and b/timber/assets/sound/chop.wav differ diff --git a/timber/assets/sound/death.wav b/timber/assets/sound/death.wav new file mode 100644 index 0000000..577933c Binary files /dev/null and b/timber/assets/sound/death.wav differ diff --git a/timber/assets/sound/out_of_time.wav b/timber/assets/sound/out_of_time.wav new file mode 100644 index 0000000..f48e065 Binary files /dev/null and b/timber/assets/sound/out_of_time.wav differ diff --git a/timber/include/core.hpp b/timber/include/core.hpp new file mode 100644 index 0000000..9e9c347 --- /dev/null +++ b/timber/include/core.hpp @@ -0,0 +1,87 @@ +#ifndef CORE_H +#define CORE_H + +#include +#include +#include +#include + +enum class Side { left, right, none }; + +struct Vector2 { + float x; + float y; +}; + +struct AspectRatio { + int x; + int y; +}; + +struct TextData { + std::string content; + int size; + sf::Color color; + sf::Font *font; +}; + + + +struct Text { + sf::Font font; + sf::Text text; + Vector2 position; + + void set_color(sf::Color color); + + void set_font(std::string path); + + void set_string(std::string str); + + void set_size(int size); + + void set_position(Vector2 pos); + + void set_origin(Vector2 origin); + + sf::FloatRect get_rect(); +}; + +struct Entity { + sf::Texture texture; + sf::Sprite sprite; + Vector2 position; + + void set_texture(std::string texture); + + void set_position(Vector2 pos); + + void set_origin(Vector2 origin); + + Vector2 get_position(); + + void set_rotation(int angle); +}; + +struct Player : public Entity { + Side side = Side::left; +}; + +struct Actor : public Entity { + bool active = false; + float speed = 0.0f; +}; + +struct Log : public Actor { + float speed_x = 1000; + float speed_y = -1500; +}; + +void update_branches(int seed); + +void draw(sf::RenderWindow *window, Entity *entity); + +void draw(sf::RenderWindow *window, Text *text); + + +#endif // CORE_H diff --git a/timber/src/core.cpp b/timber/src/core.cpp new file mode 100644 index 0000000..3cbabc9 --- /dev/null +++ b/timber/src/core.cpp @@ -0,0 +1,63 @@ +#include "../include/core.hpp" +#include +#include +#include + +void Entity::set_texture(std::string filename) { + texture.loadFromFile(filename); + sprite.setTexture(texture); +} + +void Entity::set_rotation(int angle) { + sprite.setRotation(angle); +} + +Vector2 Entity::get_position() { + sf::Vector2f pos = sprite.getPosition(); + return Vector2{pos.x, pos.y}; +} + +void Entity::set_position(Vector2 origin) { + sprite.setPosition(origin.x, origin.y); +} + +void Entity::set_origin(Vector2 origin) { + sprite.setOrigin(origin.x, origin.y); +} + +void draw(sf::RenderWindow *window, Entity *entity) { + window->draw(entity->sprite); +} + +void draw(sf::RenderWindow *window, Text *text) { + window->draw(text->text); +} + +void Text::set_font(std::string filename) { + font.loadFromFile(filename); + text.setFont(font); +} + +void Text::set_string(std::string str) { + text.setString(str); +} + +void Text::set_size(int size) { + text.setCharacterSize(size); +} + +void Text::set_color(sf::Color color) { + text.setFillColor(color); +} + +void Text::set_origin(Vector2 origin) { + text.setOrigin(origin.x, origin.y); +} + +void Text::set_position(Vector2 origin) { + text.setPosition(origin.x, origin.y); +} + +sf::FloatRect Text::get_rect() { + return text.getLocalBounds(); +} diff --git a/timber/src/main.cpp b/timber/src/main.cpp new file mode 100644 index 0000000..1d80549 --- /dev/null +++ b/timber/src/main.cpp @@ -0,0 +1,401 @@ +#include "../include/core.hpp" +#include +#include +#include +#include +#include +#include + +int player_score = 0; +char player_initial = 'N'; +float value_pi = 3.141f; +bool is_alive = true; + +const int NUM_BRANCHES = 6; +Entity branches[NUM_BRANCHES]; +Side branch_positions[NUM_BRANCHES]; + +const int NUM_CLOUDS = 3; +Actor clouds[NUM_CLOUDS]; +Vector2 cloud_positions[NUM_CLOUDS] { + Vector2{0, 0}, + Vector2{0, 250}, + Vector2{0, 500} +}; + +int main() { + AspectRatio screen_size{1920, 1080}; + sf::VideoMode vm(screen_size.x, screen_size.y); + sf::RenderWindow window(vm, "Timber", sf::Style::Fullscreen); + + Entity bg; + bg.set_texture("assets/graphics/background.png"); + bg.set_position(Vector2{0, 0}); + + Actor bee; + bee.set_texture("assets/graphics/bee.png"); + bee.set_position(Vector2{0, 800}); + + Entity tree; + tree.set_texture("assets/graphics/tree.png"); + tree.set_position(Vector2{810, 0}); + + Player player; + player.set_texture("assets/graphics/player.png"); + player.set_position(Vector2{580, 720}); + + Entity gravestone; + gravestone.set_texture("assets/graphics/rip.png"); + gravestone.set_position(Vector2{600, 860}); + + Entity axe; + axe.set_texture("assets/graphics/axe.png"); + axe.set_position(Vector2{700, 830}); + + Log log; + log.set_texture("assets/graphics/log.png"); + log.set_position(Vector2{810, 720}); + + const Vector2 AXE_POSITION{700, 1075}; + + sf::Clock clock; + + sf::RectangleShape time_bar; + float time_bar_start_width = 400; + float time_bar_height = 80; + + time_bar.setSize(sf::Vector2f(time_bar_start_width, time_bar_height)); + time_bar.setFillColor(sf::Color::Red); + time_bar.setPosition((1920.0 / 2) - time_bar_start_width / 2, 980); + + sf::Time game_time_total; + float time_remaining = 6.0f; + float time_bar_width_per_second = time_bar_start_width / time_remaining; + + bool paused = true; + + int score = 0; + + Text message_text; + message_text.set_font("assets/fonts/KOMIKAP_.ttf"); + message_text.set_string("Press Enter to start!"); + message_text.set_size(75); + message_text.set_color(sf::Color::White); + + Text score_text; + message_text.set_font("assets/fonts/KOMIKAP_.ttf"); + message_text.set_string("Score: 0"); + message_text.set_size(100); + message_text.set_color(sf::Color::White); + + + sf::FloatRect text_rect = message_text.get_rect(); + message_text.text.setOrigin(text_rect.left + text_rect.width / 2.0f, + text_rect.top + text_rect.height / 2.0f); + + message_text.set_position(Vector2{screen_size.x / 2.0f, screen_size.y / 2.0f}); + score_text.set_position(Vector2{20, 20}); + + for (int i=0; i 1920) { + clouds[0].active = false; + } + } + + if (!clouds[1].active) { + srand((int)time(0) * 20); + clouds[1].speed = (rand() % 200); + + srand((int)time(0) * 20); + float height = (rand() % 300) - 150; + clouds[1].set_position(Vector2{-200, height}); + clouds[1].active = true; + } else { + clouds[1].set_position(Vector2{clouds[1].get_position().x + + (clouds[1].speed * delta.asSeconds()), + clouds[1].get_position().y}); + + if (clouds[1].get_position().x > 1920) { + clouds[1].active = false; + } + } + + if (!clouds[2].active) { + srand((int)time(0) * 30); + clouds[2].speed = (rand() % 200); + + srand((int)time(0) * 30); + float height = (rand() % 450) - 150; + clouds[2].set_position(Vector2{-200, height}); + clouds[2].active = true; + } else { + clouds[2].set_position(Vector2{clouds[2].get_position().x + + (clouds[2].speed * delta.asSeconds()), + clouds[2].get_position().y}); + + if (clouds[2].get_position().x > 1920) { + clouds[2].active = false; + } + } + + std::stringstream ss; + ss << "Score: " << score; + score_text.set_string(ss.str()); + + for (int i=0; i 2000) { + log.active = false; + log.set_position(Vector2{810, 720}); + } + } + + if (branch_positions[5] == player.side) { + paused = true; + accept_input = false; + + gravestone.set_position(Vector2{525, 760}); + + player.set_position(Vector2{2000, 660}); + + message_text.set_string("SQUISHED!"); + + sf::FloatRect text_rect = message_text.get_rect(); + message_text.set_origin(Vector2{text_rect.left + text_rect.width / 2.0f, + text_rect.top + text_rect.height / 2.0f}); + + message_text.set_position(Vector2{1920 / 2.0f, 1080 / 2.0f}); + death.play(); + } + } + + // Draw the scene + + // Clear everything from last frame + window.clear(); + + // Draw game scene here + draw(&window, &bg); + + for (int i=0; i0; j--) { + branch_positions[j] = branch_positions[j-1]; + } + + srand((int)time(0)+seed); + int r = (rand() % 5); + + switch(r) { + case 0: + branch_positions[0] = Side::left; + break; + + case 1: + branch_positions[1] = Side::right; + break; + + case 2: + branch_positions[2] = Side::none; + break; + } +} diff --git a/zombie_shooter/.gitattributes b/zombie_shooter/.gitattributes new file mode 100644 index 0000000..b333f8b --- /dev/null +++ b/zombie_shooter/.gitattributes @@ -0,0 +1 @@ +assets/fonts/Rajdhani/*.ttf filter=lfs diff=lfs merge=lfs -text diff --git a/zombie_shooter/.gitignore b/zombie_shooter/.gitignore new file mode 100644 index 0000000..259148f --- /dev/null +++ b/zombie_shooter/.gitignore @@ -0,0 +1,32 @@ +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app diff --git a/zombie_shooter/Makefile b/zombie_shooter/Makefile new file mode 100644 index 0000000..c44e388 --- /dev/null +++ b/zombie_shooter/Makefile @@ -0,0 +1,14 @@ +CXX=g++ +CXXFLAGS=-Wall -g -std=c++11 -I/opt/sfml2/include +SFML_LIBS=-L/opt/sfml2/lib -lsfml-graphics -lsfml-window -lsfml-system -lsfml-audio + +all: zombie_shooter + +zombie_shooter: src/main.o src/core.o + $(CXX) $(CXXFLAGS) -o $@ $^ $(SFML_LIBS) + +%.o: %.cpp %.hpp + $(CXX) $(CXXFLAGS) -c $< -o $@ + +clean: + rm -f zombie_shooter *.o diff --git a/zombie_shooter/assets/fonts/Rajdhani/Rajdhani-Bold.ttf b/zombie_shooter/assets/fonts/Rajdhani/Rajdhani-Bold.ttf new file mode 100644 index 0000000..7d5e046 --- /dev/null +++ b/zombie_shooter/assets/fonts/Rajdhani/Rajdhani-Bold.ttf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0e2754864bf70da4f279189b713026551927c0c10258ff6dd431ff71fd6c8dd0 +size 373192 diff --git a/zombie_shooter/assets/fonts/Rajdhani/Rajdhani-Light.ttf b/zombie_shooter/assets/fonts/Rajdhani/Rajdhani-Light.ttf new file mode 100644 index 0000000..106d0dd --- /dev/null +++ b/zombie_shooter/assets/fonts/Rajdhani/Rajdhani-Light.ttf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9ee65da3e003d283571920f845141c3f3615f34c685357a13f8982a0b5754fea +size 357516 diff --git a/zombie_shooter/assets/fonts/Rajdhani/Rajdhani-Medium.ttf b/zombie_shooter/assets/fonts/Rajdhani/Rajdhani-Medium.ttf new file mode 100644 index 0000000..f259934 --- /dev/null +++ b/zombie_shooter/assets/fonts/Rajdhani/Rajdhani-Medium.ttf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:88a3937dc5d0d96d6b1a313b82802b78541bfdb5c004a208dfeab56192938538 +size 357884 diff --git a/zombie_shooter/assets/fonts/Rajdhani/Rajdhani-Regular.ttf b/zombie_shooter/assets/fonts/Rajdhani/Rajdhani-Regular.ttf new file mode 100644 index 0000000..9f054a5 --- /dev/null +++ b/zombie_shooter/assets/fonts/Rajdhani/Rajdhani-Regular.ttf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f0ba67d6ef91bcff8b0e43a051f7483dd83ebfcade19880cd15df29890234d2e +size 352088 diff --git a/zombie_shooter/assets/fonts/Rajdhani/Rajdhani-SemiBold.ttf b/zombie_shooter/assets/fonts/Rajdhani/Rajdhani-SemiBold.ttf new file mode 100644 index 0000000..6e00212 --- /dev/null +++ b/zombie_shooter/assets/fonts/Rajdhani/Rajdhani-SemiBold.ttf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5fd51c1334cafd3654059b0ee61aa470088a70e4637a9cfc0274557c751eb0cd +size 363500 diff --git a/zombie_shooter/assets/graphics/ammo_icon.png b/zombie_shooter/assets/graphics/ammo_icon.png new file mode 100644 index 0000000..854b87d Binary files /dev/null and b/zombie_shooter/assets/graphics/ammo_icon.png differ diff --git a/zombie_shooter/assets/graphics/ammo_pickup.png b/zombie_shooter/assets/graphics/ammo_pickup.png new file mode 100644 index 0000000..854b87d Binary files /dev/null and b/zombie_shooter/assets/graphics/ammo_pickup.png differ diff --git a/zombie_shooter/assets/graphics/background.png b/zombie_shooter/assets/graphics/background.png new file mode 100644 index 0000000..00814ea Binary files /dev/null and b/zombie_shooter/assets/graphics/background.png differ diff --git a/zombie_shooter/assets/graphics/background_sheet.png b/zombie_shooter/assets/graphics/background_sheet.png new file mode 100644 index 0000000..6254d30 Binary files /dev/null and b/zombie_shooter/assets/graphics/background_sheet.png differ diff --git a/zombie_shooter/assets/graphics/bloater.png b/zombie_shooter/assets/graphics/bloater.png new file mode 100644 index 0000000..54105d0 Binary files /dev/null and b/zombie_shooter/assets/graphics/bloater.png differ diff --git a/zombie_shooter/assets/graphics/blood.png b/zombie_shooter/assets/graphics/blood.png new file mode 100644 index 0000000..6f6d05b Binary files /dev/null and b/zombie_shooter/assets/graphics/blood.png differ diff --git a/zombie_shooter/assets/graphics/chaser.png b/zombie_shooter/assets/graphics/chaser.png new file mode 100644 index 0000000..dec6da4 Binary files /dev/null and b/zombie_shooter/assets/graphics/chaser.png differ diff --git a/zombie_shooter/assets/graphics/crawler.png b/zombie_shooter/assets/graphics/crawler.png new file mode 100644 index 0000000..99a3b0a Binary files /dev/null and b/zombie_shooter/assets/graphics/crawler.png differ diff --git a/zombie_shooter/assets/graphics/crosshair.png b/zombie_shooter/assets/graphics/crosshair.png new file mode 100644 index 0000000..42360fd Binary files /dev/null and b/zombie_shooter/assets/graphics/crosshair.png differ diff --git a/zombie_shooter/assets/graphics/health_pickup.png b/zombie_shooter/assets/graphics/health_pickup.png new file mode 100644 index 0000000..4e80e3f Binary files /dev/null and b/zombie_shooter/assets/graphics/health_pickup.png differ diff --git a/zombie_shooter/assets/graphics/player.png b/zombie_shooter/assets/graphics/player.png new file mode 100644 index 0000000..7f21b5e Binary files /dev/null and b/zombie_shooter/assets/graphics/player.png differ diff --git a/zombie_shooter/assets/graphics/sample.png b/zombie_shooter/assets/graphics/sample.png new file mode 100644 index 0000000..140513d Binary files /dev/null and b/zombie_shooter/assets/graphics/sample.png differ diff --git a/zombie_shooter/assets/sound/hit.wav b/zombie_shooter/assets/sound/hit.wav new file mode 100644 index 0000000..5f42f83 Binary files /dev/null and b/zombie_shooter/assets/sound/hit.wav differ diff --git a/zombie_shooter/assets/sound/pickup.wav b/zombie_shooter/assets/sound/pickup.wav new file mode 100644 index 0000000..2c0a023 Binary files /dev/null and b/zombie_shooter/assets/sound/pickup.wav differ diff --git a/zombie_shooter/assets/sound/powerup.wav b/zombie_shooter/assets/sound/powerup.wav new file mode 100644 index 0000000..cfe5539 Binary files /dev/null and b/zombie_shooter/assets/sound/powerup.wav differ diff --git a/zombie_shooter/assets/sound/reload.wav b/zombie_shooter/assets/sound/reload.wav new file mode 100644 index 0000000..1780d4f Binary files /dev/null and b/zombie_shooter/assets/sound/reload.wav differ diff --git a/zombie_shooter/assets/sound/reload_failed.wav b/zombie_shooter/assets/sound/reload_failed.wav new file mode 100644 index 0000000..55e7b2e Binary files /dev/null and b/zombie_shooter/assets/sound/reload_failed.wav differ diff --git a/zombie_shooter/assets/sound/shoot.wav b/zombie_shooter/assets/sound/shoot.wav new file mode 100644 index 0000000..a04b5a2 Binary files /dev/null and b/zombie_shooter/assets/sound/shoot.wav differ diff --git a/zombie_shooter/assets/sound/splat.wav b/zombie_shooter/assets/sound/splat.wav new file mode 100644 index 0000000..4f94628 Binary files /dev/null and b/zombie_shooter/assets/sound/splat.wav differ diff --git a/zombie_shooter/include/core.h b/zombie_shooter/include/core.h new file mode 100644 index 0000000..43ef18f --- /dev/null +++ b/zombie_shooter/include/core.h @@ -0,0 +1,54 @@ +#pragma once +#include +#include +#include + +struct Entity { + sf::Vector2f position; + float speed; + sf::Vector2f direction; + sf::Vector2f velocity; + + virtual void update(sf::Time delta) = 0; + void set_position(sf::Vector2f new_pos); + void set_size(sf::Vector2f new_size); +}; + + +struct Player { + const float START_SPEED = 200; + const float START_HEALTH = 100; + + sf::Vector2f position; + sf::Sprite sprite; + sf::Texture texture; + sf::Vector2f resolution; + sf::IntRect arena; + int tile_size; + + bool up_pressed; + bool down_pressed; + bool left_pressed; + bool right_pressed; + + int health; + int max_health; + sf::Time last_hit; + float speed; + + Player(); + + void spawn(sf::IntRect arena, sf::Vector2f resolution, int tile_size); + + void reset(); + + bool hit(sf::Time time_hit); + + void update(float delta, sf::Vector2i mouse_position); + + void upgrade_speed(); + + void upgrade_health(); + + void increase_health_level(int amount); +}; diff --git a/zombie_shooter/run b/zombie_shooter/run new file mode 100755 index 0000000..af5f4ee --- /dev/null +++ b/zombie_shooter/run @@ -0,0 +1,3 @@ +#!/usr/bin/zsh + +export LD_LIBRARY_PATH=/opt/sfml2/lib && ./zombie_shooter diff --git a/zombie_shooter/src/core.cpp b/zombie_shooter/src/core.cpp new file mode 100644 index 0000000..ae96572 --- /dev/null +++ b/zombie_shooter/src/core.cpp @@ -0,0 +1,115 @@ +#include "../include/core.h" +#include +#include +#include +#include + +void Entity::set_position(sf::Vector2f new_pos) { + position = new_pos; +} + +void Entity::set_size(sf::Vector2f new_size) { +} + + +Player::Player() + : speed(START_SPEED), + health(START_HEALTH), + max_health(START_HEALTH), + texture(), + sprite() +{ + texture.loadFromFile("./assets/graphics/player.png"); + sprite.setTexture(texture); + sprite.setOrigin(sf::Vector2f(25, 25)); +} + +void Player::spawn(sf::IntRect arena, sf::Vector2f resolution, int tile_size) { + // Place in the middle of the arena + position.x = arena.width / 2.0; + position.y = arena.height / 2.0; + + arena.left = arena.left; + arena.width = arena.width; + arena.top = arena.top; + arena.height = arena.height; + + tile_size = tile_size; + + resolution.x = resolution.x; + resolution.y = resolution.y; +} + +void Player::reset() { + speed = START_SPEED; + health = START_HEALTH; + max_health = START_HEALTH; +} + +bool Player::hit(sf::Time time_hit) { + bool is_hit = time_hit.asMilliseconds() - last_hit.asMilliseconds() > 200; + + if (is_hit) { + last_hit = time_hit; + health -= 10; + } + + return is_hit; +} + + +void Player::update(float delta, sf::Vector2i mouse_position) { + if (up_pressed) { + position.y -= speed * delta; + } + + if (down_pressed) { + position.y += speed * delta; + } + + if (right_pressed) { + position.x += speed * delta; + } + + if (left_pressed) { + position.x -= speed * delta; + } + + sprite.setPosition(position); + + if (position.x > arena.width - tile_size) { + position.x = arena.width - tile_size; + } + + if (position.x < arena.width + tile_size) { + position.x = arena.width + tile_size; + } + + if (position.y > arena.height - tile_size) { + position.y = arena.height - tile_size; + } + + if (position.y < arena.height + tile_size) { + position.y = arena.height + tile_size; + } + + float angle = (std::atan2(mouse_position.y - resolution.y / 2, mouse_position.x - resolution.x / 2) * 180 / 3.141); + sprite.setRotation(angle); +} + +void Player::upgrade_speed() { + speed += (START_SPEED * 0.2); +} + +void Player::upgrade_health() { + max_health += (START_HEALTH * 0.2); +} + +void Player::increase_health_level(int amount) { + health += amount; + + if (health > max_health) { + health = max_health; + } +} + diff --git a/zombie_shooter/src/main.cpp b/zombie_shooter/src/main.cpp new file mode 100644 index 0000000..cbccaaa --- /dev/null +++ b/zombie_shooter/src/main.cpp @@ -0,0 +1,199 @@ +#include "../include/core.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +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; +}