Skip to content

Commit 2d78426

Browse files
committed
hitboxes
1 parent f041bd9 commit 2d78426

17 files changed

+107
-62
lines changed

Enemigo.cpp

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,9 @@
33
Enemigo::Enemigo()
44
{
55
//ctor
6-
hitbox.w = 75;
7-
hitbox.h = 30;
8-
atacando = false;
96
}
107

118
Enemigo::~Enemigo()
129
{
1310
//dtor
1411
}
15-
16-
void Enemigo::draw(SDL_Renderer* renderer)
17-
{
18-
SDL_RenderCopy(renderer, texturas[animacion_enemigo], NULL, &rect);
19-
if(frame%100==0)
20-
{
21-
animacion_enemigo++;
22-
if(animacion_enemigo>=texturas.size())
23-
animacion_enemigo=0;
24-
}
25-
hitbox.x = rect.x + rect.w/2 - hitbox.w/2;
26-
hitbox.y = rect.y + rect.h - hitbox.h/2;
27-
SDL_RenderCopy(renderer, hitbox_azul, NULL, &hitbox);
28-
if(atacando)
29-
SDL_RenderCopy(renderer, hitbox_roja, NULL, &hitbox);
30-
frame++;
31-
32-
// hitbox.h++;
33-
// hitbox.w++;
34-
}

Enemigo.h

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,15 @@
11
#ifndef ENEMIGO_H
22
#define ENEMIGO_H
33

4-
#include<SDL2/SDL.h>
5-
#include<SDL2/SDL_image.h>
6-
#include <vector>
7-
using namespace std;
4+
#include "Personaje.h"
85

9-
class Enemigo
6+
class Enemigo : public Personaje
107
{
118
public:
12-
vector<SDL_Texture*>texturas;
13-
SDL_Texture* hitbox_azul;
14-
SDL_Texture* hitbox_roja;
15-
SDL_Rect rect,hitbox;
16-
int frame;
17-
int animacion_enemigo;
18-
bool atacando;
199

2010
Enemigo();
2111
virtual ~Enemigo();
2212

23-
virtual void draw(SDL_Renderer* renderer);
24-
virtual void act()=0;
25-
2613
protected:
2714
private:
2815
};

EnemigoAzul.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ EnemigoAzul::EnemigoAzul(SDL_Renderer* renderer)
1212
rect.y = 250;
1313

1414
frame = 0;
15-
animacion_enemigo = 0;
15+
animacion = 0;
1616
hitbox_azul = IMG_LoadTexture(renderer,"hitbox/azul.png");
1717
hitbox_roja = IMG_LoadTexture(renderer,"hitbox/roja.png");
1818
}

EnemigoRojo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ EnemigoRojo::EnemigoRojo(SDL_Renderer* renderer)
1212
rect.y = 250;
1313

1414
frame = 0;
15-
animacion_enemigo = 0;
15+
animacion = 0;
1616

1717
hitbox_azul = IMG_LoadTexture(renderer,"hitbox/azul.png");
1818
hitbox_roja = IMG_LoadTexture(renderer,"hitbox/roja.png");

EnemigoVerde.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ EnemigoVerde::EnemigoVerde(SDL_Renderer* renderer)
1212
rect.y = 250;
1313

1414
frame = 0;
15-
animacion_enemigo = 0;
15+
animacion = 0;
1616

1717
hitbox_azul = IMG_LoadTexture(renderer,"hitbox/azul.png");
1818
hitbox_roja = IMG_LoadTexture(renderer,"hitbox/roja.png");

