def menu(main_surface): maintheme = pygame.mixer.Sound('Pics/sound/maintheme2.wav') muziek = 0 while True: if muziek == 0: pygame.mixer.Sound.play(maintheme, -1) muziek = 1 startgamebuttonpng = pygame.image.load('Pics/startgame_button.png').convert_alpha() #laad de plaatjes voor het menu manualgamebuttonpng = pygame.image.load('Pics/manual_button.png').convert_alpha() quitgamebuttonpng = pygame.image.load('Pics/exitgame_button.png').convert_alpha() background = pygame.image.load('Pics/Background.jpg').convert_alpha() startgamebutton = pygame.Rect(150, 100, 265, 125) instructionbutton = pygame.Rect(150, 250, 265, 125) quitgamebutton = pygame.Rect(150, 550, 265, 125) event = pygame.event.get() #kan alle events zijn zoals mouse_click mouse_pos = pygame.mouse.get_pos() #krijgt de positie van de cursor for ev in event: if ev.type == pygame.MOUSEBUTTONDOWN and startgamebutton.collidepoint(mouse_pos): #als je op de start game knop drukt pygame.mixer.Sound.fadeout(maintheme, 2500) Spelbord.draw_board() #hier moet play game komen! muziek = 0 elif ev.type == pygame.MOUSEBUTTONDOWN and quitgamebutton.collidepoint(mouse_pos) or ev.type == pygame.QUIT: #als je op de quit game knop drukt pygame.quit() quit() elif ev.type == pygame.MOUSEBUTTONDOWN and instructionbutton.collidepoint(mouse_pos): #als je op de instructies knop drukt Manual.manual() main_surface.blit(background, (0, 0)) #Draw other Things After main_surface.blit(startgamebuttonpng, (100, 100)) #laat de plaatjes zien main_surface.blit(manualgamebuttonpng, (100, 250)) main_surface.blit(quitgamebuttonpng, (100, 550)) pygame.display.flip()
def draw_board(): main_surface.blit(background, (0, 0)) main_surface.blit(quit_in_gamebuttonpng, (950, 0)) main_surface.blit(manualbuttongame, (950, 100 + (50 / 3) + (50 / 3))) main_surface.blit(bordload, (0, 0)) main_surface.blit(shopmenubutton, (950, 200)) klik = 0 shopmenu = 0 soldier = 0 tank = 0 robot = 0 boot = 0 barak = 0 shopmenuimage = pygame.image.load('Pics/units/Shop_menu_unf.png') coordinates1 = None font = pygame.font.SysFont(None, 25) turnfont = pygame.font.SysFont(None, 48) Map = Tile.create_Tilelist() drawBase(Map) players = [(Base(1)), (Base(2)), (Base(3)), (Base(4))] currentplayer = players[0] moneycheck = False player = 0 zetten = 0 battletheme = pygame.mixer.Sound('Pics/sound/battle.wav') pygame.mixer.Sound.play(battletheme, -1) while True: mouse_pos = pygame.mouse.get_pos() # krijgt de positie van de cursor event = pygame.event.get() # kan alle events zijn zoals mouse_click coordinates = getTile(event, mouse_pos, Map) for ev in event: if ev.type == pygame.MOUSEBUTTONDOWN and quitingamebutton.collidepoint(mouse_pos): klik = 1 elif ev.type == pygame.QUIT: # Window close button clicked? pygame.quit() quit() elif ev.type == pygame.KEYDOWN and ev.key == pygame.K_ESCAPE: # back to main menu klik = 1 elif ev.type == pygame.MOUSEBUTTONDOWN and shop.collidepoint(mouse_pos): shopmenu = 1 elif ev.type == pygame.MOUSEBUTTONDOWN and manualbuttonrect.collidepoint(mouse_pos): Manual.manual() reload() if coordinates is not None: # Unit Count TEXT soldierCounttext = font.render(str(countUnits(positionchecker(coordinates, Map), 1, "Soldiers")), 1, (255, 255, 0)) main_surface.fill((0, 0, 0), (ViewSoldierButton)) main_surface.blit(soldierCounttext, (900, 700)) tankCounttext = font.render(str(countUnits(positionchecker(coordinates, Map), 3, "Tanks")), 1, (255, 0, 0)) main_surface.fill((0, 0, 0), (ViewTankButton)) main_surface.blit(tankCounttext, (900, 720)) robotCounttext = font.render(str(countUnits(positionchecker(coordinates, Map), 2, "Robots")), 1, (255, 50, 0)) main_surface.fill((0, 0, 0), (ViewRobotButton)) main_surface.blit(robotCounttext, (900, 740)) boatCounttext = font.render(str(countUnits(positionchecker(coordinates, Map), 4, "Boats")), 1, (255, 100, 0)) main_surface.fill((0, 0, 0), (ViewBoatButton)) main_surface.blit(boatCounttext, (900, 760)) # Unit Health TEXT TotalHealth = str((HealthCount(positionchecker(coordinates, Map),1))\ + (HealthCount(positionchecker(coordinates, Map),2))\ + (HealthCount(positionchecker(coordinates, Map),3))\ + (HealthCount(positionchecker(coordinates, Map),4))) Healthtext = font.render(("Total Health Units: " + TotalHealth), 1, (255,255,255)) main_surface.blit(Healthtext, (900, 780)) # Base/Barack Health TEXT Healthbuildings = str(HealthBarack(positionchecker(coordinates, Map))+ HealthBase((positionchecker(coordinates, Map)), players)) Healthtext2 = font.render(("Health Base/Barack: " + Healthbuildings), 1, (255,255,255)) main_surface.blit(Healthtext2, (900, 820)) # Unit DMG TEXT TotalDMG = str(DMGSoldier(positionchecker(coordinates, Map)) + DMGTank(positionchecker(coordinates, Map)) + DMGRobot(positionchecker(coordinates, Map))) DMGtext = font.render(("Total DMG Units: " + TotalDMG), 1, (255,255,255)) main_surface.blit(DMGtext, (900, 800)) if shopmenu == 1: UnitS = pygame.Rect(900, 300, 142, 68) UnitT = pygame.Rect(1060, 300, 142, 68) UnitR = pygame.Rect(900, 392, 140, 68) UnitB = pygame.Rect(1060, 392, 142, 68) UnitBr = pygame.Rect(900, 480, 142, 68) Back = pygame.Rect(1059, 480, 142, 68) main_surface.blit(shopmenuimage, (900, 300)) if ev.type == pygame.MOUSEBUTTONDOWN and UnitS.collidepoint(mouse_pos): soldier = 1 shopmenu = 0 reload() elif ev.type == pygame.MOUSEBUTTONDOWN and UnitT.collidepoint(mouse_pos): tank = 1 shopmenu = 0 reload() elif ev.type == pygame.MOUSEBUTTONDOWN and UnitR.collidepoint(mouse_pos): robot = 1 shopmenu = 0 reload() elif ev.type == pygame.MOUSEBUTTONDOWN and UnitB.collidepoint(mouse_pos): boot = 1 shopmenu = 0 reload() elif ev.type == pygame.MOUSEBUTTONDOWN and UnitBr.collidepoint(mouse_pos): barak = 1 shopmenu = 0 reload() elif ev.type == pygame.MOUSEBUTTONDOWN and Back.collidepoint(mouse_pos): shopmenu = 0 reload() if barak == 1: if coordinates is not None: for i in Map: if coordinates.Position.x == i.Position.x and coordinates.Position.y == i.Position.y and i.Traversable is True: if len(i.Soldier) >= 1 or len(i.Tank) >= 1 or len(i.Robot) >= 1: if len(coordinates.BarackObama) < 1 and i.Base == False: for x in i.Soldier: if x.Player == currentplayer.Player: spawnbarak(currentplayer, coordinates, i) zetten += 1 barak = 0 print("Het aantal zetten = " + str(zetten)) else: barak = 0 for x in i.Tank: if x.Player == currentplayer.Player: spawnbarak(currentplayer, coordinates, i) zetten += 1 barak = 0 print("Het aantal zetten = " + str(zetten)) else: barak = 0 for x in i.Robot: if x.Player == currentplayer.Player: spawnbarak(currentplayer, coordinates, i) zetten += 1 barak = 0 print("Het aantal zetten = " + str(zetten)) else: barak = 0 else: barak = 0 if soldier == 1: if coordinates is not None: for i in Map: if coordinates.Position.x == i.Position.x and coordinates.Position.y == i.Position.y and i.Traversable is True: if i.Barack == True or i.Base == True: for x in i.BarackObama: if x.Player == currentplayer.Player: spawnSoldier(currentplayer, i) zetten += 1 soldier = 0 print("Het aantal zetten = " + str(zetten)) else: soldier = 0 for x in i.Bases: if x.Player == currentplayer.Player: spawnSoldier(currentplayer, i) zetten += 1 soldier = 0 print("Het aantal zetten = " + str(zetten)) else: soldier = 0 else: soldier = 0 if tank == 1: if coordinates is not None: for i in Map: if coordinates.Position.x == i.Position.x and coordinates.Position.y == i.Position.y and i.Traversable is True: if i.Barack == True or i.Base == True: for x in i.BarackObama: if x.Player == currentplayer.Player: spawnTank(currentplayer, i) zetten += 1 tank = 0 print("Het aantal zetten = " + str(zetten)) else: tank = 0 for x in i.Bases: if x.Player == currentplayer.Player: spawnTank(currentplayer, i) zetten += 1 tank = 0 print("Het aantal zetten = " + str(zetten)) else: tank = 0 else: tank = 0 if robot == 1: if coordinates is not None: for i in Map: if coordinates.Position.x == i.Position.x and coordinates.Position.y == i.Position.y and i.Traversable is True: if i.Barack == True or i.Base == True: for x in i.BarackObama: if x.Player == currentplayer.Player: spawnRobot(currentplayer, i) zetten += 1 robot = 0 print("Het aantal zetten = " + str(zetten)) else: robot = 0 for x in i.Bases: if x.Player == currentplayer.Player: spawnRobot(currentplayer, i) zetten += 1 robot = 0 print("Het aantal zetten = " + str(zetten)) else: robot = 0 else: robot = 0 if boot == 1: if coordinates is not None: for i in Map: if coordinates.Position.x == i.Position.x and coordinates.Position.y == i.Position.y and i.Traversable is False: for i in Map: if (( coordinates.Position.x + 1 == i.Position.x and coordinates.Position.y == i.Position.y and ( i.Robot or i.Soldier or i.Tank)) \ or ( coordinates.Position.x - 1 == i.Position.x and coordinates.Position.y == i.Position.y and ( i.Robot or i.Soldier or i.Tank)) \ or ( coordinates.Position.x == i.Position.x and coordinates.Position.y + 1 == i.Position.y and ( i.Robot or i.Soldier or i.Tank)) \ or ( coordinates.Position.x == i.Position.x and coordinates.Position.y - 1 == i.Position.y and ( i.Robot or i.Soldier or i.Tank))) \ and (currentplayer.Money >= 1000 or ( currentplayer.Player == 3 and currentplayer.Money >= 800)): unit = UnitClasses.Boat(currentplayer.Player) coordinates.Boat.append(unit) boot = 0 zetten += 1 if currentplayer.Player == 3: currentplayer.Money -= 800 else: currentplayer.Money -= 1000 print(zetten) randint = random.randint(0, 4) if randint == 0: boat1 = pygame.mixer.Sound('Pics/sound/boat1.wav') pygame.mixer.Sound.play(boat1) if randint == 1: boat2 = pygame.mixer.Sound('Pics/sound/boat2.wav') pygame.mixer.Sound.play(boat2) if randint == 2: boat3 = pygame.mixer.Sound('Pics/sound/boat3.wav') pygame.mixer.Sound.play(boat3) if randint == 3: boat4 = pygame.mixer.Sound('Pics/sound/boat4.wav') pygame.mixer.Sound.play(boat4) if randint == 4: boat5 = pygame.mixer.Sound('Pics/sound/boat5.wav') pygame.mixer.Sound.play(boat5) Base.Moneycount(currentplayer, moneycheck, Map) moneycheck = True drawMoney(currentplayer.Money) if coordinates is not None and coordinates1 is None: if ( coordinates.Soldier != [] or coordinates.Tank != [] or coordinates.Robot != [] or coordinates.Boat != []): if len(coordinates.Soldier) > 0: soldiercheck = 0 for i in coordinates.Soldier: if i.Player == currentplayer.Player: soldiercheck += 1 if soldiercheck == len(coordinates.Soldier): coordinates1 = getTile(event, mouse_pos, Map) if len(coordinates.Robot) > 0: robotcheck = 0 for i in coordinates.Robot: if i.Player == currentplayer.Player: robotcheck += 1 if robotcheck == len(coordinates.Robot): coordinates1 = getTile(event, mouse_pos, Map) if len(coordinates.Tank) > 0: tankcheck = 0 for i in coordinates.Tank: if i.Player == currentplayer.Player: tankcheck += 1 if tankcheck == len(coordinates.Tank): coordinates1 = getTile(event, mouse_pos, Map) if len(coordinates.Boat) > 0: boatcheck = 0 for i in coordinates.Boat: if i.Player == currentplayer.Player: boatcheck += 1 if boatcheck == len(coordinates.Boat): coordinates1 = getTile(event, mouse_pos, Map) if coordinates1 != coordinates and coordinates is not None and coordinates1 is not None: if ( coordinates1.Soldier != [] or coordinates1.Tank != [] or coordinates1.Robot != [] or coordinates1.Boat != []): # print("Deze unit behoort tot player: " + str(coordinates1.Soldier[0].Player)) coordinates2 = getTile(event, mouse_pos, Map) players = Tile.selectUnit(coordinates1, coordinates2, Map, currentplayer, players) zetten += 1 print("Het aantal zetten = " + str(zetten)) coordinates1 = None coordinates2 = None coordinates = None reload() drawUnits(Map) if zetten >= 4: player += 1 if player > len(players) - 1: player = 0 currentplayer = players[player] zetten = 0 moneycheck = False TurnText = turnfont.render("Player " + str(currentplayer.Player) + "'s turn!", 1, (0, 0, 0)) TurnPNG = pygame.image.load('Pics/units/playerturn_button.png') main_surface.blit(TurnPNG, (300, 200)) main_surface.blit(TurnText, (325, 235)) if klik == 1: main_surface.blit(areyousurepng, (300, 200)) yesbutton = pygame.Rect(410, 415, 190, 100) # position yes button nobutton = pygame.Rect(630, 415, 190, 100) # position no button if ev.type == pygame.MOUSEBUTTONDOWN and yesbutton.collidepoint(mouse_pos): pygame.mixer.Sound.stop(battletheme) return elif ev.type == pygame.MOUSEBUTTONDOWN and nobutton.collidepoint(mouse_pos): klik = 2 elif klik == 2: main_surface.blit(bordload, (0, 0)) reload() klik = 0 if currentplayer.Money >= 50000: main_surface.fill(BLACK) main_surface.blit(pygame.image.load('Pics/winner.png'), (0, 0)) playertext = font.render(("Player " + str(currentplayer.Player) + " is the winner"), 1, (255, 255, 255)) main_surface.blit(playertext, (500, 670)) escapetext = font.render(("Press esc to go back to main menu"), 1, (255, 255, 255)) main_surface.blit(escapetext, (450, 700)) if ev.type == pygame.KEYDOWN and ev.key == pygame.K_ESCAPE: # back to main menu return pygame.display.flip()
) timeout = [60, 90, 150, 150] opt_dict = { 'CARLA': None, 'HOST': host, 'PORT': port, 'TIMEOUT': timeout, 'OUTPUT_SUMMARY': summary_file, 'RUNNABLE': runnable, 'CAMERAS': cameras, 'WIDTH': width, 'HEIGHT': height, 'WEATHERS': weathers, 'REPETITIONS': repetitions_per_experiment, 'START_GOAL_POSES': start_goal_poses, 'PEDESTRIANS': pedestrians, 'VEHICLES': vehicles, 'EXPERIMENTS_TO_RUN': experiments_to_run } # run experiments run_experiment(opt_dict) if (__name__ == '__main__'): # instance your controller here runnable = Manual() main(runnable)
if controller.name == 'Logitech Gamepad F710': # Is the controller the right one? controller_connected = True print('Connected to controller') Core.led_on() break except: print(event, "failed.... trying again") time.sleep(0.05) connect_controller() run = True while run: if mode == 1: RobotFighting.main() elif mode == 2: LineFollowing.main() try: # If controller disconnects catch error for event in controller.read_loop(): # For each button/joystick event if event.type == ecodes.EV_KEY: # If event was button if event.value == 1: # If button was pressed(not released) button(event) # Handle button press if event.type == 3 and mode == 0: # If event was joystick print("event joy") Manual.joystick(event) # Handle joystick input except OSError: # If controller disconnected print("Controller disconnected") connect_controller() # Reconnect to controller
from random import randint import serial # used for serial communications. came from <pip3.6 install pyserial> import RR_CommandGenerator # class developed to generate a limited number of TT robot commands import time import pickle root = tk.Tk() root.withdraw() state = RuntimeState.RuntimeState() # Setup main window main_image = Image.open("C:\\Users\\Finlay\\Documents\\Images\\MAIN.jpg") main_image_tk = ImageTk.PhotoImage(main_image) background = tk.Toplevel(root, background='black', width=640, height=480) background.title("PxlRT Studio") background.geometry("640x480") # Create 4 windows that can be displayed in the info panel initialise_panel = Initialise.Initialise(background, state) manual_panel = Manual.Manual(background, state) settings_panel = Settings.Settings(background, state) tileprint_panel = TilePrint.TilePrint(background, state) # Create main controls controls = Controls.Controls(background, initialise_panel, manual_panel, settings_panel, tileprint_panel, state) root.mainloop()
width=400, height=315, yscrollcommand=vscrollbar.set, scrollregion=(0, 0, 1000, 1000)) c.grid(row=0, column=0, sticky=tk.N + tk.S + tk.E + tk.W) # # # param_pal = tk.Frame(c, bg="grey10") param_pal.place(x=0, y=0) # tk.Label(param_pal, text="oops").pack() for i in range(30): tk.Label(param_pal, text=i, fg="yellow", bg="black").grid(row=i) tk.Entry(param_pal, fg="black").grid(row=i, column=1) id = c.create_window(10, 0, anchor=tk.NW, window=param_pal) vscrollbar.config(command=c.yview) dummyframe.place_forget() iw = Initialise.Initialise(info_initialise) info_initialise.place_forget() mw = Manual.Manual(info_manual) info_manual.place_forget() sw = Settings.Settings(background) root.mainloop()