Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Project Zavi
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mihkelhain
Project Zavi
Commits
37c8bc55
Commit
37c8bc55
authored
4 months ago
by
Jantz
Browse files
Options
Downloads
Patches
Plain Diff
Turrets now rotate
parent
ad36c14d
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
turret.py
+13
-3
13 additions, 3 deletions
turret.py
with
13 additions
and
3 deletions
turret.py
+
13
−
3
View file @
37c8bc55
import
pygame
as
pg
from
enemy
import
Enemy
import
math
class
Turret
(
pg
.
sprite
.
Sprite
):
def
__init__
(
self
,
image
,
pos
):
pg
.
sprite
.
Sprite
.
__init__
(
self
)
self
.
image
=
image
self
.
rect
=
self
.
image
.
get_rect
()
self
.
texture
=
pg
.
image
.
load
(
'
assets/images/turrets/red_turret_128x128.png
'
).
convert_alpha
()
self
.
rotated_texture
=
self
.
texture
self
.
rect
=
self
.
texture
.
get_rect
()
self
.
rotated_rect
=
self
.
rect
self
.
rect
.
center
=
pos
self
.
attack_damage
=
10
...
...
@@ -27,4 +30,11 @@ class Turret(pg.sprite.Sprite):
if
distance
<
nearest_distance
or
nearest_distance
<
0
:
nearest_enemy
=
enemy
nearest_distance
=
distance
return
nearest_enemy
\ No newline at end of file
return
nearest_enemy
def
face_at_the_current_target
(
self
,
target
:
Enemy
):
dx
=
target
.
screen_position
[
0
]
-
self
.
rect
.
center
[
0
]
dy
=
target
.
screen_position
[
1
]
-
self
.
rect
.
center
[
1
]
angle
=
math
.
degrees
(
math
.
atan2
(
-
dy
,
dx
))
self
.
rotated_texture
=
pg
.
transform
.
rotozoom
(
self
.
texture
,
angle
,
1
)
self
.
rotated_rect
=
self
.
rotated_texture
.
get_rect
(
center
=
self
.
rect
.
center
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment