Add different color stars.

This commit is contained in:
Thomas Gideon 2017-08-08 14:02:57 -04:00
parent c507233bf4
commit f4dd516208
7 changed files with 109 additions and 17 deletions

BIN
assets/blue_star.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

BIN
assets/green_star.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View file

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View file

@ -15,8 +15,8 @@
version="1.1"
id="svg8"
inkscape:version="0.92.1 r15371"
sodipodi:docname="star_template.svg"
inkscape:export-filename="/home/cmdln/src/git/susuwatari-game/assets/star.png"
sodipodi:docname="star.svg"
inkscape:export-filename="/home/cmdln/src/git/susuwatari-game/assets/green_star.png"
inkscape:export-xdpi="9.6000004"
inkscape:export-ydpi="9.6000004">
<defs
@ -29,14 +29,14 @@
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="0.35"
inkscape:cx="184.19191"
inkscape:cx="-438.66523"
inkscape:cy="182.82758"
inkscape:document-units="mm"
inkscape:current-layer="layer1"
inkscape:current-layer="g8425"
showgrid="false"
inkscape:window-width="1920"
inkscape:window-height="1025"
inkscape:window-x="0"
inkscape:window-height="1051"
inkscape:window-x="1920"
inkscape:window-y="0"
inkscape:window-maximized="1"
units="px" />
@ -48,21 +48,22 @@
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
<dc:title />
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:label="Pink Star"
inkscape:groupmode="layer"
id="layer1"
transform="translate(-13.253985,-58.111215)">
transform="translate(-13.253985,-58.111215)"
style="display:none">
<path
sodipodi:type="star"
style="opacity:0.75499998;fill:#ffaacc;fill-opacity:1;stroke:none;stroke-width:0.60730559;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path8417"
sodipodi:sides="5"
sodipodi:cx="99.326875"
sodipodi:cx="99.326874"
sodipodi:cy="153.95569"
sodipodi:r1="86.412148"
sodipodi:r2="51.019348"
@ -77,4 +78,82 @@
inkscape:export-xdpi="96"
inkscape:export-ydpi="96" />
</g>
<g
transform="translate(-13.253985,-58.111215)"
id="g8417"
inkscape:groupmode="layer"
inkscape:label="Blue Star"
style="display:none">
<path
inkscape:export-ydpi="96"
inkscape:export-xdpi="96"
inkscape:transform-center-y="-8.0016296"
inkscape:transform-center-x="0.2624264"
d="m 150.80325,223.36204 -50.974975,-18.38947 -50.603689,19.38781 1.737289,-54.16275 -34.076296,-42.1358 52.04868,-15.08495 29.543381,-45.429166 30.43056,44.839736 52.33511,14.05904 -33.24155,42.79742 z"
inkscape:randomized="0"
inkscape:rounded="0"
inkscape:flatsided="false"
sodipodi:arg2="1.5609685"
sodipodi:arg1="0.93264992"
sodipodi:r2="51.019348"
sodipodi:r1="86.412148"
sodipodi:cy="153.95569"
sodipodi:cx="99.326874"
sodipodi:sides="5"
id="path8415"
style="opacity:0.75499998;fill:#00ccff;fill-opacity:1;stroke:none;stroke-width:0.60730559;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
sodipodi:type="star" />
</g>
<g
inkscape:label="Green Star"
inkscape:groupmode="layer"
id="g8421"
transform="translate(-13.253985,-58.111215)"
style="display:inline">
<path
sodipodi:type="star"
style="opacity:0.75499998;fill:#00ff66;fill-opacity:1;stroke:none;stroke-width:0.60730559;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path8419"
sodipodi:sides="5"
sodipodi:cx="99.326874"
sodipodi:cy="153.95569"
sodipodi:r1="86.412148"
sodipodi:r2="51.019348"
sodipodi:arg1="0.93264992"
sodipodi:arg2="1.5609685"
inkscape:flatsided="false"
inkscape:rounded="0"
inkscape:randomized="0"
d="m 150.80325,223.36204 -50.974975,-18.38947 -50.603689,19.38781 1.737289,-54.16275 -34.076296,-42.1358 52.04868,-15.08495 29.543381,-45.429166 30.43056,44.839736 52.33511,14.05904 -33.24155,42.79742 z"
inkscape:transform-center-x="0.2624264"
inkscape:transform-center-y="-8.0016296"
inkscape:export-xdpi="96"
inkscape:export-ydpi="96" />
</g>
<g
transform="translate(-13.253985,-58.111215)"
id="g8425"
inkscape:groupmode="layer"
inkscape:label="Yellow Star"
style="display:none">
<path
inkscape:export-ydpi="96"
inkscape:export-xdpi="96"
inkscape:transform-center-y="-8.0016296"
inkscape:transform-center-x="0.2624264"
d="m 150.80325,223.36204 -50.974975,-18.38947 -50.603689,19.38781 1.737289,-54.16275 -34.076296,-42.1358 52.04868,-15.08495 29.543381,-45.429166 30.43056,44.839736 52.33511,14.05904 -33.24155,42.79742 z"
inkscape:randomized="0"
inkscape:rounded="0"
inkscape:flatsided="false"
sodipodi:arg2="1.5609685"
sodipodi:arg1="0.93264992"
sodipodi:r2="51.019348"
sodipodi:r1="86.412148"
sodipodi:cy="153.95569"
sodipodi:cx="99.326874"
sodipodi:sides="5"
id="path8423"
style="opacity:0.75499998;fill:#ffcc00;fill-opacity:1;stroke:none;stroke-width:0.60730559;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
sodipodi:type="star" />
</g>
</svg>

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 6 KiB

BIN
assets/yellow_star.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View file

@ -34,8 +34,14 @@ impl Game {
pub fn new(w: &mut PistonWindow) -> Game {
let mut scene = Scene::new();
let mut stars: Vec<Star> = vec![];
for _ in 1..7 {
stars.push(Star::new(w, &mut scene));
for number in 1..7 {
let color = match number % 4 {
1 => "yellow",
2 => "green",
3 => "blue",
_ => "pink",
};
stars.push(Star::new(color, w, &mut scene));
}
let player = Hero::new(w, &mut scene);
Game {

View file

@ -19,23 +19,23 @@ pub struct Star {
dir: u32,
pub collider: Cuboid2<f64>,
pub destroyed: bool,
accel: f64,
}
const DESIGNED_FOR_WIDTH: f64 = 640.0;
const SCALE_FACTOR: f64 = 0.5;
const ACCEL: f64 = 2.0;
const MOVE_DUR: f64 = 0.75;
const DESTROY_DUR: f64 = 0.75;
impl Star {
pub fn new(w: &mut PistonWindow, scene: &mut Scene<Texture<Resources>>) -> Star {
pub fn new(color: &str, w: &mut PistonWindow, scene: &mut Scene<Texture<Resources>>) -> Star {
let assets = find_folder::Search::ParentsThenKids(3, 3)
.for_folder("assets")
.unwrap();
let tex = Rc::new(Texture::from_path(&mut w.factory,
assets.join("star.png"),
assets.join(format!("{}_star.png", color)),
Flip::None,
&TextureSettings::new())
.unwrap());
@ -43,6 +43,12 @@ impl Star {
let x = rand_pos(width as f64);
let y = rand_pos(height as f64);
let scale = width as f64 / DESIGNED_FOR_WIDTH * SCALE_FACTOR;
let accel = match color {
"yellow" => 3.0,
"blue" => 1.0,
"green" => 2.0,
_ => 2.0,
};
let mut sprite = Sprite::from_texture(tex);
sprite.set_scale(scale, scale);
sprite.set_position(x, y);
@ -57,6 +63,7 @@ impl Star {
dir: rand_dir(),
collider: Cuboid2::new(Vector2::new(bounds[2], bounds[3])),
destroyed: false,
accel: accel,
}
}
@ -81,8 +88,8 @@ impl Star {
}
self.dir = rand_turn(self.dir);
let dir = lookup_dir(self.dir);
let mov_x = ACCEL * dir.0;
let mov_y = ACCEL * dir.1;
let mov_x = self.accel * dir.0;
let mov_y = self.accel * dir.1;
scene.run(self.sprite_id,
&Action(Ease(EaseFunction::CubicOut,
Box::new(MoveBy(dt * MOVE_DUR, mov_x, mov_y)))));