dano
This commit is contained in:
parent
397136b3da
commit
be34596f1d
1 changed files with 71 additions and 41 deletions
98
main.go
98
main.go
|
|
@ -17,25 +17,21 @@ const (
|
||||||
maxSpeed = 0.1
|
maxSpeed = 0.1
|
||||||
)
|
)
|
||||||
|
|
||||||
type animation int
|
|
||||||
|
|
||||||
const (
|
|
||||||
none animation = iota
|
|
||||||
shake
|
|
||||||
)
|
|
||||||
|
|
||||||
type enemy struct {
|
type enemy struct {
|
||||||
pos rl.Vector3
|
pos rl.Vector3
|
||||||
speed float32
|
speed float32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type remainingFrames int
|
||||||
|
type animationFunc func()remainingFrames
|
||||||
|
|
||||||
type building struct {
|
type building struct {
|
||||||
pos rl.Vector3
|
pos rl.Vector3
|
||||||
size rl.Vector3
|
size rl.Vector3
|
||||||
color rl.Color
|
color rl.Color
|
||||||
life int
|
life int
|
||||||
boundingBox rl.BoundingBox
|
boundingBox rl.BoundingBox
|
||||||
animation animation
|
animate animationFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
func draw_plane() {
|
func draw_plane() {
|
||||||
|
|
@ -80,21 +76,11 @@ func newBuilding(x, z float32) *building {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func draw_buildings(buildings []*building, selected *building) {
|
|
||||||
for _, building := range buildings {
|
|
||||||
|
|
||||||
color := building.color
|
func drawWireframe(building building) {
|
||||||
|
increasedSize := rl.Vector3Scale(building.size, 1.05)
|
||||||
|
|
||||||
if building == selected {
|
invertedColor := building.color
|
||||||
color = rl.RayWhite
|
|
||||||
}
|
|
||||||
|
|
||||||
increasedSize := building.size
|
|
||||||
increasedSize.X += 0.1
|
|
||||||
increasedSize.Y += 0.1
|
|
||||||
increasedSize.Z += 0.1
|
|
||||||
|
|
||||||
invertedColor := color
|
|
||||||
invertedColor.R += 127
|
invertedColor.R += 127
|
||||||
invertedColor.G += 127
|
invertedColor.G += 127
|
||||||
invertedColor.B += 127
|
invertedColor.B += 127
|
||||||
|
|
@ -104,21 +90,65 @@ func draw_buildings(buildings []*building, selected *building) {
|
||||||
increasedSize,
|
increasedSize,
|
||||||
invertedColor,
|
invertedColor,
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func shakeBuilding(b building) animationFunc {
|
||||||
|
var frame remainingFrames = 60 * 0.7
|
||||||
|
return func() remainingFrames {
|
||||||
|
|
||||||
|
building := b
|
||||||
|
|
||||||
|
if frame % 4 == 0 {
|
||||||
|
building.color = rl.RayWhite
|
||||||
|
}
|
||||||
|
|
||||||
|
drawWireframe(building)
|
||||||
|
|
||||||
shake := rl.NewVector3(
|
shake := rl.NewVector3(
|
||||||
|
rand.Float32() * .2 - .1,
|
||||||
rand.Float32() * .1 - .05,
|
rand.Float32() * .1 - .05,
|
||||||
rand.Float32() * .01 - .005,
|
rand.Float32() * .2 - .1,
|
||||||
rand.Float32() * .1 - .05,
|
|
||||||
)
|
)
|
||||||
shake = rl.Vector3Scale(shake, float32(math.Sin(rl.GetTime()) + 1)/3)
|
// shake = rl.Vector3Scale(shake, float32(math.Sin(rl.GetTime()) + 1)/3)
|
||||||
rl.DrawCubeV(
|
rl.DrawCubeV(
|
||||||
rl.Vector3Add(building.pos, shake),
|
rl.Vector3Add(building.pos, shake),
|
||||||
building.size,
|
building.size,
|
||||||
color,
|
building.color,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
frame -= 1
|
||||||
|
return frame
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func mouse_select_building(camera rl.Camera, buildings []*building) *building {
|
|
||||||
|
func draw_buildings(buildings []*building, selected *building) {
|
||||||
|
for _, building := range buildings {
|
||||||
|
|
||||||
|
hasAnimation := building.animate != nil
|
||||||
|
hit := building == selected && !hasAnimation
|
||||||
|
|
||||||
|
if !hit {
|
||||||
|
building.animate = shakeBuilding(*building)
|
||||||
|
}
|
||||||
|
|
||||||
|
if hasAnimation {
|
||||||
|
|
||||||
|
remainingFrames := building.animate()
|
||||||
|
|
||||||
|
if remainingFrames == 0 {
|
||||||
|
building.animate = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
drawWireframe(*building)
|
||||||
|
rl.DrawCubeV(building.pos, building.size, building.color)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func demage_building(camera rl.Camera, buildings []*building) *building {
|
||||||
if !rl.IsMouseButtonPressed(rl.MouseLeftButton) {
|
if !rl.IsMouseButtonPressed(rl.MouseLeftButton) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -187,13 +217,13 @@ func main() {
|
||||||
|
|
||||||
for !rl.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
|
|
||||||
shake := rl.NewVector3(
|
// shake := rl.NewVector3(
|
||||||
rand.Float32() * .4 - .2,
|
// rand.Float32() * .4 - .2,
|
||||||
rand.Float32() * .4 - .2,
|
// rand.Float32() * .4 - .2,
|
||||||
rand.Float32() * .4 - .2,
|
// rand.Float32() * .4 - .2,
|
||||||
)
|
// )
|
||||||
shake = rl.Vector3Scale(shake, float32(math.Sin(rl.GetTime()) + 1)/3)
|
// shake = rl.Vector3Scale(shake, float32(math.Sin(rl.GetTime()) + 1)/3)
|
||||||
camera.Target = rl.Vector3Add(camera.Target, shake)
|
// camera.Target = rl.Vector3Add(camera.Target, shake)
|
||||||
|
|
||||||
rl.UpdateCamera(&camera, rl.CameraFirstPerson)
|
rl.UpdateCamera(&camera, rl.CameraFirstPerson)
|
||||||
rl.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
@ -202,7 +232,7 @@ func main() {
|
||||||
rl.BeginMode3D(camera)
|
rl.BeginMode3D(camera)
|
||||||
{
|
{
|
||||||
|
|
||||||
selected := mouse_select_building(camera, buildings)
|
selected := demage_building(camera, buildings)
|
||||||
|
|
||||||
draw_plane()
|
draw_plane()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue