Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Projet l2
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
VAUTRIN Guillaume
Projet l2
Commits
9f04bee5
Commit
9f04bee5
authored
4 years ago
by
vautrin33u
Browse files
Options
Downloads
Patches
Plain Diff
Tentatives de construction de sprites dans un tableau - à corriger
parent
5c1d20fd
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
logique.c
+23
-6
23 additions, 6 deletions
logique.c
logique.h
+11
-3
11 additions, 3 deletions
logique.h
with
34 additions
and
9 deletions
logique.c
+
23
−
6
View file @
9f04bee5
...
@@ -27,7 +27,7 @@ void init_data(world_t * world){ //faux
...
@@ -27,7 +27,7 @@ void init_data(world_t * world){ //faux
build_sprite_unique
(
&
world
->
lavabo
,
'L'
,
LAVABO_LARGEUR
,
LAVABO_HAUTEUR
,
world
->
map
);
build_sprite_unique
(
&
world
->
lavabo
,
'L'
,
LAVABO_LARGEUR
,
LAVABO_HAUTEUR
,
world
->
map
);
build_sprite_unique
(
&
world
->
poubelle
,
't'
,
POUBELLE_LARGEUR
,
POUBELLE_HAUTEUR
,
world
->
map
);
build_sprite_unique
(
&
world
->
poubelle
,
't'
,
POUBELLE_LARGEUR
,
POUBELLE_HAUTEUR
,
world
->
map
);
build_sprite_unique
(
&
world
->
envoi
,
'e'
,
ZONE_ENVOI_LARGEUR
,
ZONE_ENVOI_HAUTEUR
,
world
->
map
);
build_sprite_unique
(
&
world
->
envoi
,
'e'
,
ZONE_ENVOI_LARGEUR
,
ZONE_ENVOI_HAUTEUR
,
world
->
map
);
build_sprites_tab
(
&
world
,
'
X
'
,
BLOC_COMPT_SIZE
,
BLOC_COMPT_SIZE
);
build_sprites_tab
(
world
,
'
P
'
,
BLOC_COMPT_SIZE
,
BLOC_COMPT_SIZE
,
NB_COMPT_1
);
/*
/*
...
@@ -77,15 +77,27 @@ void build_sprite_unique (sprite_t *sprite, char nom, int largeur, int hauteur,
...
@@ -77,15 +77,27 @@ void build_sprite_unique (sprite_t *sprite, char nom, int largeur, int hauteur,
if
(
comptX
==
hauteur
&&
comptY
==
largeur
){
if
(
comptX
==
hauteur
&&
comptY
==
largeur
){
init_sprite
(
sprite
,
nom
,
x
,
y
,
hauteur
,
largeur
,
0
,
0
);
init_sprite
(
sprite
,
nom
,
x
,
y
,
hauteur
,
largeur
,
0
,
0
);
}
}
print_sprite
(
sprite
);
}
}
void
build_sprites_tab
(
world_t
*
world
,
char
nomSprite
,
int
largeur
,
int
hauteur
){
void
build_sprites_tab
(
world_t
*
world
,
char
nomSprite
,
int
largeur
,
int
hauteur
,
int
nb_sprites
){
for
(
int
i
=
0
;
i
<
SCREEN_HEIGHT
;
i
++
){
int
index
=
0
;
for
(
int
j
=
0
;
j
<
SCREEN_WIDTH
;
j
++
){
for
(
int
i
=
0
;
i
<
SCREEN_HEIGHT
;
i
+=
hauteur
){
//Parcours du tableau pour repérer le premier caractère d'un
for
(
int
j
=
0
;
j
<
SCREEN_WIDTH
;
j
+=
largeur
){
//Parcours du tableau pour repérer le premier caractère d'un sprite
if
(
world
->
map
[
i
][
j
]
==
nomSprite
){
init_sprite
(
&
world
->
comptoire
[
index
],
nomSprite
,
j
-
SIZE_MUR
,
i
-
SIZE_MUR
,
largeur
,
hauteur
,
0
,
0
);
if
(
index
+
1
<
nb_sprites
){
index
++
;
// on incrémente vers le sprite suivant, a condition qu'il y ai assez de place prévu pour
}
}
}
}
}
}
for
(
int
i
=
0
;
i
<
nb_sprites
;
i
++
){
print_sprite
(
&
world
->
comptoire
[
i
]);
}
}
}
void
init_sprite
(
sprite_t
*
sprite
,
char
nom
,
int
x
,
int
y
,
int
w
,
int
h
,
int
v
,
int
state
){
//faux
void
init_sprite
(
sprite_t
*
sprite
,
char
nom
,
int
x
,
int
y
,
int
w
,
int
h
,
int
v
,
int
state
){
//faux
...
@@ -100,6 +112,11 @@ void init_sprite(sprite_t *sprite, char nom, int x, int y, int w, int h, int v,
...
@@ -100,6 +112,11 @@ void init_sprite(sprite_t *sprite, char nom, int x, int y, int w, int h, int v,
sprite
->
nom
=
nom
;
sprite
->
nom
=
nom
;
}
}
void
print_sprite
(
sprite_t
*
sprite
){
// Fonction permettant d'afficher les données contenues dans un sprite
printf
(
"nom : %c -- x= %d | y=%d | w= %d | h= %d | v= %d | visible : %d
\n
"
,
sprite
->
nom
,
sprite
->
x
,
sprite
->
y
,
sprite
->
w
,
sprite
->
h
,
sprite
->
v
,
sprite
->
is_visible
);
}
int
aleatoire
(
int
a
,
int
b
){
int
aleatoire
(
int
a
,
int
b
){
// Fonction générant une valeur aléatoire entre a (inclu) et b (exclu)
// Fonction générant une valeur aléatoire entre a (inclu) et b (exclu)
return
rand
()
%
(
b
-
a
)
+
a
;
return
rand
()
%
(
b
-
a
)
+
a
;
...
...
This diff is collapsed.
Click to expand it.
logique.h
+
11
−
3
View file @
9f04bee5
...
@@ -38,7 +38,7 @@ struct sprite_s{
...
@@ -38,7 +38,7 @@ struct sprite_s{
typedef
struct
sprite_s
sprite_t
;
typedef
struct
sprite_s
sprite_t
;
struct
world_s
{
struct
world_s
{
int
gameover
;
/*!< Champ indiquant si l'on est à la fin du jeu */
int
gameover
;
/*!< Champ indiquant si l'on est à la fin du jeu */
sprite_t
joueur
;
/*!< Sprite du joueur */
sprite_t
joueur
;
/*!< Sprite du joueur */
sprite_t
four
;
/*!< Sprite du four */
sprite_t
four
;
/*!< Sprite du four */
...
@@ -72,6 +72,13 @@ typedef struct world_s world_t;
...
@@ -72,6 +72,13 @@ typedef struct world_s world_t;
*/
*/
void
init_sprite
(
sprite_t
*
sprite
,
char
nom
,
int
x
,
int
y
,
int
w
,
int
h
,
int
v
,
int
state
);
void
init_sprite
(
sprite_t
*
sprite
,
char
nom
,
int
x
,
int
y
,
int
w
,
int
h
,
int
v
,
int
state
);
/**
* @brief Affiche certains éléments d'un sprite
*
* @param sprite
*/
void
print_sprite
(
sprite_t
*
sprite
);
/**
/**
* @brief Fonction initialisant un unique sprite (meuble)
* @brief Fonction initialisant un unique sprite (meuble)
*
*
...
@@ -86,12 +93,13 @@ void build_sprite_unique (sprite_t *sprite, char nom, int largeur, int hauteur,
...
@@ -86,12 +93,13 @@ void build_sprite_unique (sprite_t *sprite, char nom, int largeur, int hauteur,
/**
/**
* @brief Fonction initialisant un tableau de sprites
* @brief Fonction initialisant un tableau de sprites
*
*
* @param world données du monde - contenant la map et les sp
i
rtes concernés
* @param world données du monde - contenant la map et les spr
i
tes concernés
* @param nomSprite Caractère du Sprite sur la carte
* @param nomSprite Caractère du Sprite sur la carte
* @param largeur Largeur du sprite
* @param largeur Largeur du sprite
* @param hauteur Hauteur du sprite
* @param hauteur Hauteur du sprite
* @param nb_sprites nombre d'éléments max dans le tableau de sprite
*/
*/
void
build_sprites_tab
(
world_t
*
world
,
char
nomSprite
,
int
largeur
,
int
hauteur
);
void
build_sprites_tab
(
world_t
*
world
,
char
nomSprite
,
int
largeur
,
int
hauteur
,
int
nb_sprites
);
/**
/**
* \brief la fonction permet de rendre visible un sprite
* \brief la fonction permet de rendre visible un sprite
...
...
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