commit final!!!
This commit is contained in:
parent
8411609b6a
commit
6211fd4b7c
1 changed files with 20 additions and 11 deletions
31
main.go
31
main.go
|
|
@ -32,21 +32,20 @@ type ball struct {
|
||||||
// parâmetros
|
// parâmetros
|
||||||
const windowWidth = 700
|
const windowWidth = 700
|
||||||
const windowHeight = 700
|
const windowHeight = 700
|
||||||
const gridDivision = 8
|
const gridDivision = 4
|
||||||
const verticalGrids = windowHeight/gridDivision
|
const verticalGrids = windowHeight/gridDivision
|
||||||
const horizontalGrids = windowWidth/gridDivision
|
const horizontalGrids = windowWidth/gridDivision
|
||||||
const magnetsDistance float32 = 80
|
const magnetsDistance float32 = 80
|
||||||
const magnetRadius = 10
|
const magnetRadius = 10
|
||||||
const gravConst float32 = 200
|
const gravConst float32 = 50
|
||||||
const magnetsAngle = 0
|
const magnetsAngle = 0
|
||||||
const luminance = false
|
const luminance = false
|
||||||
const hideBalls = false
|
const hideBalls = true
|
||||||
const hideMagnets = false
|
const hideMagnets = false
|
||||||
var startingBallSpeed = rl.Vector2{X: 0, Y: 0} // joga a bola em alguma diração
|
var startingBallSpeed = rl.Vector2{X: 0, Y: 0} // joga a bola em alguma diração
|
||||||
// antes que ela comece a ser atraida pelos ímãs
|
// antes que ela comece a ser atraida pelos ímãs
|
||||||
var cameraOffset = rl.Vector2{X: 0, Y: 0}
|
var cameraOffset = rl.Vector2{X: 0, Y: 0}
|
||||||
|
|
||||||
|
|
||||||
func (ball *ball) update(magnets []magnet) (bool, rl.Color) {
|
func (ball *ball) update(magnets []magnet) (bool, rl.Color) {
|
||||||
magnetsPull := rl.Vector2{}
|
magnetsPull := rl.Vector2{}
|
||||||
|
|
||||||
|
|
@ -55,26 +54,31 @@ func (ball *ball) update(magnets []magnet) (bool, rl.Color) {
|
||||||
rl.Vector2Subtract(ball.pos, magnet.pos),
|
rl.Vector2Subtract(ball.pos, magnet.pos),
|
||||||
)
|
)
|
||||||
distance := rl.Vector2Distance(magnet.pos, ball.pos)
|
distance := rl.Vector2Distance(magnet.pos, ball.pos)
|
||||||
distanceSquared := float32(math.Pow(float64(distance), 2))
|
distanceSquared := math.Pow(float64(distance), 2)
|
||||||
force := gravConst / distanceSquared
|
force := gravConst / float32(distanceSquared)
|
||||||
|
|
||||||
acceleration := rl.Vector2Scale(direction, -force)
|
acceleration := rl.Vector2Scale(direction, -force)
|
||||||
|
|
||||||
magnetsPull = rl.Vector2Add(magnetsPull, acceleration)
|
magnetsPull = rl.Vector2Add(magnetsPull, acceleration)
|
||||||
}
|
}
|
||||||
|
|
||||||
// fmt.Println(magnetsPull)
|
|
||||||
ball.speed = rl.Vector2Add(ball.speed, magnetsPull)
|
ball.speed = rl.Vector2Add(ball.speed, magnetsPull)
|
||||||
ball.pos = rl.Vector2Add(ball.speed, ball.pos)
|
ball.pos = rl.Vector2Add(ball.speed, ball.pos)
|
||||||
|
|
||||||
|
// verificar se bola parou em cima de um ímã
|
||||||
for _, magnet := range magnets {
|
for _, magnet := range magnets {
|
||||||
|
|
||||||
distance := rl.Vector2Distance(ball.pos, magnet.pos)
|
distance := rl.Vector2Distance(ball.pos, magnet.pos)
|
||||||
if distance < magnet.radius + ball.radius {
|
|
||||||
|
insideMagnet := distance < magnet.radius /* + ball.radius */
|
||||||
|
// atRest := math.Abs(float64(rl.Vector2Length(ball.speed))) < 0.01
|
||||||
|
|
||||||
|
if insideMagnet /* && atRest */ {
|
||||||
if luminance { magnet.color.A = uint8(ball.steps) }
|
if luminance { magnet.color.A = uint8(ball.steps) }
|
||||||
return true, magnet.color
|
return true, magnet.color
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false, rl.NewColor(0, 0, 0, 0)
|
return false, rl.NewColor(0, 0, 0, 0)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// var colors = []rl.Color{
|
// var colors = []rl.Color{
|
||||||
|
|
@ -97,12 +101,12 @@ func main() {
|
||||||
// force: magnetForce,
|
// force: magnetForce,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
color: rl.Green,
|
color: rl.Gray,
|
||||||
radius: magnetRadius,
|
radius: magnetRadius,
|
||||||
// force: magnetForce,
|
// force: magnetForce,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
color: rl.Blue,
|
color: rl.White,
|
||||||
radius: magnetRadius,
|
radius: magnetRadius,
|
||||||
// force: magnetForce,
|
// force: magnetForce,
|
||||||
},
|
},
|
||||||
|
|
@ -111,6 +115,11 @@ func main() {
|
||||||
radius: magnetRadius,
|
radius: magnetRadius,
|
||||||
// force: magnetForce,
|
// force: magnetForce,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
color: rl.Magenta,
|
||||||
|
radius: magnetRadius,
|
||||||
|
// force: magnetForce,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// posiciona imas em volta de um circulo
|
// posiciona imas em volta de um circulo
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue