Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Mathodo2
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
MOULIAS Mattheo
Mathodo2
Commits
fc1fb6d5
Commit
fc1fb6d5
authored
2 years ago
by
SmallIshMink
Browse files
Options
Downloads
Patches
Plain Diff
Mise en place du vaisseau (1)
parent
779fe3dd
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
main.c
+69
-10
69 additions, 10 deletions
main.c
main.o
+0
-0
0 additions, 0 deletions
main.o
spacecorridor.exe
+0
-0
0 additions, 0 deletions
spacecorridor.exe
with
69 additions
and
10 deletions
main.c
+
69
−
10
View file @
fc1fb6d5
...
...
@@ -64,6 +64,7 @@
struct
textures_s
{
SDL_Texture
*
background
;
/*!< Texture liée à l'image du fond de l'écran. */
SDL_Texture
*
ship
;
/*!< Texture liée à l'image du vaisseau. */
/* A COMPLETER */
};
...
...
@@ -75,14 +76,25 @@ struct textures_s{
typedef
struct
textures_s
textures_t
;
/**
* \brief Représentation pour stocker les données du vaisseau
*
*/
struct
sprite_s
{
int
x
;
int
y
;
int
w
;
int
h
;
};
typedef
struct
sprite_s
sprite_t
;
/**
* \brief Représentation du monde du jeu
*/
struct
world_s
{
/*
A COMPLETER
*/
sprite_t
*
vaisseau
;
/*!< Représentation du vaisseau */
int
gameover
;
/*!< Champ indiquant si l'on est à la fin du jeu */
...
...
@@ -95,7 +107,14 @@ struct world_s{
typedef
struct
world_s
world_t
;
/**
* \brief Fonction qui affiche les données du vaisseau
*
*/
void
print_sprite
(
sprite_t
*
sprite
){
printf
(
"x = %d, y = %d, w = %d, h = %d
\n
"
,
sprite
->
x
,
sprite
->
y
,
sprite
->
w
,
sprite
->
h
);
}
/**
...
...
@@ -108,10 +127,20 @@ void init_data(world_t * world){
//on n'est pas à la fin du jeu
world
->
gameover
=
0
;
// Initialisation du vaisseau
world
->
vaisseau
=
malloc
(
sizeof
(
sprite_t
));
world
->
vaisseau
->
x
=
SCREEN_WIDTH
/
2
-
SHIP_SIZE
/
2
;
world
->
vaisseau
->
y
=
SCREEN_HEIGHT
-
SHIP_SIZE
;
world
->
vaisseau
->
w
=
SHIP_SIZE
;
world
->
vaisseau
->
h
=
SHIP_SIZE
;
print_sprite
(
world
->
vaisseau
);
}
/**
* \brief La fonction nettoie les données du monde
* \param world les données du monde
...
...
@@ -120,7 +149,7 @@ void init_data(world_t * world){
void
clean_data
(
world_t
*
world
){
/* utile uniquement si vous avez fait de l'allocation dynamique (malloc); la fonction ici doit permettre de libérer la mémoire (free) */
free
(
world
->
vaisseau
);
}
...
...
@@ -167,10 +196,28 @@ void handle_events(SDL_Event *event,world_t *world){
//si une touche est appuyée
if
(
event
->
type
==
SDL_KEYDOWN
){
//si la touche appuyée est 'D'
if
(
event
->
key
.
keysym
.
sym
==
SDLK_d
){
printf
(
"La touche D est appuyée
\n
"
);
}
}
switch
(
event
->
key
.
keysym
.
sym
)
{
case
SDLK_d
:
world
->
vaisseau
->
x
+=
MOVING_STEP
;
break
;
case
SDLK_q
:
world
->
vaisseau
->
x
-=
MOVING_STEP
;
break
;
case
SDLK_z
:
world
->
vaisseau
->
y
-=
MOVING_STEP
;
break
;
case
SDLK_s
:
world
->
vaisseau
->
y
+=
MOVING_STEP
;
break
;
default:
break
;
}
print_sprite
(
world
->
vaisseau
);
}
}
}
...
...
@@ -182,6 +229,7 @@ void handle_events(SDL_Event *event,world_t *world){
void
clean_textures
(
textures_t
*
textures
){
clean_texture
(
textures
->
background
);
clean_texture
(
textures
->
ship
);
/* A COMPLETER */
}
...
...
@@ -195,6 +243,7 @@ void clean_textures(textures_t *textures){
void
init_textures
(
SDL_Renderer
*
renderer
,
textures_t
*
textures
){
textures
->
background
=
load_image
(
"ressources/space-background.bmp"
,
renderer
);
textures
->
ship
=
load_image
(
"ressources/spaceship.bmp"
,
renderer
);
/* A COMPLETER */
...
...
@@ -214,7 +263,16 @@ void apply_background(SDL_Renderer *renderer, SDL_Texture *texture){
}
}
void
apply_sprite
(
SDL_Renderer
*
renderer
,
SDL_Texture
*
texture
,
sprite_t
*
sprite
){
if
(
texture
!=
NULL
){
SDL_Rect
rect
;
rect
.
x
=
sprite
->
x
;
rect
.
y
=
sprite
->
y
;
rect
.
w
=
sprite
->
w
;
rect
.
h
=
sprite
->
h
;
SDL_RenderCopy
(
renderer
,
texture
,
NULL
,
&
rect
);
}
}
...
...
@@ -233,6 +291,7 @@ void refresh_graphics(SDL_Renderer *renderer, world_t *world,textures_t *texture
//application des textures dans le renderer
apply_background
(
renderer
,
textures
->
background
);
/* A COMPLETER */
apply_sprite
(
renderer
,
textures
->
ship
,
world
->
vaisseau
);
// on met à jour l'écran
update_screen
(
renderer
);
...
...
This diff is collapsed.
Click to expand it.
main.o
+
0
−
0
View file @
fc1fb6d5
No preview for this file type
This diff is collapsed.
Click to expand it.
spacecorridor.exe
+
0
−
0
View file @
fc1fb6d5
No preview for this file type
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