Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
DoodleJumpAI
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
Tommy Billington
DoodleJumpAI
Commits
b428d1b1
Commit
b428d1b1
authored
11 months ago
by
Nicholas Danh
Browse files
Options
Downloads
Patches
Plain Diff
max agent (check in player.py update function)
parent
bb79b5b4
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
player.py
+29
-1
29 additions, 1 deletion
player.py
with
29 additions
and
1 deletion
player.py
+
29
−
1
View file @
b428d1b1
...
@@ -18,7 +18,7 @@
...
@@ -18,7 +18,7 @@
"""
"""
from
math
import
copysign
from
math
import
copysign
,
sqrt
from
pygame.math
import
Vector2
from
pygame.math
import
Vector2
from
pygame.locals
import
KEYDOWN
,
KEYUP
,
K_LEFT
,
K_RIGHT
from
pygame.locals
import
KEYDOWN
,
KEYUP
,
K_LEFT
,
K_RIGHT
from
pygame.sprite
import
collide_rect
from
pygame.sprite
import
collide_rect
...
@@ -137,6 +137,34 @@ class Player(Sprite, Singleton):
...
@@ -137,6 +137,34 @@ class Player(Sprite, Singleton):
if
self
.
camera_rect
.
y
>
config
.
YWIN
*
2
:
if
self
.
camera_rect
.
y
>
config
.
YWIN
*
2
:
self
.
dead
=
True
self
.
dead
=
True
return
return
lvl
=
Level
.
instance
if
not
len
(
lvl
.
platforms
):
return
platx
=
Level
.
instance
.
platforms
[
0
].
rect
.
centerx
platy
=
Level
.
instance
.
platforms
[
0
].
rect
.
centery
player_x
=
self
.
rect
.
centerx
player_y
=
self
.
rect
.
bottom
dist
=
[]
for
platform
in
lvl
.
platforms
:
weight
=
5
if
platform
.
rect
.
centery
>
player_y
else
50
dist
.
append
((
sqrt
((
platform
.
rect
.
centerx
-
player_x
)
**
2
+
weight
*
(
platform
.
rect
.
top
-
player_y
)
**
2
),
platform
))
if
len
(
dist
)
>
0
:
closest
=
min
(
dist
)
closest_platform
=
closest
[
1
]
if
player_x
>
closest_platform
.
rect
.
centerx
:
self
.
_velocity
.
x
=-
self
.
__startspeed
*
closest
[
0
]
/
10
self
.
_input
=
-
1
elif
player_x
<
closest_platform
.
rect
.
centerx
:
self
.
_velocity
.
x
=
self
.
__startspeed
*
closest
[
0
]
/
10
self
.
_input
=
1
else
:
self
.
_input
=
0
#Velocity update (apply gravity, input acceleration)
#Velocity update (apply gravity, input acceleration)
self
.
_velocity
.
y
+=
self
.
gravity
self
.
_velocity
.
y
+=
self
.
gravity
if
self
.
_input
:
# accelerate
if
self
.
_input
:
# accelerate
...
...
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