Eventuellement ça peut donner:
if JOUEUR_X < 670.0 && is_key_down(Right) {
JOUEUR_X += 5.0;
}
ou
if JOUEUR_X < 670.0 {
if is_key_down(Right) {
JOUEUR_X += 5.0;
}
}
Certes, mais on programme aussi pour être relu, une boucle sous-entends plusieurs itérations.
Ici tu as JOUEUR_X
qui est une constante tu va faire si vrai do X
sinon STOP.
Donc jamais plusieures itérations.
cargo clippy
Ne pas faire de variables globales pour tout.
Utiliser des structures, passer par références les structures. :)
Pourrais-je avoir un exemple d'une maniere de faire permettant d'incrementer les valeurs de certaines variables de maniere globale svp car c est pour ca que j'ai utilise des unsafe.
Quand on fait un jeu on aime eviter de melanger le code de dessin du code d'update et d'input pour des raisons de performance.... Et de bugs ultra-subtiles bien relou ;)
Dans le cas des Polygons et players j'aurais fait une seule struct au fond.
dans ce cas la un format!
aurais été préférable: to_owned()
c'est vraiment vieux et pas utile souvent.
let text2: &str = &("Votre Score est de: ".to_owned() + &SCORE.to_string());
Comment fait-on pour avoir clippy? Etant donne que je n'ai eu aucune de ces suggestions
Pour exclu générer les carré a afficher aurais été moins tordu.
par ex: on fait un [175., 265., 355.0, 445.0, 535., 625.].zip((1..=6)).iter().filter(|(_, num)| RANDOM_NUM != num)
et hop on sais quels carrrés afficher et ou.
J'ai utilise un while juste pour pouvoir relire plus facilement mon code si je peux dire ca comme ca
while JOUEUR_X < 670.0 {
if is_key_down(Right) {
JOUEUR_X += 5.0;
}
break
}
}
C'est pas une boucle ça... Au mieux un if déguisé non?
Alors maintenant le fond: Pourquoi tout ce unsafe
? C'est pas neccessaire, sans parler d'objet, on peeut faire un jeu sans faire un gloubiboulga d'unsafe.
Tu peux allouer au début du jeu et jamais réalouer, tout faire dans la pile si le jeu est petit bref pleins de solutions. Voir utiliser une Arena/allocationPool.
Mais pourquoi sortir unsafe
? On s'ennuie en rust a garantir la safety memoire.
Unsafe existe QUE pour faire des abstractions pas pour coder dans la vie de tout les jours pour "coder-crado-viteuf" ;)
Ok ça demande de passer des structs, s'organiser, etc
Clippy qui fait de l'analyse statique lègère dit des trucs interresant comme: t'aurais pu utiliser des ranges, qye des boucles sont pas des boucles etc.
warning: manual `RangeInclusive::contains` implementation
--> src/affichage.rs:58:12
|
58 | if SCORE >= 0 && SCORE <= 15 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `(0..=15).contains(&SCORE)`
|
= note: `#[warn(clippy::manual_range_contains)]` on by default
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_range_contains
warning: manual `RangeInclusive::contains` implementation
--> src/affichage.rs:60:19
|
60 | } else if SCORE >= 15 && SCORE <= 30 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `(15..=30).contains(&SCORE)`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_range_contains
warning: manual `RangeInclusive::contains` implementation
--> src/affichage.rs:62:19
|
62 | } else if SCORE >= 30 && SCORE <= 50 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `(30..=50).contains(&SCORE)`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_range_contains
warning: manual `RangeInclusive::contains` implementation
--> src/affichage.rs:64:19
|
64 | } else if SCORE >= 50 && SCORE <= 80 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `(50..=80).contains(&SCORE)`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_range_contains
warning: manual `RangeInclusive::contains` implementation
--> src/affichage.rs:66:19
|
66 | } else if SCORE >= 80 && SCORE <= 120 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `(80..=120).contains(&SCORE)`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_range_contains
warning: manual `RangeInclusive::contains` implementation
--> src/affichage.rs:69:17
|
69 | else if SCORE >= 120 && SCORE <= 150 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `(120..=150).contains(&SCORE)`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_range_contains
error: this loop never actually loops
--> src/collisions.rs:36:13
|
36 | / while JOUEUR_X > 130.0 {
37 | | if is_key_down(Left) {
38 | | //incrementate l'axe X du joueur
39 | | JOUEUR_X -= 5.0;
40 | | }
41 | | break
42 | | }
| |_____________^
|
= note: `#[deny(clippy::never_loop)]` on by default
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#never_loop
error: this loop never actually loops
--> src/collisions.rs:43:13
|
43 | / while JOUEUR_X < 670.0 {
44 | | if is_key_down(Right) {
45 | | JOUEUR_X += 5.0;
46 | | }
47 | | break
48 | | }
| |_____________^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#never_loop
error: this loop never actually loops
--> src/collisions.rs:52:13
|
52 | / while JOUEUR_X > 130.0 {
53 | | if is_key_down(Right) {
54 | | //incrementate l'axe X du joueur
55 | | JOUEUR_X -= 5.0;
56 | | }
57 | | break
58 | | }
| |_____________^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#never_loop
error: this loop never actually loops
--> src/collisions.rs:59:13
|
59 | / while JOUEUR_X < 670.0 {
60 | | if is_key_down(Left) {
61 | | JOUEUR_X += 5.0;
62 | | }
63 | | break
64 | | }
| |_____________^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#never_loop
error: this loop never actually loops
--> src/collisions.rs:99:9
|
99 | / while (FALL + 44.5) >= joueur.p1.y && (FALL - 44.5) <= joueur.p2.y {
100 | | if joueur.p1 <= carre.p3 && joueur.p3 >= carre.p1 {
101 | | GAME_OVER = true;
102 | | }
103 | | break
104 | | }
| |_________^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#never_loop
error: this loop never actually loops
--> src/collisions.rs:125:9
|
125 | / while (FALL + 10.0) <= joueur.p1.y {
126 | | draw_circle(x, FALL, 10.0, GREEN);
127 | | break
128 | | }
| |_________^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#never_loop
warning: crate `DodgetheWall` should have a snake case name
|
= note: `#[warn(non_snake_case)]` on by default
= help: convert the identifier to snake case: `dodgethe_wall`
warning: `DodgetheWall` (bin "DodgetheWall") generated 22 warnings
error: could not compile `DodgetheWall` due to 6 previous errors; 22 warnings emitted
Un projet ça se range, comme un espace de travail, les warnings sont pas la pour vous ennuyer! 16 warnings quand même... Et je demande pas de les silencier mais de résoudre! X)
cargo build
warning: unused imports: `draw_circle`, `draw_poly`
--> src/affichage.rs:1:25
|
1 | use macroquad::shapes::{draw_circle,draw_poly,draw_rectangle};
| ^^^^^^^^^^^ ^^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
warning: unnecessary parentheses around function argument
--> src/affichage.rs:151:26
|
151 | ... draw_text(text1, (screen_width() / 2.0 - taille_texte1.width / 2.0), (screen_height() / 2.0 - taille_texte1.height / 2.0), 100.0, R...
| ^ ^
|
= note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
|
151 - draw_text(text1, (screen_width() / 2.0 - taille_texte1.width / 2.0), (screen_height() / 2.0 - taille_texte1.height / 2.0), 100.0, RED);
151 + draw_text(text1, screen_width() / 2.0 - taille_texte1.width / 2.0, (screen_height() / 2.0 - taille_texte1.height / 2.0), 100.0, RED);
|
warning: unnecessary parentheses around function argument
--> src/affichage.rs:151:78
|
151 | ... draw_text(text1, (screen_width() / 2.0 - taille_texte1.width / 2.0), (screen_height() / 2.0 - taille_texte1.height / 2.0), 100.0, R...
| ^ ^
|
help: remove these parentheses
|
151 - draw_text(text1, (screen_width() / 2.0 - taille_texte1.width / 2.0), (screen_height() / 2.0 - taille_texte1.height / 2.0), 100.0, RED);
151 + draw_text(text1, (screen_width() / 2.0 - taille_texte1.width / 2.0), screen_height() / 2.0 - taille_texte1.height / 2.0, 100.0, RED);
|
warning: unnecessary parentheses around function argument
--> src/affichage.rs:152:26
|
152 | ... draw_text(text2, (screen_width() / 2.0 - taille_texte2.width / 2.0), (screen_height() / 2.0 - taille_texte2.height / 2.0)+40.0, 30....
| ^ ^
|
help: remove these parentheses
|
152 - draw_text(text2, (screen_width() / 2.0 - taille_texte2.width / 2.0), (screen_height() / 2.0 - taille_texte2.height / 2.0)+40.0, 30.0, DARKGRAY);
152 + draw_text(text2, screen_width() / 2.0 - taille_texte2.width / 2.0, (screen_height() / 2.0 - taille_texte2.height / 2.0)+40.0, 30.0, DARKGRAY);
|
warning: unnecessary parentheses around function argument
--> src/affichage.rs:153:26
|
153 | ... draw_text(text3, (screen_width() / 2.0 - taille_texte3.width / 2.0), (screen_height() / 2.0 - taille_texte3.height / 2.0)+80.0, 30....
| ^ ^
|
help: remove these parentheses
|
153 - draw_text(text3, (screen_width() / 2.0 - taille_texte3.width / 2.0), (screen_height() / 2.0 - taille_texte3.height / 2.0)+80.0, 30.0, DARKGRAY);
153 + draw_text(text3, screen_width() / 2.0 - taille_texte3.width / 2.0, (screen_height() / 2.0 - taille_texte3.height / 2.0)+80.0, 30.0, DARKGRAY);
|
warning: unused import: `RED`
--> src/collisions.rs:2:51
|
2 | use macroquad::color::{DARKPURPLE, YELLOW, Color, RED, GREEN};
| ^^^
warning: unused import: `macroquad::prelude::load_image`
--> src/main.rs:6:5
|
6 | use macroquad::prelude::load_image;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: unused imports: `draw_texture`, `load_texture`
--> src/main.rs:11:26
|
11 | use macroquad::texture::{draw_texture,load_texture};
| ^^^^^^^^^^^^ ^^^^^^^^^^^^
warning: unused import: `macroquad::color::RED`
--> src/main.rs:12:5
|
12 | use macroquad::color::RED;
| ^^^^^^^^^^^^^^^^^^^^^
warning: unused import: `crate::collisions::FALL`
--> src/main.rs:13:5
|
13 | use crate::collisions::FALL;
| ^^^^^^^^^^^^^^^^^^^^^^^
warning: unused import: `inversion`
--> src/main.rs:15:38
|
15 | use crate::collisions::{deplacement, inversion};
| ^^^^^^^^^
warning: unused variable: `inversion`
--> src/collisions.rs:117:13
|
117 | let inversion = Polygon {
| ^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_inversion`
|
= note: `#[warn(unused_variables)]` on by default
warning: field is never read: `p2`
--> src/collisions.rs:20:5
|
20 | p2:Vec2,
| ^^^^^^^
|
= note: `#[warn(dead_code)]` on by default
warning: field is never read: `p4`
--> src/collisions.rs:22:5
|
22 | p4:Vec2,
| ^^^^^^^
warning: field is never read: `p4`
--> src/collisions.rs:29:5
|
29 | p4:Vec2,
| ^^^^^^^
warning: crate `DodgetheWall` should have a snake case name
|
= note: `#[warn(non_snake_case)]` on by default
= help: convert the identifier to snake case: `dodgethe_wall`
warning: `DodgetheWall` (bin "DodgetheWall") generated 16 warnings
Finished dev [unoptimized + debuginfo] target(s) in 0.04s
Malik Rayane (b3f7882d) at 11 Jan 00:04
Malik Rayane (b3f7882d) at 11 Jan 00:04
pouvoir d inversion