Skip to content

Commit

Permalink
chore: cleanup codes and add download link
Browse files Browse the repository at this point in the history
  • Loading branch information
phuwit committed Oct 16, 2023
1 parent 794dc54 commit 5cba5db
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 26 deletions.
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ add_executable(BrainBlast source/Main.cpp)
target_link_libraries(BrainBlast PRIVATE sfml-graphics)
target_compile_features(BrainBlast PRIVATE cxx_std_17)

if(MSVC)
target_compile_options(BrainBlast PRIVATE /W4 /WX)
else()
target_compile_options(BrainBlast PRIVATE -Wall -Wextra -pedantic -Werror)
endif()

if(UNIX)
target_link_libraries(BrainBlast PRIVATE m)
endif()

if(WIN32)
add_custom_command(
TARGET BrainBlast
Expand Down
14 changes: 7 additions & 7 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ many projects/ assets are used in this one. please see [attribution.md](attribut
- [x] handle score
- [x] handle scene change
- [x] hud
- [ ] rework spawn timing
- [ ] level progression
- [ ] handle menu screen
- [x] level progression
- [x] handle menu screen
- [ ] handle paused screen
- [ ] handle gameover screen
- [ ] handle levelup screen
- [ ] handle leaderboard
- [ ] implement pickups
- [x] handle gameover screen
- [x] handle levelup screen
- [x] handle leaderboard
- [x] implement pickups
- [ ] rework spawn timing
- [ ] zombie dead animation?
- [ ] animation

Expand Down
2 changes: 1 addition & 1 deletion source/Holders/TextureHolder.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <assert.h>
#include <cassert>
#include "TextureHolder.hpp"

TextureHolder* TextureHolder::m_s_Instance = nullptr;
Expand Down
10 changes: 5 additions & 5 deletions source/Player/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,20 @@ void Player::setMovementKeyPressed(int movementKey, bool isPressed) {
}

void Player::setSpeedWithMultiplier(float multiplier) {
float m_Speed = m_BaseSpeed * multiplier;
float m_SpeedDiagonal = m_Speed * sqrt(0.5);
m_Speed = m_BaseSpeed * multiplier;
m_SpeedDiagonal = m_Speed * sqrt(0.5);
}

void Player::setSpeedReset() {
float m_Speed = m_BaseSpeed;
float m_SpeedDiagonal = m_Speed * sqrt(0.5);
m_Speed = m_BaseSpeed;
m_SpeedDiagonal = m_Speed * sqrt(0.5);
}

void Player::update(Vector2f mousePosition, Time frameTime) {
// movement
// detect diagonals
int buttonPressed = 0;
for (int i = 0; i < sizeof(MovementKey); i++) {
for (unsigned int i = 0; i < (unsigned int)(sizeof(MovementKey)); i++) {
if (m_MovementKeyPressed[i] == true) {
buttonPressed++;
}
Expand Down
4 changes: 2 additions & 2 deletions source/Player/Player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ class Player {

float m_BaseSpeed = 250;
float m_Speed = m_BaseSpeed;
float m_SpeedDiagonal = m_Speed * sqrt(0.5);
float m_SpeedDiagonal = m_Speed * std::sqrt(0.5);

bool m_MovementKeyPressed[4] = {false};
Vector2f m_Position;
void m_SetSpritesPosition();
float m_ArmAngle;
bool m_Flipped = false;
// bool m_Flipped = false;
void m_Flip();
void m_UnFlip();

Expand Down
8 changes: 4 additions & 4 deletions source/Scenes/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,9 @@ SceneChange Game::run(RenderWindow &window) {
}
}

unsigned int pickuplistsize = sizeof(m_PickUpsList);
unsigned int pickuplistsize = m_PickUpsList.size();

for (int i = 0; i < sizeof(PickupsType); i++) {
for (unsigned int i = 0; i < pickuplistsize; i++) {
if (m_PickUpsList[i].isSpawned()) {
if (m_Player.getHitbox().intersects(m_PickUpsList[i].getPosition())) {
handlePickUps_((PickupsType)i, m_PickUpsList[i].take(), m_PickUpsList[i].getBuffDuration());
Expand All @@ -320,7 +320,7 @@ SceneChange Game::run(RenderWindow &window) {
m_LastShot = seconds(0);
}

for (int i = 0; i < sizeof(MovementKey); i++) {
for (unsigned int i = 0; i < (unsigned int)sizeof(MovementKey); i++) {
m_Player.setMovementKeyPressed(i, m_MovementKeyPressed[i]);
}

Expand Down Expand Up @@ -349,7 +349,7 @@ SceneChange Game::run(RenderWindow &window) {
// window.draw(m_Zombies[i].getDrawableHitbox());
}

for (int i = 0; i < sizeof(PickupsType); i++) {
for (unsigned int i = 0; i < (unsigned int)sizeof(PickupsType); i++) {
if (m_PickUpsList[i].isSpawned()) {
window.draw(m_PickUpsList[i].getSprite());
}
Expand Down
4 changes: 2 additions & 2 deletions source/Scenes/Game.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Game : public Scenes {
int m_SpareAmmo = 24;
const int m_ClipSize = 6;
int m_BulletsInClip = m_ClipSize;
float m_FireRate = 1;
// float m_FireRate = 1;
Time m_LastShot;
const Time M_BULLET_COOLDOWN = milliseconds(100);

Expand All @@ -66,7 +66,7 @@ class Game : public Scenes {

bool m_MovementKeyPressed[sizeof(MovementKey)];
bool m_MouseKeyPressed[sizeof(MouseButton)];
int m_Stage = 0;
// int m_Stage = 0;
int m_NumZombies;
int m_NumZombiesAlive;
Zombie* m_Zombies = nullptr;
Expand Down
14 changes: 14 additions & 0 deletions source/Scenes/Info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ SceneChange Info::run(RenderWindow &window) {
attributionText.setPosition(githubText.getPosition() + Vector2f((githubText.getLocalBounds().width / 2) + (attributionText.getLocalBounds().width / 2) + BUTTON_PADDING + 50, 0));
attributionButton.setPosition(attributionText.getPosition() + Vector2f(0, BUTTON_PADDING / 2));

Text downloadText("Download Latest Build", fontBebas);
downloadText.setFillColor(Color::Black);
downloadText.setCharacterSize(60);
RectangleShape downloadButton(Vector2f(downloadText.getLocalBounds().width + BUTTON_PADDING, downloadText.getLocalBounds().height + BUTTON_PADDING));
textSetOriginCenter(downloadText);
shapeSetOriginCenter(downloadButton);
downloadText.setPosition(attributionText.getPosition() + Vector2f((attributionText.getLocalBounds().width / 2) + (downloadText.getLocalBounds().width / 2) + BUTTON_PADDING + 50, 0));
downloadButton.setPosition(downloadText.getPosition() + Vector2f(0, BUTTON_PADDING / 2));

while (window.isOpen()) {
// Update frame
Event event;
Expand All @@ -72,6 +81,7 @@ SceneChange Info::run(RenderWindow &window) {
setRectangleShapeColorOnMouseHover(exitButton, mouseScreenPosition, Color(189, 189, 189), Color::White);
setRectangleShapeColorOnMouseHover(githubButton, mouseScreenPosition, Color(189, 189, 189), Color::White);
setRectangleShapeColorOnMouseHover(attributionButton, mouseScreenPosition, Color(189, 189, 189), Color::White);
setRectangleShapeColorOnMouseHover(downloadButton, mouseScreenPosition, Color(189, 189, 189), Color::White);
} else if (event.type == Event::MouseButtonPressed) {
Vector2f mouseScreenPosition = Vector2f(Mouse::getPosition(window));

Expand All @@ -81,6 +91,8 @@ SceneChange Info::run(RenderWindow &window) {
openURL("https://github.com/phuwit/KMITL-ProgrammingFundamentals-GameDev");
} else if (attributionButton.getGlobalBounds().contains(Vector2f(mouseScreenPosition))) {
openURL("https://github.com/phuwit/KMITL-ProgrammingFundamentals-GameDev/blob/main/attribution.md");
} else if (downloadButton.getGlobalBounds().contains(Vector2f(mouseScreenPosition))) {
openURL("https://github.com/phuwit/KMITL-ProgrammingFundamentals-GameDev/actions/workflows/ci.yml\?query=branch%3Amain+is%3Asuccess");
}
} else if (event.type == Event::KeyPressed) {
if (Keyboard::isKeyPressed(Keyboard::Escape)) {
Expand All @@ -97,6 +109,8 @@ SceneChange Info::run(RenderWindow &window) {
window.draw(githubText);
window.draw(attributionButton);
window.draw(attributionText);
window.draw(downloadButton);
window.draw(downloadText);
window.display();
}

Expand Down
5 changes: 5 additions & 0 deletions source/Scenes/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ SceneChange Menu::run(RenderWindow &window) {
setRectangleShapeColorOnMouseHover(leaderboardButton, mouseScreenPosition, Color(189, 189, 189), Color::White);
setRectangleShapeColorOnMouseHover(exitButton, mouseScreenPosition, Color(189, 189, 189), Color::White);
}

if (event.type == Event::MouseButtonPressed) {
Vector2f mouseScreenPosition = Vector2f(Mouse::getPosition(window));

Expand All @@ -82,6 +83,10 @@ SceneChange Menu::run(RenderWindow &window) {
return SceneChange(ScenesList::EXIT);
}
}

if (event.type == Event::Closed || (event.type == Event::KeyPressed && event.key.code == Keyboard::Escape)) {
return SceneChange(ScenesList::EXIT);
}
}

// Draw frame
Expand Down
1 change: 1 addition & 0 deletions source/Scenes/Paused.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ class Paused : public Scenes {
};

SceneChange Paused::run(RenderWindow &window) {
window.clear(COLOR_BACKGROUND);
return SceneChange(ScenesList::SCENE_GAMEOVER);
}
2 changes: 1 addition & 1 deletion source/Scores/SaveScores.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
void saveScore(std::vector<Score>& scores) {
std::ofstream file;
file.open("scores.csv", std::ios::out);
for (int i = 0; i < scores.size(); i++) {
for (unsigned int i = 0; i < (unsigned int)scores.size(); i++) {
file << scores[i].getName() << "," << scores[i].getScore() << std::endl;
}
file.close();
Expand Down
2 changes: 1 addition & 1 deletion source/Tools/CreateBackground.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ int createBackground (VertexArray& rVA, IntRect playArea, int scale) {
// south wall
else if (h == worldHeight - 1) {
// use a random wall texture
int randomTileIndex = (rand() % WALL_NORTH_TILE_TYPES);
int randomTileIndex = (rand() % WALL_SOUTH_TILE_TYPES);
int xOffset = (randomTileIndex % SPRITESHEET_FLOOR_TILE_PER_ROW) * TILE_SIZE;
int yOffset = (randomTileIndex / SPRITESHEET_FLOOR_TILE_PER_ROW) * TILE_SIZE;
// use wall texture
Expand Down
2 changes: 1 addition & 1 deletion source/Zombie/Zombie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void Zombie::spawn(Vector2f spawnLoaction, float spriteScaling, ZombieType type,
m_SpriteScaling = spriteScaling;

Texture &texture = TextureHolder::GetTexture(M_SPRITE_FILENAME[type]);
Vector2f textureSize = (Vector2f)texture.getSize();
// Vector2f textureSize = (Vector2f)texture.getSize();
m_Sprite = Sprite(texture, M_SPRITE_CROP[type]);
m_Sprite.setScale(Vector2f(m_SpriteScaling, m_SpriteScaling));
m_CenterOffset = Vector2f((m_Sprite.getLocalBounds().width * m_SpriteScaling) / 2, ((m_Sprite.getLocalBounds().height * m_SpriteScaling) / 2));
Expand Down
2 changes: 0 additions & 2 deletions source/Zombie/Zombie.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ class Zombie {
Vector2i m_SpeedInverse = Vector2i(1, 1);
Vector2i M_BASE_INVERSE_CHANCE = Vector2i(10000, 10000);
ZombieMoveStyle m_MoveStyle;
float m_Peroid = 0;
float m_SinAmplitude = 20;
float m_Health;
bool m_Alive;

Expand Down

0 comments on commit 5cba5db

Please sign in to comment.