Exemplo n.º 1
0
def paused(gameDisplay,display_width,display_height,message,pause=False):
    #gameDisplay.fill(white)

    largeText = pygame.font.SysFont("comicsansms", 100)
    TextSurf, TextRect = displayText.display_text(message, largeText , white)
    TextRect.center = ((display_width / 2), (display_height / 5))
    gameDisplay.blit(TextSurf, TextRect)

    while pause:
        for event in pygame.event.get():

            if event.type == pygame.QUIT:
                pygame.quit()
                quit()

        continueAction = None

        continueAction = buttons.button(gameDisplay,"Continue", 350, 250, 100, 50, green, bright_green,'continue_game')
        buttons.button(gameDisplay,"Quit", 750, 250, 100, 50, red, bright_red)

        if continueAction is 'continueGame' :
            pause = False

        pygame.display.update()
        clock.tick(15)
Exemplo n.º 2
0
def drawScrollWindow(slide_pos):
    width = 165
    height = 145
    x = (display_width - width - 50)
    y = (display_height - height - 50)
    s = pygame.Surface((width, height))
    bag_slot = []
    for i in range(60):
        bag_slot.append(buttons.button(str(i), x, y, 30,
                                       30))  #initalize bag slots
    bag_length = (
        ((len(bag_slot) / 4) * 35) + 5)  #bag length in pixles or window size
    bag_bar_ratio = float(
        (float(height - 40)) /
        float(bag_length))  #ratio between bar and bag pixel size
    bar_size = int((height - 40) * bag_bar_ratio)  #slide bar size in pixles
    s.set_alpha(200)
    s.fill(gray)
    game_display.blit(s, (x, y))

    slide_up = buttons.button('/\\', x + width - 20, y + 5, 15,
                              15)  #scroll up object
    slide_up.drawButton(game_display)
    slide_down = buttons.button('\\/', x + width - 20, y + height - 20, 15,
                                15)  #scroll down object
    slide_down.drawButton(game_display)

    if pygame.mouse.get_pressed() == (1, 0, 0):  #scroll bar event handling
        if 0 < slide_pos:
            if slide_up.checkClicked():
                slide_pos -= 1
                print(bag_length, bag_bar_ratio, bar_size)
        if slide_pos < ((len(bag_slot) / 4) - 4):
            if slide_down.checkClicked():
                slide_pos += 1
                print(bag_length, bag_bar_ratio, bar_size)

    slide_bar = buttons.button('', x + width - 20, y + 20 + int(
        (35 * slide_pos) * bag_bar_ratio) + slide_pos, 15,
                               bar_size)  #create slide bar object
    slide_bar.drawButton(game_display)  #display slide bar

    #display bag slots
    for iy in range(4):
        for ix in range(4):
            bag_slot[(iy * 4) + (slide_pos * 4) + ix].setX(x + 5 + (ix * 35))
            bag_slot[(iy * 4) + (slide_pos * 4) + ix].setY(y + 5 + (iy * 35))
            bag_slot[(iy * 4) + (slide_pos * 4) + ix].drawButton(game_display)

    return (slide_pos)
Exemplo n.º 3
0
    def initUI(self):

        screen_resolution = app.desktop().screenGeometry()
        self.screen_width = screen_resolution.width()
        self.screen_height = screen_resolution.height()
        print('Screen resolution = {}x{}'.format(self.screen_width,
                                                 self.screen_height))

        # Resolution multiplicator
        if (self.screen_width == 3840 and self.screen_height == 2160):
            self.resMult = 2
        else:
            self.resMult = 1

        self.col = QColor(0, 0, 0)

        # Init layout
        self.grid()
        buttons.button(self)
        symbols.symbol(self)
        self.winLine()

        ###########################################################################
        self.statusbar = self.statusBar()
        self.statusbar.showMessage('Ready')
        self.statusbar.showMessage('Player X begin')

        menubar = self.menuBar()
        viewMenu = menubar.addMenu('View')
        resetMenu = menubar.addMenu('Play again')

        viewStatAct = QAction('View statusbar', self, checkable=True)
        viewStatAct.setStatusTip('View statusbar')
        viewStatAct.setChecked(True)
        viewStatAct.triggered.connect(self.toggleMenu)

        resetAct = QAction('Play Again', self)
        resetAct.setStatusTip('Play an other game')
        resetAct.triggered.connect(self.playAgain)
        resetAct.setShortcut('R')

        viewMenu.addAction(viewStatAct)
        resetMenu.addAction(resetAct)

        ###########################################################################
        self.setGeometry(300 * self.resMult, 300 * self.resMult,
                         600 * self.resMult, 500 * self.resMult)
        self.setWindowTitle('Tic Tac Toe')
        self.show()
