Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A 4x4 Field in Pygame
#15
This is using all modules as you have initialized them here on line 7
pygame.init()
So in your code you are already initializing mixer and ttf

You can uses system fonts, but from my experience its not a good idea when packaging a game. For example some people may have certain fonts on their system while others not, causing an error for them. Its much more solid if you just send a font along with your program.

PS you dont need all those flips everywhere.
import pygame
import random
import sys
 
go = True
 
pygame.init()
screen = pygame.display.set_mode([500,500])
pygame.display.set_caption('Pygame test')
 
font = pygame.font.SysFont(None, 60)
 
def writetext(outputtext,colour):
    text = font.render(outputtext, True, colour)
    size_rect = text.get_rect(center = (500/2, 54))
    screen.blit(text,size_rect)
 
while go:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()
        if event.type == pygame.MOUSEBUTTONDOWN:
            x = random.randint(1,2)
            if x == 1:
                writetext("Yes!", (255,255,255))
            elif x == 2:
                writetext("No!", (255,255,255))
    pygame.display.update()
Recommended Tutorials:
Reply


Messages In This Thread
A 4x4 Field in Pygame - by Piethon - Aug-11-2019, 04:29 PM
RE: A 4x4 Field in Pygame - by metulburr - Aug-11-2019, 10:06 PM
RE: A 4x4 Field in Pygame - by SheeppOSU - Aug-12-2019, 08:15 PM
RE: A 4x4 Field in Pygame - by Piethon - Aug-13-2019, 09:28 AM
RE: A 4x4 Field in Pygame - by Windspar - Aug-13-2019, 10:38 AM
RE: A 4x4 Field in Pygame - by Piethon - Aug-14-2019, 07:44 AM
RE: A 4x4 Field in Pygame - by Windspar - Aug-14-2019, 12:24 PM
RE: A 4x4 Field in Pygame - by Piethon - Aug-18-2019, 09:50 AM
RE: A 4x4 Field in Pygame - by Piethon - Aug-19-2019, 10:08 AM
RE: A 4x4 Field in Pygame - by Windspar - Aug-18-2019, 11:26 AM
RE: A 4x4 Field in Pygame - by metulburr - Aug-18-2019, 12:23 PM
RE: A 4x4 Field in Pygame - by metulburr - Aug-19-2019, 11:33 AM
RE: A 4x4 Field in Pygame - by Windspar - Aug-19-2019, 11:38 AM
RE: A 4x4 Field in Pygame - by Piethon - Aug-19-2019, 12:09 PM
RE: A 4x4 Field in Pygame - by metulburr - Aug-19-2019, 01:07 PM
RE: A 4x4 Field in Pygame - by Windspar - Aug-19-2019, 04:37 PM
RE: A 4x4 Field in Pygame - by Piethon - Aug-19-2019, 06:49 PM
RE: A 4x4 Field in Pygame - by Windspar - Aug-19-2019, 09:21 PM
RE: A 4x4 Field in Pygame - by metulburr - Aug-19-2019, 10:49 PM
RE: A 4x4 Field in Pygame - by Piethon - Aug-20-2019, 08:51 AM
RE: A 4x4 Field in Pygame - by Windspar - Aug-20-2019, 10:38 AM
RE: A 4x4 Field in Pygame - by metulburr - Aug-20-2019, 12:03 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020