Last active
December 11, 2015 03:38
-
-
Save ashbb/4538782 to your computer and use it in GitHub Desktop.
Shoes 4 Ski Jumping Game. Inspired by [Sebastjan's post](http://librelist.com/browser//shoes/2013/1/13/thank-you/) in Shoes ML. But, this is not a game, just a tiny example to learn Shoes 4. ;-)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Skier | |
def initialize app | |
app.strokewidth 2 | |
@x0, @y0 = 0, 20 | |
@img1 = app.oval @x0 + 25, @y0 - 20, 5, 5 | |
@img2 = app.line @x0 + 5, @y0, @x0 + 25, @y0 - 15 | |
@img3 = app.line @x0 + 5, @y0 - 13, @x0 + 20, @y0 - 15 | |
@img4 = app.line @x0, @y0, @x0 + 30, @y0 | |
@img5 = app.line @x0, @y0, @x0 + 30, @y0 - 10 | |
@img5.hide | |
end | |
def move x, y | |
@img1.move @x0 + x + 25, @y0 + y - 20 | |
@img2.move @x0 + x + 5, @y0 + y - 15 | |
@img3.move @x0 + x + 5, @y0 + y - 13 | |
@img4.move @x0 + x, @y0 + y | |
@img5.move @x0 + x, @y0 + y - 10 | |
end | |
def change_ski_angle | |
[@img4, @img5].each &:toggle | |
end | |
end | |
Shoes.app width: 600, height: 400 do | |
back = image File.join(File.dirname(__FILE__), 'back_image.png') | |
s = Skier.new self | |
a = animate 5 do |t| | |
v = 0.2*t**2 | |
x = v * Math.cos(Math::PI*0.2) | |
y = v * Math.sin(Math::PI*0.2) | |
t < 40 ? s.move(x, y) : (back.move(40 - t*4, -t); @air = true) | |
a.stop if t > 80 | |
end | |
keypress do |k| | |
s.change_ski_angle if @air and k == " " | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Inspired by Sebastjan's post in Shoes ML. Download back_image.png and run with Shoes 4.
Watch a demo.