File tree Expand file tree Collapse file tree 6 files changed +86
-9
lines changed
Expand file tree Collapse file tree 6 files changed +86
-9
lines changed Original file line number Diff line number Diff line change 1+ require 'yeah/sprite_look' #
2+
3+ class GuyLook < Yeah ::SpriteLook #
4+ #class GuyLook < ImageLook
5+ self . image = "guy.png" #
6+ self . size = 64 , 64
7+
8+ self . animations = {
9+ walk_up : ( 0 ..8 ) ,
10+ walk_left : ( 9 ..17 ) ,
11+ walk_down : ( 18 ..26 ) ,
12+ walk_right : { frames : ( 27 ..35 ) , mirror_x : false } ,
13+ stand_up : 0 ,
14+ stand_left : 9 ,
15+ stand_down : 18 ,
16+ stand_right : 27
17+ }
18+ end
Original file line number Diff line number Diff line change 1- require 'things/duck' #
21require 'things/cloud' #
2+ require 'things/duck' #
3+ require 'things/guy' #
34
45class World < Yeah ::Space #
56#class World < Space
67 self . size = 640 , 360
78 self . color = 0.5 , 0.7 , 0.5
89
10+ self . things = {
11+ Cloud => [
12+ -> { [ width * 0.6 , height * 0.8 ] } ,
13+ -> { [ width * 0.2 , height * 0.7 ] } ,
14+ -> { [ width * 0.1 , height * 0.9 ] }
15+ ] ,
16+
17+ Duck => [
18+ [ 10 , 10 ]
19+ ] ,
20+
21+ Guy => [
22+ -> { [ width * 0.8 , height * 0.8 ] }
23+ ]
24+ }
25+
926 def initialize ( game )
1027 super
1128
1229 things << Cloud . new ( game , x : width * 0.6 , y : height * 0.8 )
1330 things << Cloud . new ( game , x : width * 0.2 , y : height * 0.7 )
1431 things << Cloud . new ( game , x : width * 0.1 , y : height * 0.9 )
1532 things << Duck . new ( game , x : 10 , y : 10 )
33+ things << Guy . new ( game , x : width * 0.8 , y : height * 0.8 )
1634 #things << Duck.new(game, position: Vec2.divide(size, 2))
1735 end
1836end
Original file line number Diff line number Diff line change 1+ require 'yeah/thing' #
12require 'looks/cloud_look' #
23
34class Cloud < Yeah ::Thing #
Original file line number Diff line number Diff line change @@ -6,14 +6,6 @@ class Duck < Yeah::Thing #
66 self . look = DuckLook #
77
88 def act ( elapsed )
9- if keyboard . pressing? :left
10- self . x -= speed * elapsed
11- end
12-
13- if keyboard . pressing? :right
14- self . x += speed * elapsed
15- end
16-
179 if keyboard . released? :space
1810 puts "Quack!"
1911 space . color = rand , rand , rand
@@ -28,6 +20,8 @@ def act(elapsed)
2820 display . width += 10
2921 display . height += 10
3022 end
23+
24+ self . x += speed * elapsed
3125 end
3226
3327 def speed
Original file line number Diff line number Diff line change 1+ require 'yeah/thing' #
2+ require 'looks/guy_look' #
3+
4+ class Guy < Yeah ::Thing
5+ #class Guy < Thing
6+ self . look = GuyLook #
7+
8+ def act ( elapsed )
9+ walked = false
10+
11+ if keyboard . pressing? :left
12+ look . animation = :walk_left
13+ self . x -= speed * elapsed
14+ walked = true
15+ end
16+
17+ if keyboard . pressing? :right
18+ look . animation = :walk_right
19+ self . x += speed * elapsed
20+ walked = true
21+ end
22+
23+ if keyboard . pressing? :down
24+ look . animation = :walk_down
25+ self . y -= speed * elapsed
26+ walked = true
27+ end
28+
29+ if keyboard . pressing? :up
30+ look . animation = :walk_up
31+ self . y += speed * elapsed
32+ walked = true
33+ end
34+
35+ unless walked
36+ look . animation = :stand_left if keyboard . released? :left
37+ look . animation = :stand_right if keyboard . released? :right
38+ look . animation = :stand_down if keyboard . released? :down
39+ look . animation = :stand_up if keyboard . released? :up
40+ end
41+ end
42+
43+ def speed
44+ 50
45+ end
46+ end
You can’t perform that action at this time.
0 commit comments