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
|
-
|
|
|
!
-
|
|
!
-
|
-
|
|
!
|
#module
#deffunc plot int x, int y, int radius
circle x - radius, y - radius, x + radius, y + radius, 0
return
#global
#const BULLET_RADIUS 4 #const BULLET_SPEED 5 #const CANNON_RADIUS 10 #const CANNON_LENGTH 20
cannonX = 300 cannonY = 200
cannonT = 0.0 bulletX = 0.0 bulletY = 0.0
title "クリックで砲撃 / 右クリックで砲台移動"
onclick gosub *clicked
*mainLoop
gosub *calc
gosub *draw
await 6
goto *mainLoop
*calc
cannonT = atan(mousey - cannonY, mousex - cannonX)
if bullet {
bulletX += bulletVX
bulletY += bulletVY
if (bulletX < 0)|(bulletY < 0)|(ginfo_winx < bulletX)|(ginfo_winy < bulletY) : bullet = 0
}
return
*draw
redraw 0
color 255, 255, 255 : boxf
color
plot cannonX, cannonY, CANNON_RADIUS
line cannonX + cos(cannonT)*CANNON_LENGTH, cannonY + sin(cannonT)*CANNON_LENGTH, cannonX, cannonY
if bullet {
color 0, 0, 255
plot bulletX, bulletY, BULLET_RADIUS
}
redraw 1
return
*clicked
if iparam == 0 {
gosub *shotcannon
} else {
cannonX = mousex
cannonY = mousey
}
return
*shotcannon
bullet = 1
bulletX = cos(cannonT)*CANNON_LENGTH + cannonX
bulletY = sin(cannonT)*CANNON_LENGTH + cannonY
bulletVX = cos(cannonT)*BULLET_SPEED
bulletVY = sin(cannonT)*BULLET_SPEED
return
|