-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.rb
101 lines (82 loc) · 1.69 KB
/
player.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
require 'player2'
class Player
attr_accessor :player, :image, :score, :pontos, :morto, :x, :y, :estagio, :imgset
def initialize(window)
# @image = Gosu::Image::load_tiles(window, "img/pidgeottobw.png", 2.3, 3.0, 3)
@janela = window
@image = Gosu::Image.new(window, "img/players/playertiler.png", false)
@imgset = Gosu::Image::load_tiles(@janela,@image, 180,170, true)
@morto= Gosu::Image.new(window, "img/hitted.png", true)
@x = @y = @vel_x = @vel_y = @angle = 0.0
@score = 3
@pontos = 0
@acertado = false
@estagio = 1
$i = 0
$ind = 0
end
def warp(x, y)
@x, @y = x, y
end
def turn_left
@x -= 4.5
if @x < 0
@x=0
end
end
def turn_right
@x += 4.5
if @x > 640
@x = 640
end
end
def up
@vel_x += Gosu::offset_x(@angle, 0.5)
@vel_y += Gosu::offset_y(@angle, 0.5)
end
def down
@vel_x -= Gosu::offset_x(@angle, 0.5)
@vel_y -= Gosu::offset_y(@angle, 0.5)
end
def move
@vel_x *= 0.95
@vel_y *= 0.95
@x += @vel_x
@y += @vel_y
if @y<-40
@y = -40
elsif @y>380
@y=380
end
end
def draw
if @acertado
@morto.draw(@x, @y, 4)
else
# @image.draw_rot(@x,@y,1, @angle)
if $i < 6 then
$i+=1
end
if $i == 6 then
$ind+=1
$i = 0
end
if $ind >= @imgset.size then
$ind = -4
end
@imgset[$ind].draw(@x, @y, 3)
end
end
def hit_by?(bichos)
@acertado = bichos.any? {|bicho| Gosu::distance(bicho.x, bicho.y, @x, @y) < 60}
if @acertado
@score = @score - 1
else
@acertado
end
end
def reset_position
@y = rand(@janela.height)
@x = 50
end
end