Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
John Donnal
/
comms_demo
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
92d4bc41
authored
Nov 02, 2020
by
source_reader
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
added simple UI for Marvel API
parent
64ab234b
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
72 additions
and
0 deletions
marvel_demo.py
marvel_demo.py
0 → 100644
View file @
92d4bc41
import
marvel_client
import
pygame
import
sys
import
tempfile
import
requests
import
io
def
main
():
client
=
marvel_client
.
MarvelClient
(
"7e583905d15a48c849ef155bc9d6af29"
,
"f8307f988ea51a41040df0c273cd5ab36606d58d"
)
characters
=
client
.
get_characters
()
pygame
.
init
()
surf
:
pygame
.
Surface
=
pygame
.
display
.
set_mode
((
640
,
480
))
pygame
.
display
.
set_caption
(
"Marvel Hero Browser"
)
idx
=
0
display_character
(
surf
,
characters
[
idx
])
pygame
.
display
.
update
()
while
True
:
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
pygame
.
QUIT
:
pygame
.
quit
()
sys
.
exit
()
if
event
.
type
==
pygame
.
KEYDOWN
:
if
event
.
key
==
pygame
.
K_LEFT
and
idx
>
0
:
idx
-=
1
if
event
.
key
==
pygame
.
K_RIGHT
and
idx
<
(
len
(
characters
)
-
1
):
idx
+=
1
# display the new character
display_character
(
surf
,
characters
[
idx
])
pygame
.
display
.
update
()
def
display_character
(
surf
,
character
):
# create a background for the screen (erases previous character)
surf
.
fill
((
200
,
40
,
80
))
pygame
.
draw
.
rect
(
surf
,
(
250
,
250
,
40
),
(
10
,
10
,
620
,
460
),
10
)
# center the character's name at the top
name
=
create_text
(
character
.
name
,
80
,
max_width
=
surf
.
get_width
()
-
40
)
rect
=
name
.
get_rect
()
rect
.
centerx
=
surf
.
get_rect
()
.
centerx
rect
.
y
=
30
surf
.
blit
(
name
,
rect
)
# put the character's image in the center
image
=
character
.
get_image
()
rect
=
image
.
get_rect
()
rect
.
centerx
=
surf
.
get_rect
()
.
centerx
rect
.
y
=
150
surf
.
blit
(
image
,
rect
)
def
create_text
(
text
,
size
,
max_width
=
None
,
color
=
(
0
,
0
,
0
)):
font
=
pygame
.
font
.
Font
(
'./assets/FutilePro.ttf'
,
size
)
image
=
font
.
render
(
text
,
True
,
color
)
if
max_width
is
None
:
return
image
# otherwise make sure the font fits within max_width
while
True
:
rect
=
image
.
get_rect
()
if
rect
.
width
>
max_width
:
size
-=
1
# try with the next size smaller
font
=
pygame
.
font
.
Font
(
'./assets/FutilePro.ttf'
,
size
)
image
=
font
.
render
(
text
,
True
,
color
)
else
:
return
image
main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment