fantasy 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 98740063fd63398988bf5b11e625a75e2526f617ab22e9aa1ff483a65c0f91cb
4
- data.tar.gz: b4eecd987e01f24f2a1d3aef7627c195992ec0ffa0c4b124fb6ca577896a2a58
3
+ metadata.gz: 98083689a972e68c27f07ae5c9c8ef9818c1b1215fbf2baccc541233efca6827
4
+ data.tar.gz: db32ef03fd54c4711b9b38b9f4e3f4ad587839fc4d78523982c6c69f85cb0ab4
5
5
  SHA512:
6
- metadata.gz: ab99759553de96490612fbf1c6089db1113ec26969876b88d9215fbb1317a7ee08dfef98cd376c7843750013ed3981b10fc0beba0e816a6c5c7358511166b023
7
- data.tar.gz: 69c41125931104d3440c02bfe1073b6d37f27d2efebbe3fdd331165c014739bf81f92d80c83c46f636d0eda77d583a802a7f377c943ce8964a8bf9d7567f7d4d
6
+ metadata.gz: 5a6d2c503880c672d147909cd5ab5a88639ab4e3e019ea5b81601c4aa0cc967e03e5c8b48f1994309ab379e83012f5a103043ba6b64989ba8009d2c7e3950174
7
+ data.tar.gz: 93f37ba3a6fde17d55ba7aa203a1ade6645e69af8d670d37b5a7d78442c5c1dc4bb115784520cbd5b6a9ef661b18e6dbc2b094dab4c2a54feca8d37e4c527303
data/README.md CHANGED
@@ -103,9 +103,10 @@ Actors in the game will be rendered in the relative position to this camera.
103
103
 
104
104
  Easy to configure 3 basic game states:
105
105
 
106
- - Initial screen
107
- - Game
108
- - Game over screen
106
+ - Game presentation scene
107
+ - Game game scene
108
+ - Game end scene
109
+ - Other scenes, like levels or such (TODO)
109
110
 
110
111
  Each state should be independent and unique Actors and other elements can be created and configured for each state
111
112
 
@@ -123,9 +124,17 @@ Move the core functions to the top level hierarchy so I don't need to create a `
123
124
 
124
125
  Direct and easy way to play a sound
125
126
 
127
+ ### Background
128
+
129
+ Simple way to set up:
130
+
131
+ - Background color
132
+ - Image background (TODO)
133
+ - Repeatable image background (TODO)
134
+
126
135
  ### Data Persistance (TODO)
127
136
 
128
- Simple mechanismo to save data in disk. For user preferences, game progress, high scores and others
137
+ Simple mechanism to save data in disk. For user preferences, game progress, high scores and others
129
138
 
130
139
  ### User Inputs
131
140
 
@@ -147,6 +156,7 @@ Easy access to keyboard and mouse inputs on any part of the code. Specially in t
147
156
  ## Bugs
148
157
 
149
158
  - When dragging in debug mode new elements are being added to the drag (TODO)
159
+ - Rubocop is not passing
150
160
 
151
161
  ## Development
152
162
 
data/lib/fantasy/actor.rb CHANGED
@@ -3,7 +3,7 @@ class Actor
3
3
  attr_accessor :position, :direction, :speed, :solid, :scale, :name, :layer
4
4
 
5
5
  def initialize(image_name)
6
- @image = Gosu::Image.new("#{__dir__}/../images/#{image_name}.png", { retro: true })
6
+ @image = Image.new(image_name)
7
7
  @name = image_name
8
8
  @position = Coordinates.new(0, 0)
9
9
  @direction = Coordinates.new(0, 0)
@@ -23,7 +23,7 @@ class Actor
23
23
  end
24
24
 
25
25
  def image=(image_name)
26
- @image = Gosu::Image.new("#{__dir__}/../images/#{image_name}.png", { retro: true })
26
+ @image = Image.new(image_name)
27
27
  end
28
28
 
29
29
  def width
@@ -44,7 +44,7 @@ class Actor
44
44
  end
45
45
 
46
46
  def draw
47
- @image.draw(position_in_camera.x, position_in_camera.y, 0, @scale, @scale)
47
+ @image.draw(x: position_in_camera.x, y: position_in_camera.y, scale: @scale)
48
48
 
