Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AsteroidenSchauer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jakob Kirsch
AsteroidenSchauer
Commits
5dbc5b76
Commit
5dbc5b76
authored
5 years ago
by
Philipp Stahl
Browse files
Options
Downloads
Patches
Plain Diff
Add asteroids
parent
021e0858
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
main.py
+25
-6
25 additions, 6 deletions
main.py
with
25 additions
and
6 deletions
main.py
+
25
−
6
View file @
5dbc5b76
...
...
@@ -6,7 +6,7 @@ To add:
'''
import
arcade
,
math
import
arcade
,
math
,
random
SCREEN_SIZE
=
SCREEN_WIDTH
,
SCREEN_HEIGHT
=
640
,
480
NAME
=
"
Asteroids
"
...
...
@@ -35,6 +35,8 @@ class Game(arcade.Window):
self
.
player_sprite
=
None
self
.
time
=
0
self
.
view_left
=
0
self
.
view_bottom
=
0
self
.
slide
=
False
...
...
@@ -42,11 +44,16 @@ class Game(arcade.Window):
arcade
.
set_background_color
(
arcade
.
color
.
BLACK
)
# Add asteroid
def
asteroid
(
x
,
y
):
self
.
asteroid_sprite
=
arcade
.
Sprite
(
"
images/big_asteroid.png
"
,
SPRITE_SCALING
)
self
.
all_sprites_list
.
append
(
self
.
player_sprite
)
self
.
asteroid_sprite
self
.
asteroid_sprite
.
set_position
(
x
,
y
)
def
asteroid
(
self
):
x
=
random
.
randint
(
self
.
view_left
-
50
,
self
.
view_left
+
SCREEN_WIDTH
+
50
)
y
=
random
.
randint
(
self
.
view_bottom
-
50
,
self
.
view_bottom
+
SCREEN_HEIGHT
+
50
)
asteroid_sprite
=
arcade
.
Sprite
(
"
images/big_asteroid.png
"
,
SPRITE_SCALING
)
asteroid_sprite
.
set_position
(
x
,
y
)
asteroid_sprite
.
change_x
=
random
.
randint
(
-
5
,
5
)
asteroid_sprite
.
change_y
=
random
.
randint
(
-
5
,
5
)
self
.
all_sprites_list
.
append
(
asteroid_sprite
)
self
.
asteroid_list
.
append
(
asteroid_sprite
)
def
setup
(
self
):
self
.
low_x
=
0
...
...
@@ -64,6 +71,18 @@ class Game(arcade.Window):
self
.
all_sprites_list
.
append
(
self
.
player_sprite
)
def
update
(
self
,
delta_time
):
self
.
time
+=
1
if
self
.
time
%
300
==
0
:
self
.
asteroid
()
for
asteroid
in
self
.
asteroid_list
:
if
asteroid
.
center_x
<
self
.
view_left
-
300
or
asteroid
.
center_x
>
self
.
view_left
+
SCREEN_WIDTH
+
300
:
self
.
asteroid_list
.
remove
(
asteroid
)
self
.
all_sprites_list
.
remove
(
asteroid
)
if
asteroid
.
center_y
<
self
.
view_bottom
-
300
or
asteroid
.
center_y
>
self
.
view_bottom
+
SCREEN_HEIGHT
+
300
:
self
.
asteroid_list
.
remove
(
asteroid
)
self
.
all_sprites_list
.
remove
(
asteroid
)
if
not
self
.
slide
:
self
.
player_sprite
.
change_y
=
self
.
running
*
SPEED
*
math
.
cos
(
math
.
radians
(
self
.
player_sprite
.
angle
))
self
.
player_sprite
.
change_x
=
self
.
running
*
-
SPEED
*
math
.
sin
(
math
.
radians
(
self
.
player_sprite
.
angle
))
...
...
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