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
c5a49e19
Commit
c5a49e19
authored
10 months ago
by
Nicholas Danh
Browse files
Options
Downloads
Patches
Plain Diff
latest agent
parent
fe201cf3
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
+2
-2
2 additions, 2 deletions
level.py
player.py
+41
-18
41 additions, 18 deletions
player.py
settings.py
+7
-7
7 additions, 7 deletions
settings.py
with
50 additions
and
27 deletions
level.py
+
2
−
2
View file @
c5a49e19
...
@@ -191,7 +191,7 @@ class Level(Singleton):
...
@@ -191,7 +191,7 @@ 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
.
HALF_
YWIN
,
# Y POS
config
.
YWIN
/
8
,
# Y POS
*
self
.
monster_size
)
# SIZE
*
self
.
monster_size
)
# SIZE
...
@@ -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
(
1
,
3
),
speed
=
randint
(
1
,
2
),
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
+
41
−
18
View file @
c5a49e19
...
@@ -154,16 +154,40 @@ class Player(Sprite, Singleton):
...
@@ -154,16 +154,40 @@ class Player(Sprite, Singleton):
player_x
=
self
.
rect
.
centerx
player_x
=
self
.
rect
.
centerx
player_y
=
self
.
rect
.
centery
player_y
=
self
.
rect
.
centery
game_window_width
=
config
.
XWIN
-
self
.
rect
.
width
dist
=
[]
dist
=
[]
for
platform
in
lvl
.
platforms
:
for
platform
in
lvl
.
platforms
:
weight
=
2
0
if
platform
.
rect
.
centery
>
player_y
else
4
0
y_
weight
=
4
0
if
platform
.
rect
.
top
<
player_y
else
2
0
if
not
collide_rect
(
self
,
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
))
platform_x
=
platform
.
rect
.
centerx
if
(
abs
(
player_x
-
platform_x
)
<=
game_window_width
/
2
):
dist
.
append
((
sqrt
((
platform_x
-
player_x
)
**
2
+
(
y_weight
*
(
platform
.
rect
.
top
-
player_y
+
random
.
random
()))
**
2
),
platform
))
else
:
if
player_x
<
platform_x
:
dist
.
append
((
sqrt
((
game_window_width
-
platform_x
+
player_x
)
**
2
+
(
y_weight
*
(
platform
.
rect
.
top
-
player_y
+
random
.
random
()))
**
2
),
platform
))
else
:
dist
.
append
((
sqrt
((
game_window_width
+
platform_x
-
player_x
)
**
2
+
(
y_weight
*
(
platform
.
rect
.
top
-
player_y
+
random
.
random
()))
**
2
),
platform
))
danger_zone_x
=
self
.
rect
.
width
*
2
danger_zone_y
=
self
.
rect
.
height
*
2
for
monster
in
lvl
.
monsters
:
for
monster
in
lvl
.
monsters
:
weight
=
20
y_weight
=
20
if
monster
.
rect
.
bottom
<
player_y
else
10
if
monster
.
rect
.
centery
<
player_y
+
self
.
rect
.
height
:
monster_x
=
monster
.
rect
.
centerx
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
))
monster_y
=
monster
.
rect
.
centery
if
(
abs
(
player_x
-
monster_x
)
<=
game_window_width
/
2
):
if
abs
(
player_x
-
monster_x
)
<
danger_zone_x
and
abs
(
player_y
-
monster_y
)
<
danger_zone_y
:
dist
.
append
((
sqrt
((
monster_x
-
player_x
)
**
2
+
(
y_weight
*
(
monster_y
-
player_y
+
random
.
random
()))
**
2
),
monster
))
else
:
if
player_x
<
monster_x
:
x_dist
=
game_window_width
-
monster_x
+
player_x
if
abs
(
x_dist
)
<
danger_zone_x
and
abs
(
player_y
-
monster_y
)
<
danger_zone_y
:
dist
.
append
((
sqrt
((
x_dist
)
**
2
+
(
y_weight
*
(
monster_y
-
player_y
+
random
.
random
()))
**
2
),
monster
))
else
:
x_dist
=
game_window_width
+
monster_x
-
player_x
if
abs
(
x_dist
)
<
danger_zone_x
and
abs
(
player_y
-
monster_y
)
<
danger_zone_y
:
dist
.
append
((
sqrt
((
x_dist
)
**
2
+
(
y_weight
*
(
monster_y
-
player_y
+
random
.
random
()))
**
2
),
monster
))
...
@@ -173,30 +197,29 @@ class Player(Sprite, Singleton):
...
@@ -173,30 +197,29 @@ class Player(Sprite, Singleton):
speed_reduction
=
25
speed_reduction
=
25
if
not
isinstance
(
closest_object
,
Monster
):
if
not
isinstance
(
closest_object
,
Monster
):
platform_x
=
closest_object
.
rect
.
centerx
platform_x
=
closest_object
.
rect
.
centerx
game_window_width
=
config
.
XWIN
-
self
.
rect
.
width
if
((
player_x
>
platform_x
and
abs
(
player_x
-
platform_x
)
<=
game_window_width
/
2
)
or
if
((
player_x
>
platform_x
and
abs
(
player_x
-
platform_x
)
<
game_window_width
/
2
)
or
(
player_x
<
platform_x
and
abs
(
player_x
-
platform_x
)
>
game_window_width
/
2
)):
(
player_x
<
platform_x
and
abs
(
player_x
-
platform_x
)
>
game_window_width
/
2
)):
self
.
_velocity
.
x
=-
self
.
__startspeed
*
closest
[
0
]
/
speed_reduction
self
.
_velocity
.
x
=-
self
.
__startspeed
*
closest
[
0
]
/
speed_reduction
self
.
_input
=
-
1
self
.
_input
=
0
elif
((
player_x
<
platform_x
and
abs
(
player_x
-
platform_x
)
<
game_window_width
/
2
)
or
elif
((
player_x
<
platform_x
and
abs
(
player_x
-
platform_x
)
<
=
game_window_width
/
2
)
or
(
player_x
>
platform_x
and
abs
(
player_x
-
platform_x
)
>
game_window_width
/
2
)):
(
player_x
>
platform_x
and
abs
(
player_x
-
platform_x
)
>
game_window_width
/
2
)):
self
.
_velocity
.
x
=
self
.
__startspeed
*
closest
[
0
]
/
speed_reduction
self
.
_velocity
.
x
=
self
.
__startspeed
*
closest
[
0
]
/
speed_reduction
self
.
_input
=
1
self
.
_input
=
0
else
:
else
:
self
.
_velocity
.
x
=
0
self
.
_input
=
0
self
.
_input
=
0
else
:
else
:
monster_x
=
closest_object
.
rect
.
centerx
monster_x
=
closest_object
.
rect
.
centerx
monster_y
=
closest_object
.
rect
.
centery
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
):
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
.
_velocity
.
x
=
self
.
__startspeed
*
closest
[
0
]
if
player_y
>
monster_y
else
-
self
.
__startspeed
*
closest
[
0
]
self
.
_input
=
1
self
.
_input
=
0
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
):
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
.
_velocity
.
x
=-
self
.
__startspeed
*
closest
[
0
]
if
player_y
>
monster_y
else
self
.
__startspeed
*
closest
[
0
]
self
.
_input
=
-
1
self
.
_input
=
0
else
:
else
:
self
.
_velocity
.
x
=
0
self
.
_input
=
0
self
.
_input
=
0
...
...
This diff is collapsed.
Click to expand it.
settings.py
+
7
−
7
View file @
c5a49e19
...
@@ -23,11 +23,11 @@ LIGHT_BLUE = (173,216,230)
...
@@ -23,11 +23,11 @@ LIGHT_BLUE = (173,216,230)
RED
=
(
255
,
0
,
0
)
RED
=
(
255
,
0
,
0
)
# Player
# Player
PLAYER_SIZE
=
(
2
5
,
3
5
)
PLAYER_SIZE
=
(
1
5
,
1
5
)
PLAYER_COLOR
=
PINK_BEAN
PLAYER_COLOR
=
PINK_BEAN
PLAYER_MAX_SPEED
=
20
PLAYER_MAX_SPEED
=
20
PLAYER_JUMPFORCE
=
20
PLAYER_JUMPFORCE
=
20
PLAYER_BONUS_JUMPFORCE
=
7
0
PLAYER_BONUS_JUMPFORCE
=
4
0
GRAVITY
=
.
98
GRAVITY
=
.
98
# Platforms
# Platforms
...
@@ -35,16 +35,16 @@ PLATFORM_COLOR = FOREST_GREEN
...
@@ -35,16 +35,16 @@ PLATFORM_COLOR = FOREST_GREEN
PLATFORM_COLOR_LIGHT
=
LIGHT_BLUE
PLATFORM_COLOR_LIGHT
=
LIGHT_BLUE
MOB_COLOR
=
BLACK
MOB_COLOR
=
BLACK
MOVING_MOB_COLOR
=
RED
MOVING_MOB_COLOR
=
RED
PLATFORM_SIZE
=
(
1
0
0
,
10
)
PLATFORM_SIZE
=
(
1
1
0
,
10
)
MONSTER_SIZE
=
(
20
,
20
)
MONSTER_SIZE
=
(
15
,
20
)
PLATFORM_DISTANCE_GAP
=
(
50
,
2
10
)
PLATFORM_DISTANCE_GAP
=
(
50
,
1
8
0
)
MONSTER_DISTANCE_GAP
=
(
350
,
500
)
MONSTER_DISTANCE_GAP
=
(
350
,
500
)
MAX_PLATFORM_NUMBER
=
10
MAX_PLATFORM_NUMBER
=
10
MAX_MONSTER_NUMBER
=
2
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
=
5
MOVING_MONSTER_CHANCE
=
12
MOVING_MONSTER_CHANCE
=
3
# 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