Exemplo n.º 4
0
	def draw(self, choose_screen):
		clear((255,255,255),choose_screen)



		#self.pic_face = img.img((300,600),(90,0),"boyheads2.jpeg")
		#self.pic_face.draw(choose_screen)
		self.pic_hair = img.img(self.hair_list[self.hair][1],self.hair_list[self.hair][2],self.hair_list[self.hair][0])
		self.pic_hair.draw(choose_screen)
		self.pic_mouth = img.img((100,80),(200,300),self.mouth_list[self.mouth])
		self.pic_mouth.draw(choose_screen)
		self.pic_nose = img.img((60,50),(220,240),self.nose_list[self.nose])
		self.pic_nose.draw(choose_screen)
		self.pic_eyes = img.img((140,50),(180,170),self.eyes_list[self.eye])
		self.pic_eyes.draw(choose_screen)



		next1 = img.img((50,50),(420,70),"next.png")
		next1.draw(choose_screen)
		pre1 = img.img((50,50),(40,70),"pre.png")
		pre1.draw(choose_screen)
		next2 = img.img((50,50),(420,160),"next.png")
		next2.draw(choose_screen)
		pre2 = img.img((50,50),(40,160),"pre.png")
		pre2.draw(choose_screen)
		next3 = img.img((50,50),(420,220),"next.png")
		next3.draw(choose_screen)
		pre3 = img.img((50,50),(40,220),"pre.png")
		pre3.draw(choose_screen)
		next4 = img.img((50,50),(420,320),"next.png")
		next4.draw(choose_screen)
		pre4 = img.img((50,50),(40,320),"pre.png")
		pre4.draw(choose_screen)
		f = buttons.button((170,65),(325,435),(255,151,153))
		f.draw(choose_screen)
		g = label.Label((333,440),(70,70),(232,23,61), "None" , 45, "Play Again")
		g.draw(choose_screen)
		f2 = buttons.button((170,65),(0,435),(255,151,153))
		f2.draw(choose_screen)
		g2 = label.Label((10,440),(70,70),(232,23,61), "None" , 45, "Play game")
		g2.draw(choose_screen)
		pygame.display.flip()
Exemplo n.º 5
0
def drawScrollWindow(slide_pos):
    width = 165
    height = 145
    x = (display_width-width-50)
    y = (display_height-height-50)
    s = pygame.Surface((width,height))
    bag_slot = []
    for i in range(60): bag_slot.append(buttons.button(str(i),x,y,30,30))#initalize bag slots
    bag_length = (((len(bag_slot)/4)*35)+5)#bag length in pixles or window size
    bag_bar_ratio = float((float(height-40))/float(bag_length))#ratio between bar and bag pixel size
    bar_size = int((height-40)*bag_bar_ratio)#slide bar size in pixles
    s.set_alpha(200)
    s.fill(gray)
    game_display.blit(s,(x,y))

    slide_up =  buttons.button('/\\',x+width-20,y+5,15,15)#scroll up object
    slide_up.drawButton(game_display)
    slide_down = buttons.button('\\/',x+width-20,y+height-20,15,15)#scroll down object
    slide_down.drawButton(game_display)

    if pygame.mouse.get_pressed() == (1,0,0): #scroll bar event handling
        if 0 < slide_pos:
            if slide_up.checkClicked():
                slide_pos -= 1
                print(bag_length,bag_bar_ratio,bar_size)
        if slide_pos < ((len(bag_slot)/4)-4):
            if slide_down.checkClicked():
                slide_pos += 1
                print(bag_length,bag_bar_ratio,bar_size)
    
    slide_bar = buttons.button('',x+width-20,y+20+int((35*slide_pos)*bag_bar_ratio)+slide_pos,15,bar_size)#create slide bar object
    slide_bar.drawButton(game_display)#display slide bar

    #display bag slots
    for iy in range(4):
        for ix in range(4):
            bag_slot[(iy*4)+(slide_pos*4)+ix].setX(x+5+(ix*35))
            bag_slot[(iy*4)+(slide_pos*4)+ix].setY(y+5+(iy*35))
            bag_slot[(iy*4)+(slide_pos*4)+ix].drawButton(game_display)
                                        
    return(slide_pos)
Exemplo n.º 6
0
def update(main_screen, pos, place, points):
	main_game.clear((255,255,255),main_screen)
	apple = img.img((100,100),(place[0],place[1]),"apple.jpg")
	apple.location = place
	apple.draw(main_screen)
	player = img.img((100,100),pos,"screenshot.jpeg")
	player.draw(main_screen)
	f = buttons.button((170,65),(325,435),(255,151,153))
	f.draw(main_screen)
	g = label.Label((333,440),(70,70),(232,23,61), "None" , 45, str(points) + " points")
	g.draw(main_screen)
	return apple
