Skip to content

Commit 4e5e36a

Browse files
Add clouds
1 parent d295464 commit 4e5e36a

File tree

7 files changed

+200
-103
lines changed

7 files changed

+200
-103
lines changed

resources/images/Some(cloud).png

21.8 KB
Loading

src/components/barrel.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
use ggez::{Context, GameResult, graphics::Image};
2-
use ggez_goodies::{camera::{Camera, CameraDraw}, nalgebra_glm::Vec2};
1+
use ggez::{graphics::Image, Context, GameResult};
2+
use ggez_goodies::{
3+
camera::{Camera, CameraDraw},
4+
nalgebra_glm::Vec2,
5+
};
36

47
use crate::HEIGHT;
58

69
pub struct Barrel {
7-
pub pos_x: f32
10+
pub pos_x: f32,
811
}
912

1013
impl Barrel {
1114
pub fn new(pos_x: f32) -> Self {
12-
Self {
13-
pos_x
14-
}
15+
Self { pos_x }
1516
}
1617

1718
pub fn draw(
@@ -22,14 +23,13 @@ impl Barrel {
2223
) -> GameResult<()> {
2324
const HEIGHT2: f32 = HEIGHT / 2.;
2425

25-
2626
&resources[0].draw_camera(
2727
camera,
2828
ctx,
2929
Vec2::new(self.pos_x, -HEIGHT2 + (resources[0].height() + 40) as f32),
30-
0.
30+
0.,
3131
);
32-
32+
3333
Ok(())
3434
}
35-
}
35+
}

src/components/bullet.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,32 @@
1-
use ggez::{Context, GameResult, graphics::Image};
2-
use ggez_goodies::{camera::{Camera, CameraDraw}, nalgebra_glm::Vec2};
1+
use ggez::{graphics::Image, Context, GameResult};
2+
use ggez_goodies::{
3+
camera::{Camera, CameraDraw},
4+
nalgebra_glm::Vec2,
5+
};
36

47
pub struct Turbofish {
58
pub pos_x: f32,
69
pub pos_y: f32,
710

8-
traveled_count: i32
11+
traveled_count: i32,
912
}
1013

1114
impl Turbofish {
1215
pub fn new(pos_x: f32, pos_y: f32) -> Self {
1316
Self {
1417
pos_x,
1518
pos_y,
16-
traveled_count: 0
19+
traveled_count: 0,
1720
}
1821
}
1922

20-
pub fn draw(&mut self, ctx: &mut Context, camera: &Camera, resources: &Vec<Image>) -> GameResult<()> {
21-
&resources[0].draw_camera(
22-
camera,
23-
ctx,
24-
Vec2::new(self.pos_x, self.pos_y),
25-
1.5708
26-
);
23+
pub fn draw(
24+
&mut self,
25+
ctx: &mut Context,
26+
camera: &Camera,
27+
resources: &Vec<Image>,
28+
) -> GameResult<()> {
29+
&resources[0].draw_camera(camera, ctx, Vec2::new(self.pos_x, self.pos_y), 1.5708);
2730

2831
Ok(())
2932
}
@@ -34,10 +37,8 @@ impl Turbofish {
3437
self.pos_x += 10.;
3538

3639
false
37-
}
38-
39-
else {
40+
} else {
4041
true
4142
}
4243
}
43-
}
44+
}

src/components/cloud.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
use ggez::{
2+
graphics::{self, Image},
3+
mint::{Point2, Vector2},
4+
Context, GameResult,
5+
};
6+
use graphics::DrawParam;
7+
8+
use crate::WIDTH;
9+
10+
pub struct Cloud {
11+
pos_x: f32,
12+
pos_y: f32,
13+
scale: f32,
14+
speed: f32,
15+
}
16+
17+
impl Cloud {
18+
pub fn new(pos_x: f32, pos_y: f32, scale: f32, speed: f32) -> Self {
19+
Self {
20+
pos_x,
21+
pos_y,
22+
scale,
23+
speed
24+
}
25+
}
26+
27+
pub fn draw(&mut self, ctx: &mut Context, resources: &Vec<Image>) -> GameResult<()> {
28+
graphics::draw(
29+
ctx,
30+
&resources[0],
31+
DrawParam::default()
32+
.scale(Vector2 {
33+
x: self.scale,
34+
y: self.scale,
35+
})
36+
.dest(Point2 {
37+
x: self.pos_x,
38+
y: self.pos_y,
39+
}),
40+
)?;
41+
42+
Ok(())
43+
}
44+
45+
pub fn update(&mut self, ctx: &mut Context) {
46+
let delta_time = ggez::timer::delta(ctx).as_secs_f32();
47+
48+
self.pos_x += delta_time * self.speed;
49+
50+
if self.pos_x > WIDTH + 100. {
51+
self.pos_x = -100.;
52+
}
53+
}
54+
}

src/components/player.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@ impl Player {
6363
pub fn update(&mut self, gonna_boom: bool) {
6464
if self.going_boom {
6565
self.pos_y -= self.velocity;
66-
66+
6767
if self.pos_y < 0. {
6868
self.going_boom = false;
69-
69+
7070
self.pos_y = 0.;
7171
self.velocity = 0.;
7272
}
7373
}
74-
74+
7575
if self.pos_y > 0. || gonna_boom {
7676
self.velocity += self.gravity;
7777
self.pos_y -= self.velocity;
@@ -84,10 +84,11 @@ impl Player {
8484
if self.ammo != 0 {
8585
self.ammo -= 1;
8686

87-
return Some(Turbofish::new(self.pos_x + 220., (-HEIGHT2 + 106.) + self.pos_y));
88-
}
89-
90-
else {
87+
return Some(Turbofish::new(
88+
self.pos_x + 220.,
89+
(-HEIGHT2 + 106.) + self.pos_y,
90+
));
91+
} else {
9192
None
9293
}
9394
}

0 commit comments

Comments
 (0)