Skip to content

Commit 22af391

Browse files
committed
Render beam directly instead of using a texture
1 parent 952d554 commit 22af391

6 files changed

Lines changed: 41 additions & 9 deletions

File tree

assets/images/beam.bmp

-9.49 KB
Binary file not shown.

include/Draw.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class Draw {
1414
void BlitWater(SDL_Texture * texture, int rotation, int dx, int dy);
1515
void BlitOther(SDL_Texture * texture, int x, int y, int dx, int dy, int w, int h);
1616
void BlackSquare(int x, int y);
17+
void BlitBeam(int rotation, int x, int y);
1718

1819
void BlitText(char * text, int x, int y);
1920
void Flip();

include/Textures.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ class Textures {
1414
bool load();
1515

1616
SDL_Texture * getBarSprites() { return barSprites; };
17-
SDL_Texture * getBeamSprites() { return beamSprites; };
1817
SDL_Texture * getGroundSprites() { return groundSprites; };
1918
SDL_Texture * getMirrorSprites() { return mirrorSprites; };
2019
SDL_Texture * getNukeSprites() { return nukeSprites; };
@@ -35,7 +34,6 @@ class Textures {
3534
SDL_Renderer * renderer;
3635

3736
SDL_Texture * barSprites;
38-
SDL_Texture * beamSprites;
3937
SDL_Texture * groundSprites;
4038
SDL_Texture * mirrorSprites;
4139
SDL_Texture * nukeSprites;

include/Tile.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,13 @@ class Tile
192192

193193
void DisplayBeam() {
194194
if (HadFiredLeft||WasHitLeft)
195-
draw->BlitSquare(textures->getBeamSprites(), 0 ,1, x_pos, y_pos);
195+
draw->BlitBeam(0, x_pos, y_pos);
196196
if (HadFiredUp||WasHitTop)
197-
draw->BlitSquare(textures->getBeamSprites(), 1 ,1, x_pos, y_pos);
197+
draw->BlitBeam(1, x_pos, y_pos);
198198
if (HadFiredRight||WasHitRight)
199-
draw->BlitSquare(textures->getBeamSprites(), 2 ,1, x_pos, y_pos);
199+
draw->BlitBeam(2, x_pos, y_pos);
200200
if (HadFiredDown||WasHitBottom)
201-
draw->BlitSquare(textures->getBeamSprites(), 3 ,1, x_pos, y_pos);
201+
draw->BlitBeam(3, x_pos, y_pos);
202202
}
203203

204204
virtual bool MoveUp();

src/Draw.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,42 @@ void Draw::BlackSquare(int x, int y) {
6969
SDL_RenderFillRect(renderer, &r);
7070
}
7171

72+
void Draw::BlitBeam(int rotation, int x, int y) {
73+
x *= BLOCK_SIZE;
74+
y *= BLOCK_SIZE;
75+
SDL_Rect r={0, 0, 0, 0};
76+
switch(rotation) {
77+
case 0:
78+
r.x = x;
79+
r.y = y + (BLOCK_SIZE / 2) - 1;
80+
r.w = BLOCK_SIZE / 2 ;
81+
r.h = 2;
82+
break;
83+
case 1:
84+
r.x = x + (BLOCK_SIZE / 2) - 1;
85+
r.y = y;
86+
r.w = 2;
87+
r.h = BLOCK_SIZE / 2;
88+
break;
89+
case 2:
90+
r.x = x + BLOCK_SIZE / 2;
91+
r.y = y + (BLOCK_SIZE / 2) - 1;
92+
r.w = BLOCK_SIZE / 2;
93+
r.h = 2;
94+
break;
95+
case 3:
96+
r.x = x + (BLOCK_SIZE / 2) - 1;
97+
r.y = y + (BLOCK_SIZE / 2);
98+
r.w = 2;
99+
r.h = BLOCK_SIZE;
100+
break;
101+
default:
102+
return;
103+
}
104+
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
105+
SDL_RenderFillRect(renderer, &r);
106+
}
107+
72108
void Draw::BlitText(char * text, int x, int y) {
73109
SDL_Surface * surface = TTF_RenderText_Solid(font, text, {0, 255, 0, 255});
74110
if (surface == NULL) {

src/Textures.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ Textures::Textures(SDL_Renderer * renderer) : renderer(renderer) {
1010

1111
Textures::~Textures() {
1212
SDL_DestroyTexture(barSprites);
13-
SDL_DestroyTexture(beamSprites);
1413
SDL_DestroyTexture(groundSprites);
1514
SDL_DestroyTexture(mirrorSprites);
1615
SDL_DestroyTexture(nukeSprites);
@@ -28,7 +27,6 @@ Textures::~Textures() {
2827

2928
bool Textures::load() {
3029
barSprites = loadImage("bar.bmp");
31-
beamSprites = loadImage("beam.bmp");
3230
groundSprites = loadImage("ground.bmp");
3331
mirrorSprites = loadImage("mirror.bmp");
3432
nukeSprites= loadImage("nuke.bmp");
@@ -46,7 +44,6 @@ bool Textures::load() {
4644

4745
return
4846
barSprites != nullptr &&
49-
beamSprites != nullptr &&
5047
groundSprites != nullptr &&
5148
mirrorSprites != nullptr &&
5249
nukeSprites != nullptr &&

0 commit comments

Comments
 (0)