yeah 0.2.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +1 -1
  3. data/README.md +52 -20
  4. data/bin/yeah +30 -0
  5. data/lib/yeah.rb +6 -9
  6. data/lib/yeah/_platform/asset.rb +24 -0
  7. data/lib/yeah/_platform/display.rb +181 -0
  8. data/lib/yeah/_platform/image.rb +16 -0
  9. data/lib/yeah/_platform/keyboard.rb +37 -0
  10. data/lib/yeah/_platform/mouse.rb +30 -0
  11. data/lib/yeah/_platform/sound.rb +15 -0
  12. data/lib/yeah/_platform/ticker.rb +21 -0
  13. data/lib/yeah/_template/Gemfile +4 -0
  14. data/lib/yeah/_template/code/code.rb +4 -0
  15. data/lib/yeah/_template/code/game.rb +7 -0
  16. data/lib/yeah/_web.rb +9 -0
  17. data/lib/yeah/color.rb +45 -13
  18. data/lib/yeah/constants.rb +6 -0
  19. data/lib/yeah/game.rb +89 -41
  20. data/lib/yeah/vector.rb +122 -99
  21. data/lib/yeah/version.rb +3 -0
  22. data/lib/yeah/web/dependencies.rb +2 -0
  23. data/lib/yeah/web/runner.html.erb +61 -0
  24. data/lib/yeah/web/server.rb +60 -0
  25. data/lib/yeah/web/setup.rb +5 -0
  26. data/lib/yeah/web/start.rb +1 -0
  27. data/opal/yeah/web.rb +8 -0
  28. data/opal/yeah/web/asset.opal +38 -0
  29. data/opal/yeah/web/constants.opal +5 -0
  30. data/opal/yeah/web/display.opal +244 -0
  31. data/opal/yeah/web/image.opal +23 -0
  32. data/opal/yeah/web/keyboard.opal +139 -0
  33. data/opal/yeah/web/mouse.opal +58 -0
  34. data/opal/yeah/web/sound.opal +19 -0
  35. data/opal/yeah/web/ticker.opal +39 -0
  36. metadata +111 -19
  37. data/CHANGELOG.md +0 -28
  38. data/lib/monkey/numeric.rb +0 -6
  39. data/lib/yeah/basic_physics.rb +0 -11
  40. data/lib/yeah/desktop.rb +0 -72
  41. data/lib/yeah/entity.rb +0 -137
  42. data/lib/yeah/map.rb +0 -40
  43. data/lib/yeah/rectangle.rb +0 -21
  44. data/lib/yeah/surface.rb +0 -66
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3ca889c593c853c056b2945402f87240a708abc3
4
- data.tar.gz: 1a215b41c68cf68ff4ead5d5a77589dcfc2f92c4
3
+ metadata.gz: 9db2fc8ff3354619333aa00a484931deae0ac046
4
+ data.tar.gz: 2a63e5a1070e65dbc01b6a201e9b40b4d6ec38f4
5
5
  SHA512:
6
- metadata.gz: c4d99208cb6cbd3f8e86b37f4dcb0b7492233d4a3879cf1cd00fca8662306bcf5c4302c8a9c877c56cf7b81dd89b300f59b57343fb50f1d9fa8c2f9442c7ee83
7
- data.tar.gz: 172905029424fa4dbad2bd7b9db2b892a4f963a14c9d72ddc4645506124996ee46c4ce96d84bb7ec1fe4b38a7674bfddfcf77e7bbf4d0864d60f3eb943979c2e
6
+ metadata.gz: 5e96c8e05061378a88ac5f87ced6d1b3cc46d1e6bf02735b160a46024b3ff004f1022fb4f50e55a80b2f3b64a64890c8490c2dea444ddb913c47c642033d3beb
7
+ data.tar.gz: 174bacd2f5af289ad36e34e8bacb399df47f3ad4e83992af01882b4e6e8de420ca28c7de8899a2ce844b00d1938bede3af3c393b669bc47bd6078f6ae8f09e19
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013 Artur Ostrega
1
+ Copyright (c) 2013 - 2014 Artur Ostrega
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
4
 
