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
fe201cf3
Commit
fe201cf3
authored
10 months ago
by
Nicholas Danh
Browse files
Options
Downloads
Patches
Plain Diff
fixed monster spawning. need to figure out how to
make the agent work better
parent
6b0cb84e
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
level.py
+3
-3
3 additions, 3 deletions
level.py
player.py
+42
-15
42 additions, 15 deletions
player.py
settings.py
+3
-3
3 additions, 3 deletions
settings.py
with
48 additions
and
21 deletions
level.py
+
3
−
3
View file @
fe201cf3
...
@@ -191,8 +191,8 @@ class Level(Singleton):
...
@@ -191,8 +191,8 @@ class Level(Singleton):
self
.
__base_monster
=
Monster
(
self
.
__base_monster
=
Monster
(
config
.
HALF_XWIN
-
self
.
platform_size
[
0
]
//
2
,
# X POS
config
.
HALF_XWIN
-
self
.
platform_size
[
0
]
//
2
,
# X POS
config
.
YWIN
+
config
.
YWIN
/
3
,
# Y POS
config
.
HALF_YWIN
,
# Y POS
*
self
.
platform
_size
)
# SIZE
*
self
.
monster
_size
)
# SIZE
@property
@property
...
@@ -245,7 +245,7 @@ class Level(Singleton):
...
@@ -245,7 +245,7 @@ class Level(Singleton):
randint
(
0
,
config
.
XWIN
-
self
.
monster_size
[
0
]),
randint
(
0
,
config
.
XWIN
-
self
.
monster_size
[
0
]),
self
.
__monsters
[
-
1
].
rect
.
y
-
offset
,
self
.
__monsters
[
-
1
].
rect
.
y
-
offset
,
*
self
.
monster_size
,
*
self
.
monster_size
,
speed
=
randint
(
2
,
4
),
speed
=
randint
(
1
,
3
),
direction
=
randint
(
0
,
1
)
*
2
-
1
)
direction
=
randint
(
0
,
1
)
*
2
-
1
)
else
:
else
:
new_monster
=
Monster
(
new_monster
=
Monster
(
...
...
This diff is collapsed.
Click to expand it.
player.py
+
42
−
15
View file @
fe201cf3
...
@@ -27,6 +27,8 @@ from pygame.event import Event
...
@@ -27,6 +27,8 @@ from pygame.event import Event
from
singleton
import
Singleton
from
singleton
import
Singleton
from
sprite
import
Sprite
from
sprite
import
Sprite
from
level
import
Level
from
level
import
Level
from
level
import
Monster
import
random
import
settings
as
config
import
settings
as
config
...
@@ -150,28 +152,53 @@ class Player(Sprite, Singleton):
...
@@ -150,28 +152,53 @@ class Player(Sprite, Singleton):
if
not
len
(
lvl
.
platforms
):
return
if
not
len
(
lvl
.
platforms
):
return
player_x
=
self
.
rect
.
centerx
player_x
=
self
.
rect
.
centerx
player_y
=
self
.
rect
.
bottom
player_y
=
self
.
rect
.
centery
dist
=
[]
dist
=
[]
for
platform
in
lvl
.
platforms
:
for
platform
in
lvl
.
platforms
:
weight
=
20
if
platform
.
rect
.
top
>
player_y
else
40
weight
=
20
if
platform
.
rect
.
centery
>
player_y
else
40
dist
.
append
((
sqrt
((
platform
.
rect
.
centerx
-
player_x
)
**
2
+
(
weight
*
(
platform
.
rect
.
top
-
player_y
))
**
2
),
platform
))
if
not
collide_rect
(
self
,
platform
):
dist
.
append
((
sqrt
((
min
(
abs
(
platform
.
rect
.
left
-
player_x
),
abs
(
platform
.
rect
.
right
-
player_x
)))
**
2
+
(
weight
*
(
platform
.
rect
.
bottom
-
player_y
))
**
2
),
platform
))
for
monster
in
lvl
.
monsters
:
weight
=
20
if
monster
.
rect
.
centery
<
player_y
+
self
.
rect
.
height
:
dist
.
append
((
sqrt
((
min
(
abs
(
monster
.
rect
.
left
-
player_x
),
abs
(
monster
.
rect
.
right
-
player_x
)))
**
2
+
(
weight
*
(
min
(
abs
(
monster
.
rect
.
bottom
-
player_y
),
abs
(
monster
.
rect
.
top
-
player_y
))))
**
2
),
monster
))
if
len
(
dist
)
>
0
:
if
len
(
dist
)
>
0
:
closest
=
min
(
dist
)
closest
=
min
(
dist
)
closest_platform
=
closest
[
1
]
closest_object
=
closest
[
1
]
platform_x
=
closest_platform
.
rect
.
centerx
speed_reduction
=
25
game_window_width
=
config
.
XWIN
-
self
.
rect
.
width
if
not
isinstance
(
closest_object
,
Monster
):
if
((
player_x
>
platform_x
and
abs
(
player_x
-
platform_x
<
game_window_width
/
2
))
or
platform_x
=
closest_object
.
rect
.
centerx
(
player_x
<
platform_x
and
abs
(
player_x
-
platform_x
)
>
game_window_width
/
2
)):
game_window_width
=
config
.
XWIN
-
self
.
rect
.
width
self
.
_velocity
.
x
=-
self
.
__startspeed
*
closest
[
0
]
/
30
if
((
player_x
>
platform_x
and
abs
(
player_x
-
platform_x
)
<
game_window_width
/
2
)
or
self
.
_input
=
-
1
(
player_x
<
platform_x
and
abs
(
player_x
-
platform_x
)
>
game_window_width
/
2
)):
elif
((
player_x
<
platform_x
and
abs
(
player_x
-
platform_x
<
game_window_width
/
2
))
or
self
.
_velocity
.
x
=-
self
.
__startspeed
*
closest
[
0
]
/
speed_reduction
(
player_x
>
platform_x
and
abs
(
player_x
-
platform_x
)
>
game_window_width
/
2
)):
self
.
_input
=
-
1
self
.
_velocity
.
x
=
self
.
__startspeed
*
closest
[
0
]
/
30
elif
((
player_x
<
platform_x
and
abs
(
player_x
-
platform_x
)
<
game_window_width
/
2
)
or
self
.
_input
=
1
(
player_x
>
platform_x
and
abs
(
player_x
-
platform_x
)
>
game_window_width
/
2
)):
self
.
_velocity
.
x
=
self
.
__startspeed
*
closest
[
0
]
/
speed_reduction
self
.
_input
=
1
else
:
self
.
_input
=
0
else
:
else
:
self
.
_input
=
0
monster_x
=
closest_object
.
rect
.
centerx
monster_y
=
closest_object
.
rect
.
centery
danger_zone_x
=
self
.
rect
.
width
/
2
danger_zone_y
=
self
.
rect
.
height
/
2
if
((
player_x
>=
monster_x
and
abs
(
closest_object
.
rect
.
right
-
player_x
)
<
danger_zone_x
)
and
abs
(
monster_y
-
player_y
)
<
danger_zone_y
):
self
.
_velocity
.
x
=
self
.
__startspeed
*
closest
[
0
]
*
speed_reduction
self
.
_input
=
1
elif
((
player_x
<=
monster_x
and
abs
(
closest_object
.
rect
.
left
-
player_x
)
<
danger_zone_x
)
and
abs
(
monster_y
-
player_y
)
<
danger_zone_y
):
self
.
_velocity
.
x
=-
self
.
__startspeed
*
closest
[
0
]
*
speed_reduction
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
...
...
This diff is collapsed.
Click to expand it.
settings.py
+
3
−
3
View file @
fe201cf3
...
@@ -38,13 +38,13 @@ MOVING_MOB_COLOR = RED
...
@@ -38,13 +38,13 @@ MOVING_MOB_COLOR = RED
PLATFORM_SIZE
=
(
100
,
10
)
PLATFORM_SIZE
=
(
100
,
10
)
MONSTER_SIZE
=
(
20
,
20
)
MONSTER_SIZE
=
(
20
,
20
)
PLATFORM_DISTANCE_GAP
=
(
50
,
210
)
PLATFORM_DISTANCE_GAP
=
(
50
,
210
)
MONSTER_DISTANCE_GAP
=
(
10
0
,
500
)
MONSTER_DISTANCE_GAP
=
(
35
0
,
500
)
MAX_PLATFORM_NUMBER
=
10
MAX_PLATFORM_NUMBER
=
10
MAX_MONSTER_NUMBER
=
3
MAX_MONSTER_NUMBER
=
2
BONUS_SPAWN_CHANCE
=
10
BONUS_SPAWN_CHANCE
=
10
BREAKABLE_PLATFORM_CHANCE
=
12
BREAKABLE_PLATFORM_CHANCE
=
12
STATIONARY_MONSTER_CHANCE
=
10
STATIONARY_MONSTER_CHANCE
=
10
MOVING_MONSTER_CHANCE
=
1
0
MOVING_MONSTER_CHANCE
=
1
2
# Fonts
# Fonts
LARGE_FONT
=
SysFont
(
""
,
128
)
LARGE_FONT
=
SysFont
(
""
,
128
)
...
...
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