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
bf4e2202
authored
Mar 27, 2025
by
Jaime de la Chica Bergillos
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Histoirioa gestion correcta de ohjetos
parent
77492d9f
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
28 additions
and
12 deletions
Executable
Historia.cpp
Objeto.cpp
Objeto.h
PantallaInicio.cpp
PantallaMundo.cpp
PantallaMundo.h
Executable
View file @
bf4e2202
No preview for this file type
Historia.cpp
View file @
bf4e2202
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
#include "Objeto.h"
#include "Objeto.h"
#include "Sprite.h"
#include "Sprite.h"
#include "Hitbox.h"
#include "Hitbox.h"
#include "Video.h"
void
Historia
::
limpiarEstado
(){
void
Historia
::
limpiarEstado
(){
for
(
int
i
=
0
;
i
<
colPantallas
.
size
();
i
++
){
for
(
int
i
=
0
;
i
<
colPantallas
.
size
();
i
++
){
...
@@ -18,7 +19,13 @@ void Historia::limpiarEstado(){
...
@@ -18,7 +19,13 @@ void Historia::limpiarEstado(){
static
void
iniciarInicio
()
{
static
void
iniciarInicio
()
{
Sprite
sprPlanta
(
"assets/planta.png"
);
Sprite
sprPlanta
(
"assets/planta.png"
);
Hitbox
hitPlanta
(
900
,
700
,
1200
,
-
1000000000
);
Hitbox
hitPlanta
(
900
,
700
,
1200
,
-
1000000000
);
Objeto
Planta
(
sprPlanta
,
sprPlanta
,
sprPlanta
,
hitPlanta
,
1200
,
400
,
300
,
400
,
normal
);
auto
funcionPlanta
=
[](
Objeto
*
Planta
)
->
bool
{
Agapito
.
inventario
[
Agapito
.
numObjetos
]
=*
Planta
;
Agapito
.
numObjetos
++
;
play_video
(
"assets/videoPrueba"
,
"es"
);
return
true
;
};
Objeto
Planta
(
sprPlanta
,
sprPlanta
,
sprPlanta
,
hitPlanta
,
1200
,
400
,
300
,
400
,
normal
,
funcionPlanta
);
getPantalla1
()
->
anadirObjeto
(
Planta
);
getPantalla1
()
->
anadirObjeto
(
Planta
);
}
}
...
...
Objeto.cpp
View file @
bf4e2202
...
@@ -18,3 +18,7 @@ void Objeto::renderizar(SDL_Renderer *renderer, int tamx, int tamy){
...
@@ -18,3 +18,7 @@ void Objeto::renderizar(SDL_Renderer *renderer, int tamx, int tamy){
break
;
break
;
}
}
}
}
bool
Objeto
::
interactuar
(){
return
funcionInteraccion
(
this
);
}
Objeto.h
View file @
bf4e2202
...
@@ -20,13 +20,14 @@ class Objeto {
...
@@ -20,13 +20,14 @@ class Objeto {
int
y
;
int
y
;
int
w
;
int
w
;
int
h
;
int
h
;
bool
(
*
funcionInteraccion
)(
Objeto
*
);
public
:
public
:
Hitbox
&
getHitbox
();
Hitbox
&
getHitbox
();
Objeto
(
Sprite
sprite_normal_
,
Sprite
sprite_overworld_
,
Sprite
sprite_overworld_highlight_
,
Hitbox
colision_
,
int
_x
,
int
_y
,
int
_w
,
int
_h
,
State
estado_
)
:
Objeto
(
Sprite
sprite_normal_
,
Sprite
sprite_overworld_
,
Sprite
sprite_overworld_highlight_
,
Hitbox
colision_
,
int
_x
,
int
_y
,
int
_w
,
int
_h
,
State
estado_
,
bool
(
*
_funcionInteraccion
)(
Objeto
*
)
)
:
sprite_normal
(
sprite_normal_
),
sprite_overworld
(
sprite_overworld_
),
sprite_normal
(
sprite_normal_
),
sprite_overworld
(
sprite_overworld_
),
sprite_overworld_highlight
(
sprite_overworld_highlight_
),
colision
(
colision_
),
x
(
_x
),
y
(
_y
),
w
(
_w
),
h
(
_h
),
estado
(
estado_
){}
sprite_overworld_highlight
(
sprite_overworld_highlight_
),
colision
(
colision_
),
x
(
_x
),
y
(
_y
),
w
(
_w
),
h
(
_h
),
estado
(
estado_
)
,
funcionInteraccion
(
_funcionInteraccion
)
{}
void
renderizar
(
SDL_Renderer
*
renderer
,
int
tamx
,
int
tamy
);
void
renderizar
(
SDL_Renderer
*
renderer
,
int
tamx
,
int
tamy
);
...
@@ -40,4 +41,6 @@ public:
...
@@ -40,4 +41,6 @@ public:
void
setY
(
int
y
)
{
void
setY
(
int
y
)
{
this
->
y
=
y
;
this
->
y
=
y
;
}
}
bool
interactuar
();
};
};
PantallaInicio.cpp
View file @
bf4e2202
...
@@ -17,7 +17,7 @@ PantallaInicio::PantallaInicio() :
...
@@ -17,7 +17,7 @@ PantallaInicio::PantallaInicio() :
Hitbox
hitIniciarPartida
(
1247
,
649
,
699
,
501
);
Hitbox
hitIniciarPartida
(
1247
,
649
,
699
,
501
);
Objeto
IniciarPartida
(
sprIniciarPartida
,
sprIniciarPartida
,
sprIniciarPartida
,
hitIniciarPartida
,
650
,
500
,
600
,
200
,
normal
);
Objeto
IniciarPartida
(
sprIniciarPartida
,
sprIniciarPartida
,
sprIniciarPartida
,
hitIniciarPartida
,
650
,
500
,
600
,
200
,
normal
,
nullptr
);
objetos
.
push_back
(
IniciarPartida
);
objetos
.
push_back
(
IniciarPartida
);
...
...
PantallaMundo.cpp
View file @
bf4e2202
...
@@ -37,13 +37,14 @@ void PantallaMundo::comprobarColisionesActivas() {
...
@@ -37,13 +37,14 @@ void PantallaMundo::comprobarColisionesActivas() {
}
}
void
PantallaMundo
::
comprobarColisionesPasivas
()
{
void
PantallaMundo
::
comprobarColisionesPasivas
()
{
bool
checkColision
=
false
;
int
i
=
0
;
int
i
=
0
;
while
(
!
checkColision
&&
i
<
objetos
.
size
()){
while
(
!
ojo_abierto
&&
i
<
objetos
.
size
()){
checkColision
|=
Agapito
.
comprobarColisionPasiva
(
objetos
[
i
].
getHitbox
());
if
(
Agapito
.
comprobarColisionPasiva
(
objetos
[
i
].
getHitbox
())){
indiceColision
=
i
;
ojo_abierto
=
true
;
}
i
++
;
i
++
;
}
}
ojo_abierto
=
checkColision
;
}
}
void
PantallaMundo
::
manejarEntrada
(
Handle
&
handle
)
{
void
PantallaMundo
::
manejarEntrada
(
Handle
&
handle
)
{
...
@@ -78,10 +79,9 @@ void PantallaMundo::manejarEntrada(Handle &handle) {
...
@@ -78,10 +79,9 @@ void PantallaMundo::manejarEntrada(Handle &handle) {
zRaton
*=
(
1080.0
/
handle
.
getTamY
());
zRaton
*=
(
1080.0
/
handle
.
getTamY
());
cout
<<
"Raton x "
<<
xRaton
<<
" Raton z "
<<
zRaton
<<
endl
;
cout
<<
"Raton x "
<<
xRaton
<<
" Raton z "
<<
zRaton
<<
endl
;
if
(
colisionesInterfaz
[
0
].
colisiona
(
xRaton
,
zRaton
)
&&
ojo_abierto
){
if
(
colisionesInterfaz
[
0
].
colisiona
(
xRaton
,
zRaton
)
&&
ojo_abierto
){
Agapito
.
inventario
[
Agapito
.
numObjetos
]
=
objetos
[
0
];
if
(
objetos
[
indiceColision
].
interactuar
()){
Agapito
.
numObjetos
++
;
objetos
.
erase
(
objetos
.
begin
()
+
indiceColision
);
objetos
.
pop_back
();
}
play_video
(
"assets/videoPrueba"
,
"es"
);
}
}
}
}
break
;
break
;
...
...
PantallaMundo.h
View file @
bf4e2202
...
@@ -20,6 +20,8 @@ class PantallaMundo : public Pantalla {
...
@@ -20,6 +20,8 @@ class PantallaMundo : public Pantalla {
bool
ojo_abierto
=
false
;
bool
ojo_abierto
=
false
;
std
::
array
<
Sprite
,
2
>
Ojo
;
std
::
array
<
Sprite
,
2
>
Ojo
;
int
indiceColision
;
/// Colisiones al pulsar el ratón en la interfaz
/// Colisiones al pulsar el ratón en la interfaz
std
::
array
<
Hitbox
,
4
>
colisionesInterfaz
;
std
::
array
<
Hitbox
,
4
>
colisionesInterfaz
;
...
...
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