Added renderText() func
This commit is contained in:
+27
-18
@@ -73,7 +73,7 @@ class Player(pygame.sprite.Sprite):
|
|||||||
class Enemy(pygame.sprite.Sprite):
|
class Enemy(pygame.sprite.Sprite):
|
||||||
def setNextEnemyType(self, score):
|
def setNextEnemyType(self, score):
|
||||||
if score < 10:
|
if score < 10:
|
||||||
self.type = 1
|
self.type = 2
|
||||||
|
|
||||||
elif score < 25:
|
elif score < 25:
|
||||||
if random.randint(1, 100) < 95: self.type = 1
|
if random.randint(1, 100) < 95: self.type = 1
|
||||||
@@ -92,7 +92,7 @@ class Enemy(pygame.sprite.Sprite):
|
|||||||
if self.type == 1:
|
if self.type == 1:
|
||||||
self.subtype = random.randint(1, 5)
|
self.subtype = random.randint(1, 5)
|
||||||
elif self.type == 2:
|
elif self.type == 2:
|
||||||
self.subtype = random.randint(1, 3)
|
self.subtype = random.randint(1, 7)
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, screenSize, floorHeight, gameSpeed, score):
|
def __init__(self, screenSize, floorHeight, gameSpeed, score):
|
||||||
@@ -121,13 +121,16 @@ class Enemy(pygame.sprite.Sprite):
|
|||||||
self.image = pygame.Surface((50, 25))
|
self.image = pygame.Surface((50, 25))
|
||||||
self.image.fill((51, 51, 0))
|
self.image.fill((51, 51, 0))
|
||||||
self.rect = self.image.get_rect()
|
self.rect = self.image.get_rect()
|
||||||
self.height -= self.rect.height/2 + 10 + 25*self.subtype
|
self.height -= self.rect.height/2 + 10 + 10*self.subtype
|
||||||
|
|
||||||
self.rect.center = (screenSize[0] + self.rect.width, self.height)
|
self.rect.center = (screenSize[0] + self.rect.width, self.height)
|
||||||
|
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
|
if self.type == 1:
|
||||||
self.rect.x -= self.speed
|
self.rect.x -= self.speed
|
||||||
|
else:
|
||||||
|
self.rect.x -= self.speed*2
|
||||||
|
|
||||||
|
|
||||||
class Drakora():
|
class Drakora():
|
||||||
@@ -180,6 +183,10 @@ class Drakora():
|
|||||||
self.floors.add(Floor(self.screenSize, self.floorHeight))
|
self.floors.add(Floor(self.screenSize, self.floorHeight))
|
||||||
self.sprites.add(self.floors)
|
self.sprites.add(self.floors)
|
||||||
|
|
||||||
|
font = pygame.font.match_font('liberation mono')
|
||||||
|
self.fontScore = pygame.font.Font(font, 32)
|
||||||
|
self.fontMessage = pygame.font.Font(font, 56)
|
||||||
|
|
||||||
self.newGame()
|
self.newGame()
|
||||||
|
|
||||||
|
|
||||||
@@ -187,28 +194,29 @@ class Drakora():
|
|||||||
pygame.quit()
|
pygame.quit()
|
||||||
|
|
||||||
|
|
||||||
|
def renderText(self, text, font, color, center):
|
||||||
|
render = font.render(text, True, color)
|
||||||
|
rect = render.get_rect()
|
||||||
|
rect.center = center
|
||||||
|
self.screen.blit(render, rect)
|
||||||
|
|
||||||
|
|
||||||
def render(self):
|
def render(self):
|
||||||
self.screen.fill((102, 153, 255))
|
self.screen.fill((102, 153, 255))
|
||||||
self.sprites.draw(self.screen)
|
self.sprites.draw(self.screen)
|
||||||
|
|
||||||
font = pygame.font.Font(pygame.font.match_font('liberation mono'), 32)
|
self.renderText('%d'%(self.score),
|
||||||
text = font.render('%d'%(self.score), True, (255, 255, 255))
|
self.fontScore, (255, 255, 255),
|
||||||
rect = text.get_rect()
|
(self.screenSize[0]/2,20))
|
||||||
rect.midtop = (rect.width/2+10,10)
|
|
||||||
self.screen.blit(text, rect)
|
|
||||||
|
|
||||||
if self.isGameOver:
|
if self.isGameOver:
|
||||||
font = pygame.font.Font(pygame.font.match_font('liberation mono'), 56)
|
self.renderText('GAME OVER',
|
||||||
text = font.render('GAME OVER', True, (255, 255, 255))
|
self.fontMessage, (255, 255, 255),
|
||||||
rect = text.get_rect()
|
tuple(i/2 for i in self.screenSize))
|
||||||
rect.midtop = tuple(i/2 for i in self.screenSize)
|
|
||||||
self.screen.blit(text, rect)
|
|
||||||
elif self.isPaused:
|
elif self.isPaused:
|
||||||
font = pygame.font.Font(pygame.font.match_font('liberation mono'), 56)
|
self.renderText('PAUSED',
|
||||||
text = font.render('PAUSED', True, (255, 255, 255))
|
self.fontMessage, (255, 255, 255),
|
||||||
rect = text.get_rect()
|
tuple(i/2 for i in self.screenSize))
|
||||||
rect.midtop = tuple(i/2 for i in self.screenSize)
|
|
||||||
self.screen.blit(text, rect)
|
|
||||||
|
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
|
|
||||||
@@ -222,6 +230,7 @@ class Drakora():
|
|||||||
enemy.kill()
|
enemy.kill()
|
||||||
self.score += 1
|
self.score += 1
|
||||||
self.gameSpeed += 0.025
|
self.gameSpeed += 0.025
|
||||||
|
"""Quick fix of running cacti. Some good fix needed"""
|
||||||
for enemy in self.enemies: enemy.speed = self.gameSpeed
|
for enemy in self.enemies: enemy.speed = self.gameSpeed
|
||||||
|
|
||||||
for cloud in self.clouds:
|
for cloud in self.clouds:
|
||||||
|
|||||||
Reference in New Issue
Block a user