data/README.md CHANGED
@@ -1,20 +1,52 @@
1
- Yeah
2
- ====
3
- An early-stage Ruby video game framework that optimizes for development efficiency.
4
-
5
- It is in very early stages, but at version 0.3.0 the Vyzer demo should be functional. Any version below 1.0.0 is unstable and lacks backward compatibility.
6
-
7
- Planned features
8
- ----------------
9
- * An opinionated, modular API that makes common tasks easy and everything else possible.
10
- * Command line initialization script to help one hit the ground running.
11
- * Graphical tools for creating video game resources like sprites and maps.
12
- * Multiple target platforms, starting with desktop and web.
13
-
14
- Installation
15
- ------------
16
- Install with `gem install yeah`. Yeah depends on Rubygame, which depends on SDL; see [these guides](https://github.com/rubygame/rubygame/wiki/Install).
17
-
18
- Blog
19
- ----
20
- [Why am I making Yeah?](http://skofo.github.io/blog/why-am-i-making-yeah)
1
+ # Yeah
2
+
3
+ Practical Ruby video game framework, alpha stage
4
+
5
+
6
+ ## Features
7
+
8
+ * Designed to be easy to learn and fast to build games with
9
+ * Embraces Ruby's strengths (object-orientation, duck typing, focus on developer happiness)
10
+ * Platform-agnostic (currently compiles to web pages through [Opal](http://opalrb.org); PC executables and mobile apps planned)
11
+ * Convention (over configuration)-oriented
12
+ * Processing/HTML5 Canvas-style drawing API
13
+ * Command-line utilities (no monolithic IDE)
14
+ * Open source under MIT license
15
+
16
+
17
+ ## Examples
18
+
19
+ [![Asteroids](https://cdn.mediacru.sh/IkYZP46TmCsd.png)](https://yeahrb.github.io/yeah/examples/asteroids/runner.html)
20
+
21
+ [*Asteroids*](https://yeahrb.github.io/yeah/examples/asteroids/runner.html)
22
+ [(code)](https://github.com/yeahrb/yeah/tree/examples/examples/asteroids)
23
+
24
+ [![Random](https://cdn.mediacru.sh/KW9M6TndLry0.png)](https://yeahrb.github.io/yeah/examples/random/runner.html)
25
+
26
+ [*Random*](https://cdn.mediacru.sh/ZpyKf2TtdLqJ.png)
27
+ [(code)](https://github.com/yeahrb/yeah/tree/examples/examples/random)
28
+
29
+
30
+ ## Usage
31
+
32
+ NOTE: This is alpha-stage software, expect changes!
33
+
34
+ ### Installation
35
+
36
+ 1. Install Ruby 2.0+, visit [the Ruby website](http://ruby-lang.org/) for more info.
37
+ 2. In a command line, enter `gem install yeah`.
38
+ 3. Enter `yeah` to view list of commands.
39
+
40
+ ### Making a game
41
+
42
+ 1. In a command line, enter `yeah new` to generate a new game project.
43
+ 2. Change into the new `game` directory, then enter `bundle install`.
44
+ 3. Add game code to `code/game.rb`. No tutorials yet; please take a look at the [example code](https://github.com/yeahrb/yeah/tree/examples/examples) and [API reference](http://rdoc.info/github/yeahrb/yeah/9f065a6/frames).
45
+ 4. Enter `yeah serve` and visit [http://localhost:1234](http://localhost:1234) to try the game.
46
+
47
+
48
+ ## API Reference
49
+
50
+ [0.3.3](http://rdoc.info/github/yeahrb/yeah/9f065a6/frames)
51
+
52
+ [Edge](http://rdoc.info/github/yeahrb/yeah/master/frames)
data/bin/yeah ADDED
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'fileutils'
4
+
5
+ options = {}
6
+
7
+ options[:command] = ARGV.shift
8
+
9
+ case options[:command]
10
+ when 'new'
11
+ if Dir['game'].any?
12
+ puts "Error: `game` directory already exists."
13
+ else
14
+ template_path = File.expand_path('../../lib/yeah/_template', __FILE__)
15
+ FileUtils.cp_r(template_path, './game')
16
+ puts "Created new game project at `game`."
17
+ end
18
+ when 'serve'
19
+ require 'yeah/web/server'
20
+ Yeah::Web::Server.new.start
21
+ when 'version'
22
+ puts Yeah::VERSION
23
+ else
24
+ puts "Usage: yeah <command>"
25
+ puts ""
26
+ puts "Commands:"
27
+ puts " new - create a new game project"
28
+ puts " serve - serve a game over the Internet"
29
+ puts " version - print installed version"
30
+ end
data/lib/yeah.rb CHANGED
@@ -1,11 +1,8 @@
1
- module Yeah
2
- VERSION = '0.2.2'
3
- end
1
+ module Yeah; end
4
2
 
5
- require 'monkey/numeric'
3
+ require 'yeah/version'
6
4
 
7
- yeah_requires = %i(vector color surface rectangle entity map desktop game
8
- basic_physics)
9
- yeah_requires.each do |req|
10
- require "yeah/#{req}"
11
- end
5
+ require 'yeah/vector'
6
+ require 'yeah/color'
7
+ require 'yeah/constants'
8
+ require 'yeah/game'
@@ -0,0 +1,24 @@
1
+ module Yeah
2
+
3
+ # An `Asset` represents a file found in a project's `assets` directory.
4
+ # @abstract Provided by a `Platform`, subclassed to more specific assets.
5
+ class Asset
6
+ def initialize(path)
7
+ raise NotImplementedError
8
+ end
9
+
10
+ class << self
11
+ # @!method [](*args)
12
+ # @param arguments catch-all
13
+ # @return [Asset]
14
+ # Alias for ::new.
15
+ end
16
+
17
+ # @!attribute path
18
+ # @param [String] path to asset relative to `assets`
19
+ # @return [String] path to asset relative to `assets`
20
+
21
+ # @!method to_n
22
+ # @return [Native] native representation of asset for platform
23
+ end
24
+ end
@@ -0,0 +1,181 @@
1
+ module Yeah
2
+
3
+ # The `Display` is responsible for drawing to a game display. It provides a
4
+ # procedural drawing API similar to Processing or HTML5 Canvas.
5
+ # @abstract Provided by a `Platform`.
6
+ class Display
7
+ # @param [Hash] options for new object
8
+ # @option options [Vector] :size (V[1280, 720]) of display
9
+ # @option options [String] :canvas_selector ('canvas') for canvas HTML
10
+ # element (applicable only to `Web::Display`)
11
+ def initialize(options = {})
12
+ raise NotImplementedError
13
+ end
14
+
15
+ # @!attribute size
16
+ # @param [Vector] size to make display
17
+ # @return [Vector] size of display
18
+
19
+ # @!attribute width
20
+ # @param [Vector] width to make display
21
+ # @return [Vector] width of display
22
+
23
+ # @!attribute height
24
+ # @param [Vector] height to make display
25
+ # @return [Vector] height of display
26
+
27
+ # @!attribute fill_color
28
+ # @param [Color] color for fill
29
+ # @return [Color] color for fill
30
+
31
+ # @!attribute stroke_color
32
+ # @param [Color] color for stroke
33
+ # @return [Color] color for stroke
34
+
35
+ # @!attribute stroke_width
36
+ # @param [Numeric] width for stroke
37
+ # @return [Numeric] width for stroke
38
+
39
+ # @!attribute font_family
40
+ # @param [String] font family for text
41
+ # @return [String] font family for text
42
+
43
+ # @!attribute font_size
44
+ # @param [String] font size for text
45
+ # @return [String] font size for text
46
+
47
+ # @!method color_at(position)
48
+ # @param [Vector] position of pixel from which to get color
49
+ # @return [Color] color of pixel
50
+
51
+ # @!attribute [r] transformation
52
+ # @return [Array] transformation matrix
53
+
54
+ # @!method translate(displacement)
55
+ # @param [Vector] displacement in 2D
56
+ # @return [nil]
57
+ # @todo Make this work in 3D.
58
+ # Move the transformation by a 2D displacement.
59
+
60
+ # @!method scale(multiplier)
61
+ # @param [Vector] multiplier in 2D
62
+ # @return [nil]
63
+ # @todo Make this work in 3D.
64
+ # Scale the transformation by a 2D multiplier.
65
+
66
+ # @!method rotate(radians)
67
+ # @param [Numeric] radians in 2D
68
+ # @return [nil]
69
+ # @todo Make this work in 3D.
70
+ # Rotate the transformation by radians.
71
+
72
+ # @!method push
73
+ # @return [nil]
74
+ # Push transformation to the transformation stack.
75
+
76
+ # @!method pop
77
+ # @return [nil]
78
+ # Pop a transformation off the transformation stack.
79
+
80
+ # @!method stroke_line(start_pos, end_pos)
81
+ # @param [Vector] start position in 2D
82
+ # @param [Vector] end position in 2D
83
+ # @return [nil]
84
+ # Stroke a line between two positions.
85
+
86
+ # @!method stroke_rectangle(position, size)
87
+ # @param [Vector] position in 2D
88
+ # @param [Vector] size in 2D
89
+ # @return [nil]
90
+ # Stroke a rectangle at a position and size.
91
+
92
+ # @!method fill_rectangle(position, size)
93
+ # @param [Vector] position in 2D
94
+ # @param [Vector] size in 2D
95
+ # @return [nil]
96
+ # Fill a rectangle at a position and size.
97
+
98
+ # @!method stroke_ellipse(center, radius)
99
+ # @param [Vector] center position in 2D
100
+ # @param [Vector] radius in 2D
101
+ # @return [nil]
102
+ # Stroke an ellipse at a center position and 2D radius.
103
+
104
+ # @!method fill_ellipse(center, radius)
105
+ # @param [Vector] center position in 2D
106
+ # @param [Vector] radius in 2D
107
+ # @return [nil]
108
+ # Fill an ellipse at a center position and 2D radius.
109
+
110
+ # @!method clear
111
+ # @return [nil]
112
+ # Clear display with fill color.
113
+
114
+ # @!method begin_shape
115
+ # @return [nil]
116
+ # Begin new shape.
117
+
118
+ # @!method end_shape
119
+ # @return [nil]
120
+ # End shape.
121
+
122
+ # @!method move_to(position)
123
+ # @param [Vector] position
124
+ # @return [nil]
125
+ # Move shape cursor to position.
126
+
127
+ # @!method line_to(position)
128
+ # @param [Vector] position
129
+ # @return [nil]
130
+ # Draw line to position as part of shape.
131
+
132
+ # @!method curve_to(position, control)
133
+ # @param [Vector] position
134
+ # @param [Vector] control point position
135
+ # @return [nil]
136
+ # Draw curve with a control point to position as part of shape.
137
+
138
+ # @!method curve2_to(position, control1, control2)
139
+ # @param [Vector] position
140
+ # @param [Vector] first control point position
141
+ # @param [Vector] second control point position
142
+ # @return [nil]
143
+ # Draw curve with 2 control points to position as part of shape.
144
+
145
+ # @!method stroke_shape
146
+ # @return [nil]
147
+ # Stroke previously made shape.
148
+
149
+ # @!method fill_shape
150
+ # @return [nil]
151
+ # Fill previously made shape.
152
+
153
+ # @!method image(image, position)
154
+ # @param [Image] image to draw
155
+ # @param [Vector] position
156
+ # @return [nil]
157
+ # @example Draw a duck within a game
158
+ # display.image Image['images/duck.png'], V[80, 80]
159
+ # Draw an image at a position.
160
+
161
+ # @!method image_cropped(image, position, crop_position, crop_size)
162
+ # @param [Image] image to draw
163
+ # @param [Vector] position
164
+ # @param [Vector] start point of crop
165
+ # @param [Vector] size of crop
166
+ # @return [nil]
167
+ # Draw a cropped image at a position.
168
+
169
+ # @!method fill_text(text, position)
170
+ # @param [String] text value
171
+ # @param [Vector] position
172
+ # @return [nil]
173
+ # Fill text at a position.
174
+
175
+ # @!method stroke_text(text, position)
176
+ # @param [String] text value
177
+ # @param [Vector] position
178
+ # @return [nil]
179
+ # Stroke text at a position.
180
+ end
181
+ end
@@ -0,0 +1,16 @@
1
+ module Yeah
2
+
3
+ # An `Image` is an asset that a `Display` can draw.
4
+ # @abstract Provided by a `Platform`.
5
+ # @see Yeah::Display#image
6
+ class Image < Asset
7
+ # @!attribute [r] size
8
+ # @return [Vector] size of image
9
+
10
+ # @!attribute [r] width
11
+ # @return [Integer] width of image
12
+
13
+ # @!attribute [r] height
14
+ # @return [Integer] height of image
15
+ end
16
+ end
@@ -0,0 +1,37 @@
1
+ module Yeah
2
+
3
+ # The `Keyboard` provides keyboard input handling.
4
+ # @example Playing sound on key press within game
5
+ # neigh.play if keyboard.pressed? :scroll_lock
6
+ # @abstract Provided by a `Platform`.
7
+ class Keyboard
8
+ KEYS = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, :a, :alt, :b, :backquote, :backslash,
9
+ :backspace, :c, :caps_lock, :comma, :ctrl, :d, :delete, :dot, :down,
10
+ :e, :end, :enter, :equals, :escape, :f, :f1, :f10, :f11, :f12, :f2,
11
+ :f3, :f4, :f5, :f6, :f7, :f8, :f9, :fn, :g, :h, :home, :i, :insert,
12
+ :j, :k, :l, :left, :left_bracket, :m, :minus, :n, :num0, :num1,
13
+ :num2, :num3, :num4, :num5, :num6, :num7, :num8, :num9,
14
+ :num_asterisk, :num_dot, :num_lock, :num_minus, :num_plus,
15
+ :num_slash, :o, :p, :page_down, :page_up, :pause, :q, :quote, :r,
16
+ :right, :right_bracket, :s, :scroll_lock, :semicolon, :shift, :slash,
17
+ :super, :t, :tab, :u, :up, :v, :w, :x, :y, :z]
18
+
19
+ # @param [Hash] options for new object
20
+ # @option options [Ticker] :ticker for one-shot input handling
21
+ def initialize(options = {})
22
+ raise NotImplementedError
23
+ end
24
+
25
+ # @!method pressing?(key)
26
+ # @param [Symbol, Numeric] key to check
27
+ # @return [Boolean] whether key is pressed
28
+
29
+ # @!method pressed?(key)
30
+ # @param [Symbol, Numeric] key to check
31
+ # @return [Boolean] whether key was just pressed
32
+
33
+ # @!method released?(key)
34
+ # @param [Symbol, Numeric] key to check
35
+ # @return [Boolean] whether key was just released
36
+ end
37
+ end
@@ -0,0 +1,30 @@
1
+ module Yeah
2
+
3
+ # `Mouse` provides mouse input handling.
4
+ # @example Attack on button press within game
5
+ # attack if mouse.pressed? :left
6
+ # @abstract Provided by a `Platform`.
7
+ class Mouse
8
+ BUTTONS = [:left, :middle, :right, 4, 5]
9
+
10
+ # @param [Hash] options for new object
11
+ # @option options [Ticker] :ticker for one-shot input handling
12
+ # @option options [String] :canvas_selector ('canvas') for canvas HTML
13
+ # element (applicable only to `Web::Mouse`)
14
+ def initialize(options = {})
15
+ raise NotImplementedError
16
+ end
17
+
18
+ # @!method pressing?(button)
19
+ # @param [Symbol, Numeric] button to check
20
+ # @return [Boolean] whether button is pressed
21
+
22
+ # @!method pressed?(button)
23
+ # @param [Symbol, Numeric] button to check
24
+ # @return [Boolean] whether button was just pressed
25
+
26
+ # @!method released?(button)
27
+ # @param [Symbol, Numeric] button to check
28
+ # @return [Boolean] whether button was just released
29
+ end
30
+ end
@@ -0,0 +1,15 @@
1
+ module Yeah
2
+
3
+ # A `Sound` is an audio asset, which can be used to provide music and sound
4
+ # effects for a game.
5
+ # @example Playing a sound
6
+ # Sound['sounds/neigh.wav'].play
7
+ # @abstract Provided by a `Platform`.
8
+ class Sound < Asset
9
+ # @!method play
10
+ # Play sound.
11
+
12
+ # @!method pause
13
+ # Pause sound. A following call to {#play} will resume.
14
+ end
15
+ end