Exemplo n.º 7
0
def game_intro(gameDisplay, display_width, display_height, sound):
    white = (255, 255, 255)
    black = (0, 0, 0)

    red = (255, 0, 0)
    green = (0, 255, 0)
    blue = (0, 0, 255)

    bright_red = (255, 128, 0)
    bright_green = (0, 255, 128)

    intro = True

    while intro:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()

        introAction = None

        gameDisplay.fill(white)
        largeText = pygame.font.Font('freesansbold.ttf', 115)
        TextSurf, TextRect = displayText.display_text("Football Game",
                                                      largeText)
        TextRect.center = ((display_width / 2), (display_height / 2))
        gameDisplay.blit(TextSurf, TextRect)

        introAction = buttons.button(gameDisplay, "Go", 400, 450, 100, 50,
                                     green, bright_green, 'close_intro')
        buttons.button(gameDisplay, "Cancel", 800, 450, 100, 50, red,
                       bright_red, 'close_game')

        if introAction is 'closeIntroClicked':
            #pygame.mixer.Sound.play(sound)
            #pygame.mixer.music.stop()
            intro = False

        pygame.display.update()
        clock.tick(15)
 def introLoop(self): #Intro screen loop
     pygame.key.set_repeat(1,50)
     while (self.state == "INTRO"):
         self.background.fill((0, 0, 0))
         for event in pygame.event.get():
             if (event.type == pygame.QUIT):
                 sys.exit()
         self.mousePos = pygame.mouse.get_pos()
         self.mouseClick = pygame.mouse.get_pressed()
         gameIntroFont = pygame.font.SysFont("papyrus", 80)
         gameIntroMsg = gameIntroFont.render("Dungeon   Game", False, (255, 0, 0))
         self.screen.blit(gameIntroMsg, ((self.width//3.5), self.height//4))   
         pygame.display.flip()
         ### Start button generation
         startButton = button((50, 200, 50), (20, 150, 20), 192, 520, 192, 100, "Start", 50)
         startButton.isOver(self.mousePos, self.screen)
         if (startButton.isClicked(self.mousePos, self.mouseClick) == True):
             self.state = "GAME"
             self.gameLoop()
         ### Quit button generation
         quitButton = button((200, 50, 50), (170, 20, 20), 576, 520, 192, 100, "Quit", 50)
         quitButton.isOver(self.mousePos, self.screen)
         if (quitButton.isClicked(self.mousePos, self.mouseClick) == True):
             pygame.quit()        
Exemplo n.º 9
0
def initMenu():
    # init menu objects
    x = ((display_width/2)-75)
    y = ((display_height/2)-100)
    butt = []
    for i in range(5):
        butt.append(buttons.button('',x+5,y+5+(i*35),140,30))
        butt[i].setFont(small_font)
        butt[i].setTextColor((0,255,0))
        butt[i].setBackColor((0,0,255))
        butt[i].setHover(gray,True)
        butt[i].setAlpha(50)
    butt[0].setText('Continue')
    butt[4].setText('Exit')
    return(butt)
Exemplo n.º 10
0
def initMenu():
    # init menu objects
    x = ((display_width / 2) - 75)
    y = ((display_height / 2) - 100)
    butt = []
    for i in range(5):
        butt.append(buttons.button('', x + 5, y + 5 + (i * 35), 140, 30))
        butt[i].setFont(small_font)
        butt[i].setTextColor((0, 255, 0))
        butt[i].setBackColor((0, 0, 255))
        butt[i].setHover(gray, True)
        butt[i].setAlpha(50)
    butt[0].setText('Continue')
    butt[4].setText('Exit')
    return (butt)
Exemplo n.º 11
0
def run(main_screen):
	a = buttons.button((110,60),(360,255),(255,151,153))
	a.draw(main_screen)
	b = label.Label((370,270) , (75,30) , (232,32,61) , "None", 40, "Female")
	b.draw(main_screen)
	c = buttons.button((110,60),(70,255),(255,151,153))
	c.draw(main_screen)
	d = label.Label((95,270) , (75,30) , (232,23,61) , "None", 40, "Male")
	d.draw(main_screen)
	e = label.Label((180,150) , (60,60) , (232,14,33) , "None", 50, "Welcome !")
	e.draw(main_screen)
	while True:
		ev = pygame.event.poll()
		if ev.type == pygame.QUIT:
			sys.exit()
		if ev.type == pygame.MOUSEBUTTONDOWN:
			x, y = ev.pos	
			if c.rec.collidepoint(x,y):
				clear((255,255,255),main_screen)
				choose_screen.run(main_screen, True)
			if a.rec.collidepoint(x,y):
				clear((255,255,255),main_screen)	
				choose_screen.run(main_screen, False)
		pygame.display.flip()
Exemplo n.º 12
0
	def __init__(self,x,y,text="Mensaje default" , bar_text="Input" , function=none , width=Constants.prompt_default_width , height=Constants.prompt_default_height):
		""" prompt de la pantalla """
		element.__init__(self,x,y,width,height)
		self.alive = True
		self.function = function
		
		bx=Constants.prompt_title_x
		by=Constants.prompt_title_y
		bw=Constants.prompt_title_width
		bh=Constants.prompt_title_height

		tx=Constants.prompt_text_x
		ty=Constants.prompt_text_y
		tw=Constants.prompt_text_width
		th=Constants.prompt_text_height

		bux=Constants.prompt_button_x
		buy=Constants.prompt_button_y
		buw=Constants.prompt_button_width
		buh=Constants.prompt_button_height
	
		self.bar = bar(int(width*bx),int(height*by),int(width*bw),int(height*bh),bar_text,self.move)	
		self.text = plain_text(int(width*tx),int(height*ty),int(width*tw),int(height*th),text)
		self.button = button(int(width*bux),int(height*buy),int(width*buw),int(height*buh),self.__die__)
 def gameLoop(self): #Game loop
     pygame.key.set_repeat(1,50)
     while (self.state == "GAME"):
         self.background.fill((0, 0, 0))
         for event in pygame.event.get():
             if (event.type == pygame.QUIT):
                 sys.exit()
         self.mousePos = pygame.mouse.get_pos()
         self.mouseClick = pygame.mouse.get_pressed()
         pygame.display.flip()
         fightButton = button((212, 175, 55), (182, 145, 25), 800, 630, 100, 45, "Fight", 25)
         fightButton.isOver(self.mousePos, self.screen)
         runButton = button((212, 175, 55), (182, 145, 25), 800, 540, 100, 45, "Run", 25)
         runButton.isOver(self.mousePos, self.screen)
         sneakButton = button((212, 175, 55), (182, 145, 25), 800, 450, 100, 45, "Sneak", 20)
         sneakButton.isOver(self.mousePos, self.screen)
         goldButton = button((212, 175, 55), (182, 145, 25), 650, 630, 100, 45, "Gold", 25)
         goldButton.isOver(self.mousePos, self.screen)
         trapsButton = button((212, 175, 55), (182, 145, 25), 650, 540, 100, 45, "Traps", 20)
         trapsButton.isOver(self.mousePos, self.screen) 
         itemsButton = button((212, 175, 55), (182, 145, 25), 650, 450, 100, 45, "Items", 20)
         itemsButton.isOver(self.mousePos, self.screen)              
Exemplo n.º 14
0
pygame.init()

screen_x = 1280  # Screen dimension x
screen_y = 720  # Screen dimension y
window = pygame.display.set_mode((screen_x, screen_y))

bg = pygame.image.load('background/dragon_ball_z_bg.png')  # Importing background image
play_btn_img = pygame.image.load('background/btn/play_btn_red.png')
quit_btn_img = pygame.image.load('background/btn/exit_btn_red.png')
play_btn_toggle_img = pygame.image.load('background/btn/play_btn_yellow.png')
quit_btn_toggle_img = pygame.image.load('background/btn/exit_btn_yellow.png')

width = 300
height = 95
play_btn = buttons.button(screen_x / 2 - width / 2 - 200, screen_y / 2 - height / 2 - 50, width, height, (0, 0, 255), '', play_btn_img)
quit_btn = buttons.button(screen_x / 2 - width / 2 + 200, screen_y / 2 - height / 2 - 50, width, height, (0, 0, 255), '', quit_btn_img)
dim_screen = pygame.Surface((screen_x, screen_y)).convert_alpha()
dim_screen.fill((0, 0, 0, 130))

menu = True
background = True

pygame.mixer.music.load('sound/dragon_ball_bg.mp3')
pygame.mixer.music.set_volume(0.15)
pygame.mixer.music.play(-1)

hover_btn = pygame.mixer.Sound('sound/hover_btn.wav')
play_1 = True
play_2 = True
Exemplo n.º 15
0
import legs
import RPi.GPIO as GPIO

from threading import Thread  #,Lock
from time import perf_counter, sleep
import keyboard

gpioinit()  #Initialize the GPIO system so we may use the pins for I/O.


def deadzone(aValue, aLimit):
    return aValue if abs(aValue) >= aLimit else 0.0


_dtime = .03
_startupswitch = button(26)

#Sound Channels
#0 = idle
#1 = voices
#2 = body
#3 = gun


#--------------------------------------------------------
class sentrybot(object):

    _PEACE, _COMBAT, _SND1, _SND2 = range(4)

    #map of button to sound object.  This is loaded from a json file.
    #1st sound is for peacful stance, 2nd is combat stance.
Exemplo n.º 16
0
def drawcornershoe(filename):
    s=buttons.button(60,750,700,700, 0, 0, 0,  filename)
    s.draw(main_screen)
Exemplo n.º 17
0
    def __init__(self):
        os.environ['SDL_VIDEO_WINDOW_POS'] = '910,600'

        self._buttons = [button(i) for i in Clock.buttonids]
        self._pressedtime = 0  #Used to track amount of time the hour/minute set buttons are pressed.
        self._repeattime = 0  #Used to auto repeat button toggle when held down.

        self._alarmtime = (0, 0)  #Hour, Minute.
        self._alarmcheckminute = -1
        self._alarmenabled = False
        self._beep = False
        self._triggered = False
        self._beeptime = Clock.beepfreq

        self._tempdisplayinterval = Clock.defaulttempinterval

        self.tempdisplaytime = Clock.defaulttempdur
        self.tempupdateinterval = Clock.defaulttempupdate
        self.displayduration = Clock.defaultdisplaydur
        self.wh = 15  #Size of half of the segment (0-3).  IE: segment 6 is drawn at y of 30 if wh is 15.
        self.pos = (1, 10)
        self.size = (128, 64)

        pygame.init()
        self.screen = pygame.display.set_mode(self.size)
        self.clock = pygame.time.Clock()

        self.digits = (0, 0, 0, 0, 0, 0)
        self._lastsecond = 0
        self._tempdisplay = True
        self._curtime = (0, 0)
        self.temp = 0
        self.code = 3200
        self.text = 'Sunny'
        self._color = 0x00FFFF
        self.location = '21774'
        self._running = True

        self._alwaysontimes = [0, 0]
        self.alwaysontimes = Clock.defaultalwaysontimes
        self._variance = 2

        self._weathertimer = 0.0
        self._prevtime = time.time()

        self._sounds = []
        self._sounds.append(pygame.mixer.Sound('womp.wav'))
        self._sounds.append(pygame.mixer.Sound('womp2.wav'))

        self.load()

        self._wtthread = Thread(target=self.weatherthread)
        self._settingsthread = Thread(target=self.startsettings)

        ########### New stuff ###########.
        pygame.joystick.init()
        if pygame.joystick.get_count():
            joy = pygame.joystick.Joystick(0)
            joy.init()
            button.setjoy(joy)

        self._tab = 0  #0 = clock, 1 = alarm, 2 = start time, 3 = stop time
        self.dim = 0x7F
def pick_background(win):
    pygame.init()
    window = pygame.display.set_mode((1280, 720))
    city_1 = pygame.image.load('background/city_1.png')
    city_2 = pygame.image.load('background/city_2.png')
    city_3 = pygame.image.load('background/city_3.png')
    city_4 = pygame.image.load('background/city_4.png')
    bg = pygame.image.load(
        'background/no_character_bg.png')  # Importing background image
    city_1_btn_red = pygame.image.load('background/btn/city_1_btn_red.png')
    city_1_btn_yellow = pygame.image.load(
        'background/btn/city_1_btn_yellow.png')
    city_2_btn_red = pygame.image.load('background/btn/city_2_btn_red.png')
    city_2_btn_yellow = pygame.image.load(
        'background/btn/city_2_btn_yellow.png')
    city_3_btn_red = pygame.image.load('background/btn/city_3_btn_red.png')
    city_3_btn_yellow = pygame.image.load(
        'background/btn/city_3_btn_yellow.png')
    city_4_btn_red = pygame.image.load('background/btn/city_4_btn_red.png')
    city_4_btn_yellow = pygame.image.load(
        'background/btn/city_4_btn_yellow.png')

    hover_btn = pygame.mixer.Sound('sound/hover_btn.wav')

    city_1_btn = buttons.button(250, 220, 330, 190, (255, 255, 255), '',
                                city_1_btn_red)
    city_2_btn = buttons.button(650, 220, 330, 190, (255, 255, 255), '',
                                city_2_btn_red)
    city_3_btn = buttons.button(250, 450, 330, 190, (255, 255, 255), '',
                                city_3_btn_red)
    city_4_btn = buttons.button(650, 450, 330, 190, (255, 255, 255), '',
                                city_4_btn_red)
    select = True

    play_1 = True
    play_2 = True
    play_3 = True
    play_4 = True

    while select:
        global exit_game

        window.blit(bg, (0, 0))

        city_1_btn.draw(window, False)
        city_2_btn.draw(window, False)
        city_3_btn.draw(window, False)
        city_4_btn.draw(window, False)

        pygame.display.update()

        for event in pygame.event.get():
            pos = pygame.mouse.get_pos()
            if event.type == pygame.QUIT:
                select = False
                exit_game = True
            if event.type == pygame.MOUSEBUTTONDOWN:
                if city_1_btn.is_over(pos):
                    redraw_window.bg = city_1
                    select = False
                if city_2_btn.is_over(pos):
                    redraw_window.bg = city_2
                    select = False
                if city_3_btn.is_over(pos):
                    redraw_window.bg = city_3
                    select = False
                if city_4_btn.is_over(pos):
                    redraw_window.bg = city_4
                    select = False

            if event.type == pygame.MOUSEMOTION:
                if city_1_btn.is_over(pos):
                    if play_1:
                        hover_btn.play()
                        play_1 = False
                    city_1_btn.image = city_1_btn_yellow
                elif not city_1_btn.is_over(pos):
                    city_1_btn.image = city_1_btn_red
                    play_1 = True
                if city_2_btn.is_over(pos):
                    if play_2:
                        hover_btn.play()
                        play_2 = False
                    city_2_btn.image = city_2_btn_yellow
                elif not city_2_btn.is_over(pos):
                    play_2 = True
                    city_2_btn.image = city_2_btn_red
                if city_3_btn.is_over(pos):
                    if play_3:
                        hover_btn.play()
                        play_3 = False
                    city_3_btn.image = city_3_btn_yellow
                elif not city_3_btn.is_over(pos):
                    play_3 = True
                    city_3_btn.image = city_3_btn_red
                if city_4_btn.is_over(pos):
                    if play_4:
                        hover_btn.play()
                        play_4 = False
                    city_4_btn.image = city_4_btn_yellow
                elif not city_2_btn.is_over(pos):
                    play_4 = True
                    city_4_btn.image = city_4_btn_red
Exemplo n.º 19
0
    main_screen.blit(label, label_rec)





if __name__=="__main__": 
    pygame.init()
    main_screen = pygame.display.set_mode((1000, 1000))
    main_screen.fill((41,218,206))
    #button_rec = pygame.Rect(500, 500, 100, 100)
    # button_sq = pygame.Surface([100, 100])
    # main_screen.blit(button_sq, button_rec)
    screenname="shoe"

    B1 = buttons.button(150, 100, 200, 200,0, 0, 0,  'B1.jpg')
    B1.draw(main_screen)

    B2 = buttons.button(650,100,200,200,0, 0, 0, 'B2.jpg')
    B2.draw(main_screen)

    B3 = buttons.button(150, 400,200,200,0, 0, 0, 'B3.jpg')
    B3.draw(main_screen)

    B4 = buttons.button(650,400,200,200,0, 0, 0, 'B4.jpg')
    B4.draw(main_screen)

    B5 = buttons.button(150,700,200,200,0, 0, 0, 'B5.jpg')
    B5.draw(main_screen)

    B6 =buttons.button(650,700,200,200,0, 0, 0, 'B6.jpg')
Exemplo n.º 20
0
bgOne_x = 0
bgTwo_x = bgOne.get_width()

bird_mid = pygame.image.load('assets/sprites/bluebird-midflap.png')
bird_up = pygame.image.load('assets/sprites/bluebird-upflap.png')
bird_down = pygame.image.load('assets/sprites/bluebird-downflap.png')

btn_play_yellow = pygame.image.load('assets/sprites/play_btn_yellow.png')
btn_quit_yellow = pygame.image.load('assets/sprites/quit_btn_yellow.png')
btn_menu_yellow = pygame.image.load('assets/sprites/menu_btn_yellow.png')
btn_play_blue = pygame.image.load('assets/sprites/play_btn_blue.png')
btn_quit_blue = pygame.image.load('assets/sprites/quit_btn_blue.png')
btn_menu_blue = pygame.image.load('assets/sprites/menu_btn_blue.png')

play_btn = buttons.button(screen_x/2 - btn_play_yellow.get_width() - 180, screen_y/2 + 100, 212, 64, white, '', btn_play_yellow)
quit_btn = buttons.button(screen_x/2 - btn_play_yellow.get_width(), screen_y/2 + 100, 212, 64, white, '', btn_quit_yellow)
menu_btn = buttons.button(screen_x/2 - btn_play_yellow.get_width() + 180, screen_y/2 + 100, 212, 64, white, '', btn_menu_yellow)

if 7 < current_time < 18:
    background = pygame.image.load('assets/sprites/background_light.png')
else:
    background = pygame.image.load('assets/sprites/background_dark.png')
flappy_bird = pygame.image.load('assets/sprites/flappy_bird.png')
pipe = pygame.image.load('assets/sprites/green_bar.png')

timer_id1 = pygame.USEREVENT
pipe_timer = pygame.time.set_timer(timer_id1, 2000)

fly_sound = pygame.mixer.Sound('assets/audio/wing.wav')
die_sound = pygame.mixer.Sound('assets/audio/hit.wav')
Exemplo n.º 21
0
    def __init__(self):
        print("Init")
        GPIO.setwarnings(False)
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(Clock.alarmpin, GPIO.OUT)
        self._buttons = [button(i) for i in Clock.buttonids]
        self._pressedtime = 0  #Used to track amount of time the hour/minute set buttons are pressed.
        self._repeattime = 0  #Used to auto repeat button toggle when held down.

        self._alarm = GPIO.PWM(Clock.alarmpin, Clock.alarmfreq)
        self._alarmtime = (0, 0)  #Hour, Minute.
        self._alarmcheckminute = -1
        self._alarmenabled = False
        self._beep = False
        self._triggered = False
        self._beeptime = Clock.beepfreq

        self._tempdisplayinterval = Clock.defaulttempinterval

        #set properties
        self.tempdisplaytime = Clock.defaulttempdur
        self.tempupdateinterval = Clock.defaulttempupdate
        self.displayduration = Clock.defaultdisplaydur
        self.checkinterval = Clock.defaultobjectcheck
        self.wh = 15  #Size of half of the segment (0-3).  IE: segment 6 is drawn at y of 30 if wh is 15.
        self.pos = (1, 10)
        self.size = (128, 64)

        try:
            self._oled = oled(1)  #1st try later versions of the pi.
        except:
            self._oled = oled(0)  #if those fail we're using the 1st gen maybe?

        self._oled.rotation = 2
        self._oled.dim = Clock.defaultdim

        #wifi stuff.
        self._lvl = -100  #wifi level.
        self._lastsecond = 0

        self._digits = (0, 0, 0, 0, 0, 0)
        self._tempdisplay = True
        self._curtime = (0, 0)
        self.temp = 0
        self.code = 3200
        self.text = 'Sunny'
        self._color = 0x00FFFF
        self.location = '21774'  #zipcode.
        self._running = True
        self._dirtydisplay = False

        self._weathertimer = 0.0
        self._prevtime = time.time()

        self._ontime = 0.0
        self.on = True
        self._checktime = 0  #Timer for checking for object.
        self._checker = mlx()
        self._tab = 0  #0 = clock, 1 = alarm, 2 = start time, 3 = stop time

        self._alwaysontimes = [0, 0]
        self.mlxdefaults()
        self.load()

        #If no keyboard we'll get an exception here so turn off keyboard flag.
        try:
            bres = keyboard.is_pressed('q')
            self._haskeyboard = True
        except:
            self._haskeyboard = False

        self._wtthread = Thread(target=self.weatherthread)
        self._settingsthread = Thread(target=self.startsettings)
Exemplo n.º 22
0
def game_loop():
    pygame.init()  # Initialize

    screen_x = 1280  # Screen dimension x
    screen_y = 720  # Screen dimension y

    window = pygame.display.set_mode((screen_x, screen_y))  # Setting up window as screen
    pygame.display.set_caption("My Game")  # window name
    font = pygame.font.Font('ImminentLine.ttf', 80)
    space_font = pygame.font.Font('ImminentLine.ttf', 200)
    width = 300
    height = 95
    replay_img_red = pygame.image.load('background/btn/play_again_btn_red.png')
    quit_img_red = pygame.image.load('background/btn/exit_btn_red.png')
    menu_img_red = pygame.image.load('background/btn/menu_btn_red.png')
    replay_img_yellow = pygame.image.load('background/btn/play_again_btn_yellow.png')
    quit_img_yellow = pygame.image.load('background/btn/exit_btn_yellow.png')
    menu_img_yellow = pygame.image.load('background/btn/menu_btn_yellow.png')
    replay = buttons.button(screen_x / 2 - width / 2 - 320, screen_y / 2 - height / 2, width, height, (0, 255, 0), '', replay_img_red)
    quit_game = buttons.button(screen_x / 2 - width / 2 + 320, screen_y / 2 - height / 2, width, height, (0, 255, 0), '', quit_img_red)
    menu_btn = buttons.button(screen_x / 2 - width / 2, screen_y / 2 - height / 2, width, height, (0, 255, 0), '', menu_img_red)
    dim_screen = pygame.Surface((screen_x, screen_y)).convert_alpha()
    dim_screen.fill((0, 0, 0, 130))

    run = True
    game = True
    loop = True
    start = True
    global game_quit
    global draw

    p1 = player.Player(400, 580, 128, 128, False, (0, 0), f'PLAYER 1:', 1, screen_x, screen_y)
    p2 = player.Player(700, 580, 128, 128, True, (1050, 0), "PLAYER 2:", 2, screen_x, screen_y)

    while run:
        draw = False
        redraw_window.die_count = 0
        pygame.mixer.music.load('sound/dragon_ball_bg.mp3')
        pygame.mixer.music.set_volume(0.15)
        pygame.mixer.music.play(-1)

        timer = pygame.USEREVENT
        pygame.time.set_timer(timer, 1000)
        timer_sec = 90

        timer_bullet = pygame.USEREVENT + 1
        pygame.time.set_timer(timer_bullet, 1000)
        bullet_timer_sec = 3

        start_timer = pygame.USEREVENT + 2
        pygame.time.set_timer(start_timer, 1000)
        start_timer_sec = 3
        while start:
            redraw_window.die_count = 0
            redraw_window.die_count_2 = 0
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    run = False
                    game = False
                    game_quit = True
                    start = False
                if event.type == start_timer:
                    if start_timer_sec > 1:
                        start_timer_sec -= 1
                    else:
                        pygame.time.set_timer(start_timer, 0)
                        start = False
                        game = True
            redraw_window.redraw_window(window, p1, p2, screen_x, timer_sec, bullet_timer_sec, True, True)
            start_countdown = space_font.render(str(start_timer_sec), 1, (255, 255, 255))
            window.blit(start_countdown, (int(screen_x / 2 - start_countdown.get_width() / 2), int(screen_y / 2 - start_countdown.get_height() / 2)))
            window.blit(dim_screen, (0, 0))
            pygame.display.update()

        while game:
            pygame.time.delay(30)
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    run = False
                    game = False
                    start = False
                    game_quit = True
                if event.type == timer:
                    if timer_sec > 0:
                        timer_sec -= 1
                    else:
                        if p1.health > p2.health:
                            p2.die = True
                        elif p1.health < p2.health:
                            p1.die = True
                        elif p1.health == p2.health:
                            p1.die = False
                            p2.die = False
                            draw = True
                if event.type == timer_bullet:
                    if bullet_timer_sec > 0:
                        bullet_timer_sec -= 1
                    elif bullet_timer_sec == 0:
                        if p1.bullet_count < 10:
                            p1.bullet_count += 1
                            p1.bullet_bar_x -= 20
                            p1.bullet_bar_w = p1.bullet_count * 20
                        if p2.bullet_count < 10:
                            p2.bullet_count += 1

                        p1.player_bullet_count = p1.font.render(f'BULLET REMAINING: {p1.bullet_count}', False, (255, 255, 255))
                        p2.player_bullet_count = p2.font.render(f'BULLET REMAINING: {p2.bullet_count}', False, (255, 255, 255))
                        bullet_timer_sec = 3

            if p1.is_dead():
                game = False
                loop = True

            elif p2.is_dead():
                game = False
                loop = True

            elif draw:
                game = False
                loop = True

            p1.movement(True, p2, window)
            p2.movement(False, p1, window)
            redraw_window.redraw_window(window, p1, p2, screen_x, timer_sec, bullet_timer_sec)

        if p1.die or p2.die or draw:
            while loop:
                redraw_window.redraw_window(window, p1, p2, screen_x, timer_sec, bullet_timer_sec, True)
                window.blit(dim_screen, (0, 0))
                replay.draw(window, False)
                quit_game.draw(window, False)
                menu_btn.draw(window, False)
                p1.bullets = []
                p2.bullets = []
                if p1.is_dead():
                    text = font.render('PLAYER ONE WON!', 1, (255, 255, 255))
                    window.blit(text, (int(screen_x / 2 - text.get_width() / 2), int(screen_y / 2 - text.get_height() / 2 - 140)))
                elif p2.is_dead():
                    text = font.render('PLAYER TWO WON!', 1, (255, 255, 255))
                    window.blit(text, (int(screen_x / 2 - text.get_width() / 2), int(screen_y / 2 - text.get_height() / 2 - 140)))
                elif not p2.is_dead() and not p1.is_dead():
                    text = font.render('DRAW', 1, (255, 255, 255))
                    window.blit(text, (int(screen_x / 2 - text.get_width() / 2), int(screen_y / 2 - text.get_height() / 2 - 140)))

                pygame.display.update()
                for event in pygame.event.get():
                    if event.type == pygame.QUIT:
                        loop = False
                        run = False
                        game_quit = True
                    pos = pygame.mouse.get_pos()
                    if event.type == pygame.MOUSEBUTTONDOWN:
                        if replay.is_over(pos):
                            loop = False
                            game = True
                            start = True
                            p1 = player.Player(400, 580, 128, 128, False, (0, 0), f'PLAYER 1:', 1, screen_x, screen_y)
                            p2 = player.Player(700, 580, 128, 128, True, (1050, 0), "PLAYER 2:", 2, screen_x, screen_y)
                            break
                        if quit_game.is_over(pos):
                            loop = False
                            game = False
                            run = False
                            game_quit = True
                            break
                        if menu_btn.is_over(pos):
                            loop = False
                            game = False
                            run = False
                            break
                    global play_3
                    global play_2
                    global play_1
                    if event.type == pygame.MOUSEMOTION:
                        if replay.is_over(pos):
                            if play_1:
                                hover_btn.play()
                                play_1 = False
                            replay.image = replay_img_yellow
                        elif not replay.is_over(pos):
                            play_1 = True
                            replay.image = replay_img_red
                        if quit_game.is_over(pos):
                            if play_2:
                                hover_btn.play()
                                play_2 = False
                            quit_game.image = quit_img_yellow
                        elif not quit_game.is_over(pos):
                            play_2 = True
                            quit_game.image = quit_img_red
                        if menu_btn.is_over(pos):
                            if play_3:
                                hover_btn.play()
                                play_3 = False
                            menu_btn.image = menu_img_yellow
                        elif not menu_btn.is_over(pos):
                            play_3 = True
                            menu_btn.image = menu_img_red
Exemplo n.º 23
0
play_width = 300
play_height = 600
block_size = 30

top_left_x = (s_width - play_width - 250)
top_left_y = s_height - play_height

window = pygame.display.set_mode((s_width, s_height))
pygame.display.set_caption("Tetris")

menu_font = pygame.font.Font('ImminentLine.ttf', 100)
tetris_main_label = menu_font.render("TETRIS", True, light)

high_font = pygame.font.Font('ImminentLine.ttf', 50)

btn_play = buttons.button(s_width / 2 - 80 - 100, 400, 160, 40, light, "Play")
btn_quit = buttons.button(s_width / 2 - 80 + 100, 400, 160, 40, light, "Quit")

# SHAPE FORMATS

S = [['.....', '......', '..00..', '.00...', '.....'],
     ['.....', '..0..', '..00.', '...0.', '.....']]

Z = [['.....', '.....', '.00..', '..00.', '.....'],
     ['.....', '..0..', '.00..', '.0...', '.....']]

I = [['..0..', '..0..', '..0..', '..0..', '.....'],
     ['.....', '0000.', '.....', '.....', '.....']]

O = [['.....', '.....', '.00..', '.00..', '.....']]
Exemplo n.º 24
0
from lightbank import lightbank
import state

import vl53
import pca9685 as pca
import onestick

from time import perf_counter, sleep
from buttons import gpioinit, button
import keyboard


gpioinit() # Initialize the GPIO system so we may use the pins for I/O

_dtime = .03
_startupswitch = button(16)

#--------------------------------------------------------
def deadzone( aValue, aLimit ):
  return aValue if abs(aValue) >= aLimit else 0.0

#--------------------------------------------------------
class tank(object):

  _MACADDRESS = '41:42:E4:57:3E:9E'             # Controller mac address

#--------------------------------------------------------
#__RASPI Pin Indexes
  _LSIDE = (9, 10)                              # Left/right distance sensor (trigger/echo) pins
  _RSIDE = (17, 18)
Exemplo n.º 25
0
def button(line,state):
	params=line.split(delim)
	return buttons.button(int(params[1]),int(params[2]),int(params[3]),int(params[4]))
Exemplo n.º 26
0
def run(choose_screen, boolean):
	if (boolean):
		man = male.male()
		man.draw(choose_screen)
		next1 = img.img((50,50),(420,70),"next.png")
		next1.draw(choose_screen)
		pre1 = img.img((50,50),(40,70),"pre.png")
		pre1.draw(choose_screen)
		next2 = img.img((50,50),(420,160),"next.png")
		next2.draw(choose_screen)
		pre2 = img.img((50,50),(40,160),"pre.png")
		pre2.draw(choose_screen)
		next3 = img.img((50,50),(420,220),"next.png")
		next3.draw(choose_screen)
		pre3 = img.img((50,50),(40,220),"pre.png")
		pre3.draw(choose_screen)
		next4 = img.img((50,50),(420,320),"next.png")
		next4.draw(choose_screen)
		pre4 = img.img((50,50),(40,320),"pre.png")
		pre4.draw(choose_screen)
		f = buttons.button((170,65),(325,435),(255,151,153))
		f.draw(choose_screen)
		g = label.Label((333,440),(70,70),(232,23,61), "None" , 45, "Play Again")
		g.draw(choose_screen)

		f2 = buttons.button((170,65),(0,435),(255,151,153))
		f2.draw(choose_screen)
		g2 = label.Label((10,440),(70,70),(232,23,61), "None" , 45, "Play game")
		g2.draw(choose_screen)
		pygame.display.flip()
	else:
		man = female.female()
		man.draw(choose_screen)
		next1 = img.img((50,50),(420,70),"next.png")
		next1.draw(choose_screen)
		pre1 = img.img((50,50),(40,70),"pre.png")
		pre1.draw(choose_screen)
		next2 = img.img((50,50),(420,160),"next.png")
		next2.draw(choose_screen)
		pre2 = img.img((50,50),(40,160),"pre.png")
		pre2.draw(choose_screen)
		next3 = img.img((50,50),(420,220),"next.png")
		next3.draw(choose_screen)
		pre3 = img.img((50,50),(40,220),"pre.png")
		pre3.draw(choose_screen)
		next4 = img.img((50,50),(420,320),"next.png")
		next4.draw(choose_screen)
		pre4 = img.img((50,50),(40,320),"pre.png")
		pre4.draw(choose_screen)
		f = buttons.button((170,65),(325,435),(255,151,153))
		f.draw(choose_screen)
		g = label.Label((333,440),(70,70),(232,23,61), "None" , 45, "Play Again")
		g.draw(choose_screen)
		f2 = buttons.button((170,65),(0,435),(255,151,153))
		f2.draw(choose_screen)
		g2 = label.Label((10,440),(70,70),(232,23,61), "None" , 45, "Play game")
		g2.draw(choose_screen)
		pygame.display.flip()
	while True:
		ev = pygame.event.poll()

		#CODE...
		pygame.display.flip()
		if ev.type == pygame.MOUSEBUTTONDOWN:
			x, y = ev.pos	
			if f.rec.collidepoint(x,y):
				clear((255,255,255), choose_screen)
				main_game.run(choose_screen)
			if f2.rec.collidepoint(x,y):
				clear((255,255,255), choose_screen)
				game.run(choose_screen, man)
			if next1.pic.collidepoint(x,y):
				man.change_hair(1)
				man.draw(choose_screen)
			if pre1.pic.collidepoint(x,y):
				man.change_hair(-1)
				man.draw(choose_screen)
			if next2.pic.collidepoint(x,y):
				man.change_eye(1)
				man.draw(choose_screen)
			if pre2.pic.collidepoint(x,y):
				man.change_eye(-1)
				man.draw(choose_screen)
			if next3.pic.collidepoint(x,y):
				man.change_nose(1)
				man.draw(choose_screen)
			if pre3.pic.collidepoint(x,y):
				man.change_nose(-1)
				man.draw(choose_screen)
			if next4.pic.collidepoint(x,y):
				man.change_mouth(1)
				man.draw(choose_screen)
			if pre4.pic.collidepoint(x,y):
				man.change_mouth(-1)
				man.draw(choose_screen)