-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbullet.coffee
62 lines (53 loc) · 1.31 KB
/
bullet.coffee
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
# --------------------------------
# bullet.js
# 弾に関することを記述するよ
# --------------------------------
# -------------------------
# 基本の打ちおろし弾
# -------------------------
class Bullet extends Sprite
constructor : (x, y, image, frame) ->
super 16, 16
@image = image
@frame = frame
@x = x
@y = y
@scale 1.5, 1.5
setAcceleration : (acc) ->
@acc = acc
setSpeed : (speed) ->
@speed = speed
behaviorFunction : () ->
# 動きを定義する関数
# Bulletの子クラスは
# これをオーバーライドすればいいんじゃない?
@speed = 5
@y += @speed
return
checkRange : ->
unless -16 <= @x <= 528
@scene.removeChild @
return
unless -16 <= @y <= 528
@scene.removeChild @
return
onenterframe : (callback) ->
@checkRange()
@behaviorFunction()
return
# -----------------------
# 自機狙い
# -----------------------
class AimBullet extends Bullet
constructor : (x, y, dx, dy, image, frame) ->
super x, y, image, frame
@dx = dx
@dy = dy
@acc = 0
@speed = 5
rate = @speed / Math.sqrt( (x - dx) * (x - dx) + (y - dy) * (y - dy) )
@deltaX = (dx - x) * rate
@deltaY = (dy - y) * rate
behaviorFunction : () ->
@x += @deltaX
@y += @deltaY