FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
-python/data/components/flashing_coin.py at master · TobyfoxpurePython/-python · GitHub
TobyfoxpurePython
-python
Repository navigation
Code
Issues
1
(1)
Pull requests
2
(2)
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
-python
/
data
/
components
/
flashing_coin.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
69 lines (57 loc) · 2.3 KB
Breadcrumbs
-python
/
data
/
components
/
flashing_coin.py
Copy path
File metadata and controls
69 lines (57 loc) · 2.3 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
__author__
=
'justinarmstrong'
import
pygame
as
pg
from
..
import
setup
from
..
import
constants
as
c
class
Coin
(
pg
.
sprite
.
Sprite
):
"""Flashing coin next to coin total info"""
def
__init__
(
self
,
x
,
y
):
super
(
Coin
,
self
).
__init__
()
self
.
sprite_sheet
=
setup
.
GFX
[
'item_objects'
]
self
.
create_frames
()
self
.
image
=
self
.
frames
[
0
]
self
.
rect
=
self
.
image
.
get_rect
()
self
.
rect
.
x
=
x
self
.
rect
.
y
=
y
self
.
timer
=
0
self
.
first_half
=
True
self
.
frame_index
=
0
def
create_frames
(
self
):
"""Extract coin images from sprite sheet and assign them to a list"""
self
.
frames
=
[]
self
.
frame_index
=
0
self
.
frames
.
append
(
self
.
get_image
(
1
,
160
,
5
,
8
))
self
.
frames
.
append
(
self
.
get_image
(
9
,
160
,
5
,
8
))
self
.
frames
.
append
(
self
.
get_image
(
17
,
160
,
5
,
8
))
def
get_image
(
self
,
x
,
y
,
width
,
height
):
"""Extracts image from sprite sheet"""
image
=
pg
.
Surface
([
width
,
height
])
rect
=
image
.
get_rect
()
image
.
blit
(
self
.
sprite_sheet
, (
0
,
0
), (
x
,
y
,
width
,
height
))
image
.
set_colorkey
(
c
.
BLACK
)
image
=
pg
.
transform
.
scale
(
image
,
(
int
(
rect
.
width
*
c
.
BRICK_SIZE_MULTIPLIER
),
int
(
rect
.
height
*
c
.
BRICK_SIZE_MULTIPLIER
)))
return
image
def
update
(
self
,
current_time
):
"""Animates flashing coin"""
if
self
.
first_half
:
if
self
.
frame_index
==
0
:
if
(
current_time
-
self
.
timer
)
>
375
:
self
.
frame_index
+=
1
self
.
timer
=
current_time
elif
self
.
frame_index
<
2
:
if
(
current_time
-
self
.
timer
)
>
125
:
self
.
frame_index
+=
1
self
.
timer
=
current_time
elif
self
.
frame_index
==
2
:
if
(
current_time
-
self
.
timer
)
>
125
:
self
.
frame_index
-=
1
self
.
first_half
=
False
self
.
timer
=
current_time
else
:
if
self
.
frame_index
==
1
:
if
(
current_time
-
self
.
timer
)
>
125
:
self
.
frame_index
-=
1
self
.
first_half
=
True
self
.
timer
=
current_time
self
.
image
=
self
.
frames
[
self
.
frame_index
]
Back
|
FazBrowse Home
|
New Git URL