Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds texture attribute to bullet #8

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pydanmaku/include/bullet.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ class Bullet {
double width;
double radius;
double c, s; // cos and sin

char* texture;
bool broad_search(double x, double y, double radius);
bool collides(double x, double y, double radius);

Bullet(double x, double y, bool is_rect, double width, double height, double speed, double angle, double accel, double ang_m);
Bullet(double x, double y, bool is_rect, double width, double height, double speed, double angle, double accel, double ang_m, char* tex=nullptr);
bool run(double timestep);

};

#endif
#endif
3 changes: 2 additions & 1 deletion pydanmaku/src/bullet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ bool Bullet::collides(double x, double y, double radius){

Bullet:: Bullet(
double x, double y, bool is_rect, double width, double height,
double speed, double angle, double accel, double ang_m
double speed, double angle, double accel, double ang_m, char* tex
){
this->x = x;
this->y = y;
Expand All @@ -83,6 +83,7 @@ Bullet:: Bullet(
this->angle = fmod(angle, 2*M_PI);
this->acceleration = accel;
this->angular_momentum = ang_m;
this->texture = tex;
}


7 changes: 5 additions & 2 deletions pydanmaku/src/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ GLfloat *vertices_position;
GLuint *indices;
GLfloat *texture_coord;

void initialize_quads(GLfloat vertices_position[], GLuint indices[], GLfloat texture_coord[], int count) {
void initialize_quads(GLfloat vertices_position[], GLuint indices[], GLfloat texture_coord[], int count, Bullet& bullet) {
// Use a Vertex Array Object


Expand Down Expand Up @@ -76,6 +76,9 @@ void initialize_quads(GLfloat vertices_position[], GLuint indices[], GLfloat tex
glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
// start load_image
if(bullet.texture) {
amuletImage = load_image(bullet.texture, &w, &h);
}
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_BGRA, GL_UNSIGNED_BYTE, amuletImage);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
Expand Down Expand Up @@ -186,7 +189,7 @@ void render_bullets(std::list<Bullet> *bullets){
add_quad(vertices_position, indices, texture_coord, i, b->x, b->y, h, w, b->angle);
i++;
}
initialize_quads(vertices_position, indices, texture_coord, count);
initialize_quads(vertices_position, indices, texture_coord, count, bullets->front());
glBindVertexArray(vao);
glDrawElements(GL_TRIANGLES, 6*count, GL_UNSIGNED_INT, 0);
glfwSwapBuffers(window);
Expand Down