Commit
This commit is contained in:
parent
2c2eaf9507
commit
730e697258
1 changed files with 336 additions and 335 deletions
63
main.go
63
main.go
|
|
@ -4,6 +4,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"slices"
|
||||||
|
|
||||||
rl "github.com/gen2brain/raylib-go/raylib"
|
rl "github.com/gen2brain/raylib-go/raylib"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -25,7 +27,7 @@ type enemy struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type remainingFrames int
|
type remainingFrames int
|
||||||
type animationFunc func()remainingFrames
|
type animationFunc func() remainingFrames
|
||||||
|
|
||||||
type building struct {
|
type building struct {
|
||||||
pos rl.Vector3
|
pos rl.Vector3
|
||||||
|
|
@ -76,11 +78,16 @@ type emitter struct {
|
||||||
var city *scene
|
var city *scene
|
||||||
|
|
||||||
func update_emitters() {
|
func update_emitters() {
|
||||||
for i, e := range city.emitters {
|
for i := 0; i < len(city.emitters); i++ {
|
||||||
if remainingParticles := e.update(); remainingParticles == 0 {
|
|
||||||
city.emitters[i] = city.emitters[len(city.emitters)-1]
|
e := city.emitters[i]
|
||||||
city.emitters = city.emitters[:len(city.emitters)-1]
|
remainingParticles := e.update()
|
||||||
|
|
||||||
|
if remainingParticles == 0 {
|
||||||
|
city.emitters = slices.Delete(city.emitters, i, i+1)
|
||||||
|
i--
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -92,12 +99,12 @@ func newEmitter(pos rl.Vector3, particleAmount int) *emitter {
|
||||||
|
|
||||||
for i := 0; i < particleAmount; i++ {
|
for i := 0; i < particleAmount; i++ {
|
||||||
direction := rl.NewVector3(
|
direction := rl.NewVector3(
|
||||||
rand.Float32()*2 - 1,
|
rand.Float32()*2-1,
|
||||||
1,
|
1,
|
||||||
rand.Float32()*2 - 1,
|
rand.Float32()*2-1,
|
||||||
)
|
)
|
||||||
direction = rl.Vector3Normalize(direction)
|
direction = rl.Vector3Normalize(direction)
|
||||||
direction = rl.Vector3Scale(direction, 0.3 + rand.Float32()/3)
|
direction = rl.Vector3Scale(direction, 0.3+rand.Float32()/3)
|
||||||
particle := particle{
|
particle := particle{
|
||||||
lifetime: rl.GetTime() + 2,
|
lifetime: rl.GetTime() + 2,
|
||||||
speed: direction,
|
speed: direction,
|
||||||
|
|
@ -168,7 +175,6 @@ func update_projectiles() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (c *character) kill_aurea() {
|
func (c *character) kill_aurea() {
|
||||||
const min = 10
|
const min = 10
|
||||||
for _, b := range city.buildings {
|
for _, b := range city.buildings {
|
||||||
|
|
@ -178,7 +184,7 @@ func (c *character) kill_aurea() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *character) throw_bomb(){
|
func (c *character) throw_bomb() {
|
||||||
if !rl.IsMouseButtonPressed(rl.MouseRightButton) {
|
if !rl.IsMouseButtonPressed(rl.MouseRightButton) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -195,9 +201,9 @@ func (c *character) throw_bomb(){
|
||||||
|
|
||||||
func (c *character) update() {
|
func (c *character) update() {
|
||||||
shake := rl.NewVector3(
|
shake := rl.NewVector3(
|
||||||
randomShake(0.003) * city.healthBar.damageTaken,
|
randomShake(0.003)*city.healthBar.damageTaken,
|
||||||
randomShake(0.003) * city.healthBar.damageTaken,
|
randomShake(0.003)*city.healthBar.damageTaken,
|
||||||
randomShake(0.003) * city.healthBar.damageTaken,
|
randomShake(0.003)*city.healthBar.damageTaken,
|
||||||
)
|
)
|
||||||
c.camera.Target = rl.Vector3Add(c.camera.Target, shake)
|
c.camera.Target = rl.Vector3Add(c.camera.Target, shake)
|
||||||
|
|
||||||
|
|
@ -232,7 +238,7 @@ func draw_plane() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func randomShake(amount float32) float32 {
|
func randomShake(amount float32) float32 {
|
||||||
return rand.Float32() * amount - amount/2
|
return rand.Float32()*amount - amount/2
|
||||||
}
|
}
|
||||||
|
|
||||||
func (hb *healthBar) update() {
|
func (hb *healthBar) update() {
|
||||||
|
|
@ -245,7 +251,7 @@ func (hb *healthBar) update() {
|
||||||
currentLife += b.life
|
currentLife += b.life
|
||||||
}
|
}
|
||||||
position := rl.NewVector2(MARGIN, 10)
|
position := rl.NewVector2(MARGIN, 10)
|
||||||
barWidth := BARWIDTH * currentLife/maxLife
|
barWidth := BARWIDTH * currentLife / maxLife
|
||||||
|
|
||||||
size := rl.NewVector2(float32(barWidth), 10)
|
size := rl.NewVector2(float32(barWidth), 10)
|
||||||
|
|
||||||
|
|
@ -256,8 +262,8 @@ func (hb *healthBar) update() {
|
||||||
(float32(currentLife) + hb.damageTaken) / float32(maxLife)
|
(float32(currentLife) + hb.damageTaken) / float32(maxLife)
|
||||||
|
|
||||||
shake := rl.NewVector2(
|
shake := rl.NewVector2(
|
||||||
randomShake(0.4) * hb.damageTaken,
|
randomShake(0.4)*hb.damageTaken,
|
||||||
randomShake(0.4) * hb.damageTaken,
|
randomShake(0.4)*hb.damageTaken,
|
||||||
)
|
)
|
||||||
position = rl.Vector2Add(position, shake)
|
position = rl.Vector2Add(position, shake)
|
||||||
|
|
||||||
|
|
@ -292,21 +298,21 @@ func newBuilding(x, z float32) *building {
|
||||||
255,
|
255,
|
||||||
)
|
)
|
||||||
|
|
||||||
pos := rl.NewVector3(x * buildingSpacing, 0, z * buildingSpacing)
|
pos := rl.NewVector3(x*buildingSpacing, 0, z*buildingSpacing)
|
||||||
size := rl.NewVector3(
|
size := rl.NewVector3(
|
||||||
buildingSize,
|
buildingSize,
|
||||||
float32(rl.GetRandomValue(1, maxBuildingHeight)),
|
float32(rl.GetRandomValue(1, maxBuildingHeight)),
|
||||||
buildingSize,
|
buildingSize,
|
||||||
)
|
)
|
||||||
min := rl.NewVector3(
|
min := rl.NewVector3(
|
||||||
pos.X - buildingSize/2,
|
pos.X-buildingSize/2,
|
||||||
0,
|
0,
|
||||||
pos.Z - buildingSize/2,
|
pos.Z-buildingSize/2,
|
||||||
)
|
)
|
||||||
max := rl.NewVector3(
|
max := rl.NewVector3(
|
||||||
pos.X + buildingSize/2,
|
pos.X+buildingSize/2,
|
||||||
size.Y/2,
|
size.Y/2,
|
||||||
pos.Z + buildingSize/2,
|
pos.Z+buildingSize/2,
|
||||||
)
|
)
|
||||||
|
|
||||||
return &building{
|
return &building{
|
||||||
|
|
@ -318,7 +324,6 @@ func newBuilding(x, z float32) *building {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func drawWireframe(building building) {
|
func drawWireframe(building building) {
|
||||||
increasedSize := rl.Vector3Scale(building.size, 1.05)
|
increasedSize := rl.Vector3Scale(building.size, 1.05)
|
||||||
|
|
||||||
|
|
@ -340,7 +345,7 @@ func shakeBuilding(b *building) animationFunc {
|
||||||
|
|
||||||
building := *b
|
building := *b
|
||||||
|
|
||||||
if frame % 4 == 0 {
|
if frame%4 == 0 {
|
||||||
if b.life == 0 {
|
if b.life == 0 {
|
||||||
building.color = rl.NewColor(255, 0, 0, 255)
|
building.color = rl.NewColor(255, 0, 0, 255)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -351,9 +356,9 @@ func shakeBuilding(b *building) animationFunc {
|
||||||
drawWireframe(building)
|
drawWireframe(building)
|
||||||
|
|
||||||
shake := rl.NewVector3(
|
shake := rl.NewVector3(
|
||||||
rand.Float32() * .2 - .1,
|
rand.Float32()*.2-.1,
|
||||||
rand.Float32() * .1 - .05,
|
rand.Float32()*.1-.05,
|
||||||
rand.Float32() * .2 - .1,
|
rand.Float32()*.2-.1,
|
||||||
)
|
)
|
||||||
// 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(
|
||||||
|
|
@ -367,7 +372,6 @@ func shakeBuilding(b *building) animationFunc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func draw_buildings() {
|
func draw_buildings() {
|
||||||
for _, building := range city.buildings {
|
for _, building := range city.buildings {
|
||||||
|
|
||||||
|
|
@ -466,7 +470,6 @@ func main() {
|
||||||
|
|
||||||
for !rl.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
|
|
||||||
|
|
||||||
rl.UpdateCamera(&character.camera, rl.CameraFirstPerson)
|
rl.UpdateCamera(&character.camera, rl.CameraFirstPerson)
|
||||||
rl.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
rl.ClearBackground(rl.LightGray)
|
rl.ClearBackground(rl.LightGray)
|
||||||
|
|
@ -483,8 +486,6 @@ func main() {
|
||||||
|
|
||||||
update_emitters()
|
update_emitters()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// direction = rl.Vector3Subtract(
|
// direction = rl.Vector3Subtract(
|
||||||
// character.camera.Target, character.camera.Position)
|
// character.camera.Target, character.camera.Position)
|
||||||
// aim = rl.Vector3Lerp(direction, aim, 0.95)
|
// aim = rl.Vector3Lerp(direction, aim, 0.95)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue