-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathilevel.go
More file actions
133 lines (113 loc) · 2.8 KB
/
Copy pathilevel.go
File metadata and controls
133 lines (113 loc) · 2.8 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package main
import (
"slices"
"time"
"github.com/hajimehoshi/ebiten/v2"
"github.com/setanarut/coll"
)
const (
ParryFreezeDuration = time.Millisecond * 150
DamageFlashDuration = time.Millisecond * 100
)
type ILevel interface {
Init()
Update()
Draw(s *ebiten.Image)
Bodies() *[]*Body
OnBodyRemove(b *Body)
OnParry(b *Body)
OnDamage(b *Body)
OnSensorEntered(b *Body)
Save()
Load()
}
func UpdateILevel(lvl ILevel) {
if GamePaused {
return
}
if GameFreeze {
GameFreezeTimer += Tick
if GameFreezeTimer >= ParryFreezeDuration {
GameFreeze = false
GameFreezeTimer = 0
}
}
if !GameFreeze {
for _, b := range *lvl.Bodies() {
b.Update()
}
lvl.Update()
Cuphead.Update()
ShootManag.Update()
for _, body := range *lvl.Bodies() {
for _, sh := range body.Shapes {
switch shape := sh.(type) {
// level.go içindeki switch bloğu yerine:
case *BoxShape:
playerBox(Cuphead, shape, lvl)
// PLAYER-BOX
if !shape.IgnoreBullet {
ShootManag.Bullets = slices.DeleteFunc(ShootManag.Bullets, func(blt *Bullet) bool {
// 1. Ekran dışı kontrolü (Önce ucuz işlem)
if blt.Pos.X > MainCamera.Right() || blt.Pos.X < MainCamera.X ||
blt.Pos.Y < MainCamera.Y || blt.Pos.Y > MainCamera.Bottom() {
ShootManag.SpawnDeathEffect(blt.Pos)
return true
}
// 2. Çarpışma yoksa devam et
if !shape.Solid || !coll.BoxCircleSweep2(&shape.AABB, &blt.Circle, shape.GetDelta(), blt.vel, nil) {
return false
}
// 3. Çarpışma gerçekleşti
if shape.CanTakeBulletDamage {
body.Hp--
body.DamageFlash()
}
ShootManag.SpawnDeathEffect(blt.Pos)
return true
})
}
case *CircleShape:
// PLAYER-CIRCLE
playerCircle(Cuphead, shape, lvl)
// BULLETS-CIRCLE
ShootManag.Bullets = slices.DeleteFunc(
ShootManag.Bullets,
func(blt *Bullet) bool {
if !shape.IgnoreBullet {
if coll.CircleCircleSweep2(&shape.Circle, &blt.Circle, shape.GetDelta(), blt.vel, nil) {
if shape.Solid {
if shape.CanTakeBulletDamage {
body.Hp--
body.DamageFlash()
lvl.OnDamage(body)
}
ShootManag.SpawnDeathEffect(blt.Pos)
return true
}
}
}
offScreen := blt.Pos.X > MainCamera.Right() ||
blt.Pos.X < MainCamera.X ||
blt.Pos.Y < MainCamera.Y ||
blt.Pos.Y > MainCamera.Bottom()
if offScreen {
ShootManag.SpawnDeathEffect(blt.Pos)
}
return offScreen
},
)
}
}
}
// Remove bodies
bd := lvl.Bodies()
*bd = slices.DeleteFunc(*bd, func(body *Body) bool {
shouldRemove := body.Hp <= 0
if shouldRemove {
lvl.OnBodyRemove(body)
}
return shouldRemove
})
}
}