Thursday, June 2, 2022
HomeGame DevelopmentIn pygame I'm attempting so as to add the textual content as...

In pygame I’m attempting so as to add the textual content as an integet and it retains crashing


import pygame
from sys import exit 
import random


pygame.init()

#Creating the rating font 
arial_font=pygame.font.SysFont("arial",20)
textual content=arial_font.render("Scoreboard", False, (255,0,0),(0,0,0))
#Creating the quantity rating font
arial_font2=pygame.font.SysFont("arial",20)
rating=arial_font2.render(scoreline, False, (255,0,0),(0,0,0))

#Rating variable
scoreline=0

#Variables for the snake
step_len = 5
participant=[(580,400)]
width=10
top=10
white=(255,255,255)
rising= False

#variabels for the ball
ball_width=110
ball_height=500

clock = pygame.time.Clock()

whereas True:
    for occasion in pygame.occasion.get():
        if occasion.sort == pygame.QUIT:
            pygame.stop()
            exit()
            
            
    #Display Particulars
    display=pygame.show.set_mode((1200,800))
    ball=pygame.draw.circle(display,white,(ball_width,ball_height),3)
    pygame.draw.rect(display,(255,0,0),(10,0,1160,800),1)
    display.blit(rating,(300,400))
    def rating():
        display.blit(textual content ,(200,300))
        
            
            
    rating()
    snake = None
    for i in vary(len(participant)):
        node = pygame.draw.rect(display,white,(participant[i][0],participant[i][1],width,top),0)
        if i ==0:
            snake = node
    pygame.show.set_caption("Snake Sport")
    
    
    #Keyboard enter
    key_pressed=pygame.key.get_pressed()        

    playerx,playery = participant[0][0],participant[0][1]
    isMoved = True
    if key_pressed[pygame.K_UP]:
        playery-=step_len
    elif key_pressed[pygame.K_DOWN]:
        playery+=step_len
    elif key_pressed[pygame.K_LEFT]:
        playerx-=step_len
    elif key_pressed[pygame.K_RIGHT]:
        playerx+=step_len
    else:
        isMoved = False
    
    if isMoved:
        #Limiting the snake within the field on x dimension
        if playerx >1160:
            pygame.stop()
        if playerx < 0:
            pygame.stop()
            
        #Limiting the snake in field on y dimension
        if playery >800:
            pygame.stop()
        if playery<0:
            pygame.stop()
        
        participant.insert(0,(playerx,playery))
        #Colliding with the ball 
        if snake.colliderect(ball):
            scoreline+=1
            ball_width=random.alternative(vary(0,1160))
            ball_height=random.alternative(vary(0,700))
            
        else:
            participant.pop(-1)
            
       
        
        
        
    
    pygame.show.replace()
    clock.tick(50)

‘ I’m attempting to transform the string as an integer when I’m utilizing the font.render nevertheless it retains saying various things from ‘it needs to be a unicode or string’ and so forth. I’m attempting to show the scoreboard as textual content and in the appropriate dimension the rating which is getting +1 everytime snake will get the collision with the ball. ‘

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments