Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
GAME INSA PROJECT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
3EII INFO LKCH
GAME INSA PROJECT
Commits
0efef6b7
Commit
0efef6b7
authored
4 years ago
by
Kaan.Korucan
Browse files
Options
Downloads
Patches
Plain Diff
query functions added
parent
a0bbc8a9
No related branches found
Branches containing commit
No related tags found
4 merge requests
!8
Modele
,
!7
Modele
,
!6
Modele
,
!5
Modele Version 1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
GAME/cmake-build-debug/ressource/begin.png
+0
-0
0 additions, 0 deletions
GAME/cmake-build-debug/ressource/begin.png
GAME/include/GAME.h
+6
-0
6 additions, 0 deletions
GAME/include/GAME.h
GAME/main.c
+24
-72
24 additions, 72 deletions
GAME/main.c
GAME/src/GAME.c
+78
-0
78 additions, 0 deletions
GAME/src/GAME.c
with
108 additions
and
72 deletions
GAME/cmake-build-debug/ressource/begin.png
0 → 100644
+
0
−
0
View file @
0efef6b7
5.61 KiB
This diff is collapsed.
Click to expand it.
GAME/include/GAME.h
+
6
−
0
View file @
0efef6b7
...
...
@@ -19,6 +19,9 @@
#include
<SDL2/SDL.h>
#include
"personnage.h"
#include
"prof.h"
#include
"DS.h"
#include
"map.h"
/*!
* \def WINDOW_WIDTH
...
...
@@ -40,5 +43,8 @@
SDL_Texture
*
query_hero
(
Personnage
*
hero
,
SDL_Rect
*
hero_rect
,
SDL_Renderer
*
renderer
,
SDL_Window
*
window
);
SDL_Texture
*
query_teacher
(
Prof
*
prof
,
SDL_Rect
*
teacher_rect
,
SDL_Renderer
*
renderer
,
SDL_Window
*
window
);
SDL_Texture
*
query_exam
(
DS
*
exam
,
SDL_Rect
*
exam_rect
,
SDL_Renderer
*
renderer
,
SDL_Window
*
window
);
SDL_Texture
*
query_map
(
MAP
*
map
,
SDL_Renderer
*
renderer
,
SDL_Window
*
window
);
#endif
/*INSAGAME_GAME_H*/
This diff is collapsed.
Click to expand it.
GAME/main.c
+
24
−
72
View file @
0efef6b7
...
...
@@ -36,94 +36,46 @@ int main(int argc, char* args[])
SDL_Quit
();
return
1
;
}
//Create Map and give it the functional matrix
MAP
map_game
;
init_map
(
&
map_game
,
"ressource/colored.bmp"
,
"ressource/mapvis.bmp"
);
map_game
.
functional
=
maptomatrix
(
&
map_game
);
//Create a texture for map
SDL_Texture
*
texture_map
=
IMG_LoadTexture
(
renderer
,
map_game
.
visual_path
);
if
(
!
texture_map
)
//texture for beginning page
SDL_Texture
*
texture_begin_page
;
texture_begin_page
=
IMG_LoadTexture
(
renderer
,
"ressource/begin.png"
);
if
(
!
texture_begin_page
)
{
printf
(
"error creating texture
for map
: %s
\n
"
,
SDL_GetError
());
printf
(
"error creating texture: %s
\n
"
,
SDL_GetError
());
SDL_DestroyRenderer
(
renderer
);
SDL_DestroyWindow
(
window
);
SDL_Quit
();
return
1
;
}
//create a Personnage "hero" and query his texture
SDL_RenderCopy
(
renderer
,
texture_begin_page
,
NULL
,
NULL
);
SDL_RenderPresent
(
renderer
);
SDL_Delay
(
2000
);
SDL_DestroyTexture
(
texture_begin_page
);
//Create the Map and query its texture
MAP
map_game
;
SDL_Texture
*
texture_map
=
query_map
(
&
map_game
,
renderer
,
window
);
//create a Personnage "hero" and query its texture
Personnage
hero
;
SDL_Rect
hero_rect
;
SDL_Texture
*
texture_hero
=
query_hero
(
&
hero
,
&
hero_rect
,
renderer
,
window
);
if
(
!
texture_hero
){
return
1
;
}
//create a Prof "teacher" and query his texture
//create a Prof "teacher" and query its texture
Prof
teacher
;
init_prof
(
&
teacher
,
350
,
380
,
40
,
25
,
SPEED
,
"ressource/prof.png"
);
// load the image data into the graphics hardware's memory
SDL_Texture
*
texture_teacher
=
IMG_LoadTexture
(
renderer
,
teacher
.
image_prof
);
if
(
!
texture_teacher
)
{
printf
(
"Cannot create texture for prof: %s
\n
"
,
SDL_GetError
());
SDL_DestroyRenderer
(
renderer
);
SDL_DestroyWindow
(
window
);
SDL_Quit
();
return
1
;
}
// struct to hold the position and size of prof
SDL_Rect
teacher_rect
;
// get and scale the dimensions of texture
SDL_QueryTexture
(
texture_teacher
,
NULL
,
NULL
,
&
teacher_rect
.
w
,
&
teacher_rect
.
h
);
teacher_rect
.
w
=
teacher
.
larg_prof
;
teacher_rect
.
h
=
teacher
.
long_prof
;
teacher_rect
.
x
=
teacher
.
x_prof
;
teacher_rect
.
y
=
teacher
.
y_prof
;
SDL_Rect
teacher_rect
;
SDL_Texture
*
texture_teacher
=
query_teacher
(
&
teacher
,
&
teacher_rect
,
renderer
,
window
);
//Create a DS "exam" and its texture
DS
exam
;
fflush
(
stdin
);
int
r
=
2
+
rand
()
%
9
;
//random [2,10] because bug door 1 impossible => for complete 11->30
init_DS
(
&
exam
,
r
,
"ressource/DS.png"
);
// load the image data into the graphics hardware's memory
SDL_Texture
*
texture_DS
=
IMG_LoadTexture
(
renderer
,
exam
.
image_DS
);
SDL_Rect
exam_rect
;
SDL_Texture
*
texture_exam
=
query_exam
(
&
exam
,
&
exam_rect
,
renderer
,
window
);
if
(
!
texture_DS
)
{
printf
(
"error creating texture: %s
\n
"
,
SDL_GetError
());
SDL_DestroyRenderer
(
renderer
);
SDL_DestroyWindow
(
window
);
SDL_Quit
();
if
(
!
texture_map
||
!
texture_hero
||
!
texture_teacher
||
!
texture_exam
){
return
1
;
}
SDL_Rect
exam_rect
;
SDL_QueryTexture
(
texture_DS
,
NULL
,
NULL
,
&
exam_rect
.
w
,
&
exam_rect
.
h
);
exam_rect
.
w
/=
30
;
exam_rect
.
h
/=
35
;
exam_rect
.
x
=
exam
.
x_DS
;
exam_rect
.
y
=
exam
.
y_DS
;
// collision detection
int
collision
;
//result variable
...
...
@@ -226,7 +178,7 @@ int main(int argc, char* args[])
SDL_RenderCopy
(
renderer
,
texture_map
,
NULL
,
NULL
);
SDL_RenderCopy
(
renderer
,
texture_hero
,
NULL
,
&
hero_rect
);
SDL_RenderCopy
(
renderer
,
texture_teacher
,
NULL
,
&
teacher_rect
);
SDL_RenderCopy
(
renderer
,
texture_
DS
,
NULL
,
&
exam_rect
);
SDL_RenderCopy
(
renderer
,
texture_
exam
,
NULL
,
&
exam_rect
);
SDL_RenderPresent
(
renderer
);
// wait 17ms
...
...
@@ -236,7 +188,7 @@ int main(int argc, char* args[])
SDL_DestroyTexture
(
texture_map
);
SDL_DestroyTexture
(
texture_hero
);
SDL_DestroyTexture
(
texture_teacher
);
SDL_DestroyTexture
(
texture_
DS
);
SDL_DestroyTexture
(
texture_
exam
);
//texture for endgame
SDL_Texture
*
texture_endgame
;
...
...
This diff is collapsed.
Click to expand it.
GAME/src/GAME.c
+
78
−
0
View file @
0efef6b7
...
...
@@ -49,3 +49,81 @@ SDL_Texture * query_hero(Personnage * hero, SDL_Rect * hero_rect, SDL_Renderer *
}
SDL_Texture
*
query_teacher
(
Prof
*
teacher
,
SDL_Rect
*
teacher_rect
,
SDL_Renderer
*
renderer
,
SDL_Window
*
window
){
SDL_Texture
*
texture_teacher
;
init_prof
(
teacher
,
350
,
380
,
40
,
25
,
SPEED
,
"ressource/prof.png"
);
// load the image data into the graphics hardware's memory
texture_teacher
=
IMG_LoadTexture
(
renderer
,
teacher
->
image_prof
);
if
(
!
texture_teacher
)
{
printf
(
"Cannot create texture for prof: %s
\n
"
,
SDL_GetError
());
SDL_DestroyRenderer
(
renderer
);
SDL_DestroyWindow
(
window
);
SDL_Quit
();
return
NULL
;
}
// get and scale the dimensions of texture
SDL_QueryTexture
(
texture_teacher
,
NULL
,
NULL
,
&
teacher_rect
->
w
,
&
teacher_rect
->
h
);
teacher_rect
->
w
=
teacher
->
larg_prof
;
teacher_rect
->
h
=
teacher
->
long_prof
;
teacher_rect
->
x
=
teacher
->
x_prof
;
teacher_rect
->
y
=
teacher
->
y_prof
;
return
texture_teacher
;
}
SDL_Texture
*
query_exam
(
DS
*
exam
,
SDL_Rect
*
exam_rect
,
SDL_Renderer
*
renderer
,
SDL_Window
*
window
){
fflush
(
stdin
);
int
r
=
2
+
rand
()
%
9
;
//random [2,10] because bug door 1 impossible => for complete 11->30
SDL_Texture
*
texture_exam
;
init_DS
(
exam
,
r
,
"ressource/DS.png"
);
// load the image data into the graphics hardware's memory
texture_exam
=
IMG_LoadTexture
(
renderer
,
exam
->
image_DS
);
if
(
!
texture_exam
)
{
printf
(
"error creating texture: %s
\n
"
,
SDL_GetError
());
SDL_DestroyRenderer
(
renderer
);
SDL_DestroyWindow
(
window
);
SDL_Quit
();
return
NULL
;
}
SDL_QueryTexture
(
texture_exam
,
NULL
,
NULL
,
&
exam_rect
->
w
,
&
exam_rect
->
h
);
exam_rect
->
w
/=
30
;
exam_rect
->
h
/=
35
;
exam_rect
->
x
=
exam
->
x_DS
;
exam_rect
->
y
=
exam
->
y_DS
;
return
texture_exam
;
}
SDL_Texture
*
query_map
(
MAP
*
map_game
,
SDL_Renderer
*
renderer
,
SDL_Window
*
window
){
init_map
(
map_game
,
"ressource/colored.bmp"
,
"ressource/mapvis.bmp"
);
map_game
->
functional
=
maptomatrix
(
map_game
);
//Create a texture for map
SDL_Texture
*
texture_map
=
IMG_LoadTexture
(
renderer
,
map_game
->
visual_path
);
if
(
!
texture_map
)
{
printf
(
"error creating texture for map: %s
\n
"
,
SDL_GetError
());
SDL_DestroyRenderer
(
renderer
);
SDL_DestroyWindow
(
window
);
SDL_Quit
();
return
NULL
;
}
return
texture_map
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment