# See the License for the specific language governing permissions and # limitations under the License. # #This is the second project in the "Space invaders" series. #This project adds missles to the game when the player #presses the button. #Imports, need sys for exit function from rstem import led_matrix from rstem import accel import RPi.GPIO as GPIO import time #Initialize matrix, accelerometer, and GPIO, the matrix layout and accelerometer channel may changes from user to user led_matrix.init_grid(2) accel.init(1) GPIO.setmode(GPIO.BCM) GPIO.setup(4, GPIO.IN, pull_up_down=GPIO.PUD_UP) #Game entity data player_pos = [7, 0] missles = [] #Game timing data, missles get updated and therefore move roughly sixty times faster than enemies initialy game_tick = 0 game_tick_max = 64 enemy_tick = 60 start_time = time.time() #Function to add missle at the players position to set of current missles
#In this project the user adds the Ball class, which handles #most of the game physics, and adds the win and lose functions. #Imports from rstem import led_matrix from rstem import accel import sys import time #Initialize hardware led_matrix.init_grid(2, 2) accel.init(1) #Initialize game data bricks = [] score = 0 start_time = time.time() ball_tick = 0 MAX_BALL_TICK = 8 #Useful clamp function def clamp(value, minimum, maximum): return min(maximum, max(value, minimum)) #Display losing score def lose(): string = "You lost! Score: %i" % (score) msg = led_matrix.LEDText(string, font_name='large') for i in range(len(string)*6 + 15): led_matrix.fill(0) led_matrix.text(msg, (15 - i, 7)) led_matrix.show()