{"id":6858,"date":"2021-09-04T02:39:11","date_gmt":"2021-09-03T19:39:11","guid":{"rendered":"https:\/\/www.phidgets.com\/education\/?page_id=6858"},"modified":"2022-08-30T04:23:01","modified_gmt":"2022-08-29T21:23:01","slug":"space-invaders","status":"publish","type":"page","link":"https:\/\/www.phidgets.com\/education\/learn\/projects\/pygame-zero-projects\/space-invaders\/","title":{"rendered":"Space Invaders"},"content":{"rendered":"<p>[et_pb_section bb_built=&#8221;1&#8243; specialty=&#8221;off&#8221; next_background_color=&#8221;#000000&#8243; _builder_version=&#8221;4.4.1&#8243; custom_padding=&#8221;||0px|&#8221; box_shadow_horizontal_tablet=&#8221;0px&#8221; box_shadow_vertical_tablet=&#8221;0px&#8221; box_shadow_blur_tablet=&#8221;40px&#8221; box_shadow_spread_tablet=&#8221;0px&#8221; vertical_offset_tablet=&#8221;0&#8243; horizontal_offset_tablet=&#8221;0&#8243; z_index_tablet=&#8221;0&#8243;][et_pb_row _builder_version=&#8221;4.4.1&#8243; use_custom_gutter=&#8221;on&#8221; gutter_width=&#8221;3&#8243; box_shadow_horizontal_tablet=&#8221;0px&#8221; box_shadow_vertical_tablet=&#8221;0px&#8221; box_shadow_blur_tablet=&#8221;40px&#8221; box_shadow_spread_tablet=&#8221;0px&#8221; vertical_offset_tablet=&#8221;0&#8243; horizontal_offset_tablet=&#8221;0&#8243; z_index_tablet=&#8221;0&#8243;][et_pb_column type=&#8221;1_2&#8243; custom_padding__hover=&#8221;|||&#8221; custom_padding=&#8221;|||&#8221;][et_pb_code admin_label=&#8221;Space Invaders and Phidgets&#8221; _builder_version=&#8221;4.6.6&#8243; box_shadow_horizontal_tablet=&#8221;0px&#8221; box_shadow_vertical_tablet=&#8221;0px&#8221; box_shadow_blur_tablet=&#8221;40px&#8221; box_shadow_spread_tablet=&#8221;0px&#8221; vertical_offset_tablet=&#8221;0&#8243; horizontal_offset_tablet=&#8221;0&#8243; z_index_tablet=&#8221;0&#8243;]<\/p>\n<div class=\"ph-overline-text\"><!-- [et_pb_line_break_holder] -->    <a href=\"\/education\/learn\/projects\">Projects<\/a><!-- [et_pb_line_break_holder] -->    <\/div>\n<p><!-- [et_pb_line_break_holder] --><\/p>\n<h1>Space Invaders with Pygame Zero and Phidgets<\/h1>\n<p>[\/et_pb_code][et_pb_code admin_label=&#8221;Description&#8221; _builder_version=&#8221;4.6.6&#8243; box_shadow_horizontal_tablet=&#8221;0px&#8221; box_shadow_vertical_tablet=&#8221;0px&#8221; box_shadow_blur_tablet=&#8221;40px&#8221; box_shadow_spread_tablet=&#8221;0px&#8221; vertical_offset_tablet=&#8221;0&#8243; horizontal_offset_tablet=&#8221;0&#8243; z_index_tablet=&#8221;0&#8243;]<pee>Pygame Zero allows you to create simple games in Python. In this project, you will modify a Space Invaders game to use the buttons from your Getting Started Kit and a Thumbstick Phidget!<\/pee>[\/et_pb_code][et_pb_code admin_label=&#8221;ph-button-cta: Start&#8221; _builder_version=&#8221;4.6.6&#8243; box_shadow_horizontal_tablet=&#8221;0px&#8221; box_shadow_vertical_tablet=&#8221;0px&#8221; box_shadow_blur_tablet=&#8221;40px&#8221; box_shadow_spread_tablet=&#8221;0px&#8221; vertical_offset_tablet=&#8221;0&#8243; horizontal_offset_tablet=&#8221;0&#8243; z_index_tablet=&#8221;0&#8243;]<a class=\"ph-button-cta\" href=\"#setup\"><!-- [et_pb_line_break_holder] -->  <\/p>\n<div class=\"ph-button-cta__icon\"><\/div>\n<p><!-- [et_pb_line_break_holder] -->  Start<!-- [et_pb_line_break_holder] --><\/a>[\/et_pb_code][\/et_pb_column][et_pb_column type=&#8221;1_2&#8243; custom_padding__hover=&#8221;|||&#8221; custom_padding=&#8221;|||&#8221;][et_pb_video _builder_version=&#8221;4.6.6&#8243; src=&#8221;https:\/\/www.phidgets.com\/education\/wp-content\/uploads\/2021\/09\/space_invaders.mp4&#8243; box_shadow_horizontal_tablet=&#8221;0px&#8221; box_shadow_vertical_tablet=&#8221;0px&#8221; box_shadow_blur_tablet=&#8221;40px&#8221; box_shadow_spread_tablet=&#8221;0px&#8221; vertical_offset_tablet=&#8221;0&#8243; horizontal_offset_tablet=&#8221;0&#8243; z_index_tablet=&#8221;0&#8243; \/][\/et_pb_column][\/et_pb_row][\/et_pb_section][et_pb_section bb_built=&#8221;1&#8243; specialty=&#8221;on&#8221; _builder_version=&#8221;4.4.1&#8243; use_custom_gutter=&#8221;on&#8221; gutter_width=&#8221;3&#8243; box_shadow_horizontal_tablet=&#8221;0px&#8221; box_shadow_vertical_tablet=&#8221;0px&#8221; box_shadow_blur_tablet=&#8221;40px&#8221; box_shadow_spread_tablet=&#8221;0px&#8221; vertical_offset_tablet=&#8221;0&#8243; horizontal_offset_tablet=&#8221;0&#8243; z_index_tablet=&#8221;0&#8243; prev_background_color=&#8221;#000000&#8243;][et_pb_column type=&#8221;1_4&#8243;][et_pb_code admin_label=&#8221;ph-vertical-nav&#8221; _builder_version=&#8221;4.6.6&#8243; box_shadow_horizontal_tablet=&#8221;0px&#8221; box_shadow_vertical_tablet=&#8221;0px&#8221; box_shadow_blur_tablet=&#8221;40px&#8221; box_shadow_spread_tablet=&#8221;0px&#8221; vertical_offset_tablet=&#8221;0&#8243; horizontal_offset_tablet=&#8221;0&#8243; z_index_tablet=&#8221;0&#8243; saved_tabs=&#8221;all&#8221;]<\/p>\n<div class=\"ph-vertical-nav ph-vertical-sticky\"><!-- [et_pb_line_break_holder] -->  <a href=\"#prereq\" class=\"ph-vertical-nav-item\">Prerequisites<\/a><!-- [et_pb_line_break_holder] -->  <a href=\"#setup\" class=\"ph-vertical-nav-item\">Setup<\/a><!-- [et_pb_line_break_holder] -->  <a href=\"#install\" class=\"ph-vertical-nav-item\">Install<\/a><!-- [et_pb_line_break_holder] -->  <a href=\"#create\" class=\"ph-vertical-nav-item\">Create Project Structure<\/a><!-- [et_pb_line_break_holder] -->  <a href=\"#write-code\" class=\"ph-vertical-nav-item\">Write Code<\/a><!-- [et_pb_line_break_holder] -->  <a href=\"#review\" class=\"ph-vertical-nav-item\">Code Review<\/a><!-- [et_pb_line_break_holder] -->  <a href=\"#practice\" class=\"ph-vertical-nav-item\">Practice<\/a><!-- [et_pb_line_break_holder] --><\/div>\n<p>[\/et_pb_code][\/et_pb_column][et_pb_column type=&#8221;3_4&#8243; specialty_columns=&#8221;3&#8243;][et_pb_row_inner _builder_version=&#8221;4.6.6&#8243; box_shadow_horizontal_tablet=&#8221;0px&#8221; box_shadow_vertical_tablet=&#8221;0px&#8221; box_shadow_blur_tablet=&#8221;40px&#8221; box_shadow_spread_tablet=&#8221;0px&#8221; vertical_offset_tablet=&#8221;0&#8243; horizontal_offset_tablet=&#8221;0&#8243; z_index_tablet=&#8221;0&#8243; module_id=&#8221;prereq&#8221;][et_pb_column_inner type=&#8221;4_4&#8243; saved_specialty_column_type=&#8221;3_4&#8243; custom_padding__hover=&#8221;|||&#8221; custom_padding=&#8221;|||&#8221; saved_specialty_column_type=&#8221;3_4&#8243;][et_pb_code admin_label=&#8221;Prerequisites&#8221; _builder_version=&#8221;4.6.6&#8243; box_shadow_horizontal_tablet=&#8221;0px&#8221; box_shadow_vertical_tablet=&#8221;0px&#8221; box_shadow_blur_tablet=&#8221;40px&#8221; box_shadow_spread_tablet=&#8221;0px&#8221; vertical_offset_tablet=&#8221;0&#8243; horizontal_offset_tablet=&#8221;0&#8243; z_index_tablet=&#8221;0&#8243; module_id=&#8221;setup&#8221;]<\/p>\n<h2>Prerequisites<\/h2>\n<p><!-- [et_pb_line_break_holder] --><pee>You should review the following before moving on:<\/pee><!-- [et_pb_line_break_holder] --><\/p>\n<ul><!-- [et_pb_line_break_holder] --><\/p>\n<li><a href=\"\/education\/learn\/projects\/pygame-zero-projects\/buttons\/\" target=\"_blank\" rel=\"noopener noreferrer\">Buttons with Pygame Zero.<\/a><\/li>\n<p><!-- [et_pb_line_break_holder] --><\/p>\n<li><a href=\"\/education\/learn\/projects\/pygame-zero-projects\/thumbstick\/\" target=\"_blank\" rel=\"noopener noreferrer\">Thumbstick Phidget with Pygame Zero.<\/a><\/li>\n<p><!-- [et_pb_line_break_holder] --><\/ul>\n<p>[\/et_pb_code][\/et_pb_column_inner][\/et_pb_row_inner][et_pb_row_inner _builder_version=&#8221;4.4.1&#8243; box_shadow_horizontal_tablet=&#8221;0px&#8221; box_shadow_vertical_tablet=&#8221;0px&#8221; box_shadow_blur_tablet=&#8221;40px&#8221; box_shadow_spread_tablet=&#8221;0px&#8221; vertical_offset_tablet=&#8221;0&#8243; horizontal_offset_tablet=&#8221;0&#8243; z_index_tablet=&#8221;0&#8243; module_id=&#8221;setup&#8221;][et_pb_column_inner type=&#8221;4_4&#8243; saved_specialty_column_type=&#8221;3_4&#8243; custom_padding__hover=&#8221;|||&#8221; custom_padding=&#8221;|||&#8221; saved_specialty_column_type=&#8221;3_4&#8243;][et_pb_code admin_label=&#8221;Setup&#8221; _builder_version=&#8221;4.6.6&#8243; box_shadow_horizontal_tablet=&#8221;0px&#8221; box_shadow_vertical_tablet=&#8221;0px&#8221; box_shadow_blur_tablet=&#8221;40px&#8221; box_shadow_spread_tablet=&#8221;0px&#8221; vertical_offset_tablet=&#8221;0&#8243; horizontal_offset_tablet=&#8221;0&#8243; z_index_tablet=&#8221;0&#8243; module_id=&#8221;setup&#8221;]<\/p>\n<h2>Setup<\/h2>\n<p><!-- [et_pb_line_break_holder] --><pee>All you need for this project is the Getting Started Kit.<\/strong><\/pee>[\/et_pb_code][\/et_pb_column_inner][\/et_pb_row_inner][et_pb_row_inner _builder_version=&#8221;4.4.1&#8243; box_shadow_horizontal_tablet=&#8221;0px&#8221; box_shadow_vertical_tablet=&#8221;0px&#8221; box_shadow_blur_tablet=&#8221;40px&#8221; box_shadow_spread_tablet=&#8221;0px&#8221; vertical_offset_tablet=&#8221;0&#8243; horizontal_offset_tablet=&#8221;0&#8243; z_index_tablet=&#8221;0&#8243; custom_padding=&#8221;||0px|&#8221;][et_pb_column_inner type=&#8221;1_3&#8243; saved_specialty_column_type=&#8221;3_4&#8243; custom_padding__hover=&#8221;|||&#8221; custom_padding=&#8221;|||&#8221; saved_specialty_column_type=&#8221;3_4&#8243;][et_pb_code admin_label=&#8221;Part: GSK&#8221; _builder_version=&#8221;4.18.0&#8243; box_shadow_horizontal_tablet=&#8221;0px&#8221; box_shadow_vertical_tablet=&#8221;0px&#8221; box_shadow_blur_tablet=&#8221;40px&#8221; box_shadow_spread_tablet=&#8221;0px&#8221; vertical_offset_tablet=&#8221;0&#8243; horizontal_offset_tablet=&#8221;0&#8243; z_index_tablet=&#8221;0&#8243; saved_tabs=&#8221;all&#8221; background_pattern_color=&#8221;rgba(0,0,0,0.2)&#8221; background_mask_color=&#8221;#ffffff&#8221; global_module=&#8221;8489&#8243;]<\/p>\n<div class=\"ph-part-card\"><!-- [et_pb_line_break_holder] -->  <\/p>\n<div class=\"ph-part-card__top\"><!-- [et_pb_line_break_holder] -->    <\/p>\n<div class=\"ph-part-card__type\"><!-- [et_pb_line_break_holder] -->      <\/p>\n<div class=\"ph-overline-text\"><!-- [et_pb_line_break_holder] -->        <a href=\"\">Kit\/<\/a><!-- [et_pb_line_break_holder] -->        <a href=\"\">Getting Started Kit<\/a><!-- [et_pb_line_break_holder] -->      <\/div>\n<p><!-- [et_pb_line_break_holder] -->    <\/div>\n<p><!-- [et_pb_line_break_holder] -->    <\/p>\n<div class=\"ph-part-card__title\"><!-- [et_pb_line_break_holder] -->      <\/p>\n<h3>Getting Started Kit<\/h3>\n<p><!-- [et_pb_line_break_holder] -->    <\/div>\n<p><!-- [et_pb_line_break_holder] -->  <\/div>\n<p><!-- [et_pb_line_break_holder] -->  <\/p>\n<div class=\"ph-part-card__bottom\"><!-- [et_pb_line_break_holder] -->    <img decoding=\"async\" src=\"\/education\/wp-content\/uploads\/2022\/08\/KIT4003_2_Square.jpg\" ><!-- [et_pb_line_break_holder] -->  <\/div>\n<p><!-- [et_pb_line_break_holder] --><\/div>\n<p>[\/et_pb_code][\/et_pb_column_inner][et_pb_column_inner type=&#8221;1_3&#8243; saved_specialty_column_type=&#8221;3_4&#8243; custom_padding__hover=&#8221;|||&#8221; custom_padding=&#8221;|||&#8221; saved_specialty_column_type=&#8221;3_4&#8243;][\/et_pb_column_inner][et_pb_column_inner type=&#8221;1_3&#8243; saved_specialty_column_type=&#8221;3_4&#8243; custom_padding__hover=&#8221;|||&#8221; custom_padding=&#8221;|||&#8221; saved_specialty_column_type=&#8221;3_4&#8243;][\/et_pb_column_inner][\/et_pb_row_inner][et_pb_row_inner admin_label=&#8221;Row&#8221; _builder_version=&#8221;4.6.6&#8243; box_shadow_horizontal_tablet=&#8221;0px&#8221; box_shadow_vertical_tablet=&#8221;0px&#8221; box_shadow_blur_tablet=&#8221;40px&#8221; box_shadow_spread_tablet=&#8221;0px&#8221; vertical_offset_tablet=&#8221;0&#8243; horizontal_offset_tablet=&#8221;0&#8243; z_index_tablet=&#8221;0&#8243;][et_pb_column_inner type=&#8221;4_4&#8243; saved_specialty_column_type=&#8221;3_4&#8243; custom_padding__hover=&#8221;|||&#8221; custom_padding=&#8221;|||&#8221; saved_specialty_column_type=&#8221;3_4&#8243;][\/et_pb_column_inner][\/et_pb_row_inner][et_pb_row_inner admin_label=&#8221;Row&#8221; _builder_version=&#8221;4.6.6&#8243; box_shadow_horizontal_tablet=&#8221;0px&#8221; box_shadow_vertical_tablet=&#8221;0px&#8221; box_shadow_blur_tablet=&#8221;40px&#8221; box_shadow_spread_tablet=&#8221;0px&#8221; module_id=&#8221;install&#8221; vertical_offset_tablet=&#8221;0&#8243; horizontal_offset_tablet=&#8221;0&#8243; z_index_tablet=&#8221;0&#8243;][et_pb_column_inner type=&#8221;4_4&#8243; saved_specialty_column_type=&#8221;3_4&#8243; custom_padding__hover=&#8221;|||&#8221; custom_padding=&#8221;|||&#8221; saved_specialty_column_type=&#8221;3_4&#8243;][et_pb_code admin_label=&#8221;Install&#8221; _builder_version=&#8221;4.6.6&#8243; box_shadow_horizontal_tablet=&#8221;0px&#8221; box_shadow_vertical_tablet=&#8221;0px&#8221; box_shadow_blur_tablet=&#8221;40px&#8221; box_shadow_spread_tablet=&#8221;0px&#8221; vertical_offset_tablet=&#8221;0&#8243; horizontal_offset_tablet=&#8221;0&#8243; z_index_tablet=&#8221;0&#8243; module_id=&#8221;install&#8221;]<\/p>\n<h2>Install Pygame Zero<\/h2>\n<p><!-- [et_pb_line_break_holder] --><pee>In order to use Pygame Zero, you first have to install it. You do this in the same way you previously installed the Phidget22 library. Simply navigate to your package manager,  search for <strong>pgzero<\/strong> and press install!<\/pee>[\/et_pb_code][\/et_pb_column_inner][\/et_pb_row_inner][et_pb_row_inner admin_label=&#8221;Row&#8221; _builder_version=&#8221;4.6.6&#8243; box_shadow_horizontal_tablet=&#8221;0px&#8221; box_shadow_vertical_tablet=&#8221;0px&#8221; box_shadow_blur_tablet=&#8221;40px&#8221; box_shadow_spread_tablet=&#8221;0px&#8221; disabled=&#8221;off&#8221; disabled_on=&#8221;off|off|off&#8221; vertical_offset_tablet=&#8221;0&#8243; horizontal_offset_tablet=&#8221;0&#8243; z_index_tablet=&#8221;0&#8243;][et_pb_column_inner type=&#8221;1_2&#8243; saved_specialty_column_type=&#8221;3_4&#8243; custom_padding__hover=&#8221;|||&#8221; custom_padding=&#8221;|||&#8221; saved_specialty_column_type=&#8221;3_4&#8243;][et_pb_code admin_label=&#8221;Thonny&#8221; _builder_version=&#8221;4.6.6&#8243; box_shadow_horizontal_tablet=&#8221;0px&#8221; box_shadow_vertical_tablet=&#8221;0px&#8221; box_shadow_blur_tablet=&#8221;40px&#8221; box_shadow_spread_tablet=&#8221;0px&#8221; vertical_offset_tablet=&#8221;0&#8243; horizontal_offset_tablet=&#8221;0&#8243; z_index_tablet=&#8221;0&#8243;]<\/p>\n<h3>Thonny<\/h3>\n<p><!-- [et_pb_line_break_holder] --><pee>If you&#8217;re using Thonny, select Tools > Manage Packages and search for pgzero.<\/pee>[\/et_pb_code][\/et_pb_column_inner][et_pb_column_inner type=&#8221;1_2&#8243; saved_specialty_column_type=&#8221;3_4&#8243; custom_padding__hover=&#8221;|||&#8221; custom_padding=&#8221;|||&#8221; saved_specialty_column_type=&#8221;3_4&#8243;][et_pb_image _builder_version=&#8221;4.6.6&#8243; src=&#8221;https:\/\/www.phidgets.com\/education\/wp-content\/uploads\/2021\/04\/pgzero_thonny.png&#8221; box_shadow_horizontal_tablet=&#8221;0px&#8221; box_shadow_vertical_tablet=&#8221;0px&#8221; box_shadow_blur_tablet=&#8221;40px&#8221; box_shadow_spread_tablet=&#8221;0px&#8221; vertical_offset_tablet=&#8221;0&#8243; horizontal_offset_tablet=&#8221;0&#8243; z_index_tablet=&#8221;0&#8243; show_in_lightbox=&#8221;on&#8221; title_text=&#8221;Thonny&#8221; \/][\/et_pb_column_inner][\/et_pb_row_inner][et_pb_row_inner admin_label=&#8221;Row&#8221; _builder_version=&#8221;4.6.6&#8243; box_shadow_horizontal_tablet=&#8221;0px&#8221; box_shadow_vertical_tablet=&#8221;0px&#8221; box_shadow_blur_tablet=&#8221;40px&#8221; box_shadow_spread_tablet=&#8221;0px&#8221; disabled=&#8221;off&#8221; disabled_on=&#8221;off|off|off&#8221; vertical_offset_tablet=&#8221;0&#8243; horizontal_offset_tablet=&#8221;0&#8243; z_index_tablet=&#8221;0&#8243;][et_pb_column_inner type=&#8221;1_2&#8243; saved_specialty_column_type=&#8221;3_4&#8243; custom_padding__hover=&#8221;|||&#8221; custom_padding=&#8221;|||&#8221; saved_specialty_column_type=&#8221;3_4&#8243;][et_pb_code admin_label=&#8221;PyCharm&#8221; _builder_version=&#8221;4.6.6&#8243; box_shadow_horizontal_tablet=&#8221;0px&#8221; box_shadow_vertical_tablet=&#8221;0px&#8221; box_shadow_blur_tablet=&#8221;40px&#8221; box_shadow_spread_tablet=&#8221;0px&#8221; vertical_offset_tablet=&#8221;0&#8243; horizontal_offset_tablet=&#8221;0&#8243; z_index_tablet=&#8221;0&#8243;]<\/p>\n<h3>PyCharm<\/h3>\n<p><!-- [et_pb_line_break_holder] --><pee>If you&#8217;re using PyCharm, select File > Settings > Python Interpreter and use the <strong>+<\/strong> symbol to install pgzero.<\/pee>[\/et_pb_code][\/et_pb_column_inner][et_pb_column_inner type=&#8221;1_2&#8243; saved_specialty_column_type=&#8221;3_4&#8243; custom_padding__hover=&#8221;|||&#8221; custom_padding=&#8221;|||&#8221; saved_specialty_column_type=&#8221;3_4&#8243;][et_pb_image _builder_version=&#8221;4.6.6&#8243; src=&#8221;https:\/\/www.phidgets.com\/education\/wp-content\/uploads\/2021\/04\/pgzero_pycharm.png&#8221; box_shadow_horizontal_tablet=&#8221;0px&#8221; box_shadow_vertical_tablet=&#8221;0px&#8221; box_shadow_blur_tablet=&#8221;40px&#8221; box_shadow_spread_tablet=&#8221;0px&#8221; vertical_offset_tablet=&#8221;0&#8243; horizontal_offset_tablet=&#8221;0&#8243; z_index_tablet=&#8221;0&#8243; show_in_lightbox=&#8221;on&#8221; \/][\/et_pb_column_inner][\/et_pb_row_inner][et_pb_row_inner admin_label=&#8221;Row&#8221; _builder_version=&#8221;4.6.6&#8243; box_shadow_horizontal_tablet=&#8221;0px&#8221; box_shadow_vertical_tablet=&#8221;0px&#8221; box_shadow_blur_tablet=&#8221;40px&#8221; box_shadow_spread_tablet=&#8221;0px&#8221; disabled=&#8221;off&#8221; disabled_on=&#8221;off|off|off&#8221; vertical_offset_tablet=&#8221;0&#8243; horizontal_offset_tablet=&#8221;0&#8243; z_index_tablet=&#8221;0&#8243;][et_pb_column_inner type=&#8221;1_2&#8243; saved_specialty_column_type=&#8221;3_4&#8243; custom_padding__hover=&#8221;|||&#8221; custom_padding=&#8221;|||&#8221; saved_specialty_column_type=&#8221;3_4&#8243;][et_pb_code admin_label=&#8221;PyScripter&#8221; _builder_version=&#8221;4.6.6&#8243; box_shadow_horizontal_tablet=&#8221;0px&#8221; box_shadow_vertical_tablet=&#8221;0px&#8221; box_shadow_blur_tablet=&#8221;40px&#8221; box_shadow_spread_tablet=&#8221;0px&#8221; vertical_offset_tablet=&#8221;0&#8243; horizontal_offset_tablet=&#8221;0&#8243; z_index_tablet=&#8221;0&#8243;]<\/p>\n<h3>PyScripter<\/h3>\n<p><!-- [et_pb_line_break_holder] --><pee>If you&#8217;re using PyScripter, select Tools > Tools > Install Packages with pip and enter pgzero.<\/pee>[\/et_pb_code][\/et_pb_column_inner][et_pb_column_inner type=&#8221;1_2&#8243; saved_specialty_column_type=&#8221;3_4&#8243; custom_padding__hover=&#8221;|||&#8221; custom_padding=&#8221;|||&#8221; saved_specialty_column_type=&#8221;3_4&#8243;][et_pb_image _builder_version=&#8221;4.6.6&#8243; src=&#8221;https:\/\/www.phidgets.com\/education\/wp-content\/uploads\/2021\/04\/pgzero_pyscripter.png&#8221; box_shadow_horizontal_tablet=&#8221;0px&#8221; box_shadow_vertical_tablet=&#8221;0px&#8221; box_shadow_blur_tablet=&#8221;40px&#8221; box_shadow_spread_tablet=&#8221;0px&#8221; vertical_offset_tablet=&#8221;0&#8243; horizontal_offset_tablet=&#8221;0&#8243; z_index_tablet=&#8221;0&#8243; show_in_lightbox=&#8221;on&#8221; \/][\/et_pb_column_inner][\/et_pb_row_inner][et_pb_row_inner _builder_version=&#8221;4.6.6&#8243; box_shadow_horizontal_tablet=&#8221;0px&#8221; box_shadow_vertical_tablet=&#8221;0px&#8221; box_shadow_blur_tablet=&#8221;40px&#8221; box_shadow_spread_tablet=&#8221;0px&#8221; vertical_offset_tablet=&#8221;0&#8243; horizontal_offset_tablet=&#8221;0&#8243; z_index_tablet=&#8221;0&#8243; module_id=&#8221;create&#8221;][et_pb_column_inner type=&#8221;4_4&#8243; saved_specialty_column_type=&#8221;3_4&#8243; custom_padding__hover=&#8221;|||&#8221; custom_padding=&#8221;|||&#8221; saved_specialty_column_type=&#8221;3_4&#8243;][et_pb_code admin_label=&#8221;Create Project Structure&#8221; _builder_version=&#8221;4.18.0&#8243; box_shadow_horizontal_tablet=&#8221;0px&#8221; box_shadow_vertical_tablet=&#8221;0px&#8221; box_shadow_blur_tablet=&#8221;40px&#8221; box_shadow_spread_tablet=&#8221;0px&#8221; vertical_offset_tablet=&#8221;0&#8243; horizontal_offset_tablet=&#8221;0&#8243; z_index_tablet=&#8221;0&#8243; background_pattern_color=&#8221;rgba(0,0,0,0.2)&#8221; background_mask_color=&#8221;#ffffff&#8221;]<\/p>\n<h2>Create Project Structure<\/h2>\n<p><!-- [et_pb_line_break_holder] --><pee>Create a python script called space_invaders.py in a location of your choice. Download the required images and place them in a folder called <strong>images<\/strong> in the same location as your python file.<\/pee><!-- [et_pb_line_break_holder] --><\/p>\n<ul><!-- [et_pb_line_break_holder] --><\/p>\n<li><a href=\"\/education\/wp-content\/uploads\/2022\/08\/background.png\">background.png<\/a><\/li>\n<p><!-- [et_pb_line_break_holder] --><\/p>\n<li><a href=\"\/education\/wp-content\/uploads\/2022\/08\/player.png\">player.png<\/a><\/li>\n<p><!-- [et_pb_line_break_holder] --><\/p>\n<li><a href=\"\/education\/wp-content\/uploads\/2022\/08\/alien1.png\">alien1.png<\/a><\/li>\n<p><!-- [et_pb_line_break_holder] --><\/p>\n<li><a href=\"\/education\/wp-content\/uploads\/2022\/08\/alien1b.png\">alien1b.png<\/a><\/li>\n<p><!-- [et_pb_line_break_holder] --><\/p>\n<li><a href=\"\/education\/wp-content\/uploads\/2022\/08\/base1.png\">base1.png<\/a><\/li>\n<p><!-- [et_pb_line_break_holder] --><\/p>\n<li><a href=\"\/education\/wp-content\/uploads\/2022\/08\/laser1.png\">laser1.png<\/a><\/li>\n<p><!-- [et_pb_line_break_holder] --><\/p>\n<li><a href=\"\/education\/wp-content\/uploads\/2022\/08\/laser2.png\">laser2.png<\/a><\/li>\n<p><!-- [et_pb_line_break_holder] --><\/p>\n<li><a href=\"\/education\/wp-content\/uploads\/2022\/08\/explosion1.png\">explosion1.png<\/a><\/li>\n<p><!-- [et_pb_line_break_holder] --><\/p>\n<li><a href=\"\/education\/wp-content\/uploads\/2022\/08\/explosion2.png\">explosion2.png<\/a><!-- [et_pb_line_break_holder] --><\/li>\n<p><!-- [et_pb_line_break_holder] --><\/p>\n<li><a href=\"\/education\/wp-content\/uploads\/2022\/08\/explosion3.png\">explosion3.png<\/a><!-- [et_pb_line_break_holder] --><\/li>\n<p><!-- [et_pb_line_break_holder] --><\/ul>\n<p>[\/et_pb_code][et_pb_image _builder_version=&#8221;4.6.6&#8243; src=&#8221;https:\/\/www.phidgets.com\/education\/wp-content\/uploads\/2021\/09\/pgzero_spaceinvade_structure.png&#8221; show_in_lightbox=&#8221;on&#8221; box_shadow_horizontal_tablet=&#8221;0px&#8221; box_shadow_vertical_tablet=&#8221;0px&#8221; box_shadow_blur_tablet=&#8221;40px&#8221; box_shadow_spread_tablet=&#8221;0px&#8221; vertical_offset_tablet=&#8221;0&#8243; horizontal_offset_tablet=&#8221;0&#8243; z_index_tablet=&#8221;0&#8243; width=&#8221;75%&#8221; align=&#8221;center&#8221; \/][\/et_pb_column_inner][\/et_pb_row_inner][et_pb_row_inner admin_label=&#8221;Row&#8221; disabled_on=&#8221;on|on|on&#8221; disabled=&#8221;on&#8221;][et_pb_column_inner type=&#8221;4_4&#8243; saved_specialty_column_type=&#8221;3_4&#8243; custom_padding__hover=&#8221;|||&#8221; custom_padding=&#8221;|||&#8221; saved_specialty_column_type=&#8221;3_4&#8243;][et_pb_code admin_label=&#8221; (invisible anchor)&#8221; _builder_version=&#8221;4.4.1&#8243; box_shadow_horizontal_tablet=&#8221;0px&#8221; box_shadow_vertical_tablet=&#8221;0px&#8221; box_shadow_blur_tablet=&#8221;40px&#8221; box_shadow_spread_tablet=&#8221;0px&#8221; module_id=&#8221;move&#8221; module_class=&#8221;ph-hidden-anchor&#8221; vertical_offset_tablet=&#8221;0&#8243; horizontal_offset_tablet=&#8221;0&#8243; z_index_tablet=&#8221;0&#8243; \/][\/et_pb_column_inner][\/et_pb_row_inner][et_pb_row_inner _builder_version=&#8221;4.6.6&#8243; box_shadow_horizontal_tablet=&#8221;0px&#8221; box_shadow_vertical_tablet=&#8221;0px&#8221; box_shadow_blur_tablet=&#8221;40px&#8221; box_shadow_spread_tablet=&#8221;0px&#8221; vertical_offset_tablet=&#8221;0&#8243; horizontal_offset_tablet=&#8221;0&#8243; z_index_tablet=&#8221;0&#8243; module_id=&#8221;write-code&#8221;][et_pb_column_inner type=&#8221;4_4&#8243; saved_specialty_column_type=&#8221;3_4&#8243; custom_padding__hover=&#8221;|||&#8221; custom_padding=&#8221;|||&#8221; saved_specialty_column_type=&#8221;3_4&#8243;][et_pb_code admin_label=&#8221;Write code Python&#8221; _builder_version=&#8221;4.6.6&#8243; box_shadow_horizontal_tablet=&#8221;0px&#8221; box_shadow_vertical_tablet=&#8221;0px&#8221; box_shadow_blur_tablet=&#8221;40px&#8221; box_shadow_spread_tablet=&#8221;0px&#8221; vertical_offset_tablet=&#8221;0&#8243; horizontal_offset_tablet=&#8221;0&#8243; z_index_tablet=&#8221;0&#8243;]<\/p>\n<h2>Write code (Python)<\/h2>\n<p><!-- [et_pb_line_break_holder] --><pee>Copy the code below into your python script <i>spaceinvaders.py<\/i>.<\/pee>[\/et_pb_code][et_pb_code admin_label=&#8221;Code Sample&#8221; _builder_version=&#8221;4.6.6&#8243; box_shadow_horizontal_tablet=&#8221;0px&#8221; box_shadow_vertical_tablet=&#8221;0px&#8221; box_shadow_blur_tablet=&#8221;40px&#8221; box_shadow_spread_tablet=&#8221;0px&#8221; vertical_offset_tablet=&#8221;0&#8243; horizontal_offset_tablet=&#8221;0&#8243; z_index_tablet=&#8221;0&#8243;]<\/p>\n<pre class=\"language-python\"><!-- [et_pb_line_break_holder] -->  <code><!-- [et_pb_line_break_holder] -->#Add Phidgets Library<!-- [et_pb_line_break_holder] -->from Phidget22.Phidget import *<!-- [et_pb_line_break_holder] -->from Phidget22.Devices.VoltageRatioInput import *<!-- [et_pb_line_break_holder] -->from Phidget22.Devices.DigitalInput import *<!-- [et_pb_line_break_holder] --><!-- [et_pb_line_break_holder] -->import pgzrun<!-- [et_pb_line_break_holder] -->from random import randint<!-- [et_pb_line_break_holder] -->import math<!-- [et_pb_line_break_holder] -->DIFFICULTY = 1<!-- [et_pb_line_break_holder] -->player = Actor(\"player\", (400, 550)) # Load in the player Actor image<!-- [et_pb_line_break_holder] --><!-- [et_pb_line_break_holder] -->def draw(): # Pygame Zero draw function<!-- [et_pb_line_break_holder] -->    screen.blit('background', (0, 0))<!-- [et_pb_line_break_holder] -->    player.image = player.images[math.floor(player.status\/6)]<!-- [et_pb_line_break_holder] -->    player.draw()<!-- [et_pb_line_break_holder] -->    drawLasers()<!-- [et_pb_line_break_holder] -->    drawAliens()<!-- [et_pb_line_break_holder] -->    drawBases()<!-- [et_pb_line_break_holder] -->    screen.draw.text(str(score) , topright=(780, 10), owidth=0.5, ocolor=(255,255,255), color=(0,64,255) , fontsize=60)<!-- [et_pb_line_break_holder] -->    if player.status >= 30:<!-- [et_pb_line_break_holder] -->        screen.draw.text(\"GAME OVER\\nPress Enter to play again\" , center=(400, 300), owidth=0.5, ocolor=(255,255,255), color=(255,64,0) , fontsize=60)<!-- [et_pb_line_break_holder] -->    if len(aliens) == 0 :<!-- [et_pb_line_break_holder] -->        screen.draw.text(\"YOU WON!\\nPress Enter to play again\" , center=(400, 300), owidth=0.5, ocolor=(255,255,255), color=(255,64,0) , fontsize=60)<!-- [et_pb_line_break_holder] -->        <!-- [et_pb_line_break_holder] -->def update(): # Pygame Zero update function<!-- [et_pb_line_break_holder] -->    global moveCounter,player<!-- [et_pb_line_break_holder] -->    if player.status < 30 and len(aliens) > 0:<!-- [et_pb_line_break_holder] -->        checkThumbstick() #Check Phidgets Thumbstick<!-- [et_pb_line_break_holder] -->        updateLasers()<!-- [et_pb_line_break_holder] -->        moveCounter += 1<!-- [et_pb_line_break_holder] -->        if moveCounter == moveDelay:<!-- [et_pb_line_break_holder] -->            moveCounter = 0<!-- [et_pb_line_break_holder] -->            updateAliens() <!-- [et_pb_line_break_holder] -->        if player.status > 0: player.status += 1<!-- [et_pb_line_break_holder] -->    else:<!-- [et_pb_line_break_holder] -->        if keyboard.RETURN: init()<!-- [et_pb_line_break_holder] --><!-- [et_pb_line_break_holder] -->def drawAliens():<!-- [et_pb_line_break_holder] -->    for a in range(len(aliens)): aliens[a].draw()<!-- [et_pb_line_break_holder] --><!-- [et_pb_line_break_holder] -->def drawBases():<!-- [et_pb_line_break_holder] -->    for b in range(len(bases)): bases[b].drawClipped()<!-- [et_pb_line_break_holder] --><!-- [et_pb_line_break_holder] -->def drawLasers():<!-- [et_pb_line_break_holder] -->    for l in range(len(lasers)): lasers[l].draw()<!-- [et_pb_line_break_holder] --><!-- [et_pb_line_break_holder] -->#Phidgets Code Start<!-- [et_pb_line_break_holder] -->def checkThumbstick():<!-- [et_pb_line_break_holder] -->    global player<!-- [et_pb_line_break_holder] -->    if (horizontal.getVoltageRatio() < -0.2):<!-- [et_pb_line_break_holder] -->        if (player.x > 40):<!-- [et_pb_line_break_holder] -->            player.x-=5<!-- [et_pb_line_break_holder] -->    if (horizontal.getVoltageRatio() > 0.2):<!-- [et_pb_line_break_holder] -->        if (player.x < 760):<!-- [et_pb_line_break_holder] -->            player.x+=5<!-- [et_pb_line_break_holder] -->#Phidgets Code End            <!-- [et_pb_line_break_holder] --><!-- [et_pb_line_break_holder] -->def makeLaserActive():<!-- [et_pb_line_break_holder] -->    global player<!-- [et_pb_line_break_holder] -->    player.laserActive = 1<!-- [et_pb_line_break_holder] -->            <!-- [et_pb_line_break_holder] -->def checkBases():<!-- [et_pb_line_break_holder] -->    for b in range(len(bases)):<!-- [et_pb_line_break_holder] -->        if l < len(bases):<!-- [et_pb_line_break_holder] -->            if bases[b].height < 5:<!-- [et_pb_line_break_holder] -->                del bases[b]<!-- [et_pb_line_break_holder] --><!-- [et_pb_line_break_holder] -->def updateLasers():<!-- [et_pb_line_break_holder] -->    global lasers, aliens<!-- [et_pb_line_break_holder] -->    for l in range(len(lasers)):<!-- [et_pb_line_break_holder] -->        if lasers[l].type == 0:<!-- [et_pb_line_break_holder] -->            lasers[l].y += (2*DIFFICULTY)<!-- [et_pb_line_break_holder] -->            checkLaserHit(l)<!-- [et_pb_line_break_holder] -->            if lasers[l].y > 600: lasers[l].status = 1<!-- [et_pb_line_break_holder] -->        if lasers[l].type == 1:<!-- [et_pb_line_break_holder] -->            lasers[l].y -= 5<!-- [et_pb_line_break_holder] -->            checkPlayerLaserHit(l)<!-- [et_pb_line_break_holder] -->            if lasers[l].y < 10: lasers[l].status = 1<!-- [et_pb_line_break_holder] -->    lasers = listCleanup(lasers)<!-- [et_pb_line_break_holder] -->    aliens = listCleanup(aliens)<!-- [et_pb_line_break_holder] --><!-- [et_pb_line_break_holder] -->def listCleanup(l):<!-- [et_pb_line_break_holder] -->    newList = []<!-- [et_pb_line_break_holder] -->    for i in range(len(l)):<!-- [et_pb_line_break_holder] -->        if l[i].status == 0: newList.append(l[i])<!-- [et_pb_line_break_holder] -->    return newList<!-- [et_pb_line_break_holder] -->    <!-- [et_pb_line_break_holder] -->def checkLaserHit(l):<!-- [et_pb_line_break_holder] -->    global player<!-- [et_pb_line_break_holder] -->    if player.collidepoint((lasers[l].x, lasers[l].y)):<!-- [et_pb_line_break_holder] -->        player.status = 1<!-- [et_pb_line_break_holder] -->        lasers[l].status = 1<!-- [et_pb_line_break_holder] -->    for b in range(len(bases)):<!-- [et_pb_line_break_holder] -->        if bases[b].collideLaser(lasers[l]):<!-- [et_pb_line_break_holder] -->            bases[b].height -= 10<!-- [et_pb_line_break_holder] -->            lasers[l].status = 1<!-- [et_pb_line_break_holder] --><!-- [et_pb_line_break_holder] -->def checkPlayerLaserHit(l):<!-- [et_pb_line_break_holder] -->    global score<!-- [et_pb_line_break_holder] -->    for b in range(len(bases)):<!-- [et_pb_line_break_holder] -->        if bases[b].collideLaser(lasers[l]): lasers[l].status = 1<!-- [et_pb_line_break_holder] -->    for a in range(len(aliens)):<!-- [et_pb_line_break_holder] -->        if aliens[a].collidepoint((lasers[l].x, lasers[l].y)):<!-- [et_pb_line_break_holder] -->            lasers[l].status = 1<!-- [et_pb_line_break_holder] -->            aliens[a].status = 1<!-- [et_pb_line_break_holder] -->            score += 1000<!-- [et_pb_line_break_holder] -->            <!-- [et_pb_line_break_holder] -->def updateAliens():<!-- [et_pb_line_break_holder] -->    global moveSequence, lasers, moveDelay<!-- [et_pb_line_break_holder] -->    movex = movey = 0<!-- [et_pb_line_break_holder] -->    if moveSequence < 10 or moveSequence > 30: movex = -15<!-- [et_pb_line_break_holder] -->    if moveSequence == 10 or moveSequence == 30:<!-- [et_pb_line_break_holder] -->        movey = 50 + (10 * DIFFICULTY)<!-- [et_pb_line_break_holder] -->        moveDelay -= 1<!-- [et_pb_line_break_holder] -->    if moveSequence >10 and moveSequence < 30: movex = 15<!-- [et_pb_line_break_holder] -->    for a in range(len(aliens)):<!-- [et_pb_line_break_holder] -->        animate(aliens[a], pos=(aliens[a].x + movex, aliens[a].y + movey), duration=0.5, tween='linear')<!-- [et_pb_line_break_holder] -->        if randint(0, 1) == 0:<!-- [et_pb_line_break_holder] -->            aliens[a].image = \"alien1\"<!-- [et_pb_line_break_holder] -->        else:<!-- [et_pb_line_break_holder] -->            aliens[a].image = \"alien1b\"<!-- [et_pb_line_break_holder] -->            if randint(0, 5) == 0:<!-- [et_pb_line_break_holder] -->                lasers.append(Actor(\"laser1\", (aliens[a].x,aliens[a].y)))<!-- [et_pb_line_break_holder] -->                lasers[len(lasers)-1].status = 0<!-- [et_pb_line_break_holder] -->                lasers[len(lasers)-1].type = 0<!-- [et_pb_line_break_holder] -->        if aliens[a].y > player.y and player.status == 0:<!-- [et_pb_line_break_holder] -->            player.status = 1<!-- [et_pb_line_break_holder] -->    moveSequence +=1<!-- [et_pb_line_break_holder] -->    if moveSequence == 40: moveSequence = 0<!-- [et_pb_line_break_holder] --><!-- [et_pb_line_break_holder] -->def init():<!-- [et_pb_line_break_holder] -->    global lasers, score, player, moveSequence, moveCounter, moveDelay<!-- [et_pb_line_break_holder] -->    initAliens()<!-- [et_pb_line_break_holder] -->    initBases()<!-- [et_pb_line_break_holder] -->    moveCounter = moveSequence = player.status = score = player.laserCountdown = 0<!-- [et_pb_line_break_holder] -->    lasers = []<!-- [et_pb_line_break_holder] -->    moveDelay = 30<!-- [et_pb_line_break_holder] -->    player.images = [\"player\",\"explosion1\",\"explosion2\",\"explosion3\",\"explosion4\",\"explosion5\"]<!-- [et_pb_line_break_holder] -->    player.laserActive = 1<!-- [et_pb_line_break_holder] --><!-- [et_pb_line_break_holder] -->def initAliens():<!-- [et_pb_line_break_holder] -->    global aliens<!-- [et_pb_line_break_holder] -->    aliens = []<!-- [et_pb_line_break_holder] -->    for a in range(18):<!-- [et_pb_line_break_holder] -->        aliens.append(Actor(\"alien1\", (210+(a % 6)*80,100+(int(a\/6)*64))))<!-- [et_pb_line_break_holder] -->        aliens[a].status = 0<!-- [et_pb_line_break_holder] --><!-- [et_pb_line_break_holder] -->def drawClipped(self):<!-- [et_pb_line_break_holder] -->    screen.surface.blit(self._surf, (self.x-32, self.y-self.height+30),(0,0,64,self.height))<!-- [et_pb_line_break_holder] --><!-- [et_pb_line_break_holder] -->def collideLaser(self, other):<!-- [et_pb_line_break_holder] -->    return (<!-- [et_pb_line_break_holder] -->        self.x-20 < other.x+5 and<!-- [et_pb_line_break_holder] -->        self.y-self.height+30 < other.y and<!-- [et_pb_line_break_holder] -->        self.x+32 > other.x+5 and<!-- [et_pb_line_break_holder] -->        self.y-self.height+30 + self.height > other.y<!-- [et_pb_line_break_holder] -->    )<!-- [et_pb_line_break_holder] --><!-- [et_pb_line_break_holder] -->def initBases():<!-- [et_pb_line_break_holder] -->    global bases<!-- [et_pb_line_break_holder] -->    bases = []<!-- [et_pb_line_break_holder] -->    bc = 0<!-- [et_pb_line_break_holder] -->    for b in range(3):<!-- [et_pb_line_break_holder] -->        for p in range(3):<!-- [et_pb_line_break_holder] -->            bases.append(Actor(\"base1\", midbottom=(150+(b*200)+(p*40),520)))<!-- [et_pb_line_break_holder] -->            bases[bc].drawClipped = drawClipped.__get__(bases[bc])<!-- [et_pb_line_break_holder] -->            bases[bc].collideLaser = collideLaser.__get__(bases[bc])<!-- [et_pb_line_break_holder] -->            bases[bc].height = 60<!-- [et_pb_line_break_holder] -->            bc +=1<!-- [et_pb_line_break_holder] --><!-- [et_pb_line_break_holder] -->#Phidgets Code Start<!-- [et_pb_line_break_holder] -->#Event<!-- [et_pb_line_break_holder] -->def onRedButton_StateChange(self, state):<!-- [et_pb_line_break_holder] -->    global player, lasers<!-- [et_pb_line_break_holder] -->    if (state):<!-- [et_pb_line_break_holder] -->        if (player.laserActive == 1):<!-- [et_pb_line_break_holder] -->            player.laserActive = 0<!-- [et_pb_line_break_holder] -->            clock.schedule(makeLaserActive, 1.0)<!-- [et_pb_line_break_holder] -->            l = len(lasers)<!-- [et_pb_line_break_holder] -->            lasers.append(Actor(\"laser2\", (player.x,player.y-32)))<!-- [et_pb_line_break_holder] -->            lasers[l].status = 0<!-- [et_pb_line_break_holder] -->            lasers[l].type = 1<!-- [et_pb_line_break_holder] --><!-- [et_pb_line_break_holder] -->#Create<!-- [et_pb_line_break_holder] -->redButton = DigitalInput()<!-- [et_pb_line_break_holder] -->horizontal = VoltageRatioInput()<!-- [et_pb_line_break_holder] --><!-- [et_pb_line_break_holder] -->#Address<!-- [et_pb_line_break_holder] -->redButton.setHubPort(0)<!-- [et_pb_line_break_holder] -->redButton.setIsHubPortDevice(True)<!-- [et_pb_line_break_holder] -->horizontal.setChannel(1)<!-- [et_pb_line_break_holder] --><!-- [et_pb_line_break_holder] -->#Subscribe to Events<!-- [et_pb_line_break_holder] -->redButton.setOnStateChangeHandler(onRedButton_StateChange)<!-- [et_pb_line_break_holder] --><!-- [et_pb_line_break_holder] -->#Open<!-- [et_pb_line_break_holder] -->redButton.openWaitForAttachment(1000)<!-- [et_pb_line_break_holder] -->horizontal.openWaitForAttachment(1000)<!-- [et_pb_line_break_holder] --><!-- [et_pb_line_break_holder] -->#Set data interval to minimum<!-- [et_pb_line_break_holder] -->horizontal.setDataInterval(horizontal.getMinDataInterval())<!-- [et_pb_line_break_holder] -->#Phidgets Code End<!-- [et_pb_line_break_holder] -->    <!-- [et_pb_line_break_holder] -->init()<!-- [et_pb_line_break_holder] -->pgzrun.go()<!-- [et_pb_line_break_holder] -->  <\/code><!-- [et_pb_line_break_holder] --><\/pre>\n<p>[\/et_pb_code][\/et_pb_column_inner][\/et_pb_row_inner][et_pb_row_inner _builder_version=&#8221;4.6.6&#8243; box_shadow_horizontal_tablet=&#8221;0px&#8221; box_shadow_vertical_tablet=&#8221;0px&#8221; box_shadow_blur_tablet=&#8221;40px&#8221; box_shadow_spread_tablet=&#8221;0px&#8221; vertical_offset_tablet=&#8221;0&#8243; horizontal_offset_tablet=&#8221;0&#8243; z_index_tablet=&#8221;0&#8243;][et_pb_column_inner type=&#8221;4_4&#8243; saved_specialty_column_type=&#8221;3_4&#8243; custom_padding__hover=&#8221;|||&#8221; custom_padding=&#8221;|||&#8221; saved_specialty_column_type=&#8221;3_4&#8243;][et_pb_code admin_label=&#8221;Run your code&#8221; _builder_version=&#8221;4.6.6&#8243; box_shadow_horizontal_tablet=&#8221;0px&#8221; box_shadow_vertical_tablet=&#8221;0px&#8221; box_shadow_blur_tablet=&#8221;40px&#8221; box_shadow_spread_tablet=&#8221;0px&#8221; vertical_offset_tablet=&#8221;0&#8243; horizontal_offset_tablet=&#8221;0&#8243; z_index_tablet=&#8221;0&#8243;]<\/p>\n<h3>Run Your Program<\/h3>\n<p><!-- [et_pb_line_break_holder] --><pee>When you move your Thumbstick Phidget, your spaceship will move. When you press the red button, a laser will be fired.<\/pee>[\/et_pb_code][et_pb_image _builder_version=&#8221;4.18.0&#8243; src=&#8221;https:\/\/www.phidgets.com\/education\/wp-content\/uploads\/2022\/08\/project_spaceinvade_title2.jpg&#8221; show_in_lightbox=&#8221;on&#8221; box_shadow_horizontal_tablet=&#8221;0px&#8221; box_shadow_vertical_tablet=&#8221;0px&#8221; box_shadow_blur_tablet=&#8221;40px&#8221; box_shadow_spread_tablet=&#8221;0px&#8221; vertical_offset_tablet=&#8221;0&#8243; horizontal_offset_tablet=&#8221;0&#8243; z_index_tablet=&#8221;0&#8243; width=&#8221;50%&#8221; align=&#8221;center&#8221; background_pattern_color=&#8221;rgba(0,0,0,0.2)&#8221; background_mask_color=&#8221;#ffffff&#8221; \/][\/et_pb_column_inner][\/et_pb_row_inner][et_pb_row_inner _builder_version=&#8221;4.6.6&#8243; box_shadow_horizontal_tablet=&#8221;0px&#8221; box_shadow_vertical_tablet=&#8221;0px&#8221; box_shadow_blur_tablet=&#8221;40px&#8221; box_shadow_spread_tablet=&#8221;0px&#8221; vertical_offset_tablet=&#8221;0&#8243; horizontal_offset_tablet=&#8221;0&#8243; z_index_tablet=&#8221;0&#8243; module_id=&#8221;review&#8221;][et_pb_column_inner type=&#8221;4_4&#8243; saved_specialty_column_type=&#8221;3_4&#8243; custom_padding__hover=&#8221;|||&#8221; custom_padding=&#8221;|||&#8221; saved_specialty_column_type=&#8221;3_4&#8243;][et_pb_code admin_label=&#8221;Code Review&#8221; _builder_version=&#8221;4.6.6&#8243; box_shadow_horizontal_tablet=&#8221;0px&#8221; box_shadow_vertical_tablet=&#8221;0px&#8221; box_shadow_blur_tablet=&#8221;40px&#8221; box_shadow_spread_tablet=&#8221;0px&#8221; vertical_offset_tablet=&#8221;0&#8243; horizontal_offset_tablet=&#8221;0&#8243; z_index_tablet=&#8221;0&#8243;]<\/p>\n<h2>Code Review<\/h2>\n<p><!-- [et_pb_line_break_holder] --><pee>In this example, the Thumbstick Phidget is being used instead of the left and right keys, and the red button is used instead of the spacebar. You can view the original code <a href=\"https:\/\/github.com\/TechnoVisual\/Pygame-Zero\/tree\/master\/invaders\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a> to compare<\/pee>[\/et_pb_code][\/et_pb_column_inner][\/et_pb_row_inner][et_pb_row_inner _builder_version=&#8221;4.4.1&#8243; box_shadow_horizontal_tablet=&#8221;0px&#8221; box_shadow_vertical_tablet=&#8221;0px&#8221; box_shadow_blur_tablet=&#8221;40px&#8221; box_shadow_spread_tablet=&#8221;0px&#8221; vertical_offset_tablet=&#8221;0&#8243; horizontal_offset_tablet=&#8221;0&#8243; z_index_tablet=&#8221;0&#8243; module_id=&#8221;practice&#8221;][et_pb_column_inner type=&#8221;4_4&#8243; saved_specialty_column_type=&#8221;3_4&#8243; custom_padding__hover=&#8221;|||&#8221; custom_padding=&#8221;|||&#8221; saved_specialty_column_type=&#8221;3_4&#8243;][et_pb_code admin_label=&#8221;Practice&#8221; _builder_version=&#8221;4.6.6&#8243; box_shadow_horizontal_tablet=&#8221;0px&#8221; box_shadow_vertical_tablet=&#8221;0px&#8221; box_shadow_blur_tablet=&#8221;40px&#8221; box_shadow_spread_tablet=&#8221;0px&#8221; vertical_offset_tablet=&#8221;0&#8243; horizontal_offset_tablet=&#8221;0&#8243; z_index_tablet=&#8221;0&#8243;]<\/p>\n<h2>Practice<\/h2>\n<p><!-- [et_pb_line_break_holder] --><\/p>\n<ol><!-- [et_pb_line_break_holder] --><\/p>\n<li>Add new functionality to your game using the green button. Some examples may be pausing the game, ending the game, speeding the game up, slowing the game down, etc.<\/li>\n<p><!-- [et_pb_line_break_holder] --><\/ol>\n<p>[\/et_pb_code][\/et_pb_column_inner][\/et_pb_row_inner][et_pb_row_inner admin_label=&#8221;Row&#8221; _builder_version=&#8221;4.6.6&#8243;][et_pb_column_inner type=&#8221;4_4&#8243; saved_specialty_column_type=&#8221;3_4&#8243; custom_padding__hover=&#8221;|||&#8221; custom_padding=&#8221;|||&#8221; saved_specialty_column_type=&#8221;3_4&#8243;][et_pb_code admin_label=&#8221;ph-button-cta: Back to Projects&#8221; _builder_version=&#8221;4.6.6&#8243; box_shadow_horizontal_tablet=&#8221;0px&#8221; box_shadow_vertical_tablet=&#8221;0px&#8221; box_shadow_blur_tablet=&#8221;40px&#8221; box_shadow_spread_tablet=&#8221;0px&#8221; vertical_offset_tablet=&#8221;0&#8243; horizontal_offset_tablet=&#8221;0&#8243; z_index_tablet=&#8221;0&#8243;]<a class=\"ph-button-cta\" href=\"\/education\/learn\/projects\/pygame-zero-projects\"><!-- [et_pb_line_break_holder] -->  <\/p>\n<div class=\"ph-button-cta__icon\"><\/div>\n<p><!-- [et_pb_line_break_holder] -->  Back to Pygame Zero Projects<!-- [et_pb_line_break_holder] --><\/a>[\/et_pb_code][\/et_pb_column_inner][\/et_pb_row_inner][\/et_pb_column][\/et_pb_section]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>#Add Phidgets Libraryfrom Phidget22.Phidget import *from Phidget22.Devices.VoltageRatioInput import *from Phidget22.Devices.DigitalInput import *import pgzrunfrom random import randintimport mathDIFFICULTY = 1player = Actor(&#8220;player&#8221;, (400, 550)) # Load in the player Actor imagedef draw(): # Pygame Zero draw function screen.blit(&#8216;background&#8217;, (0, 0)) player.image = player.images[math.floor(player.status\/6)] player.draw() drawLasers() drawAliens() drawBases() screen.draw.text(str(score) , topright=(780, 10), owidth=0.5, ocolor=(255,255,255), color=(0,64,255) , fontsize=60) [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"parent":5547,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_et_pb_use_builder":"on","_et_pb_old_content":"<!-- wp:paragraph -->\r\n<p>This is an example page. It's different from a blog post because it will stay in one place and will show up in your site navigation (in most themes). Most people start with an About page that introduces them to potential site visitors. It might say something like this:<\/p>\r\n<!-- \/wp:paragraph --><!-- wp:quote -->\r\n<blockquote class=\"wp-block-quote\">\r\n<p>Hi there! I'm a bike messenger by day, aspiring actor by night, and this is my website. I live in Los Angeles, have a great dog named Jack, and I like pi\u00f1a coladas. (And gettin' caught in the rain.)<\/p>\r\n<\/blockquote>\r\n<!-- \/wp:quote --><!-- wp:paragraph -->\r\n<p>...or something like this:<\/p>\r\n<!-- \/wp:paragraph --><!-- wp:quote -->\r\n<blockquote class=\"wp-block-quote\">\r\n<p>The XYZ Doohickey Company was founded in 1971, and has been providing quality doohickeys to the public ever since. Located in Gotham City, XYZ employs over 2,000 people and does all kinds of awesome things for the Gotham community.<\/p>\r\n<\/blockquote>\r\n<!-- \/wp:quote --><!-- wp:paragraph -->\r\n<p>As a new WordPress user, you should go to <a href=\"https:\/\/www.phidgets.com\/education\/wp-admin\/\">your dashboard<\/a> to delete this page and create new pages for your content. Have fun!<\/p>\r\n<!-- \/wp:paragraph -->","_et_gb_content_width":"","footnotes":""},"class_list":["post-6858","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.phidgets.com\/education\/wp-json\/wp\/v2\/pages\/6858","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.phidgets.com\/education\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.phidgets.com\/education\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.phidgets.com\/education\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.phidgets.com\/education\/wp-json\/wp\/v2\/comments?post=6858"}],"version-history":[{"count":11,"href":"https:\/\/www.phidgets.com\/education\/wp-json\/wp\/v2\/pages\/6858\/revisions"}],"predecessor-version":[{"id":8555,"href":"https:\/\/www.phidgets.com\/education\/wp-json\/wp\/v2\/pages\/6858\/revisions\/8555"}],"up":[{"embeddable":true,"href":"https:\/\/www.phidgets.com\/education\/wp-json\/wp\/v2\/pages\/5547"}],"wp:attachment":[{"href":"https:\/\/www.phidgets.com\/education\/wp-json\/wp\/v2\/media?parent=6858"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}