-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenemy.go
77 lines (66 loc) · 2.45 KB
/
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package game_manager
import (
"fmt"
"github.com/veandco/go-sdl2/sdl"
)
type Enemy struct {
position Vector2D
velocity Vector2D
acceleration Vector2D
width int32
height int32
textureID string
currentRow int
currentFrame int32
}
//*****************************************************************************
// NewEnemy
//*****************************************************************************
func NewEnemy(x float32, y float32, width int32, height int32, textureID string) *Enemy {
return &Enemy{position: Vector2D{x, y}, velocity: Vector2D{0.001, 2}, width: width, height: height, textureID: textureID,
currentRow: 1, currentFrame: 1}
}
//*****************************************************************************
// Position
//*****************************************************************************
func (enemy *Enemy) Position() Vector2D {
return enemy.position
}
//*****************************************************************************
// Width
//*****************************************************************************
func (enemy *Enemy) Width() int32 {
return enemy.width
}
//*****************************************************************************
// Height
//*****************************************************************************
func (enemy *Enemy) Height() int32 {
return enemy.height
}
//*****************************************************************************
// draw
//*****************************************************************************
func (enemy *Enemy) draw(game *Game) {
game.textureManager.drawFrame(enemy.textureID, enemy.position.X, enemy.position.Y, enemy.width, enemy.height, enemy.currentRow,
enemy.currentFrame, game.renderer, sdl.FLIP_NONE)
}
//*****************************************************************************
// update
//*****************************************************************************
func (enemy *Enemy) update(game *Game) {
enemy.currentFrame = int32(((sdl.GetTicks() / 100) % 6))
if enemy.position.Y < 0 {
enemy.velocity.Y = 2
} else if enemy.position.Y > 400 {
enemy.velocity.Y = -2
}
// enemy.velocity = enemy.velocity.Add(&enemy.acceleration)
enemy.position = enemy.position.Add(&enemy.velocity)
}
//*****************************************************************************
// clean
//*****************************************************************************
func (enemy *Enemy) clean() {
fmt.Println("clean enemy")
}