forked from Metalab/The-Flying-Camera
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Score.rb
52 lines (45 loc) · 1.09 KB
/
Score.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#
# Score.rb
# The Flying Camera
#
# Created by Thomas R. Koll on 12.12.10.
# Copyright (c) 2010 ananasblau. All rights reserved.
#
class Score
attr_accessor :score, :point_size, :x, :y, :z, :binary
def initialize(x,y,z)
self.x = x
self.y = y
self.z = z
self.score = 0
self.point_size = 0.03
self.binary = true
end
def draw
(self.binary ?
(self.score.to_i/16).to_s(2).split('').reverse :
self.score.to_i.to_s.split('').reverse)
.each_with_index do |p, i|
glPushMatrix
c = self.binary ? (p == "1" ? 0.8 : 0.2) : p.to_f/10.0
glColor3f(c, c, c)
glTranslatef(self.x + (i * point_size) + (point_size / 4.0), self.y, 0)
glBegin(GL_QUADS)
glVertex3f( 0.0, 0.0, 0.0);
glVertex3f( 0.0, point_size, 0.0);
glVertex3f( - point_size, point_size, 0.0);
glVertex3f( - point_size, 0.0, 0.0);
glVertex3f( 0.0, 0.0, 0.0);
glEnd
glPopMatrix
end
end
def +(score)
self.score += score
self
end
def -(score)
self.score -= score
self
end
end