Skip to content

Commit 3192a18

Browse files
author
Artur Ostręga
committed
Update example
1 parent 74b8859 commit 3192a18

File tree

4 files changed

+25
-11
lines changed

4 files changed

+25
-11
lines changed

example/src/game.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'spaces/world' #
22

3-
class Example < Yeah::Game
4-
#class Example < Game
3+
class Game < Yeah::Game
4+
self.title = "Example Game"
55
display.size = 640, 360
66
self.space = World
77
end

example/src/spaces/world.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
class World < Yeah::Space #
55
#class World < Space
66
self.size = 640, 360
7-
self.clear_color = 0.5, 0.7, 0.5
7+
self.color = 0.5, 0.7, 0.5
88

9-
def initialize
9+
def initialize(game)
1010
super
1111

12-
things << Cloud.new(x: width * 0.6, y: height * 0.8)
13-
things << Cloud.new(x: width * 0.2, y: height * 0.7)
14-
things << Cloud.new(x: width * 0.1, y: height * 0.9)
15-
things << Duck.new(x: 10, y: 10)
12+
things << Cloud.new(game: game, x: width * 0.6, y: height * 0.8)
13+
things << Cloud.new(game: game, x: width * 0.2, y: height * 0.7)
14+
things << Cloud.new(game: game, x: width * 0.1, y: height * 0.9)
15+
things << Duck.new(game: game, x: 10, y: 10)
1616
#things << Duck.new(position: Vec2.divide(size, 2))
1717
end
1818
end

example/src/things/cloud.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class Cloud < Yeah::Thing #
44
#class Cloud < Thing
55
self.look = CloudLook #
66

7-
def act(input, space, elapsed)
7+
def act(elapsed)
88
self.x -= 10 * elapsed
99
end
1010
end

example/src/things/duck.rb

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,21 @@ class Duck < Yeah::Thing #
55
#class Duck < Thing
66
self.look = DuckLook #
77

8-
def act(input, space, elapsed)
9-
self.x += 30 * elapsed
8+
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+
17+
if keyboard.released? :space
18+
puts "Quack!"
19+
end
20+
end
21+
22+
def speed
23+
30
1024
end
1125
end

0 commit comments

Comments
 (0)