Skip to content
GitLab
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Primary navigation
Search or go to…
Project
A
arcade-space
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
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
Privacy statement
Keyboard shortcuts
?
What's new
4
Snippets
Groups
Projects
Show more breadcrumbs
Jittat Fakcharoenphol
arcade-space
Commits
4a44b08b
Commit
4a44b08b
authored
8 years ago
by
Jittat Fakcharoenphol
Browse files
Options
Downloads
Patches
Plain Diff
random astroids
parent
94e351fa
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
models.py
+41
-2
41 additions, 2 deletions
models.py
space.py
+7
-1
7 additions, 1 deletion
space.py
with
48 additions
and
3 deletions
models.py
+
41
−
2
View file @
4a44b08b
import
arcade.key
from
random
import
randint
from
random
import
randint
,
random
class
Model
:
def
__init__
(
self
,
world
,
x
,
y
,
angle
):
...
...
@@ -51,9 +51,34 @@ class Gold(Model):
def
random_location
(
self
):
self
.
x
=
randint
(
0
,
self
.
world
.
width
-
1
)
self
.
y
=
randint
(
0
,
self
.
world
.
height
-
1
)
class
Asteroid
(
Model
):
def
__init__
(
self
,
world
,
x
,
y
,
vx
,
vy
):
super
().
__init__
(
world
,
x
,
y
,
0
)
self
.
vx
=
vx
self
.
vy
=
vy
self
.
angle
=
randint
(
0
,
359
)
def
random_direction
(
self
):
self
.
vx
=
5
*
random
()
self
.
vy
=
5
*
random
()
def
animate
(
self
,
delta
):
if
(
self
.
x
<
0
)
or
(
self
.
x
>
self
.
world
.
width
):
self
.
vx
=
-
self
.
vx
if
(
self
.
y
<
0
)
or
(
self
.
y
>
self
.
world
.
height
):
self
.
vy
=
-
self
.
vy
self
.
x
+=
self
.
vx
self
.
y
+=
self
.
vy
self
.
angle
+=
3
class
World
:
NUM_ASTEROID
=
10
def
__init__
(
self
,
width
,
height
):
self
.
width
=
width
self
.
height
=
height
...
...
@@ -61,15 +86,29 @@ class World:
self
.
ship
=
Ship
(
self
,
100
,
100
)
self
.
gold
=
Gold
(
self
,
400
,
400
)
self
.
asteroids
=
[]
for
i
in
range
(
World
.
NUM_ASTEROID
):
asteroid
=
Asteroid
(
self
,
0
,
0
,
0
,
0
)
asteroid
.
random_direction
()
self
.
asteroids
.
append
(
asteroid
)
self
.
score
=
0
def
animate
(
self
,
delta
):
self
.
ship
.
animate
(
delta
)
if
self
.
ship
.
hit
(
self
.
gold
,
10
):
self
.
gold
.
random_location
()
self
.
score
+=
1
for
asteroid
in
self
.
asteroids
:
asteroid
.
animate
(
delta
)
if
self
.
ship
.
hit
(
asteroid
,
10
):
self
.
score
-=
1
asteroid
.
x
=
0
asteroid
.
y
=
0
asteroid
.
random_direction
()
def
on_key_press
(
self
,
key
,
key_modifiers
):
if
key
==
arcade
.
key
.
SPACE
:
self
.
ship
.
switch_direction
()
This diff is collapsed.
Click to expand it.
space.py
+
7
−
1
View file @
4a44b08b
...
...
@@ -31,15 +31,21 @@ class SpaceGameWindow(arcade.Window):
self
.
ship_sprite
=
ModelSprite
(
'
images/ship.png
'
,
model
=
self
.
world
.
ship
)
self
.
gold_sprite
=
ModelSprite
(
'
images/gold.png
'
,
model
=
self
.
world
.
gold
)
self
.
asteroid_sprites
=
[]
for
asteroid
in
self
.
world
.
asteroids
:
self
.
asteroid_sprites
.
append
(
ModelSprite
(
'
images/ship.png
'
,
scale
=
0.5
,
model
=
asteroid
))
def
on_draw
(
self
):
arcade
.
start_render
()
self
.
gold_sprite
.
draw
()
self
.
ship_sprite
.
draw
()
for
sprite
in
self
.
asteroid_sprites
:
sprite
.
draw
()
arcade
.
draw_text
(
str
(
self
.
world
.
score
),
self
.
width
-
3
0
,
self
.
height
-
30
,
self
.
width
-
6
0
,
self
.
height
-
30
,
arcade
.
color
.
WHITE
,
20
)
...
...
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