Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Program: Terzo script
- Author: Lorenzo Benevento
- First - Last data modified: 15-02-2014 - 15-02-2014
- Description: Software di prova.
- PyVersion = 2.*
- """
- import pygame
- from pygame.locals import *
- import cwiid
- import time
- import sys
- def initWiimote():
- while True:
- print("Press 1 + 2 on your wiimote now...")
- time.sleep(1)
- try:
- wm = cwiid.Wiimote()
- break
- except RuntimeError:
- tempVar = raw_input("Error while connecting wiimote. Press enter to retry, other button and enter to close software> ")
- if tempVar == "":
- pass
- else:
- sys.exit()
- print("Connected.")
- wm.rpt_mode = cwiid.RPT_BTN
- return wm
- def initJoystick():
- joystick = None
- if pygame.joystick.get_count() > 0:
- joystick = pygame.joystick.Joystick(0)
- joystick.init()
- if joystick is None:
- print ("Siamo spiacenti, ma hai bisogno di un joystick con almeno 10 tasti!")
- sys.exit()
- return joystick
- def main(controller, velocita):
- pygame.init()
- pressedButtons = set()
- pointerImm = "puntatore.png"
- speed = 500
- clock = pygame.time.Clock()
- if controller == "wiimote":
- wm = initWiimote()
- screen = pygame.display.set_mode((640,480), DOUBLEBUF | HWSURFACE, 32)
- pygame.display.set_caption("Input Vari")
- backgroundIntro = pygame.image.load("introduzione.jpg").convert()
- backgroundGame = pygame.image.load("giocoavviato.jpg").convert()
- background = backgroundIntro
- pointer = pygame.image.load(pointerImm).convert_alpha()
- tasto_start = pygame.Rect((200,100),(200,200))
- if controller == "joystick":
- joystick = initJoystick()
- x , y = 0,0
- move_x, move_y = 0,0
- while True:
- if controller == "wiimote":
- buttons = wm.state["buttons"]
- if (buttons - cwiid.BTN_UP == 0):
- pressedButtons.add("UP")
- move_y = -1
- elif "UP" in pressedButtons:
- pressedButtons.remove("UP")
- move_y = 0
- if (buttons - cwiid.BTN_DOWN == 0):
- pressedButtons.add("DOWN")
- move_y = 1
- elif "DOWN" in pressedButtons:
- pressedButtons.remove("DOWN")
- move_y = 0
- if (buttons - cwiid.BTN_LEFT == 0):
- pressedButtons.add("LEFT")
- move_x = -1
- elif "LEFT" in pressedButtons:
- pressedButtons.remove("LEFT")
- move_x = 0
- if (buttons - cwiid.BTN_RIGHT == 0):
- pressedButtons.add("RIGHT")
- move_x = 1
- elif "RIGHT" in pressedButtons:
- pressedButtons.remove("RIGHT")
- move_x = 0
- if (buttons - cwiid.BTN_HOME == 0):
- background = backgroundIntro
- if (buttons - cwiid.BTN_A == 0):
- background = backgroundGame
- if (buttons - cwiid.BTN_PLUS - cwiid.BTN_MINUS == 0):
- wm.rumble = 1
- time.sleep(1)
- wm.rumble = 0
- sys.exit(wm)
- for event in pygame.event.get():
- if event.type == QUIT:
- sys.exit()
- if controller == "keyboard" or controller == "joystick":
- if event.type == KEYDOWN:
- tasti_premuti = pygame.key.get_pressed()
- if tasti_premuti[K_ESCAPE]:
- sys.exit(wm)
- if tasti_premuti[K_LALT] and tasti_premuti[K_F4]:
- sys.exit(wm)
- if event.key == K_UP:
- move_y = -1
- if event.key == K_DOWN:
- move_y = 1
- if event.key == K_LEFT:
- move_x = -1
- if event.key == K_RIGHT:
- move_x = 1
- elif event.type == KEYUP:
- if event.key == K_UP:
- move_y = 0
- if event.key == K_DOWN:
- move_y = 0
- if event.key == K_LEFT:
- move_x = 0
- if event.key == K_RIGHT:
- move_x = 0
- if controller == "joystick":
- if joystick != None and joystick.get_button(7):
- if background == backgroundIntro:
- background = backgroundGame
- pygame.mouse.set_visible(False)
- timeSpent = clock.tick(30)
- timeSpentSec = timeSpent/1000.0
- movementDistance = timeSpentSec*speed
- x += move_x * movementDistance
- y += move_y * movementDistance
- tasto_start.move_ip(move_x * movementDistance,move_y * movementDistance)
- screen.fill((0,0,0))
- screen.blit(background, (x,y))
- if controller == "keyboard":
- pulsanti_mouse = pygame.mouse.get_pressed()
- coordinate_mouse = pygame.mouse.get_pos()
- if pulsanti_mouse[0]==1:
- if background == backgroundIntro:
- if tasto_start.collidepoint(coordinate_mouse):
- background = backgroundGame
- if pulsanti_mouse[2]==1:
- if background == backgroundGame:
- background = backgroundIntro
- screen.blit(pointer, coordinate_mouse)
- pygame.display.flip()
Advertisement
Add Comment
Please, Sign In to add comment