Jump to content

Renfield-64

Members
  • Posts

    323
  • Joined

  • Last visited

Everything posted by Renfield-64

  1. Thanks, I will try the print statement. Meanwhile here is my code hopefully formatted properly: My code in code tags : [ code]# PiBuster Code# PiBuster from Raspberry Pi for Dummies import pygame, sys, time, random from pygame.locals import * pygame.init() # initialize pygame # This section deals with setting up the game window gameSurface=pygame.display.set_mode((440,480)) # playing area size (pixels - width,height) pygame.display.set_caption('MrG-PiBuster') # Caption on window title bar pygame.mouse.set_visible(0) # You won't see the mouse pointer in the game window # This section deals with the colours used in the game (note: we have to use the American spelling of 'color' (boo! hiss!)) SHADOW = (192, 192, 192) # The numbers in the brackets are the RED, GREEN and BLUE (RGB) values for the colours WHITE = (255, 255, 255) # Example: 255, 255, 255 is white, 0, 0, 0 is black, 200, 0, 0 is RED LIGHTGREEN = (0, 255, 0) # In this game we will use the colours we have created GREEN = (0, 200, 0) # here as it is easier than typing in the numbers BLUE = (0, 0, 128) LIGHTBLUE = (0, 0, 255) RED = (200, 0, 0) LIGHTRED = (255, 100, 100) PURPLE = (102, 0, 102) LIGHTPURPLE = (153, 0, 153) gameSurface.fill(WHITE) # Turns the game surface white pygame.display.update() # This section deals with positioning the ball def drawball(x,y): pygame.draw.circle (gameSurface,BLUE,(realx(x)+10,realy(y)+10),10,0) pygame.draw.circle (gameSurface,LIGHTBLUE,(realx(x)+6,realy(y)+6),2,0) pygame.display.update() # drawbat - Routine to draw the bat def drawbat(x): pygame.draw.rect (gameSurface,LIGHTPURPLE,(realx(x),realy(BATY),40,4)) pygame.draw.rect (gameSurface,PURPLE,(realx(x),realy(BATY)+4,40,6)) pygame.draw.rect (gameSurface,SHADOW,(realx(x),realy(BATY)+10,40,2)) pygame.draw.rect (gameSurface,SHADOW,(realx(x)+38,realy(BATY),2,12)) # This section deals with drawing shapes on the game surface #pygame.draw.rect(gameSurface,PURPLE,(16,16,406,2)) #pygame.draw.rect(gameSurface,PURPLE,(16,16,2,440)) #pygame.draw.rect(gameSurface,PURPLE,(422,16,2,440)) # This section deals with drawing the bricks def realx(x): x=x*20 return x def realy(y): y=y*20 return y def drawbrick(xcoord,ycoord,col): if col==1: boxcolor=GREEN highlightcolor=LIGHTGREEN else: boxcolor=RED highlightcolor=LIGHTRED pygame.draw.rect (gameSurface,boxcolor,(realx(xcoord),realy(ycoord),20,20)) pygame.draw.rect (gameSurface,highlightcolor,(realx(xcoord),realy(ycoord),2,20)) pygame.draw.rect (gameSurface,highlightcolor,(realx(xcoord),realy(ycoord),20,2)) pygame.draw.rect (gameSurface,SHADOW,(realx(xcoord)+18,realy(ycoord),2,20)) pygame.draw.rect (gameSurface,SHADOW,(realx(xcoord),realy(ycoord)+18,20,2)) # This section deals with displaying 'End of game' type messages def showtext(text): fontObj=pygame.font.Font('freesansbold.ttf',64) # The font name and size. textsurface=fontObj.render(text, True, PURPLE, WHITE) # PURPLE is the text colour, WHITE is the background color. textRectObj=textsurface.get_rect() # Creates a rectangle to display the text. textRectObj.center=(220,200) # Puts the rectangle at position X=220 and Y=200 (note the American spelling of 'center') gameSurface.blit(textsurface,textRectObj) # Puts your text in the rectangle. pygame.display.update() # Now we can create some functions to tell the program what text we would like in the box. def gameover(): showtext('GAME OVER') time.sleep(8) # Show the message for 8 seconds. engame() # This bit runs the 'endgame' function & quits Pygame and closes the PiBuster window. def gamewon(): showtext('GAME WON!') time.sleep(8) # Show the message for 8 seconds. engame() # This bit runs the 'endgame' function & quits Pygame and closes the PiBuster window. def endgame(): # The 'endgame' funtion. pygame.quit() sys.exit() # This funtion checks the program to see if the player has won. def havetheywon(): if score==brickcount: # Every time the player knocks out a brick the program checks return True # the remaining bricks against the original number of bricks and adds one else: # to the score and keeps going (return False) until they are all gone (return True). return False # This section deals with creating the game map map=[ #--------0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9-- # There is a space between each number on this line [0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,0], [0,0,0,1,1,1,1,0,0,0,0,0,0,1,1,1,1,0,0,0], [0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0], [0,0,0,0,0,1,1,1,1,0,0,1,1,1,1,0,0,0,0,0], [0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,2,2,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,2,2,2,2,2,2,2,2,0,0,0,0,0,0], [0,0,0,0,0,2,2,2,2,2,2,2,2,2,2,0,0,0,0,0], [0,0,0,0,0,2,2,2,2,2,2,2,2,2,2,0,0,0,0,0], [0,0,0,0,2,2,2,2,2,2,2,2,2,2,2,2,0,0,0,0], [0,0,0,0,2,2,2,2,2,2,2,2,2,2,2,2,0,0,0,0], [0,0,0,0,0,2,2,2,2,2,2,2,2,2,2,0,0,0,0,0], [0,0,0,0,0,2,2,2,2,2,2,2,2,2,2,0,0,0,0,0], [0,0,0,0,0,0,2,2,2,2,2,2,2,2,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,2,2,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], ] # This section checks the game map to see if there should be a brick there. brickcount=0 for x in range(1,21): for y in range(1,20): if map[y-1][x-1]!=0: drawbrick(x,y,map[y-1][x-1]) brickcount+=1 pygame.display.update() # This section deals with positioning the bat and setting the players score to zero at the start of game. #initialize bat and score batx=random.randint(1,19) # Puts the bat in a random place at bottom of screen BATY=20 drawbat(batx) # Draws the bat by calling the routine we created earlier called 'drawbat' score=0 # Sets the score to zero pygame.display.update() def blank(x,y): pygame.draw.rect (gameSurface,WHITE,(realx(x),realy(y),20,20)) # This draws a white square where the bat used to be # before you moved it. Its used to make the ball move # too and make bricks disappear. def clearbat(x): # This routine clears the bat. Because the bat is 2 squares long we have to run it twice. blank(x,BATY) blank(x+1,BATY) pygame.display.update() # This section deals with randomly putting the ball in an empty area at the top of the screen. ballx=0 bally=0 while map[bally-1][ballx-1]!=0 or ballx==0: ballx=random.randint(1,20) bally=random.randint(1,7) ballxdir=1 ballydir=-1 drawball(ballx,bally) # This section defines how fast the ball will travel. FPS=20 # Frames per second = 20 fpsClock=pygame.time.Clock() pygame.key.set_repeat(1,1) # This bit enables the key to be held down to move the bat without having to keep pressing it. # This bit updates the screen and creates a slight delay #(2.5 seconds in this case) before the game starts. pygame.display.update() time.sleep(2.5) # This section is the main game loop, it checks for key presses, # moves the bat if required, moves the ball, knocks out bricks, # updates the screen, checks if a player has won. # MAIN GAME LOOP while True: for event in pygame.event.get(): oldbat=batx if event.type == QUIT: endgame() if event.type==KEYDOWN: if event.key==K_RIGHT: # If the Right arrow key is pressed batx=batx+1 # move the bat 1 space to the right. elif event.key==K_LEFT: # If the Left arrow key is pressed batx=batx-1 # move the bat 1 space to the left. if batx==0 or batx==20: # This bit stops batx=oldbat # the bat from clearbat(oldbat) # going off drawbat(batx) # the screen. # This section deals with making the ball move. oldballx=ballx oldbally=bally if ballx==1: ballxdir=10 if ballxdir==20: ballxdir=-1 if bally==1: ballydir=1 # uncomment the two lines below for cheat mode. # if bally==BATY-1: # ballydir=-1 pygame.display.update() if havetheywon()==True: # If the conditions to win the game have been met gamewon() # then go to 'gamewon' function. fpsClock.tick(FPS) # This section deals with the ball hitting the bat. if bally==BATY-1: # This is the batleft=batx # code for bouncing batright=batx+1 # the ball off the bat. if ballx>=batleft and ballx<=batright: ballydir=-1 if ballx+ballxdir>=batleft and ballx+ballxdir<=batright: # This code finds out ballydir=-1 # if the ball has reached if bally==BATY: # the same level as the bat, gameover() # if so, the game is over. ballx+=ballxdir # This code changes the direction if map[bally-1][ballx-1]==0: # of the ball depending bally+=ballydir # on what it hits. # This section deals with the scoring. if map[bally-1][ballx-1]!=0: blank(ballx,bally) map[bally-1][ballx-1]=0 bally=oldbally ballx=oldballx ballydir=-ballydir if random.randint(1,10)>5 and map[bally+ballydir-1][ballx-ballxdir-1]==0: ballxdir=-ballxdir score+=1 blank(oldballx,oldbally) drawball(ballx,bally) [ /code]
  2. Hi, I have been trying to recreate the PiBuster game described in 'Raspberry Pi for Dummies' and have copied the code exactly out of the book but I keep getting this error: "IndexError: list index out of range" when I run it. If anyone can throw some light on this (or has the complete working code) I would be grateful. This is the line that it refers to (highlighted in bold) which is very near to the end of the code: ballx+=ballxdir # This code changes the direction if map[bally-1][ballx-1]==0: # of the ball depending bally+=ballydir # on what it hits. And this is the complete code: # PiBuster Code # PiBuster from Raspberry Pi for Dummies import pygame, sys, time, random from pygame.locals import * pygame.init() # initialize pygame # This section deals with setting up the game window gameSurface=pygame.display.set_mode((440,480)) # playing area size (pixels - width,height) pygame.display.set_caption('MrG-PiBuster') # Caption on window title bar pygame.mouse.set_visible(0) # You won't see the mouse pointer in the game window # This section deals with the colours used in the game (note: we have to use the American spelling of 'color' (boo! hiss!)) SHADOW = (192, 192, 192) # The numbers in the brackets are the RED, GREEN and BLUE (RGB) values for the colours WHITE = (255, 255, 255) # Example: 255, 255, 255 is white, 0, 0, 0 is black, 200, 0, 0 is RED LIGHTGREEN = (0, 255, 0) # In this game we will use the colours we have created GREEN = (0, 200, 0) # here as it is easier than typing in the numbers BLUE = (0, 0, 128) LIGHTBLUE = (0, 0, 255) RED = (200, 0, 0) LIGHTRED = (255, 100, 100) PURPLE = (102, 0, 102) LIGHTPURPLE = (153, 0, 153) gameSurface.fill(WHITE) # Turns the game surface white pygame.display.update() # This section deals with positioning the ball def drawball(x,y): pygame.draw.circle (gameSurface,BLUE,(realx(x)+10,realy(y)+10),10,0) pygame.draw.circle (gameSurface,LIGHTBLUE,(realx(x)+6,realy(y)+6),2,0) pygame.display.update() # drawbat - Routine to draw the bat def drawbat(x): pygame.draw.rect (gameSurface,LIGHTPURPLE,(realx(x),realy(BATY),40,4)) pygame.draw.rect (gameSurface,PURPLE,(realx(x),realy(BATY)+4,40,6)) pygame.draw.rect (gameSurface,SHADOW,(realx(x),realy(BATY)+10,40,2)) pygame.draw.rect (gameSurface,SHADOW,(realx(x)+38,realy(BATY),2,12)) # This section deals with drawing shapes on the game surface #pygame.draw.rect(gameSurface,PURPLE,(16,16,406,2)) #pygame.draw.rect(gameSurface,PURPLE,(16,16,2,440)) #pygame.draw.rect(gameSurface,PURPLE,(422,16,2,440)) # This section deals with drawing the bricks def realx(x): x=x*20 return x def realy(y): y=y*20 return y def drawbrick(xcoord,ycoord,col): if col==1: boxcolor=GREEN highlightcolor=LIGHTGREEN else: boxcolor=RED highlightcolor=LIGHTRED pygame.draw.rect (gameSurface,boxcolor,(realx(xcoord),realy(ycoord),20,20)) pygame.draw.rect (gameSurface,highlightcolor,(realx(xcoord),realy(ycoord),2,20)) pygame.draw.rect (gameSurface,highlightcolor,(realx(xcoord),realy(ycoord),20,2)) pygame.draw.rect (gameSurface,SHADOW,(realx(xcoord)+18,realy(ycoord),2,20)) pygame.draw.rect (gameSurface,SHADOW,(realx(xcoord),realy(ycoord)+18,20,2)) # This section deals with displaying 'End of game' type messages def showtext(text): fontObj=pygame.font.Font('freesansbold.ttf',64) # The font name and size. textsurface=fontObj.render(text, True, PURPLE, WHITE) # PURPLE is the text colour, WHITE is the background color. textRectObj=textsurface.get_rect() # Creates a rectangle to display the text. textRectObj.center=(220,200) # Puts the rectangle at position X=220 and Y=200 (note the American spelling of 'center') gameSurface.blit(textsurface,textRectObj) # Puts your text in the rectangle. pygame.display.update() # Now we can create some functions to tell the program what text we would like in the box. def gameover(): showtext('GAME OVER') time.sleep(8) # Show the message for 8 seconds. engame() # This bit runs the 'endgame' function & quits Pygame and closes the PiBuster window. def gamewon(): showtext('GAME WON!') time.sleep(8) # Show the message for 8 seconds. engame() # This bit runs the 'endgame' function & quits Pygame and closes the PiBuster window. def endgame(): # The 'endgame' funtion. pygame.quit() sys.exit() # This funtion checks the program to see if the player has won. def havetheywon(): if score==brickcount: # Every time the player knocks out a brick the program checks return True # the remaining bricks against the original number of bricks and adds one else: # to the score and keeps going (return False) until they are all gone (return True). return False # This section deals with creating the game map map=[ #--------0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9-- # There is a space between each number on this line [0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,0], [0,0,0,1,1,1,1,0,0,0,0,0,0,1,1,1,1,0,0,0], [0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0], [0,0,0,0,0,1,1,1,1,0,0,1,1,1,1,0,0,0,0,0], [0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,2,2,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,2,2,2,2,2,2,2,2,0,0,0,0,0,0], [0,0,0,0,0,2,2,2,2,2,2,2,2,2,2,0,0,0,0,0], [0,0,0,0,0,2,2,2,2,2,2,2,2,2,2,0,0,0,0,0], [0,0,0,0,2,2,2,2,2,2,2,2,2,2,2,2,0,0,0,0], [0,0,0,0,2,2,2,2,2,2,2,2,2,2,2,2,0,0,0,0], [0,0,0,0,0,2,2,2,2,2,2,2,2,2,2,0,0,0,0,0], [0,0,0,0,0,2,2,2,2,2,2,2,2,2,2,0,0,0,0,0], [0,0,0,0,0,0,2,2,2,2,2,2,2,2,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,2,2,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], ] # This section checks the game map to see if there should be a brick there. brickcount=0 for x in range(1,21): for y in range(1,20): if map[y-1][x-1]!=0: drawbrick(x,y,map[y-1][x-1]) brickcount+=1 pygame.display.update() # This section deals with positioning the bat and setting the players score to zero at the start of game. #initialize bat and score batx=random.randint(1,19) # Puts the bat in a random place at bottom of screen BATY=20 drawbat(batx) # Draws the bat by calling the routine we created earlier called 'drawbat' score=0 # Sets the score to zero pygame.display.update() def blank(x,y): pygame.draw.rect (gameSurface,WHITE,(realx(x),realy(y),20,20)) # This draws a white square where the bat used to be # before you moved it. Its used to make the ball move # too and make bricks disappear. def clearbat(x): # This routine clears the bat. Because the bat is 2 squares long we have to run it twice. blank(x,BATY) blank(x+1,BATY) pygame.display.update() # This section deals with randomly putting the ball in an empty area at the top of the screen. ballx=0 bally=0 while map[bally-1][ballx-1]!=0 or ballx==0: ballx=random.randint(1,20) bally=random.randint(1,7) ballxdir=1 ballydir=-1 drawball(ballx,bally) # This section defines how fast the ball will travel. FPS=20 # Frames per second = 20 fpsClock=pygame.time.Clock() pygame.key.set_repeat(1,1) # This bit enables the key to be held down to move the bat without having to keep pressing it. # This bit updates the screen and creates a slight delay #(2.5 seconds in this case) before the game starts. pygame.display.update() time.sleep(2.5) # This section is the main game loop, it checks for key presses, # moves the bat if required, moves the ball, knocks out bricks, # updates the screen, checks if a player has won. # MAIN GAME LOOP while True: for event in pygame.event.get(): oldbat=batx if event.type == QUIT: endgame() if event.type==KEYDOWN: if event.key==K_RIGHT: # If the Right arrow key is pressed batx=batx+1 # move the bat 1 space to the right. elif event.key==K_LEFT: # If the Left arrow key is pressed batx=batx-1 # move the bat 1 space to the left. if batx==0 or batx==20: # This bit stops batx=oldbat # the bat from clearbat(oldbat) # going off drawbat(batx) # the screen. # This section deals with making the ball move. oldballx=ballx oldbally=bally if ballx==1: ballxdir=10 if ballxdir==20: ballxdir=-1 if bally==1: ballydir=1 # uncomment the two lines below for cheat mode. # if bally==BATY-1: # ballydir=-1 pygame.display.update() if havetheywon()==True: # If the conditions to win the game have been met gamewon() # then go to 'gamewon' function. fpsClock.tick(FPS) # This section deals with the ball hitting the bat. if bally==BATY-1: # This is the batleft=batx # code for bouncing batright=batx+1 # the ball off the bat. if ballx>=batleft and ballx<=batright: ballydir=-1 if ballx+ballxdir>=batleft and ballx+ballxdir<=batright: # This code finds out ballydir=-1 # if the ball has reached if bally==BATY: # the same level as the bat, gameover() # if so, the game is over. ballx+=ballxdir # This code changes the direction if map[bally-1][ballx-1]==0: # of the ball depending bally+=ballydir # on what it hits. # This section deals with the scoring. if map[bally-1][ballx-1]!=0: blank(ballx,bally) map[bally-1][ballx-1]=0 bally=oldbally ballx=oldballx ballydir=-ballydir if random.randint(1,10)>5 and map[bally+ballydir-1][ballx-ballxdir-1]==0: ballxdir=-ballxdir score+=1 blank(oldballx,oldbally) drawball(ballx,bally)
  3. I have been running an after school Raspberry Pi club for Y5 & Y6 children - using 5 devices, 2 children per device. I have fitted Pibrellas to all of them and we have been coding things in Python like traffic lights, pelican crossing etc.
  4. Ok thanks guys, I'll try these out. Cheers.
  5. Thanks, I'll take a look at this.
  6. The problem with Wordpad is its ok if they're just doing a bit of typing but if its project work etc, with pictures and wordart its not really up to it.
  7. Hi Does anyone know if there is a way of disabling spelling, punctuation and grammar in Word etc? Some teachers have asked that it be turned off as kids are just using it rather than learning the proper way. Is it likely that I would have to turn it off across the whole network? Office 2013 is installed on all PCs thro' group policy. Anyone had experience of this?
  8. I will try another cable but it would still have to go thro' the HDMI - VGA convertor as the projector is only VGA.
  9. Ah, no, if I disconnect the PC signal the wobble goes away
  10. Yes I always use 1024 x 768 as the resolution so it can't be that
  11. The signal is HDMI coming from the PC thro' a convertor to VGA to the projector.
  12. Its the image, the board is mounted on a solid wall. The image wobbled continuously throughout the lesson.
  13. Thanks, I'll check it out.
  14. Hi, I checked that and its tight
  15. Hi, one of our projectors, an Epson EB-X11 has recently started suffering from image wobble. It doesn't seem to be related to the ceiling mount as there is no one above and even if I hold it still it still happens. IS this perhaps a sign of something in the projector failing? Has anyone experienced this?
  16. I am getting somewhere now with Apple Support. I need to contact one of the 3 resellers Apple have in this country (none of which we bought from). I'll see where it goes from there.
  17. Thanks, I'll give that a go.
  18. No it still gives the same result. The link you give takes me to: Then sign in and get: Click on 'Get started' and get: Sign in again and get: And finally:
  19. Yes tried Safari now and still the same result.
  20. I first tried it on Chrome then IE 11.
  21. When ever I try to use the volume purchasing (after signing in) I see the message "This Apple ID has not yet been used with the Volume Purchase Program" then click on "Continue" I get "an unknown error has occurred". Anyone else had this? Its driving me nuts!
  22. The only bit I can't get to work is the last bit: sudo pip install pibrella. sudo apt-get -o Acquire::http:proxy="http://proxyurlport" update sudo apt-get -o Acquire::http:proxy="http://proxyurlport" upgrade sudo apt-get -o Acquire::http:proxy="http://proxyurlport" install python-pip all work ok.
  23. Thanks all, I found this on another post in the end which worked: sudo apt-get -o Acquire::http::proxy="http://proxyurl:port" update
  24. Hi Thanks for your reply but when I type this at the command prompt I get this: bash: Acquire::http::proxy command not found (the 'p' of proxy keeps turning into a smiley in my post....Grrr)
×
×
  • Create New...