-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathball.nbis
More file actions
49 lines (38 loc) · 1011 Bytes
/
Copy pathball.nbis
File metadata and controls
49 lines (38 loc) · 1011 Bytes
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
from graphics import *;
from math import abs, round;
from random import random;
# Window setup
init(800, 600)
set_bg("#0d1117")
set_title("Bouncing Ball")
# Ball state
bx = 400.0
by = 300.0
vx = random() * 10 - 5
vy = random() * 10 - 5
radius = 30
while not quit_requested() do {
# Update position
if mouse_down() then {
bx = mouse_x()
by = mouse_y()
} else {
bx = round(bx + vx)
by = round(by + vy)
}
# Bounce off walls
if bx - radius < 0 or bx + radius > 800 then { vx = vx * -1 }
if by - radius < 0 or by + radius > 600 then { vy = vy * -1 }
# Background panel
rounded_rect(10, 10, 780, 580, 16, "#161b22", true)
# Ball shadow
circle(bx + 4, by + 4, radius, "#00000066", true)
# Ball
circle(bx, by, radius, "#58a6ff", true)
# Highlight
circle(bx - 8, by - 8, radius / 4, "#ffffff44", true)
# HUD
text(20, 20, "pos: (" + (bx -> Str) + ", " + (by -> Str) + ")",
14, "#8b949e")
blit()
}