import turtle import os import math import random import pygame #set up the screen wn = turtle.Screen() wn.bgcolor("black") wn.title("Space invaders") wn.bgpic("space_invaders_backgrounds.gif") pygame.init() #Register the shapes turtle.register_shape("ship.gif") turtle.register_shape("Enemy.gif") #Drawing my border border_pen = turtle.Turtle() border_pen.speed(0) border_pen.color("white") border_pen.penup() border_pen.setposition(-300,-300) border_pen.pendown() border_pen.pensize(3) for side in range(4): border_pen.fd(600) border_pen.lt(90) border_pen.hideturtle() #Set the score to 0 score = 0 #Draw the score score_pen = turtle.Turtle() score_pen.speed(0) score_pen.color("white") score_pen.penup() score_pen.setposition(-290, 280) scorestring = "Score: %s" %score score_pen.write(scorestring, False, align="left", font=("Arial", 14, "normal")) score_pen.hideturtle() #create the player turtle player = turtle.Turtle() player.color("blue") player.shape("ship.gif") player.penup() player.speed(0) player.setposition(0, -250) player.setheading(90) playerspeed = 18 #Choose a number of enemies number_of_enemies …

Member Avatar
+0 forum 0

Hello! I am looking for some help, and have provided the code. I'm just trying to do some simple stuff. I'm trying to create a simple game without using classes (but using lists). What I'm trying to do is create collision detection among list objects ("bullets" and "baddies"), as you'll be able to see in the code. I'm also trying to fire 10 bullets at once from an "ammoCrate". My problem is that I have to stay on the "ammoCrate" in order for the bullets to do their thing, otherwise they stop in place and disappear, but continue if the …

Member Avatar
Member Avatar
+0 forum 2

I'm currently working on multithreading with PyAudio and Pygame, but when I try to run the audio, I get an error saying "OSError: [Errno -9996] Invalid output device (no default output device)." So far I've tried these on Terminal: >>> import pyaudio >>> pa = pyaudio.PyAudio() >>> pa.get_default_input_device_info() {'name': 'Built-in Microphone', 'defaultHighInputLatency': 0.013151927437641724, 'defaultLowInputLatency': 0.002993197278911565, 'maxInputChannels': 2, 'defaultSampleRate': 44100.0, 'structVersion': 2, 'maxOutputChannels': 0, 'defaultHighOutputLatency': 0.1, 'hostApi': 0, 'index': 0, 'defaultLowOutputLatency': 0.01} >>> pa.get_default_output_device_info() {'name': 'Built-in Output', 'defaultHighInputLatency': 0.1, 'defaultLowInputLatency': 0.01, 'maxInputChannels': 0, 'defaultSampleRate': 44100.0, 'structVersion': 2, 'maxOutputChannels': 2, 'defaultHighOutputLatency': 0.01401360544217687, 'hostApi': 0, 'index': 1, 'defaultLowOutputLatency': 0.003854875283446712} >>> pyaudio.pa.__file__ '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site- packages/_portaudio.cpython-35m-darwin.so' …

Member Avatar
Member Avatar
+0 forum 6

i am building a pong like game and cant seem to figure out how to add in a pause feature everything else works i have movement and collision detection, sound, game over and restart options but cant figure out how to pause the game any help would be greatly appreciated this is the entire code for the game i am new to python so im sure this is probably not the best way to do it. [CODE] import pygame,sys,random from pygame.locals import * pause=0 pygame.init() screen=pygame.display.set_mode((1024,768),0,32) pygame.mouse.set_visible(False) background=pygame.image.load('window.jpg').convert() ball=pygame.image.load('ball.png').convert_alpha() stopper1=pygame.image.load('bar1.png').convert_alpha() stopper2=pygame.image.load('bar2.png').convert_alpha() sound=pygame.mixer.Sound('Laser.ogg') x=random.uniform(0.0,1000.0) y=random.uniform(0.0,728.0) x2=1010 y2=300 speeds=600 speedx=200 speedy=200 clock=pygame.time.Clock() …

Member Avatar
Member Avatar
+0 forum 2

So, I'm making a ton of games like Bubble Blaster but will anyone help me with my currunt one, CodeNet! Currently this is the code. #CodeNet.com #Game Script import time print('Welcome') menu = ['Accept', 'Cancel'] from Tkinter import * HEIGHT = 626 WIDTH = 1238 window = Tk() window.title('Code Net.com') c = Canvas(window, width=WIDTH, height=HEIGHT, bg='white') c.pack() I know thisis in DevMode but still plz help me. I started with Tkinter and having difficultlies with the message box module on Tkinter. I don't think it even works! from tkinter import * import tkinter, messagebox Traceback (most recent call last): File …

Member Avatar
Member Avatar
+0 forum 2

Hi, i was want to add an image that is displayed before my game and then the user will click or press enter and the image will disappear and my game will start. I have tried "blit" and a few other thinks to try and get the image to appear but have not succeeded. Can anyone help me on where to start. import os import pygame import random pygame.init() #Colours im using in the game white = (255,255,255) black = (0,0,0) red = (255,0,0) FPS = 60 #The dimension of the game display_width = 680 display_height = 440 #Class for …

