-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayer.rb
More file actions
57 lines (49 loc) · 1.2 KB
/
player.rb
File metadata and controls
57 lines (49 loc) · 1.2 KB
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
# coding: utf-8
class Player < Sprite
attr_accessor :x1,:y1,:move,:jflag,:vy,:vy0,:g,:height
def initialize(x,y,image,height)
@x1 = x * 2
@y1 = y
@move = 4.0
@jflag = false
@vy = 0
@vy0 = -18.0
@g = 0.5
@height = height
super
end
def h
return @height
end
def f
return @jflag
end
def f_false
@jflag = false
end
def update
if (Input.key_down?(K_RIGHT) && self.x < self.x1-self.image.width ) # →キーを押したか
self.x += self.move;
end
if (Input.key_down?(K_LEFT) && self.x > 0 ) #←キーを押したか
self.x -= self.move;
end
if (self.jflag)
self.y += self.vy;
if ( self.vy == self.vy0 * (-1.0) )
self.jflag = false;
end
self.vy += self.g;
else
if (Input.key_down?(K_SPACE))
self.jflag = true;
self.vy = self.vy0;
Sound[:jump].play
end
end
self.y += 6
end
def c(island)
self.y = island.y - self.height
end
end