0
I’m creating a simple replica of the game Space Invaders in Python3.7, at first I was creating the screen all with Turtle, but the game entered in a kind of infinite loop and did not execute the commands. After a friend suggested to use Bib pygame I developed the code below.
Code:
from turtle import Turtle, Screen
import pygame
pygame.init()
gameDisplay = pygame.display.set_mode((800, 600))
pygame.display.set_caption('Space Invaders')
clock = pygame.time.Clock()
#Cria a borda
border_pen = Turtle()
border_pen.speed(0)
border_pen.color("white")
border_pen.penup()
border_pen.setposition(-270, -260)
border_pen.pendown()
border_pen.pensize(3)
for side in range(4):
border_pen.fd(530)
border_pen.lt(90)
border_pen.hideturtle()
#Cria a nave do usuario
player = Turtle()
player.color("blue")
player.shape("triangle")
player.penup()
player.speed(0)
player.setposition(0, -200)
player.setheading(90)
playerspeed = 10
#Mover a nave
def move_left():
x = player.xcor()
x -= playerspeed
player.setx(x)
def move_right():
x = player.xcor()
x += playerspeed
player.setx(x)
#Cria movimento de tecla
screen = Screen()
screen.listen()
screen.onkey(move_left, "Left")
screen.onkey(move_right, "Right")
crashed = False
while not crashed:
for event in pygame.event.get():
if event.type == pygame.QUIT:
crashed = True
pygame.display.update()
clock.tick(60)
pygame.quit()
quit()
I’m having the following mistake:
2019-04-12 15:44:18.808 Python[9273:62443] -[PYGSDLApplication
_setup:]: unrecognized selector sent to instance 0x7fe3adf83cf0
2019-04-12 15:44:18.815 Python[9273:62443] *** Terminating app due to
uncaught exception 'NSInvalidArgumentException', reason: '-
[PYGSDLApplication _setup:]: unrecognized selector sent to instance
0x7fe3adf83cf0'
*** First throw call stack: { ... }
libc++abi.dylib: terminating with uncaught exception of type
NSException
how did you install this pygame? What operating system is using?
– jsbueno