Previously I have posted a very useful blog explaining how to Remotely Find Raspberry Pi IP Address. This used a tool called Nmap which works on Linux, Macs and Windows.
Nmap is very powerful and is a great tool to use.
Recently however I was introduced to a very simple to use app called Fing.
Fing is an app which is available for most smartphones and tablets. I run it off both Android and an iPad.
Simply install it, and then load it up. It analyses your network and returns a list of all the IP Addresses and the Computers name associated with them. It really is that simple!
Here is the entry for my Raspberry Pi, which clearly shows the IP address is 192.168.1.110.
Fing is such a simple and easy tool to use I am sure you will find it indispensable in no time!
Since writing my blog post explaining how to Write Pong Using Python and Pygame the guys over at Webucator (a Python Training Company) have refactored it to include OOP. They have created an excellent video tutorial on this as part of their new free self-paced "Python Solutions from the Web" course they are developing.
You should definitely check out the video as they really have done an awesome job!
Nat who helped create the tutorial was also kind enough to provide the source code which I have included below, which will help you follow the video.
Enjoy!
importpygame,sysfrompygame.localsimport*# Set up the coloursBLACK=(0,0,0)WHITE=(255,255,255)window_width=400window_height=300display_surf=pygame.display.set_mode((window_width,window_height))fps_clock=pygame.time.Clock()fps=40# Number of frames per secondclassGame():def__init__(self,line_thickness=10,speed=5):self.line_thickness=line_thicknessself.speed=speedself.score=0#Initiate variable and set starting positions#any future changes made within rectanglesball_x=int(window_width/2-self.line_thickness/2)ball_y=int(window_height/2-self.line_thickness/2)self.ball=Ball(ball_x,ball_y,self.line_thickness,self.line_thickness,self.speed)self.paddles={}paddle_height=50paddle_width=self.line_thicknessuser_paddle_x=20computer_paddle_x=window_width-paddle_width-20self.paddles['user']=Paddle(user_paddle_x,paddle_width,paddle_height)self.paddles['computer']=AutoPaddle(computer_paddle_x,paddle_width,paddle_height,self.ball,self.speed)self.scoreboard=Scoreboard(0)#Draws the arena the game will be played in. defdraw_arena(self):display_surf.fill((0,0,0))#Draw outline of arenapygame.draw.rect(display_surf,WHITE,((0,0),(window_width,window_height)),self.line_thickness*2)#Draw centre linepygame.draw.line(display_surf,WHITE,(int(window_width/2),0),(int(window_width/2),window_height),int(self.line_thickness/4))defupdate(self):self.ball.move()self.paddles['computer'].move()ifself.ball.hit_paddle(self.paddles['computer']):self.ball.bounce('x')elifself.ball.hit_paddle(self.paddles['user']):self.ball.bounce('x')self.score+=1elifself.ball.pass_computer():self.score+=5elifself.ball.pass_player():self.score=0self.draw_arena()self.ball.draw()self.paddles['user'].draw()self.paddles['computer'].draw()self.scoreboard.display(self.score)classPaddle(pygame.sprite.Sprite):def__init__(self,x,w,h):self.x=xself.w=wself.h=hself.y=int(window_height/2-self.h/2)#Creates Rectangle for paddle.self.rect=pygame.Rect(self.x,self.y,self.w,self.h)#Draws the paddledefdraw(self):#Stops paddle moving too lowifself.rect.bottom>window_height-self.w:self.rect.bottom=window_height-self.w#Stops paddle moving too highelifself.rect.top<self.w:self.rect.top=self.w#Draws paddlepygame.draw.rect(display_surf,WHITE,self.rect)#Moves the paddledefmove(self,pos):self.rect.y=pos[1]classAutoPaddle(Paddle):def__init__(self,x,w,h,ball,speed):super().__init__(x,w,h)self.ball=ballself.speed=speeddefmove(self):#If ball is moving away from paddle, center batifself.ball.dir_x==-1:ifself.rect.centery<int(window_height/2):self.rect.y+=self.speedelifself.rect.centery>int(window_height/2):self.rect.y-=self.speed#if ball moving towards bat, track its movement. elifself.ball.dir_x==1:ifself.rect.centery<self.ball.rect.centery:self.rect.y+=self.speedelse:self.rect.y-=self.speedclassBall(pygame.sprite.Sprite):def__init__(self,x,y,w,h,speed):self.x=xself.y=yself.w=wself.h=hself.speed=speedself.dir_x=-1## -1 = left 1 = rightself.dir_y=-1## -1 = up 1 = downself.rect=pygame.Rect(self.x,self.y,self.w,self.h)#draws the balldefdraw(self):pygame.draw.rect(display_surf,WHITE,self.rect)#moves the ball returns new positiondefmove(self):self.rect.x+=(self.dir_x*self.speed)self.rect.y+=(self.dir_y*self.speed)#Checks for a collision with a wall, and 'bounces' ball off it.ifself.hit_ceiling()orself.hit_floor():self.bounce('y')ifself.hit_wall():self.bounce('x')defbounce(self,axis):ifaxis=='x':self.dir_x*=-1elifaxis=='y':self.dir_y*=-1defhit_paddle(self,paddle):ifpygame.sprite.collide_rect(self,paddle):returnTrueelse:returnFalsedefhit_wall(self):if((self.dir_x==-1andself.rect.left<=self.w)or(self.dir_x==1andself.rect.right>=window_width-self.w)):returnTrueelse:returnFalsedefhit_ceiling(self):ifself.dir_y==-1andself.rect.top<=self.w:returnTrueelse:returnFalsedefhit_floor(self):ifself.dir_y==1andself.rect.bottom>=window_height-self.w:returnTrueelse:returnFalsedefpass_player(self):ifself.rect.left<=self.w:returnTrueelse:returnFalsedefpass_computer(self):ifself.rect.right>=window_width-self.w:returnTrueelse:returnFalseclassScoreboard():def__init__(self,score=0,x=window_width-150,y=25,font_size=20):self.score=scoreself.x=xself.y=yself.font=pygame.font.Font('freesansbold.ttf',font_size)#Displays the current score on the screendefdisplay(self,score):self.score=scoreresult_surf=self.font.render('Score = %s'%(self.score),True,WHITE)rect=result_surf.get_rect()rect.topleft=(self.x,self.y)display_surf.blit(result_surf,rect)#Main functiondefmain():pygame.init()pygame.display.set_caption('Pong')pygame.mouse.set_visible(0)# make cursor invisiblegame=Game(speed=4)whileTrue:#main game loopforeventinpygame.event.get():ifevent.type==QUIT:pygame.quit()sys.exit()# mouse movement commandselifevent.type==MOUSEMOTION:game.paddles['user'].move(event.pos)game.update()pygame.display.update()fps_clock.tick(fps)if__name__=='__main__':main()