-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
yasaminjln
committed
Jan 12, 2020
1 parent
ccbcd53
commit 3117a6a
Showing
9 changed files
with
533 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#pragma once | ||
#include "MapObject.hpp" | ||
#include "Spells.hpp" | ||
#include "Shield.hpp" | ||
#include "Spells.hpp" | ||
#include <allegro5/allegro_audio.h> | ||
#include <allegro5/allegro_acodec.h> | ||
#include <list> | ||
|
||
class FireShield: public Shield { | ||
public: | ||
FireShield(int start_x, int start_y, float dir_x, float dir_y,bool subshield); | ||
~FireShield(); | ||
|
||
int get_damage(); | ||
|
||
virtual void on_collision(MapObject &other); | ||
virtual void draw(int camera_x, int camera_y); | ||
|
||
std::list<std::list<int>> generate_subshield_coordinates(); | ||
|
||
private: | ||
ALLEGRO_BITMAP* sprite; | ||
int damage; | ||
bool subshield; | ||
ALLEGRO_SAMPLE* music11; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#pragma once | ||
#include "MapObject.hpp" | ||
#include "Spells.hpp" | ||
#include "Shield.hpp" | ||
#include "Spells.hpp" | ||
#include <allegro5/allegro_audio.h> | ||
#include <allegro5/allegro_acodec.h> | ||
#include <list> | ||
|
||
class RockShield: public Shield { | ||
public: | ||
RockShield(int start_x, int start_y, float dir_x, float dir_y,bool subshield); | ||
~RockShield(); | ||
|
||
int get_damage(); | ||
|
||
virtual void on_collision(MapObject &other); | ||
virtual void draw(int camera_x, int camera_y); | ||
|
||
std::list<std::list<int>> generate_subshield_coordinates(); | ||
|
||
private: | ||
ALLEGRO_BITMAP* sprite; | ||
int damage; | ||
bool subshield; | ||
ALLEGRO_SAMPLE* music11; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#pragma once | ||
#include "MapObject.hpp" | ||
#include "Spells.hpp" | ||
#include "Shield.hpp" | ||
#include "Spells.hpp" | ||
#include <allegro5/allegro_audio.h> | ||
#include <allegro5/allegro_acodec.h> | ||
#include <list> | ||
|
||
class WaterShield: public Shield { | ||
public: | ||
WaterShield(int start_x, int start_y, float dir_x, float dir_y,bool subshield); | ||
~WaterShield(); | ||
|
||
int get_damage(); | ||
|
||
virtual void on_collision(MapObject &other); | ||
virtual void draw(int camera_x, int camera_y); | ||
|
||
std::list<std::list<int>> generate_subshield_coordinates(); | ||
|
||
private: | ||
ALLEGRO_BITMAP* sprite; | ||
int damage; | ||
bool subshield; | ||
ALLEGRO_SAMPLE* music11; | ||
}; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
#include "../headers/FireShield.hpp" | ||
#include <iostream> | ||
#include <math.h> | ||
#include <allegro5/allegro_audio.h> | ||
#include <allegro5/allegro_acodec.h> | ||
#include <allegro5/allegro_primitives.h> | ||
#include <list> | ||
|
||
FireShield::FireShield(int start_x, int start_y, float dir_x, float dir_y,bool subshield) | ||
: Shield::Shield(start_x, start_y, dir_x, dir_y, 16, 16, false) { | ||
damage = 0; | ||
sprite = al_load_bitmap("resources/shield3.bmp"); | ||
int time1 = 0; | ||
music11 = al_load_sample("resources/main_shield.wav"); | ||
if (music11) al_play_sample(music11, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, 0); //(SAMPLE NAME, gain(volumn), pan(balance), speed, play_mode, sample_id); | ||
} | ||
|
||
FireShield::~FireShield(){ | ||
al_destroy_sample(music11); | ||
al_destroy_bitmap(sprite); | ||
} | ||
|
||
int FireShield::get_damage() { | ||
return damage; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
void FireShield::draw(int camera_x, int camera_y) { | ||
// al_draw_filled_rectangle(x - camera_x, y - camera_y, x + width - camera_x, y + height - camera_y, al_map_rgb(255, 255, 100)); | ||
//time1=time1+1; | ||
//if (time1>30) { | ||
// this->garbage_collect = true; | ||
//} | ||
//float angle = atan2(dir_y,dir_x); | ||
//al_draw_scaled_rotated_bitmap(this->sprite,50,5, x - camera_x, y - camera_y,2,2, angle,0); | ||
if (subshield==true){ | ||
time1=time1+1; | ||
if (time1>300) { | ||
this->garbage_collect = true; | ||
} | ||
float angle = atan2(dir_y,dir_x); | ||
float bitmapw = al_get_bitmap_width(sprite); | ||
float bitmaph = al_get_bitmap_height(sprite); | ||
al_draw_scaled_rotated_bitmap(this->sprite,0,bitmaph/2, x - camera_x, y - camera_y,2,2, angle,0); | ||
} | ||
} | ||
|
||
void FireShield::on_collision(MapObject &other) { | ||
if (!this->get_garbage_collect() && !other.get_noclip()) { | ||
this->hit_animation = true; | ||
this->noclip = true; | ||
//other.preventhit(); | ||
} | ||
} | ||
|
||
std::list<std::list<int>> FireShield::generate_subshield_coordinates() { | ||
float angle = atan2(dir_y,dir_x); | ||
//let x, y be the point representing the position of the rotated sprite which was set exactly in the middle of the sprite | ||
std::list<std::list<int>> result = std::list<std::list<int>>(); | ||
float covered_distance = 0; | ||
const int height_of_rectangle = 10; | ||
const int width_of_rectangle = height_of_rectangle * atan(angle); | ||
|
||
//computation to get x and y need to be done | ||
float dx= x + dir_x; | ||
float dy= y + dir_y; | ||
float a = dir_y/dir_x; | ||
float gam = dy+dx/a; | ||
float left_x = (a*a*gam-a*dx+dy+sqrt((a*a*gam+a*dx-dy)*(a*a*gam+a*dx-dy)-(a*a+1)*(dy*dy+dx*dx-2*a*gam*dx+(gam*a)*(gam*a))-2500))/(a*a+1); | ||
float top_y = a*gam-a*left_x; | ||
|
||
//let position_x and position_y be the positions of the vertice at the top | ||
|
||
while (covered_distance < 100) { | ||
covered_distance += sqrt( pow( height_of_rectangle,2) + pow(width_of_rectangle,2) ); | ||
std::list<int> one_rectangle = std::list<int>(); | ||
//case 1 | ||
if (0 < angle && angle < ALLEGRO_PI/2) {//angle is with respect to the vertical axis | ||
one_rectangle.push_back(left_x); | ||
one_rectangle.push_back(top_y); | ||
one_rectangle.push_back(width_of_rectangle); | ||
one_rectangle.push_back(height_of_rectangle); | ||
|
||
result.push_back(one_rectangle); | ||
top_y += width_of_rectangle; | ||
left_x += height_of_rectangle; | ||
} | ||
//case 2 | ||
if (ALLEGRO_PI/2 < angle && angle < ALLEGRO_PI) { | ||
one_rectangle.push_back(left_x-width_of_rectangle); | ||
one_rectangle.push_back(top_y); | ||
one_rectangle.push_back(width_of_rectangle); | ||
one_rectangle.push_back(height_of_rectangle); | ||
|
||
result.push_back(one_rectangle); | ||
top_y += height_of_rectangle; | ||
left_x += -width_of_rectangle; | ||
} | ||
//case 3 | ||
if (-ALLEGRO_PI < angle && angle < -ALLEGRO_PI/2) { | ||
one_rectangle.push_back(left_x-width_of_rectangle); | ||
one_rectangle.push_back(top_y-height_of_rectangle); | ||
one_rectangle.push_back(width_of_rectangle); | ||
one_rectangle.push_back(height_of_rectangle); | ||
|
||
result.push_back(one_rectangle); | ||
top_y += -height_of_rectangle; | ||
left_x += -width_of_rectangle; | ||
} | ||
//case 4 | ||
if (-ALLEGRO_PI/2 < angle && angle < 0) { | ||
one_rectangle.push_back(left_x); | ||
one_rectangle.push_back(top_y-height_of_rectangle); | ||
one_rectangle.push_back(width_of_rectangle); | ||
one_rectangle.push_back(height_of_rectangle); | ||
|
||
result.push_back(one_rectangle); | ||
top_y += -height_of_rectangle; | ||
left_x += width_of_rectangle; | ||
} | ||
} | ||
|
||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
#include "../headers/RockShield.hpp" | ||
#include <iostream> | ||
#include <math.h> | ||
#include <allegro5/allegro_audio.h> | ||
#include <allegro5/allegro_acodec.h> | ||
#include <allegro5/allegro_primitives.h> | ||
#include <list> | ||
|
||
RockShield::RockShield(int start_x, int start_y, float dir_x, float dir_y,bool subshield) | ||
: Shield::Shield(start_x, start_y, dir_x, dir_y, 16, 16, false) { | ||
damage = 0; | ||
sprite = al_load_bitmap("resources/shield2.bmp"); | ||
int time1 = 0; | ||
music11 = al_load_sample("resources/main_shield.wav"); | ||
if (music11) al_play_sample(music11, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, 0); //(SAMPLE NAME, gain(volumn), pan(balance), speed, play_mode, sample_id); | ||
} | ||
|
||
RockShield::~RockShield(){ | ||
al_destroy_sample(music11); | ||
al_destroy_bitmap(sprite); | ||
} | ||
|
||
int RockShield::get_damage() { | ||
return damage; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
void RockShield::draw(int camera_x, int camera_y) { | ||
// al_draw_filled_rectangle(x - camera_x, y - camera_y, x + width - camera_x, y + height - camera_y, al_map_rgb(255, 255, 100)); | ||
//time1=time1+1; | ||
//if (time1>30) { | ||
// this->garbage_collect = true; | ||
//} | ||
//float angle = atan2(dir_y,dir_x); | ||
//al_draw_scaled_rotated_bitmap(this->sprite,50,5, x - camera_x, y - camera_y,2,2, angle,0); | ||
if (subshield==true){ | ||
time1=time1+1; | ||
if (time1>300) { | ||
this->garbage_collect = true; | ||
} | ||
float angle = atan2(dir_y,dir_x); | ||
float bitmapw = al_get_bitmap_width(sprite); | ||
float bitmaph = al_get_bitmap_height(sprite); | ||
al_draw_scaled_rotated_bitmap(this->sprite,0,bitmaph/2, x - camera_x, y - camera_y,2,2, angle,0); | ||
} | ||
} | ||
|
||
void RockShield::on_collision(MapObject &other) { | ||
if (!this->get_garbage_collect() && !other.get_noclip()) { | ||
this->hit_animation = true; | ||
this->noclip = true; | ||
//other.preventhit(); | ||
} | ||
} | ||
|
||
std::list<std::list<int>> RockShield::generate_subshield_coordinates() { | ||
float angle = atan2(dir_y,dir_x); | ||
//let x, y be the point representing the position of the rotated sprite which was set exactly in the middle of the sprite | ||
std::list<std::list<int>> result = std::list<std::list<int>>(); | ||
float covered_distance = 0; | ||
const int height_of_rectangle = 10; | ||
const int width_of_rectangle = height_of_rectangle * atan(angle); | ||
|
||
//computation to get x and y need to be done | ||
float dx= x + dir_x; | ||
float dy= y + dir_y; | ||
float a = dir_y/dir_x; | ||
float gam = dy+dx/a; | ||
float left_x = (a*a*gam-a*dx+dy+sqrt((a*a*gam+a*dx-dy)*(a*a*gam+a*dx-dy)-(a*a+1)*(dy*dy+dx*dx-2*a*gam*dx+(gam*a)*(gam*a))-2500))/(a*a+1); | ||
float top_y = a*gam-a*left_x; | ||
|
||
//let position_x and position_y be the positions of the vertice at the top | ||
|
||
while (covered_distance < 100) { | ||
covered_distance += sqrt( pow( height_of_rectangle,2) + pow(width_of_rectangle,2) ); | ||
std::list<int> one_rectangle = std::list<int>(); | ||
//case 1 | ||
if (0 < angle && angle < ALLEGRO_PI/2) {//angle is with respect to the vertical axis | ||
one_rectangle.push_back(left_x); | ||
one_rectangle.push_back(top_y); | ||
one_rectangle.push_back(width_of_rectangle); | ||
one_rectangle.push_back(height_of_rectangle); | ||
|
||
result.push_back(one_rectangle); | ||
top_y += width_of_rectangle; | ||
left_x += height_of_rectangle; | ||
} | ||
//case 2 | ||
if (ALLEGRO_PI/2 < angle && angle < ALLEGRO_PI) { | ||
one_rectangle.push_back(left_x-width_of_rectangle); | ||
one_rectangle.push_back(top_y); | ||
one_rectangle.push_back(width_of_rectangle); | ||
one_rectangle.push_back(height_of_rectangle); | ||
|
||
result.push_back(one_rectangle); | ||
top_y += height_of_rectangle; | ||
left_x += -width_of_rectangle; | ||
} | ||
//case 3 | ||
if (-ALLEGRO_PI < angle && angle < -ALLEGRO_PI/2) { | ||
one_rectangle.push_back(left_x-width_of_rectangle); | ||
one_rectangle.push_back(top_y-height_of_rectangle); | ||
one_rectangle.push_back(width_of_rectangle); | ||
one_rectangle.push_back(height_of_rectangle); | ||
|
||
result.push_back(one_rectangle); | ||
top_y += -height_of_rectangle; | ||
left_x += -width_of_rectangle; | ||
} | ||
//case 4 | ||
if (-ALLEGRO_PI/2 < angle && angle < 0) { | ||
one_rectangle.push_back(left_x); | ||
one_rectangle.push_back(top_y-height_of_rectangle); | ||
one_rectangle.push_back(width_of_rectangle); | ||
one_rectangle.push_back(height_of_rectangle); | ||
|
||
result.push_back(one_rectangle); | ||
top_y += -height_of_rectangle; | ||
left_x += width_of_rectangle; | ||
} | ||
} | ||
|
||
return result; | ||
} |
Oops, something went wrong.