Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Pypalla V2 - palla.py

palla.py

Caricato da: Key-blade
Scarica il programma completo

  1. # -*- coding: cp1252 -*-
  2. #Autore =Key-blade
  3. #v=1.0
  4. #
  5. #   Copyright (C) 2009  Keyblade
  6. #
  7. #   This program is free software: you can redistribute it and/or modify
  8. #   it under the terms of the GNU General Public License as published by
  9. #   the Free Software Foundation, either version 3 of the License, or
  10. #   (at your option) any later version.
  11. #
  12. #   This program is distributed in the hope that it will be useful,
  13. #   but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. #   GNU General Public License for more details.
  16. #
  17. #   You should have received a copy of the GNU General Public License
  18. #   along with this program.  If not, see <http://www.gnu.org/licenses/>.
  19.  
  20. ###################################
  21. #Importo I moduli
  22. import os, sys, pygame, random
  23. from pygame.locals import *
  24. from pygame import *
  25.  
  26.  
  27. import sys
  28. ####################################
  29. #Inzizio Programma
  30. os.environ['SDL_VIDEO_CENTERED'] = "1"
  31. pygame.init()
  32. pygame.display.set_caption("PallaPy")
  33. icon = pygame.image.load("icona.png")
  34. icon = pygame.display.set_icon(icon)
  35. screen = pygame.display.set_mode((640,480))#,pygame.FULLSCREEN)
  36. pygame.mouse.set_visible(0)
  37. ballpic = image.load('palla.png')
  38. ballx = 9      
  39. bally = 6
  40. ballxmove = 60
  41. ballymove = 100
  42. vita=5
  43.  
  44. ####################################
  45. #Sfondo
  46. background = pygame.Surface(screen.get_size())
  47. background = background.convert()
  48. background.fill((0,0,0))
  49. ###################################    
  50. #Sistema conteggio punti
  51.        
  52. class Score(pygame.sprite.Sprite):
  53.     def __init__(self):
  54.         pygame.sprite.Sprite.__init__(self)
  55.         self.vita = time.get_ticks()/1000
  56.         self.font = pygame.font.Font(None, 25)
  57.        
  58.     def update(self):
  59.         self.text = "Punteggio: %d" % (self.vita)
  60.         self.image = self.font.render(self.text, 1, (0, 255, 0))
  61.         self.rect = self.image.get_rect()
  62.         self.rect.center = (320,20)
  63.  
  64.  
  65.        
  66. ###################################################################        
  67. #Gioco
  68. def game():
  69.     ballx = 9  
  70.     bally = 6
  71.     ballxmove = 5
  72.     ballymove = 5
  73.     vita=5
  74.     global score
  75.     score = Score()
  76.     scoreSprite = pygame.sprite.Group(score)
  77.     clock = pygame.time.Clock()
  78.     keepGoing = True
  79.     counter = 0
  80.     #Main Loop
  81.     while keepGoing:
  82.        clock.tick(30)
  83.        screen.fill(0)  
  84.        screen.blit(ballpic, (ballx, bally))    
  85.        scoreSprite.update()
  86.        scoreSprite.draw(screen)
  87.        pygame.display.flip()
  88.        ballx = ballx + ballxmove       
  89.        bally = bally + ballymove
  90.        if score.vita ==-10:
  91.            sys.exit()
  92.        if ballx > 600:
  93.            ballxmove = -3
  94.            score.vita += -10
  95.        if ballx < 0:
  96.            ballxmove = 3
  97.            score.vita += -10
  98.        if bally > 440:
  99.            ballymove = -3
  100.            score.vita += -10
  101.        if bally < 0:
  102.            ballymove = 3
  103.            score.vita += -10
  104.        if screen.get_at((mouse.get_pos())) == (255, 255, 255, 255):
  105.            done=True
  106.  
  107.        for e in event.get():
  108.            if e.type == KEYUP:
  109.                if e.key == K_RIGHT:
  110.                    ballxmove = 3
  111.                    score.vita += +10
  112.                if e.key == K_LEFT :
  113.                    ballxmove = -3
  114.                    score.vita += +10
  115.                if e.key == K_ESCAPE :
  116.                    sys.exit()
  117.                if e.key == K_UP  :
  118.                    score.vita += +10  
  119.                    ballymove = -3
  120.                if e.key == K_DOWN:
  121.                    ballymove  = 3
  122.                    score.vita += +10  
  123. if __name__ == "__main__":
  124.     game()