Member Avatar
Member Avatar
+0 forum 2

Hi, im trying to add a slapsh screen before my game. It will display a png and the use can either press "e" to continue or "q" to quit. when i run this in my game is says that pygame.display.update() is the problem. Please help thanks. def game_intro(): intro = True while intro : for event in pygame.event.get(): if even.type == pygame.Quit: pygame.quit() quit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_e: intro = False if event.key == pygame.K_q: pygame.quit() quit() intro_background = pygame.image.load("rock floor.png") #Load the image file intro_background = pygame.transform.scale(intro_background,(display_width,display_height)) #Make it the same size as the screen …

Member Avatar
Member Avatar
+0 forum 2

A short example of Pygame showing an image with a known internet url.

Member Avatar
Member Avatar
+0 forum 1

hi, so ive been trying to add a splash screen to the start of my game. the user presses "e" to continue and "q" to quit. it's not working, could anyone help. import os import pygame import random pygame.init() #Colours im using in the game white = (255,255,255) black = (0,0,0) red = (255,0,0) FPS = 60 #The dimension of the game display_width = 680 display_height = 440 def game_intro(): intro = True while intro : for event in pygame.event.get(): if even.type == pygame.Quit: pygame.quit() quit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_e: intro = False if event.key == …

Member Avatar
+0 forum 0

hi, im making a game in pygame game and i was wanting to add an image (just a png of the story) before my game. I was wondering if anyone can help me with how i would do this. thanks

Member Avatar
Member Avatar
+0 forum 2

Hi, i'm making a maze game. As you can see i have added an image for my floor and i'm trying to add an image to my walls. I am having trouble adding the image to the walls. Could anyone start me on my path on how to do this please. import os import pygame import random pygame.init() #Colours im using in the game white = (255,255,255) black = (0,0,0) red = (255,0,0) FPS = 60 #The dimension of the game display_width = 680 display_height = 440 #Class for the player class Player(object): def __init__(self): self.rect = pygame.Rect(40, 40, 30, …

Member Avatar
+0 forum 0

Hi, this is a maze I have been working on. As you can see everything is just flat colors. I was wanting to make it so i can add more detail like having it so i could have a picture of some tree textures as the walls to my maze and not just green, same for the path. I have tried many things but nothing seems to work. If anyone could help it would be amazing. import os import pygame import random pygame.init() white = (255,255,255) black = (0,0,0) red = (255,0,0) green = (0,155,0) brown = (205,133,63) blue = …

Member Avatar
Member Avatar
+0 forum 1

Hi, at the end of the maze you see a red square. I was trying to make it say "you win , would you like to play again y or n". i have tried using def mes and gameover = false but nothing seems to work. would help a lot if someone could help. (sorry this is a school project and we have to use PYGAME.) import os import pygame import random pygame.init() white = (255,255,255) black = (0,0,0) red = (255,0,0) green = (0,155,0) brown = (205,133,63) blue = (135,206,250) FPS = 60 #the dimension of the game display_width …

Member Avatar
Member Avatar
+0 forum 1

I have a simple pygame code that doesn't seem to be functioning correctly, check it out: import pygame, time active = True screen_size = (1052, 700) pygame.init() DISPLAY = pygame.display.set_mode(screen_size) firstimg = pygame.image.load('firstimage.png') secondimg = pygame.image.load('secondimage.png') clock = pygame.time.Clock() def WHITESCREEN: DISPLAY.fill(255, 255, 255) def DisplayFirstImg(): DISPLAY.blit(firstimg, (1, 1)) def DisplaySecondImg(): DISPLAY.blit(secondimg, (1, 1)) WHITESCREEN() DisplayFirstImg() time.sleep(3) DisplaySecondImg() while active: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() pygame.display.update() clock.tick(15) So this should display 'firstimage.png', wait three seconds, and then display 'secondimage.png'. However it skips the first two steps, going straight to the delay and then displays the second …

Member Avatar
+0 forum 0

Okay so I'm writing a code for a game and the way its currently programmed is the main menu is contained within a large function that references another function, and so on. Not too complicated. But (as you'll see with the code below) I have all the essential variables set before the functions even happen, at the very beginning of the code. import pygame, sys, time, math ##This is where the variables are set pygame.init() DISPLAY = pygame.display.set_mode((1023, 647)) WHITE = (255, 255, 255) BLACK = (0, 0, 0) GREEN = (0, 255, 0) clock = pygame.time.Clock() active = True …

Member Avatar
Member Avatar
+0 forum 1

This 'sticky' thread is for working examples of Python GUI code. Note that most wxPython examples have their own thread. Please use comments in your code to help the reader. The example code should be usable as a template, so folks get a feel for the toolkit and can use those examples/templates as a basis for more complex programs. We also welcome code that compares the various GUI toolkits. Again, don't clutter up the sticky with questions. Ask question in the regular forum. A brief history of GUI based Operating Systems migh be in order: The first Graphical User Interface …