49
49
  draw_debug if Global.debug
50
50
  end
@@ -28,7 +28,7 @@ module Global
28
28
  @clocks = []
29
29
  @last_frame_at = Time.now
30
30
  @debug = false
31
- @pixel_font = Gosu::Font.new(20, { name: "#{__dir__}/../fonts/VT323-Regular.ttf" } )
31
+ @pixel_font = Gosu::Font.new(20, { name: "#{__dir__}/../../fonts/VT323-Regular.ttf" } )
32
32
  @d_key_pressed = false
33
33
  @references = OpenStruct.new
34
34
  @camera = Camera.new(position: Coordinates.zero)
@@ -4,7 +4,7 @@ class HudImage
4
4
  attr_accessor :name, :scale, :color, :visible, :position, :layer
5
5
 
6
6
  def initialize(position:, image_name: )
7
- @image = Gosu::Image.new("#{__dir__}/../images/#{image_name}.png", { retro: true })
7
+ @image = Image.new(image_name)
8
8
  @name = image_name
9
9
  @position = position
10
10
  @scale = 1
@@ -30,7 +30,7 @@ class HudImage
30
30
 
31
31
  def draw
32
32
  if visible
33
- @image.draw(@position.x, @position.y, 0, @scale, @scale)
33
+ @image.draw(x: @position.x, y: @position.y, scale: @scale)
34
34
  end
35
35
 
36
36
  draw_debug if Global.debug
@@ -0,0 +1,42 @@
1
+ class Image
2
+ def initialize(image_name)
3
+ @image = Image.load(image_name)
4
+ end
5
+
6
+ def draw(x:, y:, scale: 1)
7
+ @image.draw(x, y, 0, scale, scale)
8
+ end
9
+
10
+ def width
11
+ @image.width
12
+ end
13
+
14
+ def height
15
+ @image.height
16
+ end
17
+
18
+ class << self
19
+ @@images = {}
20
+
21
+ def load(image_name)
22
+ locate_image(image_name)
23
+ end
24
+
25
+ private
26
+
27
+ def locate_image(image_name)
28
+ return @@images[image_name] if @@images[image_name]
29
+
30
+ puts "Initialize image: '#{image_name}'"
31
+
32
+ base_path = "#{Dir.pwd}/images"
33
+ file_name = Dir.entries(base_path).find { |e| e.start_with?("#{image_name}.") }
34
+
35
+ raise "Image file not found with name '#{image_name}'" if file_name.nil?
36
+
37
+ @@images[image_name] = Gosu::Image.new("#{base_path}/#{file_name}", { retro: true })
38
+
39
+ return @@images[image_name]
40
+ end
41
+ end
42
+ end
data/lib/fantasy/sound.rb CHANGED
@@ -11,8 +11,11 @@ module Sound
11
11
 
12
12
  puts "Initialize Sound: '#{sound_name}'"
13
13
 
14
- base_path = "#{__dir__}/../sounds"
15
- file_name = Dir.entries(base_path).find { |e| e.start_with?(sound_name) }
14
+ base_path = "#{Dir.pwd}/sounds"
15
+ file_name = Dir.entries(base_path).find { |e| e.start_with?("#{sound_name}.") }
16
+
17
+ raise "Sound file not found with name '#{sound_name}'" if file_name.nil?
18
+
16
19
  @@sounds[sound_name] = Gosu::Sample.new("#{base_path}/#{file_name}")
17
20
 
18
21
  return @@sounds[sound_name]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Fantasy
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
data/lib/fantasy.rb CHANGED
@@ -14,4 +14,5 @@ require_relative "fantasy/hud_text"
14
14
  require_relative "fantasy/hud_image"
15
15
  require_relative "fantasy/sound"
16
16
  require_relative "fantasy/camera"
17
+ require_relative "fantasy/image"
17
18
  require_relative "fantasy/base"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fantasy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fernando Guillen
@@ -67,6 +67,7 @@ files:
67
67
  - lib/fantasy/global.rb
68
68
  - lib/fantasy/hud_image.rb
69
69
  - lib/fantasy/hud_text.rb
70
+ - lib/fantasy/image.rb
70
71
  - lib/fantasy/loop.rb
71
72
  - lib/fantasy/sound.rb
72
73
  - lib/fantasy/utils.rb