Personaje.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include "Personaje.h"
2+
3+
Personaje::Personaje()
4+
{
5+
hitbox.w = 75;
6+
hitbox.h = 30;
7+
atacando = false;
8+
}
9+
10+
Personaje::~Personaje()
11+
{
12+
//dtor
13+
}
14+
15+
void Personaje::draw(SDL_Renderer* renderer)
16+
{
17+
SDL_RenderCopy(renderer, texturas[animacion], NULL, &rect);
18+
if(frame%100==0)
19+
{
20+
animacion++;
21+
if(animacion>=texturas.size())
22+
animacion=0;
23+
}
24+
hitbox.x = rect.x + rect.w/2 - hitbox.w/2;
25+
hitbox.y = rect.y + rect.h - hitbox.h/2;
26+
SDL_RenderCopy(renderer, hitbox_azul, NULL, &hitbox);
27+
if(atacando)
28+
SDL_RenderCopy(renderer, hitbox_roja, NULL, &hitbox);
29+
frame++;
30+
31+
// hitbox.h++;
32+
// hitbox.w++;
33+
}

Personaje.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#ifndef PERSONAJE_H
2+
#define PERSONAJE_H
3+
4+
#include<SDL2/SDL.h>
5+
#include<SDL2/SDL_image.h>
6+
#include <vector>
7+
using namespace std;
8+
9+
class Personaje
10+
{
11+
public:
12+
13+
vector<SDL_Texture*>texturas;
14+
SDL_Texture* hitbox_azul;
15+
SDL_Texture* hitbox_roja;
16+
SDL_Rect rect,hitbox;
17+
int frame;
18+
int animacion;
19+
bool atacando;
20+
21+
virtual void draw(SDL_Renderer* renderer);
22+
virtual void act()=0;
23+
24+
Personaje();
25+
virtual ~Personaje();
26+
protected:
27+
private:
28+
};
29+
30+
#endif // PERSONAJE_H

SDL2Testground.cbp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
<Unit filename="EnemigoRojo.h" />
4141
<Unit filename="EnemigoVerde.cpp" />
4242
<Unit filename="EnemigoVerde.h" />
43+
<Unit filename="Personaje.cpp" />
44+
<Unit filename="Personaje.h" />
4345
<Unit filename="Sho.cpp" />
4446
<Unit filename="Sho.h" />
4547
<Unit filename="main.cpp" />

SDL2Testground.depend

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -576,29 +576,35 @@
576576
1422648136 source:/home/turupawn/Projects/Clases/Progra3/SDL2TestSimple-master/Sho.cpp
577577
"Sho.h"
578578

579-
1423849494 source:/home/turupawn/Projects/Clases/Progra3/SDL2TestSimple-master/Enemigo.cpp
579+
1423852183 source:/home/turupawn/Projects/Clases/Progra3/SDL2TestSimple-master/Enemigo.cpp
580580
"Enemigo.h"
581581

582-
1423850737 /home/turupawn/Projects/Clases/Progra3/SDL2TestSimple-master/Enemigo.h
583-
<SDL2/SDL.h>
584-
<SDL2/SDL_image.h>
585-
<vector>
582+
1423852523 /home/turupawn/Projects/Clases/Progra3/SDL2TestSimple-master/Enemigo.h
583+
"Personaje.h"
586584

587585
1423248725 /home/turupawn/Projects/Clases/Progra3/SDL2TestSimple-master/EnemigoAzul.h
588586
"Enemigo.h"
589587

590-
1423849438 source:/home/turupawn/Projects/Clases/Progra3/SDL2TestSimple-master/EnemigoAzul.cpp
588+
1423852188 source:/home/turupawn/Projects/Clases/Progra3/SDL2TestSimple-master/EnemigoAzul.cpp
591589
"EnemigoAzul.h"
592590

593-
1423849448 source:/home/turupawn/Projects/Clases/Progra3/SDL2TestSimple-master/EnemigoRojo.cpp
591+
1423852191 source:/home/turupawn/Projects/Clases/Progra3/SDL2TestSimple-master/EnemigoRojo.cpp
594592
"EnemigoRojo.h"
595593

596594
1423250451 /home/turupawn/Projects/Clases/Progra3/SDL2TestSimple-master/EnemigoRojo.h
597595
"Enemigo.h"
598596

599-
1423849449 source:/home/turupawn/Projects/Clases/Progra3/SDL2TestSimple-master/EnemigoVerde.cpp
597+
1423852196 source:/home/turupawn/Projects/Clases/Progra3/SDL2TestSimple-master/EnemigoVerde.cpp
600598
"EnemigoVerde.h"
601599