Member Avatar
Member Avatar
+9 forum 235

A very basic pygame sprite example. Moving a sprite with the arrow keys, could be the start of a great space game.

Member Avatar
+0 forum 0

This simple code shows how to write text with a given font, font size and color using the module pygame ...

Member Avatar
Member Avatar
+4 forum 8

Dear all, Currently I am facing the problem on getting the resources for getting Tkinter and pygame to work together. Sadly, I do not have any leads til now(Which worries me alot!! :( ) so I hope the people here can point me to the correct direction. So basically I want to do something like this... [img]http://i41.tinypic.com/34h9cpl.jpg[/img] the latest research development is these two links.. I think the closest is this... [url]http://www.daniweb.com/forums/thread104130.html#[/url] and [url]http://translate.google.com/translate?j[/url] ... auto&tl=en :?: but I am not very sure on how to make it work... Really appreciate it if someone can point me to the correct …

Member Avatar
Member Avatar
+0 forum 2

after importing pygame, when we convert an image an assign it to a variable, what is the type of that variable?

Member Avatar
Member Avatar
+0 forum 4

Hello, Simple question: how can I command pgs4a to use android-10 (2.2.3) instead of always using android-8 (2.2)? I've tried using the target commands, but to no avail, unless I have missing files? I have my game set up and built, i've successfully created 2.2 apk's but cannot figure out how to make 2.2.3 apk's. Any help would be greatly appreciated.

Member Avatar
+0 forum 0

Hi, I am wondering if there is any easy way to up the frame rate of a pygame program. For example locking the frame rate? I don't know. Thanks in advance! 26BM

Member Avatar
Member Avatar
+0 forum 2

# Heading Here # Trying to add a webcam fee to a panel inside of my wxpython GUI. I have buttons on the left currently, and a black panel on the right. I'm confused as to how to add a webcam feed to that panel? here is the code being used to the camera feed, I'm using pygame for it. pygame.camera.init() screen = pygame.display.set_mode((640,340)) cam = pygame.camera.Camera("/dev/video0", (300,220)) cam.start() while 1: image = cam.get_image() screen.blit(image,(200,100)) pygame.display.update() for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() the Gui panel i'm trying to add the feed to is like this. self.panel = …

Member Avatar
Member Avatar
+0 forum 1

Hello everyone! I have made a game intended for the Rasberry pi in python. It is called Pi Blocks, but all of my friends with windows want to play it, so I've been trying and trying to get the game into an exectutable format, but nothing seems to work! I've tried just about everything the internet has to offer.. so, does someone smarter than me want to convert this to an exe?: [Download this and convert it please :)](http://host-a.net/u/PlanetForgeGame/Pygame_game.zip)

Member Avatar
Member Avatar
+0 forum 4

First of all, I should say I'm brand new to PyGame and am pretty new to advanced Python. I'm trying to make a side-scrolling game but just making a sprite move back and forth with keyboard input is proving to be a problem. It appears that the loop is running really slowly, so when pygame.event.get() is called, it doesn't consistently "catch" any events, if that makes any sense. This is apparent when trying to close the window with the X button - it only closes if the button is clicked repeatedly. Here's the code: import pygame, sys from pygame.locals import …

Member Avatar
Member Avatar
+0 forum 1

Hi, I'm wondering if anybody knows of a python compiler to make an exe with. I have tries cx_freeze and py2exe so far, but I haven't been able to get it to work. If anyone has any good python to exe compilers please post here. Thanks, 26bm

Member Avatar
Member Avatar
+0 forum 4

im trying to get this script to draw a line from the center of the rectangle to the mouse BUT i only want it to draw about 10 pixels out. how can i find that point that is 10 pixels(or points) out? code so far: import pygame from pygame.locals import * import math pygame.init() screen = pygame.display.set_mode((640, 480)) red = (255,0,0) green = (0,255,0) blue = (0,0,255) darkBlue = (0,0,128) white = (255,255,255) black = (0,0,0) pink = (255,200,200) x = 5 y = 5 username = "Bob" delta = 0 print len(username) running = 1 while running: for event …

Member Avatar
Member Avatar
+0 forum 2

Hi, I am tring to make a custom cursor in pygame and I would like to use a XBM file to do so. I am wondering if somebody could please give me an example on how to create a XBM cursor, how to load it into pygame, and how to set it as your current cursor. Thanks.

Member Avatar
+0 forum 0

Just a code sample that allows you to play your midi or mp3 music files with Python and module pygame.

Member Avatar
+4 forum 0

I have a qucik question for you guys. Is there a way to change the taskbar icon? Im done with my game and im gonna show it in class on tuesday 14 and I just thought it would be cool to have an icon that represents the game and not just the standard code bit. I tried pygame.display.set_icon(icon) but that only changed the window icon in the taskbar its still the same onld standard one.

Member Avatar
+0 forum 0

The End.