pygame分数未显示在屏幕上

时间:2019-01-21 11:37:12

标签: python pygame display

[Unit]
Description=Api

[Service]
WorkingDirectory=/media/data/Services/Api
ExecStart=/usr/bin/dotnet /media/data/Services/Api/Api.dll --sever.urls=http://*:7034
Restart=always
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=Api
User=www-data
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
TimeoutStopSec=90

[Install]
WantedBy=multi-user.target

这是用于在屏幕上添加文本的代码,该代码可以使用,但是如果在'Score'不起作用之后添加了score,则分数更新位于代码的底部。

systemd-escape "<value-to-escape>"
sudo systemctl enable api.service
sudo systemctl start api.service
sudo systemctl status api.service

这是在触摸每枚硬币时会更新的地方,但它不会显示在屏幕上。分数会更新,因为在触摸硬币时会打印出分数。

[![score: next to it is empty which is where the score is supposed to go][1]][1] 
import pygame
import os 
import random 
from pygame.locals import * # Constants
import math
import sys
import random

pygame.init()  

screen=pygame.display.set_mode((1280,700)) #(length,height)
screen_rect=screen.get_rect()
background = pygame.Surface(screen.get_size())
background = pygame.image.load('stage.png').convert()
Black=(0,0,0)

class Player(pygame.sprite.Sprite):
def __init__(self):
    super().__init__()  
    self.image = pygame.Surface((50,25)) 
    self.image.fill((0,0,128))    
    self.image =  pygame.image.load('sprite4.png')
    self.rect = self.image.get_rect(topleft =(20,615))  

    self.dist = 10

def update(self): # code to make the character move when the arrow keys are pressed
    if self.rect.right > 100:   # These are to make the player so move constantly
         self.rect.y += 1
         self.rect.x += 2
    if self.rect.bottom == 700:
         pygame.quit() 

    keys = pygame.key.get_pressed()
    if keys[K_LEFT]:
        self.rect.move_ip(-1,0)
    elif keys[K_RIGHT]:
        self.rect.move_ip(0.5,0)
    elif keys[K_UP]:
        self.rect.move_ip(0,-0.5)
    elif keys[K_DOWN]:
        self.rect.move_ip(0,1)
    self.rect.clamp_ip(screen_rect)
    #while self.rect == (20,615):
    if keys [K_SPACE]:
        self.rect = self.image.get_rect(topleft =(100,100))

player = Player()



class Enemy(pygame.sprite.Sprite): 
def __init__(self):
    super().__init__()
    self.image = pygame.Surface((50,25))  # This creates the surafce with the width and length given
    self.image.fill((128,0,0))   # This fills the surface with colour
    self.rect = self.image.get_rect(topleft=(300, 50))  # This is to make the image into a rectangle
    self.direction = 0

def update(self):
    self.rect.y += 1 if self.direction == 0 else -1
    if self.rect.bottom >= 600:
        self.direction = 1
    if self.rect.top <= 50:
        self.direction = 0

class Coin(pygame.sprite.Sprite): 
    def __init__(self):
    super().__init__()
    self.image =  pygame.image.load('coin.png')
    self.rect = self.image.get_rect(topleft=(250, 200))  

myfont = pygame.font.SysFont('OpenSans', 30)        
textsurface = myfont.render('Level ONE:   Greenland', False, (0, 0, 0))        
background.blit(textsurface,(500,10))

textsurface = myfont.render('Score:', False, (0, 0, 0))        
background.blit(textsurface,(10,10))

0 个答案:

没有答案