-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalentine_quest_main.rb
85 lines (70 loc) · 2.17 KB
/
valentine_quest_main.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
require 'gosu'
require_relative 'heart'
require_relative 'player'
class ValentineQuestMain < Gosu::Window
WINDOW_WIDTH = 1024
WINDOW_HEIGHT = 768
def initialize
super WINDOW_WIDTH, WINDOW_HEIGHT
self.caption = "Valentine Quest"
@background_image = Gosu::Image.new("assets/images/gradient.png", tileable: false)
@cursor_image = Gosu::Image.new("assets/images/cursor.png", tileable: false)
@hit = Gosu::Sample.new('assets/sounds/boost1.wav')
@hit_success = Gosu::Sample.new('assets/sounds/afterburn.wav')
@score_text = Gosu::Font.new(64)
@hearts = []
@frames = 0
@player = Player.new
end
def update
@frames += 1
@hearts << Heart.new(rand(WINDOW_WIDTH), 0) if @frames % 15 == 0
@hearts.map(&:update)
@hearts.reject!{|heart| !heart.underscreen?}
end
def draw
@background_image.draw(0, 0, 0)
@hearts.map(&:draw)
@cursor_image.draw(self.mouse_x, self.mouse_y, 2, 0.2, 0.2)
@score_text.draw("#{@player.scores[:single]} forever alones", 10, 0*50+10, 2, 1.0, 1.0, 0xff_000000)
@score_text.draw("#{@player.scores[:hetero]} hetero couples", 10, 1*50+10, 2, 1.0, 1.0, 0xff_000000)
@score_text.draw("#{@player.scores[:homo]} homo couples", 10, 2*50+10, 2, 1.0, 1.0, 0xff_000000)
@score_text.draw("#{@player.scores[:poly]} polyamourous", 10, 3*50+10, 2, 1.0, 1.0, 0xff_000000)
end
def button_down(id)
if id == Gosu::MsLeft
hit_hearts = @hearts.select{|heart| heart.hit?(self.mouse_x, self.mouse_y)}
hearts_hit(hit_hearts)
elsif id == Gosu::KbEscape
close
end
end
def hearts_hit(hit_hearts)
add_score hit_hearts
play_sound hit_hearts
remove_hearts hit_hearts
end
def remove_hearts(hearts)
@hearts -= hearts
end
def add_score(hearts)
return if hearts.size == 0
if hearts.size == 1
type = :single
elsif hearts.size == 2
if hearts[0].gender == hearts[1].gender
type = :homo
else
type = :hetero
end
else
type = :poly
end
@player.add_to_score(type, 1)
end
def play_sound(hearts)
hearts.empty? ? @hit.play : @hit_success.play
end
end
window = ValentineQuestMain.new
window.show