-
Notifications
You must be signed in to change notification settings - Fork 0
/
basic_enemy.go
49 lines (39 loc) · 1.13 KB
/
basic_enemy.go
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
package main
import (
"fmt"
"github.com/veandco/go-sdl2/sdl"
)
const basicEnemySize = 105
// creates a basic enemy
func newBasicEnemy(renderer *sdl.Renderer, x, y float64) *element {
basicEnemy := &element{}
// establishes position
basicEnemy.position = vector{x: x, y: y}
// establishes roation
basicEnemy.rotation = 180
idleSequence, err := newSequence("sprites/basic_enemy/idle", 5, true, renderer)
if err != nil {
panic(fmt.Errorf("creating idle sequence: %v", err))
}
destroySequence, err := newSequence("sprites/basic_enemy/destroy", 15, false, renderer)
if err != nil {
panic(fmt.Errorf("creating destroy sequence: %v", err))
}
sequences := map[string]*sequence{
"idle": idleSequence,
"destroy": destroySequence,
}
animator := newAnimator(basicEnemy, sequences, "idle")
basicEnemy.addComponent(animator)
// render from bmp file
// Add basic enemy components to element
vtb := newVulnerableToBullets(basicEnemy)
basicEnemy.addComponent(vtb)
col := circle{
center: basicEnemy.position,
radius: 38,
}
basicEnemy.collisions = append(basicEnemy.collisions, col)
basicEnemy.active = true
return basicEnemy
}