602600
1423250236 /home/turupawn/Projects/Clases/Progra3/SDL2TestSimple-master/EnemigoVerde.h
603601
"Enemigo.h"
604602

603+
1423852529 /home/turupawn/Projects/Clases/Progra3/SDL2TestSimple-master/Personaje.h
604+
<SDL2/SDL.h>
605+
<SDL2/SDL_image.h>
606+
<vector>
607+
608+
1423852224 source:/home/turupawn/Projects/Clases/Progra3/SDL2TestSimple-master/Personaje.cpp
609+
"Personaje.h"
610+

SDL2Testground.layout

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,49 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
22
<CodeBlocks_layout_file>
33
<ActiveTarget name="Debug" />
4-
<File name="EnemigoAzul.h" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="7" zoom_2="0">
4+
<File name="Sho.h" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="6" zoom_2="0">
55
<Cursor>
6-
<Cursor1 position="65" topLine="0" />
6+
<Cursor1 position="287" topLine="0" />
7+
</Cursor>
8+
</File>
9+
<File name="EnemigoRojo.cpp" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="4" zoom_2="0">
10+
<Cursor>
11+
<Cursor1 position="529" topLine="0" />
12+
</Cursor>
13+
</File>
14+
<File name="Enemigo.h" open="1" top="1" tabpos="2" split="0" active="1" splitpos="0" zoom_1="4" zoom_2="0">
15+
<Cursor>
16+
<Cursor1 position="59" topLine="0" />
717
</Cursor>
818
</File>
9-
<File name="EnemigoAzul.cpp" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="7" zoom_2="0">
19+
<File name="EnemigoAzul.cpp" open="0" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="4" zoom_2="0">
1020
<Cursor>
11-
<Cursor1 position="77" topLine="0" />
21+
<Cursor1 position="529" topLine="9" />
1222
</Cursor>
1323
</File>
14-
<File name="Sho.cpp" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="3" zoom_2="0">
24+
<File name="Sho.cpp" open="0" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="3" zoom_2="0">
1525
<Cursor>
1626
<Cursor1 position="506" topLine="6" />
1727
</Cursor>
1828
</File>
19-
<File name="main.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="2" zoom_2="0">
29+
<File name="EnemigoAzul.h" open="0" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="7" zoom_2="0">
2030
<Cursor>
21-
<Cursor1 position="1789" topLine="57" />
31+
<Cursor1 position="65" topLine="0" />
2232
</Cursor>
2333
</File>
24-
<File name="Enemigo.cpp" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="5" zoom_2="0">
34+
<File name="Enemigo.cpp" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="5" zoom_2="0">
2535
<Cursor>
26-
<Cursor1 position="112" topLine="0" />
36+
<Cursor1 position="370" topLine="10" />
2737
</Cursor>
2838
</File>
29-
<File name="Sho.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="6" zoom_2="0">
39+
<File name="main.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="2" zoom_2="0">
3040
<Cursor>
31-
<Cursor1 position="287" topLine="0" />
41+
<Cursor1 position="1789" topLine="60" />
3242
</Cursor>
3343
</File>
34-
<File name="EnemigoVerde.cpp" open="1" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
44+
<File name="EnemigoVerde.cpp" open="0" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="5" zoom_2="0">
3545
<Cursor>
36-
<Cursor1 position="76" topLine="0" />
46+
<Cursor1 position="536" topLine="0" />
3747
</Cursor>
3848
</File>
3949
</CodeBlocks_layout_file>

bin/Debug/SDL2Testground

2.3 KB
Binary file not shown.

obj/Debug/Enemigo.o

-31.6 KB
Binary file not shown.

obj/Debug/EnemigoAzul.o

48 Bytes
Binary file not shown.

obj/Debug/EnemigoRojo.o

48 Bytes
Binary file not shown.

obj/Debug/EnemigoVerde.o

48 Bytes
Binary file not shown.

obj/Debug/Personaje.o

39.7 KB
Binary file not shown.

obj/Debug/main.o

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)