Tetris 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 920049a38587822e567263172d651ade6c07cf21
4
- data.tar.gz: 20876771f521d6ede743e1f8e4f65a98ef0fe603
3
+ metadata.gz: c424ad531190659c50649d57b2fb564cc77f5c0e
4
+ data.tar.gz: 0aeaa132f69651e0da58aeaa069d748cc8f927e5
5
5
  SHA512:
6
- metadata.gz: 1fbbcc69193a3b7ea4fd169de8d464f5562d8ad6c67aa523cfccb6240fa224908c3513e540dae2affb02a3f647b035dc58685c097a3cb9a9493418d813b421b6
7
- data.tar.gz: 0603d41a6d1b62e8ec2d1bccbf2e2592f9fbb3b933dda5b29bfb80e871611241cf2aad1156562c36c472499b27517e43f0c5b457d83815dff3d3cf036024f2e5
6
+ metadata.gz: 3d4a7c1c1343fe6301503aadadd62e8c71e76e783de9e66ca40ff4ffa802390b64530743160b2446cf8b8334d5543dd0e0d5afcd62fbea4e05df155c5754bf95
7
+ data.tar.gz: b93889efd142f39aadb142d7ad9b695fc2f41f1ad2ea427e7714eb8e124f68f141ae10b425f2f7d5a51bf1a7b9401bcaf573d8e97217d993e068b6e582be3f39
@@ -35,6 +35,7 @@ class Block
35
35
  @@image.draw(@x, @y, 0, 1, 1, @color)
36
36
  end
37
37
 
38
+ # Tests whether a block collides with other blocks
38
39
  def collides_with_blocks?
39
40
  @game.blocks.each do |block|
40
41
  return true if block.x == @x && block.y == @y
@@ -4,6 +4,7 @@ require 'gosu'
4
4
  class Shape
5
5
  attr_accessor :rotation, :x, :y
6
6
  attr_reader :blocks
7
+ attr_writer :falling
7
8
 
8
9
  def initialize(game)
9
10
  @game = game
@@ -26,39 +27,46 @@ class Shape
26
27
  def update
27
28
  return unless @falling
28
29
 
29
- old_x = @x
30
- old_y = @y
30
+ # first handle x change
31
+ move_x
31
32
 
32
- # first handle x change (handle keyboard - movement -
33
- # and check for collision)
34
- if update_move_x
35
- if @game.button_down?(Gosu::KbLeft)
36
- @x -= 32
37
- elsif @game.button_down?(Gosu::KbRight)
38
- @x += 32
39
- end
33
+ # then handle y change
34
+ move_y
35
+ end
36
+
37
+ # Move the shape on the x axis, if there is the need to
38
+ def move_x
39
+ return unless update_move_x
40
40
 
41
- @x = old_x if collides?
41
+ old_x = @x
42
+
43
+ if @game.button_down?(Gosu::KbLeft)
44
+ @x -= 32
45
+ elsif @game.button_down?(Gosu::KbRight)
46
+ @x += 32
42
47
  end
43
48
 
44
- # then handle y change, so we can set @falling to false
45
- # game speed check
49
+ @x = old_x if collides?
50
+ end
46
51
 
47
- if update_move_y
48
- @y += 32
52
+ # Move the shape on the y axis -- movement down
53
+ def move_y
54
+ return unless update_move_y
49
55
 
50
- if collides?
51
- @y = old_y
52
- @falling = false
53
- end
54
- end
56
+ old_y = @y
57
+ @y += 32
58
+
59
+ return unless collides?
60
+
61
+ @y = old_y
62
+ @falling = false
55
63
  end
56
64
 
57
- # Rotates the shape
65
+ # rotates the shape
58
66
  def rotate
59
67
  return if @rotation_block.nil?
60
68
 
61
- (1..@rotation % @rotations).each do |_i|
69
+ (1..@rotation % @rotations).each do
62
70
  @blocks.each do |block|
63
71
  old_x = block.x
64
72
  old_y = block.y
@@ -68,21 +76,15 @@ class Shape
68
76
  end
69
77
  end
70
78
 
71
- def shape_to_array
72
- blocks_array = []
73
- get_blocks.each do |block|
74
- blocks_array << [block.x, block.y]
75
- end
76
- blocks_array
77
- end
78
-
79
- # updates move counter
79
+ # updates move_x counter
80
+ # returns nil if there is no need to update it
80
81
  def update_move_x
81
- if @game.elapsed_seconds > @game.last_move_x + 0.05
82
- @game.last_move_x = @game.elapsed_seconds
83
- end
82
+ return unless @game.elapsed_seconds > @game.last_move_x + 0.05
83
+
84
+ @game.last_move_x = @game.elapsed_seconds
84
85
  end
85
86
 
87
+ # updates move_y counter, checks for speed up
86
88
  def update_move_y
87
89
  if @game.button_down?(Gosu::KbDown)
88
90
  @game.game_speed *= 0.2
@@ -90,19 +92,18 @@ class Shape
90
92
  @game.game_speed = 1
91
93
  end
92
94
 
93
- if @game.elapsed_seconds > @game.last_move_y + @game.game_speed
94
- @game.last_move_y = @game.elapsed_seconds
95
- end
95
+ return unless @game.elapsed_seconds > @game.last_move_y + @game.game_speed
96
+
97
+ @game.last_move_y = @game.elapsed_seconds
96
98
  end
97
99
 
100
+ # checks whether the shape collides with walls or blocks
98
101
  def collides?
99
- if collides_with_walls? || collides_with_blocks?
100
- return true
101
- end
102
-
102
+ return true if collides_with_walls? || collides_with_blocks?
103
103
  false
104
104
  end
105
105
 
106
+ # checks whether the shape collides with walls (and floor)
106
107
  def collides_with_walls?
107
108
  max_y = maximum_y_block
108
109
  min_x = minimum_x_block
@@ -111,6 +112,7 @@ class Shape
111
112
  min_x.x < 0 || max_x.x >= @game.screen_width || max_y.y + Block.height > @game.screen_height
112
113
  end
113
114
 
115
+ # checks whether the shape collides with any blocks
114
116
  def collides_with_blocks?
115
117
  get_blocks.each do |block|
116
118
  return true if block.collides_with_blocks?
@@ -119,15 +121,18 @@ class Shape
119
121
  false
120
122
  end
121
123
 
124
+ # gets the maximum y block of the shape
122
125
  # note that maximum y means the lowest block!
123
126
  def maximum_y_block
124
127
  get_blocks.max_by(&:y)
125
128
  end
126
129
 
130
+ # gets the lefmost block of the shape
127
131
  def minimum_x_block
128
132
  get_blocks.min_by(&:x)
129
133
  end
130
134
 
135
+ # gets the rightmost block of the shape
131
136
  def maximum_x_block
132
137
  get_blocks.max_by(&:x)
133
138
  end
@@ -149,6 +154,4 @@ class Shape
149
154
  def falling?
150
155
  @falling
151
156
  end
152
-
153
- attr_writer :falling
154
157
  end
@@ -1,5 +1,5 @@
1
- require 'shape.rb'
2
- require 'block.rb'
1
+ require_relative 'shape'
2
+ require_relative 'block'
3
3
 
4
4
  # [ ]
5
5
  # [ ]
@@ -22,6 +22,7 @@ class ShapeI < Shape
22
22
  end
23
23
  end
24
24
 
25
+ # updates shape position and returns its blocks
25
26
  def get_blocks
26
27
  @blocks[0].x = @x
27
28
  @blocks[1].x = @x
@@ -1,10 +1,10 @@
1
- require 'shapeL.rb'
2
- require 'block.rb'
1
+ require_relative 'shapeL'
3
2
 
4
3
  # [ ]
5
4
  # [ ]
6
5
  # [ ][ ]
7
6
  class ShapeJ < ShapeL
7
+ # updates shape position and returns its blocks
8
8
  def get_blocks
9
9
  old_rotation = @rotation
10
10
  @rotation = 0
@@ -1,5 +1,5 @@
1
- require 'shape.rb'
2
- require 'block.rb'
1
+ require_relative 'shape'
2
+ require_relative 'block'
3
3
 
4
4
  # [ ]
5
5
  # [ ]
@@ -21,6 +21,7 @@ class ShapeL < Shape
21
21
  end
