Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CM1101 Team Project
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
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
Code review analytics
Issue analytics
Insights
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
Harry Wyatt
CM1101 Team Project
Commits
c07cf3d0
Commit
c07cf3d0
authored
2 years ago
by
Matthew Aked
Browse files
Options
Downloads
Patches
Plain Diff
Contains classes for the moving objects in the minigame
parent
80014ca1
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
movableObjects.py
+119
-0
119 additions, 0 deletions
movableObjects.py
with
119 additions
and
0 deletions
movableObjects.py
0 → 100644
+
119
−
0
View file @
c07cf3d0
class
MovableObject
:
def
__init__
(
self
,
game_info_dict
,
x
,
y
,
w
,
h
,
char
):
# Give the movable object access to the game map info
self
.
game_info_dict
=
game_info_dict
self
.
x
=
x
self
.
y
=
y
self
.
w
=
w
self
.
h
=
h
# character to represent object
self
.
char
=
char
self
.
body
=
self
.
create_body
()
def
create_body
(
self
):
body
=
[]
for
y_change
in
range
(
0
,
self
.
h
):
for
x_change
in
range
(
0
,
self
.
w
):
body
.
append
([
self
.
x
+
x_change
,
self
.
y
+
y_change
])
return
body
def
add_to_map
(
self
,
game_map
,
char
):
for
body_part
in
self
.
body
:
game_map
[
int
(
body_part
[
1
])][
int
(
body_part
[
0
])]
=
char
return
game_map
def
check_if_move_valid
(
self
,
body_part
):
if
body_part
[
1
]
>
self
.
game_info_dict
[
"
height
"
]
or
body_part
[
1
]
<
self
.
game_info_dict
[
"
border_y
"
]:
return
False
elif
body_part
[
0
]
>
self
.
game_info_dict
[
"
width
"
]
or
body_part
[
0
]
<
self
.
game_info_dict
[
"
border_x
"
]:
return
False
return
True
def
handle_invalid_move
(
self
,
game_map
):
return
self
.
add_to_map
(
game_map
,
"
"
),
False
def
move
(
self
,
game_map
,
change_x
,
change_y
):
body
=
[]
for
body_part
in
self
.
body
:
new_body_part
=
[
body_part
[
0
]
+
change_x
,
body_part
[
1
]
+
change_y
]
if
self
.
check_if_move_valid
(
new_body_part
):
body
.
append
(
new_body_part
)
else
:
return
self
.
handle_invalid_move
(
game_map
)
game_map
=
self
.
add_to_map
(
game_map
,
"
"
)
self
.
body
=
body
game_map
=
self
.
add_to_map
(
game_map
,
self
.
char
)
return
game_map
,
True
class
Enemy
(
MovableObject
):
def
__init__
(
self
,
game_info_dict
,
x
,
y
,
w
,
h
,
char
):
super
().
__init__
(
game_info_dict
,
x
,
y
,
w
,
h
,
char
)
self
.
direction
=
1
def
handle_invalid_move
(
self
,
game_map
):
if
self
.
direction
==
1
:
self
.
direction
=
-
1
else
:
self
.
direction
=
1
return
game_map
,
True
def
move
(
self
,
game_map
,
change_x
,
change_y
):
return
super
().
move
(
game_map
,
change_x
,
int
(
change_y
*
self
.
direction
))
class
Arrow
(
MovableObject
):
def
__init__
(
self
,
game_info_dict
,
x
,
y
,
w
,
h
,
vel_x
,
vel_y
,
char
):
super
().
__init__
(
game_info_dict
,
x
,
y
,
w
,
h
,
char
)
self
.
vel_x
=
vel_x
self
.
vel_y
=
vel_y
self
.
acc
=
0.05
def
apply_velocity
(
self
,
dt
):
#change_x = self.vel_x * dt * 10
#change_y = self.vel_y * dt * 10
change_x
=
self
.
vel_x
change_y
=
self
.
vel_y
self
.
vel_y
+=
self
.
acc
return
change_x
,
change_y
def
arrow_move
(
self
,
game_map
,
dt
):
change_x
,
change_y
=
self
.
apply_velocity
(
dt
)
return
super
().
move
(
game_map
,
change_x
,
change_y
)
class
PowerBar
(
MovableObject
):
def
__init__
(
self
,
game_info_dict
,
max_length
,
x
,
y
,
w
,
h
,
char
):
super
().
__init__
(
game_info_dict
,
x
,
y
,
w
,
h
,
char
)
self
.
max_length
=
max_length
self
.
power_index
=
0
self
.
going_up
=
True
def
reset_bar
(
self
):
self
.
w
=
0
self
.
body
=
self
.
create_body
()
def
get_power
(
self
):
return
self
.
w
def
next_level
(
self
,
game_map
):
if
self
.
going_up
:
if
self
.
w
+
1
>
self
.
max_length
:
self
.
going_up
=
False
else
:
self
.
w
+=
1
else
:
if
self
.
w
<
1
:
self
.
going_up
=
True
else
:
self
.
w
-=
1
self
.
add_to_map
(
game_map
,
"
"
)
self
.
body
=
self
.
create_body
()
return
self
.
add_to_map
(
game_map
,
"
█
"
)
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