def start(): display.fill(white) message('Racecar Dodge', lobsterL, -75) message('By Shaunak Warty', lobsterS, 0) message('Press any key to start', lobsterS, 50) gear = pygame.image.load(r'Images\gear.png') gearRect = gear.get_rect(topright=(dispWD - 3, 3)) display.blit(gear, gearRect) pygame.display.update() while True: for event in pygame.event.get(): if event.type == pygame.QUIT: end() elif event.type == pygame.KEYUP: main() start() elif event.type == pygame.MOUSEBUTTONUP: mouse = pygame.mouse.get_pos() if gearRect.collidepoint(mouse): settings() start() clock.tick(10)
def main(): # Вступление start() # Работа на ферме work() # Последнее задание (подсчет веса и завершение программы) end()
def settings(): colorRects = {} back = lobsterS.render('Back', True, black) backRect = back.get_rect(topleft=(5, 3)) while True: for event in pygame.event.get(): if event.type == pygame.QUIT: end() elif event.type == pygame.MOUSEBUTTONUP: mouse = pygame.mouse.get_pos() if backRect.collidepoint(mouse): return for color in colorRects.keys(): if colorRects[color].collidepoint(mouse): shelf['rectColor'] = color elif event.type == pygame.KEYUP and event.key == pygame.K_ESCAPE: return display.fill(white) display.blit(back, backRect) display.blit(oswald.render('Change obstacle color:', True, black), (5, 75)) for i, color in enumerate(rectColors): pos = (dispWD - len(rectColors) * 100) / (len(rectColors) + 1) * (i + 1) + i * 100 colorRects[color] = pygame.Rect(pos, 150, 100, 100) if shelf['rectColor'] == color: pygame.draw.rect(display, green, (pos - 3, 147, 106, 106)) pygame.draw.rect(display, color, (pos, 150, 100, 100)) pygame.display.update() clock.tick(10)
def main(): dodged = 0 carX = (dispWD - carWD) / 2 carY = dispHT - 5 - carHT carSpeed = 3 keys = {'left':[False, False], 'right':[False, False], 'up': [False, False], 'down': [False, False]} rectX = random.randrange(0, dispWD - 100) rectY = -500 rectSpeed = 6 while True: for event in pygame.event.get(): if event.type == pygame.QUIT: end() elif event.type == pygame.KEYDOWN: #? Maybe find some way to create a switch statement? if event.key == pygame.K_LEFT: keys['left'][0] = True elif event.key == pygame.K_a: keys['left'][1] = True elif event.key == pygame.K_RIGHT: keys['right'][0] = True elif event.key == pygame.K_d: keys['right'][1] = True elif event.key == pygame.K_UP: keys['up'][0] = True elif event.key == pygame.K_w: keys['up'][1] = True elif event.key == pygame.K_DOWN: keys['down'][0] = True elif event.key == pygame.K_s: keys['down'][1] = True elif event.type == pygame.KEYUP: if event.key == pygame.K_LEFT: keys['left'][0] = False elif event.key == pygame.K_a: keys['left'][1] = False elif event.key == pygame.K_RIGHT: keys['right'][0] = False elif event.key == pygame.K_d: keys['right'][1] = False elif event.key == pygame.K_UP: keys['up'][0] = False elif event.key == pygame.K_w: keys['up'][1] = False elif event.key == pygame.K_DOWN: keys['down'][0] = False elif event.key == pygame.K_s: keys['down'][1] = False elif event.key == pygame.K_ESCAPE: # Paused btnClicked = pause() if btnClicked == crashButton.restart: main() return elif btnClicked == crashButton.home: return keys = {'left':[False, False], 'right':[False, False], 'up': [False, False], 'down': [False, False]} if (keys['left'][0] or keys['left'][1]) and carX > 0: carX -= int(carSpeed) if (keys['right'][0] or keys['right'][1]) and carX < dispWD - carWD: carX += int(carSpeed) if (keys['up'][0] or keys['up'][1]) and carY > 0: carY -= int(carSpeed) if (keys['down'][0] or keys['down'][1]) and carY < dispHT - carHT: carY += int(carSpeed) rectY += rectSpeed display.fill(white) display.blit(car, (carX, carY)) rect = (rectX, rectY, 100, 100) pygame.draw.rect(display, shelf['rectColor'], rect) display.blit(lobsterS.render('Dodged: ' + str(dodged), True, green), (3, 3)) record = lobsterS.render('Record: ' + str(shelf['record']), True, blue) display.blit(record, record.get_rect(topright=(dispWD - 3, 3))) pygame.display.update() clock.tick(60) # When user crashes if car.get_rect(topleft=(carX, carY)).colliderect(rect): btnClicked = crash(dodged) if btnClicked == crashButton.restart: main() return elif btnClicked == crashButton.home: return # When user dodges obstacle if rectY > dispHT: dodged += 1 rectX = random.randrange(0, dispWD - 100) rectY = -100 rectSpeed += 1 carSpeed += 0.4
import functions as app if __name__ == '__main__': app.init() app.process() app.end()
# -*- coding: utf-8 -*- """ Created on Thu Jun 6 11:42:48 2019 @author: Kartik """ #importing libraries import os as os os.system('cls') #clears screen before displaying ASCII art import objects as obj import functions as func os.system('cls') #clears screen again before initiating battle sequence playAgain = "Y" #to run the first instance while playAgain == 'Y' or playAgain == 'y': func.intro() func.instance.score = 0 obj.Player.gold = 0 func.instance() func.store() func.end() break
def exitGame(): scrabbleDestroy() func.root.destroy() print("Thanks for playing! Hope you enjoyed! Have a nice day.") func.end()