parâmetros
This commit is contained in:
parent
de94235fb9
commit
c8c06724e7
1 changed files with 40 additions and 38 deletions
78
main.go
78
main.go
|
|
@ -16,12 +16,6 @@ type magnet struct {
|
|||
radius float32
|
||||
}
|
||||
|
||||
type state struct {
|
||||
windowHeight int32
|
||||
windowWidth int32
|
||||
magnetsDistance float32
|
||||
}
|
||||
|
||||
type ball struct {
|
||||
pos rl.Vector2
|
||||
originGrid rl.Vector2
|
||||
|
|
@ -29,11 +23,21 @@ type ball struct {
|
|||
speed rl.Vector2
|
||||
}
|
||||
|
||||
// parametros
|
||||
const windowWidth = 800
|
||||
const windowHeight = 450
|
||||
const magnetRadius = 15
|
||||
const magnetForce = 8
|
||||
const magnetsDistance float32 = 80
|
||||
const verticalGrids = 100
|
||||
const horizontalGrids = 100
|
||||
const ballMass float32 = 2
|
||||
const gravConst float32 = 8
|
||||
const magnetsAngle = 45
|
||||
|
||||
|
||||
func (ball *ball) update(magnets []magnet) (bool, rl.Color) {
|
||||
magnetsPull := rl.Vector2{}
|
||||
const ballMass float32 = 1
|
||||
const gravConst float32 = 8
|
||||
|
||||
for _, magnet := range magnets {
|
||||
direction := rl.Vector2Normalize(
|
||||
|
|
@ -64,55 +68,44 @@ func (ball *ball) update(magnets []magnet) (bool, rl.Color) {
|
|||
|
||||
func main() {
|
||||
|
||||
state := state{
|
||||
windowWidth: 800,
|
||||
windowHeight: 450,
|
||||
}
|
||||
|
||||
rl.InitWindow(
|
||||
state.windowWidth, state.windowHeight,
|
||||
windowWidth, windowHeight,
|
||||
"raylib [core] example - basic window",
|
||||
)
|
||||
defer rl.CloseWindow()
|
||||
// rl.SetTargetFPS(60)
|
||||
|
||||
const RADIUS = 10
|
||||
const FORCE = 8
|
||||
|
||||
magnets := []magnet{
|
||||
{
|
||||
color: rl.Red,
|
||||
radius: RADIUS,
|
||||
force: FORCE,
|
||||
radius: magnetRadius,
|
||||
force: magnetForce,
|
||||
},
|
||||
{
|
||||
color: rl.Green,
|
||||
radius: RADIUS,
|
||||
force: FORCE,
|
||||
radius: magnetRadius,
|
||||
force: magnetForce,
|
||||
},
|
||||
{
|
||||
color: rl.Blue,
|
||||
radius: RADIUS,
|
||||
force: FORCE,
|
||||
radius: magnetRadius,
|
||||
force: magnetForce,
|
||||
},
|
||||
}
|
||||
|
||||
// pocisionar imas no meio da tela
|
||||
xCenter := float32(state.windowWidth / 2)
|
||||
yCenter := float32(state.windowHeight / 2)
|
||||
var magnetsDistance float32 = 80
|
||||
xCenter := float32(windowWidth / 2)
|
||||
yCenter := float32(windowHeight / 2)
|
||||
for i := range magnets {
|
||||
angle := 2.0 * math.Pi * float64(i) / float64(len(magnets))
|
||||
angle := 2.0 * math.Pi * float64(i) / float64(len(magnets)) + magnetsAngle
|
||||
|
||||
magnets[i].pos = rl.Vector2{
|
||||
X: float32(math.Cos(angle)) * magnetsDistance + xCenter,
|
||||
Y: float32(math.Sin(angle)) * magnetsDistance + yCenter,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
verticalGrids := 60
|
||||
horizontalGrids := 60
|
||||
|
||||
grid := make([][]rl.Color, verticalGrids)
|
||||
for i := range grid {
|
||||
|
|
@ -128,8 +121,8 @@ func main() {
|
|||
// }
|
||||
//
|
||||
gridSize := rl.Vector2{
|
||||
X: float32(state.windowWidth / int32(verticalGrids)),
|
||||
Y: float32(state.windowHeight / int32(horizontalGrids)),
|
||||
X: float32(windowWidth / int32(verticalGrids)),
|
||||
Y: float32(windowHeight / int32(horizontalGrids)),
|
||||
}
|
||||
|
||||
var fallingBall []*ball
|
||||
|
|
@ -154,7 +147,7 @@ func main() {
|
|||
fallingBall = append(fallingBall, &ball{
|
||||
pos: rl.Vector2{X: x, Y: y},
|
||||
speed: rl.Vector2{},
|
||||
radius: RADIUS/2,
|
||||
radius: magnetRadius/2,
|
||||
originGrid: randomGrid,
|
||||
})
|
||||
}
|
||||
|
|
@ -173,8 +166,8 @@ func main() {
|
|||
}
|
||||
}
|
||||
for i := range magnets {
|
||||
rl.DrawCircleV(magnets[i].pos, RADIUS+2, rl.Black)
|
||||
rl.DrawCircleV(magnets[i].pos, RADIUS, magnets[i].color)
|
||||
rl.DrawCircleV(magnets[i].pos, magnetRadius+2, rl.Black)
|
||||
rl.DrawCircleV(magnets[i].pos, magnetRadius, magnets[i].color)
|
||||
}
|
||||
|
||||
if len(fallingBall) == 0 {
|
||||
|
|
@ -186,11 +179,20 @@ func main() {
|
|||
for i := 0; i < len(fallingBall); i++ {
|
||||
ball := fallingBall[i]
|
||||
|
||||
rl.DrawCircleV(
|
||||
ball.pos, ball.radius/2+1, rl.Black,
|
||||
// rl.DrawCircleV(
|
||||
// ball.pos, ball.radius/2+1, rl.Black,
|
||||
// )
|
||||
// rl.DrawCircleV(
|
||||
// ball.pos, ball.radius/2,
|
||||
// rl.NewColor(100, 100, 100, 255),
|
||||
// )
|
||||
rl.DrawRectangleV(
|
||||
rl.Vector2{X: ball.pos.X-1, Y: ball.pos.Y-1 },
|
||||
rl.Vector2{X: ball.radius+1, Y: ball.radius+1},
|
||||
rl.Black,
|
||||
)
|
||||
rl.DrawCircleV(
|
||||
ball.pos, ball.radius/2,
|
||||
rl.DrawRectangleV(
|
||||
ball.pos, rl.Vector2{X: ball.radius, Y: ball.radius},
|
||||
rl.NewColor(100, 100, 100, 255),
|
||||
)
|
||||
if hit, color := ball.update(magnets); hit {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue