Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
José Pardo Madera
/
ProjectoMultimeda2025
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
64d7c77c
authored
Mar 11, 2025
by
Jaime de la Chica Bergillos
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Hitbox implementadas
parent
c90bd355
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
33 additions
and
26 deletions
Executable
Hitbox.cpp
Hitbox.h
Objeto.cpp
Objeto.h
Personaje.h
main.cpp
Executable
0 → 100755
View file @
64d7c77c
No preview for this file type
Hitbox.cpp
View file @
64d7c77c
#include "Hitbox.h"
bool
Hitbox
::
colisiona
(
int
x
,
int
y
){
if
(
x
>
xSuperiorDer
&&
x
<
xInferiorIzq
&&
y
>
ySuperiorDer
&&
y
<
yInferiorIzq
){
bool
Hitbox
::
colisiona
(
int
x
,
int
z
){
if
(
x
<=
xMaximo
&&
x
>=
xMinimo
&&
z
<=
zMaximo
&&
z
>=
zMinimo
){
std
::
cout
<<
"Esta colisionando"
;
return
true
;
}
else
return
false
;
}
\ No newline at end of file
Hitbox.h
View file @
64d7c77c
#ifndef HITBOX_H
#define HITBOX_H
#include <iostream>
class
Hitbox
{
int
xSuperiorDer
;
int
xInferiorIzq
;
int
ySuperiorDer
;
int
yInferiorIzq
;
public
:
bool
colisiona
(
int
x
,
int
y
);
int
xMaximo
;
int
xMinimo
;
int
zMaximo
;
int
zMinimo
;
bool
colisiona
(
int
x
,
int
z
);
Hitbox
(
int
xSD
,
int
xII
,
int
ySD
,
int
yII
)
:
xSuperiorDer
(
xSD
),
xInferiorIzq
(
xII
),
ySuperiorDer
(
ySD
),
yInferiorIzq
(
yII
){}
int
getxSuperiorDer
(){
return
xSuperiorDer
;}
int
getySuperiorDer
(){
return
ySuperiorDer
;}
int
getxInferiorIzq
(){
return
xInferiorIzq
;}
int
getyInferiorIzq
(){
return
yInferiorIzq
;}
Hitbox
(
int
xS
,
int
xI
,
int
zS
,
int
zI
)
:
xMaximo
(
xS
),
xMinimo
(
xI
),
zMaximo
(
zS
),
zMinimo
(
zI
){}
};
#endif // HITBOX_H
Objeto.cpp
View file @
64d7c77c
...
...
@@ -5,14 +5,15 @@ Hitbox & Objeto::getHitbox(){
}
void
Objeto
::
renderizar
(
SDL_Renderer
*
renderer
){
std
::
cout
<<
estado
<<
std
::
endl
;
switch
(
estado
){
normal
:
case
normal
:
sprite_normal
.
renderizar
(
renderer
,
x
,
y
,
w
,
h
);
break
;
overworld
:
case
overworld
:
sprite_overworld
.
renderizar
(
renderer
,
x
,
y
,
w
,
h
);
break
;
overworld_highlight
:
case
overworld_highlight
:
sprite_overworld_highlight
.
renderizar
(
renderer
,
x
,
y
,
w
,
h
);
break
;
}
...
...
Objeto.h
View file @
64d7c77c
...
...
@@ -2,6 +2,7 @@
#include "Sprite.h"
#include "Hitbox.h"
#include <iostream>
enum
State
{
...
...
@@ -23,9 +24,9 @@ class Objeto {
public
:
Hitbox
&
getHitbox
();
Objeto
(
Sprite
sprite_normal_
,
Sprite
sprite_overworld_
,
Sprite
sprite_overworld_highlight_
,
Hitbox
colision_
,
int
_x
,
int
_y
,
int
_w
,
int
_h
)
:
Objeto
(
Sprite
sprite_normal_
,
Sprite
sprite_overworld_
,
Sprite
sprite_overworld_highlight_
,
Hitbox
colision_
,
int
_x
,
int
_y
,
int
_w
,
int
_h
,
State
estado_
)
:
sprite_normal
(
sprite_normal_
),
sprite_overworld
(
sprite_overworld_
),
sprite_overworld_highlight
(
sprite_overworld_highlight_
),
colision
(
colision_
),
x
(
_x
),
y
(
_y
),
w
(
_w
),
h
(
_h
){}
sprite_overworld_highlight
(
sprite_overworld_highlight_
),
colision
(
colision_
),
x
(
_x
),
y
(
_y
),
w
(
_w
),
h
(
_h
)
,
estado
(
estado_
)
{}
void
renderizar
(
SDL_Renderer
*
renderer
);
};
Personaje.h
View file @
64d7c77c
...
...
@@ -28,11 +28,11 @@ class Personaje {
Facing
estado
=
Frente
;
int
indice_movimiento
=
0
;
int
x
=
100
;
int
profundidades
=
100
;
public
:
int
x
=
100
;
int
profundidades
=
100
;
Personaje
();
void
move
(
Facing
direcion
);
...
...
main.cpp
View file @
64d7c77c
...
...
@@ -67,13 +67,19 @@ int main(){
}
vector
<
Objeto
*>
objetos
;
vector
<
Hitbox
*>
colisiones
;
Sprite
Fondo1
(
"assets/fondoHabitacion.jpg"
);
Sprite
sprPlanta
(
"assets/planta.png"
);
Hitbox
hitPlanta
(
10
,
50
,
110
,
100
);
Objeto
Planta
(
sprPlanta
,
sprPlanta
,
sprPlanta
,
hitPlanta
,
10
,
50
,
100
,
50
);
Hitbox
hitPlanta
(
350
,
80
,
450
,
120
);
Hitbox
hitCama
(
10
,
50
,
300
,
300
);
Hitbox
hitFondo
(
1000000
,
-
10000000
,
50
,
0
);
Objeto
Planta
(
sprPlanta
,
sprPlanta
,
sprPlanta
,
hitPlanta
,
1200
,
400
,
300
,
400
,
normal
);
objetos
.
push_back
(
&
Planta
);
colisiones
.
push_back
(
&
hitPlanta
);
colisiones
.
push_back
(
&
hitCama
);
colisiones
.
push_back
(
&
hitFondo
);
Personaje
Agapito
;
...
...
@@ -98,16 +104,15 @@ int main(){
Agapito
.
move
(
Frente
);
break
;
}
for
(
int
i
=
0
;
i
<
objetos
.
size
();
i
++
){
Agapito
.
comprobarColision
(
objetos
[
i
]
->
getHitbox
());
std
::
cout
<<
"Agapito "
<<
Agapito
.
x
<<
" "
<<
Agapito
.
profundidades
<<
std
::
endl
;
for
(
int
i
=
0
;
i
<
colisiones
.
size
();
i
++
){
Agapito
.
comprobarColision
(
*
colisiones
[
i
]);
}
break
;
case
SDL_QUIT
:
exit
(
0
);
}
printf
(
"Pito
\n
"
);
}
printf
(
"Buclee
\n
"
);
Fondo1
.
renderizar
(
Renderer
,
0
,
0
,
1920
,
1080
);
for
(
int
i
=
0
;
i
<
objetos
.
size
();
i
++
){
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment