examples

line-hit-debug-gjk.js

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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
world.frame()

elem = display.emoji("๐Ÿ™‚")
physics.add(elem, { radius: 35 })
elem.tap(() => {
  elem.applyImpulse(random.num(-1, 1)*50, -50)
})


var n=display.line(400, 400, 100, 100)
n.style=LineStyle.hearts
n.width = 5
n.alpha = 0.5

var l=display.line(860, 100, 860, 540)
l.alpha = 0.5

var r=display.rect(display.center, 50, 50)
r.alpha = 0.5
r.angle = random.num(0,360)

var c=display.circle(display.center.x, 100, 55)
c.alpha = 0.5
c.angle = random.num(0,360)

var p=display.polygon(display.center.x, 540, 55, 4)
p.alpha = 0.5
p.angle = random.num(0,360)

var pollly = display.polygon(100, 100, 50, 6)
pollly.alpha = 0.5
pollly.rotate(5)
physics.add(pollly)

var ellispse = display.ellipse(display.center, 40, 60)
ellispse.alpha = 0.5
ellispse.scale = 1
ellispse.rotate(10)
physics.add(ellispse)

function nuclear() {
  let ellis = [
    display.ellipse(display.center, 30, 80),
    display.ellipse(display.center, 30, 80),
    display.ellipse(display.center, 30, 80)
  ]

  for (const elli of ellis) {
    elli.color = color.hsb(0,0,0,0)
    elli.borderColor = color.hsb(0,0,100)
    elli.borderWidth = 2
  }

  ellis[0].angle = 0
  ellis[1].angle = 60
  ellis[2].angle = 120

  return ellis
}
ells = nuclear()

timer.every(1500, () => {

  p.vertices = random.num(3, 9)
  n.width = random.num(15, 30)
  r.animate(
    { duration: 400, easing: Easing.easeInOutSine },
    (to) => {
      to.size = random.size(50, 250)
    }
  )
  if (r.notInView()) {
    r.position = display.center
  }
})

update(() => {
  display.all((el) => el.updateHitbox())

  for (const el of ells) {
    el.rotate(1)
  }
  r.move(2)
  r.ifOnEdgeBounce()
  c.move(2)
  c.ifOnEdgeBounce()
  p.move(2)
  p.ifOnEdgeBounce()

  elem.pointTo(r)
})

input.point((e) => {
  if (e.began) {
    l = display.line(e.position, e.position)
    l.alpha = 0.5
    l.collision((e) => {
      print(Date.now(), "collision", e.tag)
    })
  }
  if (e.updated) {
    l.to(e.position)
  }
  if (e.ended) {
    l.destroy()
  }
})

app.draw((ctx) => {
  ctx.save()
  for (const elem of display.drawElems) {
    if (elem.hitbox !== undefined) {
      for (const v of elem.hitbox) {
        ctx.fillStyle = "red"
        ctx.beginPath()
        ctx.arc(v.x, v.y, 2, 0, 2 * Math.PI)
        ctx.fill()
      }

      for (const v of elem.verts) {
        ctx.fillStyle = "blue"
        ctx.beginPath()
        var p = v.data.slice(-2)
        ctx.arc(elem.x + p[0], elem.y + p[1], 2, 0, 2 * Math.PI)
        ctx.fill()
      }
    }

    if (elem.center !== undefined) {
      ctx.fillStyle = "green"
      ctx.beginPath()
      ctx.arc(elem.center.x, elem.center.y, 2, 0, 2 * Math.PI)
      ctx.fill()
    }
  }
  ctx.restore()
})