diff --git a/bullet_factory.cpp b/bullet_factory.cpp new file mode 100644 index 0000000..b291697 --- /dev/null +++ b/bullet_factory.cpp @@ -0,0 +1,63 @@ + #include "bullet_factory.h" + #include "globals.h" + #include + #include + + std::vector BulletFactory::SprayProjectiles(ProjectileType type, point_2d origin, vector_2d direction, int count, float spread) { + std::vector bullets; + + float angleStep = spread / (count - 1); + float startAngle = -spread / 2; + + for (int i = 0; i < count; i++) { + float angle = startAngle + i * angleStep; + vector_2d rotatedDirection = RotateVector(direction, angle); + + sprite bullet = CreateBullet(type, origin, rotatedDirection); + if (bullet) { + bullets.push_back(bullet); + std::cout << "Created bullet at (" << sprite_x(bullet) << ", " << sprite_y(bullet) << ")" << std::endl; + } + } + + return bullets; + } + + sprite BulletFactory::CreateBullet(ProjectileType type, point_2d origin, vector_2d direction) { + if (!bitmap_valid(bullet)) { + std::cout << "Error: Could not load bullet bitmap in CreateBullet" << std::endl; + return nullptr; + } + + sprite bullet_sprite = create_sprite(bullet); + + // Scale the sprite + //sprite_set_scale(bullet_sprite,0.2); // Scale by 50% + + sprite_set_position(bullet_sprite, origin); + + vector_2d velocity; + switch (type) { + case ProjectileType::NORMAL: + velocity = vector_multiply(direction, 5); + break; + case ProjectileType::FAST: + velocity = vector_multiply(direction, 10); + break; + case ProjectileType::EXPLOSIVE: + velocity = vector_multiply(direction, 3); + break; + } + sprite_set_velocity(bullet_sprite, velocity); + + return bullet_sprite; + } + + vector_2d BulletFactory::RotateVector(vector_2d vec, float angle) { + float cos_a = std::cos(angle); + float sin_a = std::sin(angle); + return vector_2d{ + vec.x * cos_a - vec.y * sin_a, + vec.x * sin_a + vec.y * cos_a + }; + } \ No newline at end of file diff --git a/bullet_factory.h b/bullet_factory.h new file mode 100644 index 0000000..9d3d55a --- /dev/null +++ b/bullet_factory.h @@ -0,0 +1,22 @@ +#ifndef BULLET_FACTORY_H +#define BULLET_FACTORY_H + +#include "splashkit.h" +#include + +enum class ProjectileType { + NORMAL, + FAST, + EXPLOSIVE +}; + +class BulletFactory { +public: + static std::vector SprayProjectiles(ProjectileType type, point_2d origin, vector_2d direction, int count, float spread); + +private: + static sprite CreateBullet(ProjectileType type, point_2d origin, vector_2d direction); + static vector_2d RotateVector(vector_2d vec, float angle); +}; + +#endif // BULLET_FACTORY_H \ No newline at end of file diff --git a/game.exe b/game.exe index 0dee3e1..d0e228a 100644 Binary files a/game.exe and b/game.exe differ diff --git a/globals.h b/globals.h index fbdcb68..0cb2e8a 100644 --- a/globals.h +++ b/globals.h @@ -4,6 +4,7 @@ extern bitmap background; extern bitmap bee; extern bitmap box; +extern bitmap bullet; extern float player_posx; extern float player_posy; extern int RIGHT_BOUNDARY ; diff --git a/images/bullet.png b/images/bullet.png new file mode 100644 index 0000000..e2bc886 Binary files /dev/null and b/images/bullet.png differ diff --git a/images/pollen.png b/images/pollen.png new file mode 100644 index 0000000..639c9ab Binary files /dev/null and b/images/pollen.png differ diff --git a/images/raindrop2.png b/images/raindrop2.png new file mode 100644 index 0000000..0b8b47d Binary files /dev/null and b/images/raindrop2.png differ diff --git a/obstacle.cpp b/obstacle.cpp index 15b38a5..cfa7acb 100644 --- a/obstacle.cpp +++ b/obstacle.cpp @@ -17,7 +17,12 @@ void Obstacle::update(){ } void Obstacle::draw() { - draw_bitmap(box, x, y, option_to_screen()); + double center_x = this->x + this->width/2; + double center_y = this->y + this->height/2; + point_2d box_position = point_at(center_x,center_y); + circle scaled_box_circle = bitmap_cell_circle(box, box_position,1); + draw_bitmap(box, x, y, option_to_screen()); + draw_circle(COLOR_RED,scaled_box_circle); } void Obstacle::CollisionUpdate(bool is_collision) { diff --git a/program.cpp b/program.cpp index 9c36c87..277f1df 100644 --- a/program.cpp +++ b/program.cpp @@ -1,19 +1,21 @@ // import #include "splashkit.h" #include "globals.h" // <- added this import -//#include #include #include "player.h" #include "obstacle.h" #include "Observer.h" #include "Subject.h" #include -#include -//skm g++ program.cpp player.cpp obstacle.cpp -o game.exe +#include "bullet_factory.h" +#include +#include +//skm g++ program.cpp player.cpp obstacle.cpp bullet_factory.cpp -o game.exe bitmap background = bitmap_named("images/Background.jpg"); bitmap bee = bitmap_named("images/Bee.png"); -bitmap box = bitmap_named("images/box.png"); +bitmap box = bitmap_named("images/raindrop2.png"); +bitmap bullet = bitmap_named("images/pollen.png"); float player_posx = 550.0f; float player_posy = 650.0f; int RIGHT_BOUNDARY = 1200;