22
22
  end
23
23
 
24
+ # updates shape position and returns its blocks
24
25
  def get_blocks
25
26
  @blocks[0].x = @x
26
27
  @blocks[1].x = @x
@@ -1,5 +1,5 @@
1
- require 'shape.rb'
2
- require 'block.rb'
1
+ require_relative 'shape'
2
+ require_relative 'block'
3
3
 
4
4
  # [ ][ ]
5
5
  # [ ][ ]
@@ -19,6 +19,7 @@ class ShapeO < Shape
19
19
  end
20
20
  end
21
21
 
22
+ # updates shape position and returns its blocks
22
23
  def get_blocks
23
24
  @blocks[0].x = @x
24
25
  @blocks[1].x = @x + Block.width
@@ -1,5 +1,5 @@
1
- require 'shape.rb'
2
- require 'block.rb'
1
+ require_relative 'shape'
2
+ require_relative 'block'
3
3
 
4
4
  # [ ]
5
5
  # [ ][ ]
@@ -21,6 +21,7 @@ class ShapeS < Shape
21
21
  end
22
22
  end
23
23
 
24
+ # updates shape position and returns its blocks
24
25
  def get_blocks
25
26
  @blocks[0].x = @x
26
27
  @blocks[1].x = @x
@@ -1,5 +1,5 @@
1
- require 'shape.rb'
2
- require 'block.rb'
1
+ require_relative 'shape'
2
+ require_relative 'block'
3
3
 
4
4
  # [ ][ ][ ]
5
5
  # [ ]
@@ -21,6 +21,7 @@ class ShapeT < Shape
21
21
  end
22
22
  end
23
23
 
24
+ # updates shape position and returns its blocks
24
25
  def get_blocks
25
26
  @blocks[0].x = @x
26
27
  @blocks[1].x = @x + Block.width
@@ -1,10 +1,10 @@
1
- require 'shapeS.rb'
2
- require 'block.rb'
1
+ require_relative 'shapeS'
3
2
 
4
3
  # [ ]
5
4
  # [ ][ ]
6
5
  # [ ]
7
6
  class ShapeZ < ShapeS
7
+ # updates shape position and returns its blocks
8
8
  def get_blocks
9
9
  super
10
10
  translate_by_y
@@ -1,13 +1,13 @@
1
1
  require 'rubygems'
2
2
  require 'gosu'
3
- require 'block.rb'
4
- require 'shapeL.rb'
5
- require 'shapeJ.rb'
6
- require 'shapeI.rb'
7
- require 'shapeO.rb'
8
- require 'shapeT.rb'
9
- require 'shapeZ.rb'
10
- require 'shapeS.rb'
3
+ require_relative 'block'
4
+ require_relative 'shapeL'
5
+ require_relative 'shapeJ'
6
+ require_relative 'shapeI'
7
+ require_relative 'shapeO'
8
+ require_relative 'shapeT'
9
+ require_relative 'shapeZ'
10
+ require_relative 'shapeS'
11
11
 
12
12
  # Main class for Tetris.
13
13
  class Game < Gosu::Window
metadata CHANGED
@@ -1,16 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Tetris
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
- - Filip Vondrasek
7
+ - Filip Vondrášek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2015-02-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: A simple Tetris game
13
+ description: A simple Tetris game created as a semestral project for Programming in
14
+ Ruby course at FIT CTU.
14
15
  email: filip@vondrasek.net
15
16
  executables: []
16
17
  extensions: []
@@ -41,9 +42,9 @@ require_paths:
41
42
  - lib
42
43
  required_ruby_version: !ruby/object:Gem::Requirement
43
44
  requirements:
44
- - - '='
45
+ - - "~>"
45
46
  - !ruby/object:Gem::Version
46
- version: 2.0.0
47
+ version: '2.0'
47
48
  required_rubygems_version: !ruby/object:Gem::Requirement
48
49
  requirements:
49
50
  - - ">="
@@ -54,5 +55,5 @@ rubyforge_project:
54
55
  rubygems_version: 2.4.5
55
56
  signing_key:
56
57
  specification_version: 4
57
- summary: A simple Tetris game
58
+ summary: A simple Tetris game.
58
59
  test_files: []