Aug-23-2018, 12:45 AM
(This post was last modified: Aug-23-2018, 12:45 AM by TheNumericDolfin.)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
import pygame from pygame. locals import * import os pygame.init() def keyhandler(screenxsize, screenysize, mouseclicked): keycombo = False running = True keypressed = False key = [] keysheld = pygame.key.get_pressed() mousestate = pygame.mouse.get_pressed() mouseheld = mousestate[ 0 ] opressed = False mpos = pygame.mouse.get_pos() bob = 0 for event in pygame.event.get(): if event. type = = pygame.QUIT: running = False print ( "Quitting" ) if event. type = = pygame.KEYDOWN: keypressed = True if keysheld[K_LSHIFT]: caps = True else : caps = False print ( "keypressed" ) if event.key = = pygame.K_a: if caps = = True : key.append( "A" ) else : key.append( "a" ) if event.key = = pygame.K_b: if caps = = True : key.append( "B" ) else : key.append( "b" ) if event.key = = pygame.K_c: if caps = = True : key.append( "C" ) else : key.append( "c" ) if event.key = = pygame.K_d: if caps = = True : key.append( "D" ) else : key.append( "d" ) if event.key = = pygame.K_e: if caps = = True : key.append( "E" ) else : key.append( "e" ) if event.key = = pygame.K_f: if caps = = True : key.append( "F" ) else : key.append( "f" ) if event.key = = pygame.K_g: if caps = = True : key.append( "G" ) else : key.append( "g" ) if event.key = = pygame.K_h: if caps = = True : key.append( "H" ) else : key.append( "h" ) if event.key = = pygame.K_i: if caps = = True : key.append( "I" ) else : key.append( "i" ) if event.key = = pygame.K_j: if caps = = True : key.append( "J" ) else : key.append( "j" ) if event.key = = pygame.K_k: if caps = = True : key.append( "K" ) else : key.append( "k" ) if event.key = = pygame.K_l: if caps = = True : key.append( "L" ) else : key.append( "l" ) if event.key = = pygame.K_m: if caps = = True : key.append( "M" ) else : key.append( "m" ) if event.key = = pygame.K_n: if caps = = True : key.append( "N" ) else : key.append( "n" ) if event.key = = pygame.K_o: if caps = = True : key.append( "O" ) else : key.append( "o" ) opressed = True if keysheld[K_p]: keycombo = "op" else : keycombo = [] if event.key = = pygame.K_p: if caps = = True : key.append( "P" ) else : key.append( "p" ) if opressed = = True : keycombo = "op" if keysheld[K_o]: keycombo = "op" else : keycombo = [] if event.key = = pygame.K_q: if caps = = True : key.append( "Q" ) else : key.append( "q" ) if event.key = = pygame.K_r: if caps = = True : key.append( "R" ) else : key.append( "r" ) if event.key = = pygame.K_s: if caps = = True : key.append( "S" ) else : key.append( "s" ) if event.key = = pygame.K_t: if caps = = True : key.append( "T" ) else : key.append( "t" ) if event.key = = pygame.K_u: if caps = = True : key.append( "U" ) else : key.append( "u" ) if event.key = = pygame.K_v: if caps = = True : key.append( "V" ) else : key.append( "v" ) if event.key = = pygame.K_w: if caps = = True : key.append( "W" ) else : key.append( "w" ) if event.key = = pygame.K_x: if caps = = True : key.append( "X" ) else : key.append( "x" ) if event.key = = pygame.K_y: if caps = = True : key.append( "Y" ) else : key.append( "y" ) if event.key = = pygame.K_z: if caps = = True : key.append( "Z" ) else : key.append( "z" ) if event.key = = pygame.K_LSHIFT: key.append( "LShift" ) if event. type = = pygame.KEYUP: keypressed = False if event. type = = pygame.MOUSEBUTTONDOWN: mouseclicked = True print ( "THIS IS DETECTING!" ) else : mouseclicked = False if event. type = = pygame.MOUSEBUTTONUP: mouseclicked = False if event. type = = pygame.VIDEORESIZE: print ( "Resizing" ) screenxsize = event.w screenysize = event.h key = ''.join(key) print (mouseclicked) # THIS IS NOT DETECTING THE PRESS DESPITE THE FACT THAT IT SHOULD HAVE BEEN SET TO TRUE< AS DEMONSTRATED BY THE LINE #PRINTING A FEW LINES ABOVE! return running, key, keypressed, keysheld, keycombo, mouseclicked, mouseheld, mpos, screenxsize, screenysize |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
import pygame from pygame. locals import * import os import Keyhandler import Menues x, y = 0 , 0 position = ( 0 , 30 ) os.environ[ 'SDL_VIDEO_WINDOW_POS' ] = "%d,%d" % (x,y) os.environ[ 'SDL_VIDEO_WINDOW_POS' ] = str (position[ 0 ]) + "," + str (position[ 1 ]) infoObject = pygame.display.Info() screenxsize, screenysize = infoObject.current_w, (infoObject.current_h - 30 ) running, time, leftmousepress, mouseclicked, mouselefthold, keypressed, screenresizedyet, keycombopressed, helptext, pressed, clickedon, menuenum = True , 0 , False , False , False , False , False , False , " " , False , False , "Start" mpos, mouseheld, key = ( 0 , 0 ), False , [] font = pygame.font.SysFont( 'Comic Sans MS' , 10 ) pygame.init() pygame.font.init() screen = pygame.display.set_mode([( int (screenxsize)), ( int (screenysize))], RESIZABLE) pygame.display.set_caption( 'Dnd reimagined' ) while running: time = time + 1 running, key, keypressed, keysheld, keycombo, mouseclicked, mouseheld, mpos, screenxsize, screenysize = Keyhandler.keyhandler(screenxsize, screenysize, mouseclicked) menuenum = Menues.drawmenues(screen, screenxsize, screenysize, mpos, mouseclicked, mouseheld, menuenum) Menues.drawmenues(screen, screenxsize, screenysize, mpos, mouseclicked, mouseheld, menuenum) if len (key) > 0 : print (key) if mouseclicked = = True : print ( "True" ) if mouseheld = = True : print ( "boobs" ) print ( "do" ) pygame.display.update() |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
import pygame from pygame. locals import * font = pygame.font.SysFont( 'Comic Sans MS' , 10 ) mpos, mouseheld = False , False menuenum = "Start" pygame.init() def drawbutton(screen, mpos, held, clickedon, posx, posy, buttonwidth, buttonheight, text): if held = = True : pygame.draw.rect(screen, ( 100 , 10 , 100 ), (posx, posy, buttonwidth, buttonheight)) pygame.draw.rect(screen, ( 100 , 100 , 100 ), (posx + (buttonwidth * . 1 ), posy + (buttonheight * . 1 ), (buttonwidth * . 8 ), (buttonheight * . 8 ))) else : pygame.draw.rect(screen, ( 100 , 100 , 100 ), (posx, posy, buttonwidth, buttonheight)) pygame.draw.rect(screen, ( 100 , 10 , 100 ), (posx + (buttonwidth * . 1 ), posy + (buttonheight * . 1 ), (buttonwidth * . 8 ), (buttonheight * . 8 ))) buttontext = font.render(text, False , ( 255 , 255 , 255 )) screen.blit(buttontext, (posx, posy)) def drawanddetect(screen, mpos, mouseclicked, mouseheld, posx, posy, buttonwidth, buttonheight, text): clickedon = False held = False if ((posx < mpos[ 0 ] < (posx + buttonwidth)) & (posy < mpos[ 1 ] < (posy + buttonheight))): if mouseheld = = True : held = True else : held = False if mouseclicked = = True : clickedon = True else : clickedon = False drawbutton(screen, mpos, held, clickedon, posx, posy, buttonwidth, buttonheight, text) if mouseclicked = = True : print ( "True" ) return clickedon def startmenue(screen, screenxsize, screenysize, mpos, mouseclicked, mouseheld): Startscreen = pygame.image.load( 'Dnd.png' ) screen.blit(pygame.transform.scale(Startscreen, (screenxsize, screenysize)), ( 0 , 0 )) menuenum = "Start" buttonwidth = screenxsize / / 20 buttonheight = screenysize / / 20 posx = (screenxsize / / 2 ) - buttonwidth posy = (screenysize / / 2 ) - buttonheight text = "Start" drawanddetect(screen, mpos, mouseclicked, mouseheld, posx, posy, buttonwidth, buttonheight, text) clickedon = drawanddetect(screen, mpos, mouseclicked, mouseheld, posx, posy, buttonwidth, buttonheight, text) if clickedon = = True : menuenum = "Charactorcreatior" if mouseclicked = = True : print ( "True" ) buttonwidth = screenxsize / / 20 buttonheight = screenysize / / 20 posx = (screenxsize) - buttonwidth posy = (screenysize) - buttonheight text = "Help" drawanddetect(screen, mpos, mouseclicked, mouseheld, posx, posy, buttonwidth, buttonheight, text) clickedon = drawanddetect(screen, mpos, mouseclicked, mouseheld, posx, posy, buttonwidth, buttonheight, text) if clickedon = = True : menuenum = "help" if mouseclicked = = True : print ( "True" ) return menuenum def helpmenue(screen, screenxsize, screenysize, mpos, mouseclicked, mouseheld): screen.fill(( 0 , 0 , 0 )) menuenum = "help" buttonwidth = screenxsize / / 20 buttonheight = screenysize / / 20 posx = (screenxsize / / 2 ) - buttonwidth posy = (screenysize / / 2 ) - buttonheight text = "Back" drawanddetect(screen, mpos, mouseclicked, mouseheld, posx, posy, buttonwidth, buttonheight, text) clickedon = drawanddetect(screen, mpos, mouseclicked, mouseheld, posx, posy, buttonwidth, buttonheight, text) if clickedon = = True : menuenum = "Start" if mouseclicked = = True : print ( "True" ) return menuenum def drawmenues(screen, screenxsize, screenysize, mpos, mouseclicked, mouseheld, menuenum): if menuenum = = "Start" : startmenue(screen, screenxsize, screenysize, mpos, mouseclicked, mouseheld) menuenum = startmenue(screen, screenxsize, screenysize, mpos, mouseclicked, mouseheld) if menuenum = = "help" : menuenum = helpmenue(screen, screenxsize, screenysize, mpos, mouseclicked, mouseheld) helpmenue(screen, screenxsize, screenysize, mpos, mouseclicked, mouseheld) if mouseclicked = = True : print ( "True" ) return menuenum |