Skip to content

Commit

Permalink
3d render
Browse files Browse the repository at this point in the history
  • Loading branch information
kulesy committed Mar 25, 2021
1 parent 66fc985 commit 40d26c0
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 35 deletions.
Binary file added __pycache__/play.cpython-39.pyc
Binary file not shown.
1 change: 1 addition & 0 deletions highscore.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
180
22 changes: 10 additions & 12 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ def display_menu(self):
game.check_events()
self.check_input()
game.display.blit(MAIN_MENU, (0,0))
self.menu_font_back.render(f'Highscore: {str(game.highscore)}', game.display, ((WIDTH - game.large_font.width(f'Highscore: {str(game.highscore)}') + 2) / 2, 10 + self.back_offset))
self.menu_font.render(f'Highscore: {str(game.highscore)}', game.display, ((WIDTH - self.menu_font.width(f'Highscore: {str(game.highscore)}')) / 2, 10))
self.menu_font_back.render('Start Game', game.display, (((WIDTH + 2 - self.menu_font.width('Start Game'))/ 2) , self.starty + self.back_offset))
self.menu_font.render('Start Game', game.display, ((WIDTH - self.menu_font.width('Start Game')) / 2, self.starty))
self.menu_font_back.render('Options', game.display, ((WIDTH + self.back_offset - self.menu_font.width('Options')) / 2 , self.optionsy + self.back_offset))
self.menu_font.render('Options', game.display, ((WIDTH - self.menu_font.width('Options')) / 2, self.optionsy))
self.menu_font_back.render('Quit', game.display, ((WIDTH + self.back_offset - self.menu_font.width('Quit'))/ 2, self.quity + self.back_offset))
self.menu_font.render('Quit', game.display, ((WIDTH - self.menu_font.width('Quit')) / 2, self.quity))
game.text_3D(self.menu_font_back, self.menu_font, f'Highscore: {str(game.highscore)}', game.display, ((WIDTH - game.large_font.width(f'Highscore: {str(game.highscore)}') + 2) / 2, 10 + self.back_offset))
# self.menu_font.render(f'Highscore: {str(game.highscore)}', game.display, ((WIDTH - self.menu_font.width(f'Highscore: {str(game.highscore)}')) / 2, 10))
game.text_3D(self.menu_font_back, self.menu_font,'Start Game', game.display, (((WIDTH + 2 - self.menu_font.width('Start Game'))/ 2) , self.starty + self.back_offset))
# self.menu_font.render('Start Game', game.display, ((WIDTH - self.menu_font.width('Start Game')) / 2, self.starty))
game.text_3D(self.menu_font_back, self.menu_font, 'Options', game.display, ((WIDTH + self.back_offset - self.menu_font.width('Options')) / 2 , self.optionsy + self.back_offset))
# self.menu_font.render('Options', game.display, ((WIDTH - self.menu_font.width('Options')) / 2, self.optionsy))
game.text_3D(self.menu_font_back, self.menu_font, 'Quit', game.display, ((WIDTH + self.back_offset - self.menu_font.width('Quit'))/ 2, self.quity + self.back_offset))
# self.menu_font.render('Quit', game.display, ((WIDTH - self.menu_font.width('Quit')) / 2, self.quity))
self.draw_cursor()
self.blit_screen()

Expand Down Expand Up @@ -111,10 +111,8 @@ def display_menu(self):
game.check_events()
self.check_input()
game.display_window()
self.menu_font_back.render('Play Again?', game.display, (((WIDTH - self.menu_font.width('Play Again?')) / 2) + 1, self.starty + 1))
self.menu_font.render('Play Again?', game.display, ((WIDTH - self.menu_font.width('Play Again?')) / 2, self.starty))
self.menu_font_back.render('Exit', game.display, (((WIDTH - self.menu_font.width('Exit')) / 2) + 1, self.exity + 1))
self.menu_font.render('Exit', game.display, ((WIDTH - self.menu_font.width('Exit')) / 2, self.exity))
game.text_3D(self.menu_font, self.menu_font_back, 'Play Again?', game.display, (((WIDTH - self.menu_font.width('Play Again?')) / 2) + 1, self.starty + 1))
game.text_3D(self.menu_font_back, self.menu_font, 'Exit', game.display, (((WIDTH - self.menu_font.width('Exit')) / 2) + 1, self.exity + 1))
self.draw_cursor()
self.blit_screen()

Expand Down
23 changes: 7 additions & 16 deletions play.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,6 @@
# Font
font = pygame.image.load(os.path.join('data', 'font', 'small_font.png'))

# Menu
MAIN_MENU = pygame.image.load(os.path.join('data', 'assets', 'Main_Menu.png'))
MAIN_MENU.set_colorkey((BLACK))

# Cursor
CURSOR = pygame.image.load(os.path.join('data', 'assets', 'cursor.png'))
CURSOR.set_colorkey((BLACK))

class Laser:
def __init__(self, x, y, img):
self.x = x
Expand Down Expand Up @@ -301,7 +293,7 @@ def display_window(self):

elif self.highscore <= self.player.score:
self.highscore = self.player.score
win_label = self.end_font.render(f"New Highscore! : {self.highscore}", self.display, ((WIDTH//2 - 60), (scoreh)))
win_label = self.end_font_back.render(f"New Highscore! : {self.highscore}", self.display, ((WIDTH//2 - 60), (scoreh)))
win_label = self.end_font.render(f"New Highscore! : {self.highscore}", self.display, ((WIDTH//2 - 60) - 1, (scoreh) - 1))
with open(os.path.join(self.dir, HS_FILE), 'w') as f:
f.write(str(self.player.score))
Expand Down Expand Up @@ -390,13 +382,12 @@ def enemy_behaviour(self):
def reset_keys(self):
self.W_KEY, self.A_KEY, self.S_KEY, self.D_KEY, self.SPACE_KEY, self.START_KEY, self.BACK_KEY = False, False, False, False, False, False, False

def draw_text(self, text, size, x, y ):
font = pygame.font.SysFont("comicsans", size)
text_surface = font.render(text, True, WHITE)
text_rect = text_surface.get_rect()
text_rect.center = (x,y)
self.display.blit(text_surface,text_rect)

def text_3D(self, font1, font2, text, surf, loc):
font1.render(text, surf, loc)
coord = [pos - 1 for pos in loc]
loc_new = (coord[0], coord[1])
font2.render(text, surf, loc_new)

def update_lives(self):
offset = ((LIVES.get_width() / 2) - 3)
for i in range(self.lives):
Expand Down
Binary file modified scripts/__pycache__/text.cpython-39.pyc
Binary file not shown.
14 changes: 7 additions & 7 deletions scripts/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ def render(self, text, surf, loc, line_width=0):
y_offset += self.line_spacing + self.line_height
x_offset = 0

def render_3D(self, text, surf1, surf2, loc, line_width=0)
render(text, surf1, loc, line_width=0)
coord = []
for pos in loc:
coord.append(pos + 2)
loc_new = (coord[0], coord[1])
render(text, surf2, loc_new, line_width=0)
# def render_3D(self, text, surf1, surf2, loc, line_width=0):
# render(text, surf1, loc, line_width)
# coord = []
# for pos in loc:
# coord.append(pos + 2)
# loc_new = (coord[0], coord[1])
# render(text, surf2, loc_new, line_width)

0 comments on commit 40d26c0

Please sign in to comment.