Tetris 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/block.rb +1 -0
- data/lib/shape.rb +46 -43
- data/lib/shapeI.rb +3 -2
- data/lib/shapeJ.rb +2 -2
- data/lib/shapeL.rb +3 -2
- data/lib/shapeO.rb +3 -2
- data/lib/shapeS.rb +3 -2
- data/lib/shapeT.rb +3 -2
- data/lib/shapeZ.rb +2 -2
- data/lib/tetris.rb +8 -8
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c424ad531190659c50649d57b2fb564cc77f5c0e
|
4
|
+
data.tar.gz: 0aeaa132f69651e0da58aeaa069d748cc8f927e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d4a7c1c1343fe6301503aadadd62e8c71e76e783de9e66ca40ff4ffa802390b64530743160b2446cf8b8334d5543dd0e0d5afcd62fbea4e05df155c5754bf95
|
7
|
+
data.tar.gz: b93889efd142f39aadb142d7ad9b695fc2f41f1ad2ea427e7714eb8e124f68f141ae10b425f2f7d5a51bf1a7b9401bcaf573d8e97217d993e068b6e582be3f39
|
data/lib/block.rb
CHANGED
data/lib/shape.rb
CHANGED
@@ -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
|
-
|
30
|
-
|
30
|
+
# first handle x change
|
31
|
+
move_x
|
31
32
|
|
32
|
-
#
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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
|
-
|
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
|
-
|
45
|
-
|
49
|
+
@x = old_x if collides?
|
50
|
+
end
|
46
51
|
|
47
|
-
|
48
|
-
|
52
|
+
# Move the shape on the y axis -- movement down
|
53
|
+
def move_y
|
54
|
+
return unless update_move_y
|
49
55
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
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
|
-
#
|
65
|
+
# rotates the shape
|
58
66
|
def rotate
|
59
67
|
return if @rotation_block.nil?
|
60
68
|
|
61
|
-
(1..@rotation % @rotations).each do
|
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
|
-
|
72
|
-
|
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
|
-
|
82
|
-
|
83
|
-
|
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
|
-
|
94
|
-
|
95
|
-
|
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
|
data/lib/shapeI.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
|
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
|
data/lib/shapeJ.rb
CHANGED
data/lib/shapeL.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
|
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
|
data/lib/shapeO.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
|
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
|
data/lib/shapeS.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
|
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
|
data/lib/shapeT.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
|
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
|
data/lib/shapeZ.rb
CHANGED
data/lib/tetris.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'gosu'
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Filip
|
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
|
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: []
|