-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Cynthion21x/scenes-and-menus
Scenes and menus
- Loading branch information
Showing
13 changed files
with
216 additions
and
67 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
File renamed without changes
File renamed without changes
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import pygame | ||
import src.math.vectors as v | ||
import src.shared.constants as c | ||
|
||
class UiElement: | ||
|
||
def __init__(self, pos, size): | ||
|
||
self.pos = pos | ||
self.size = size | ||
|
||
class text(UiElement): | ||
|
||
def __init__(self, pos, size, text, font=None, colour=c.Colours.WHITE): | ||
|
||
super().__init__(pos, size) | ||
|
||
self.textImg = font.render(text, True, colour) | ||
|
||
ratio = self.textImg.get_size()[1] / self.textImg.get_size()[0] | ||
|
||
newSize = v.Vector(size.x, size.x * ratio) | ||
|
||
self.textImg = pygame.transform.smoothscale(self.textImg, newSize.value()) | ||
|
||
def render(self, display): | ||
|
||
display.blit(self.textImg, self.pos.value()) | ||
|
||
class photo(UiElement): | ||
|
||
def __init__(self, pos, size, image, preserveAspect = False): | ||
|
||
super().__init__(pos, size) | ||
|
||
if preserveAspect == False: | ||
|
||
self.image = pygame.transform.smoothscale(image, size.value()) | ||
|
||
else: | ||
|
||
ratio = image.get_size()[1] / image.get_size()[0] | ||
|
||
newSize = v.Vector(size.x, size.x * ratio) | ||
|
||
self.image = pygame.transform.smoothscale(image, newSize.value()) | ||
|
||
def render(self, display): | ||
|
||
display.blit(self.image, self.pos.value()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
class mainMenu: | ||
|
||
def __init__(self, game): | ||
|
||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import src.shared.constants as c | ||
import src.core.UI.elements as elements | ||
import src.core.content.contentManager as content | ||
import src.math.vectors as v | ||
import pygame | ||
|
||
class splashScreen: | ||
|
||
def __init__(self, game): | ||
|
||
self.game = game | ||
|
||
center = v.mult(v.Vector(c.SCREEN_WIDTH, c.SCREEN_HEIGHT), 0.5) | ||
|
||
TitleSize = v.Vector(900, 500) | ||
|
||
self.title = elements.photo( | ||
|
||
v.add(v.sub(center, v.mult(TitleSize, 0.5)), v.Vector(0, -60)), TitleSize, | ||
content.fetch().Sprite("Titles\\gameTitle-alt"), | ||
True | ||
|
||
) | ||
|
||
self.prompts = elements.text( | ||
|
||
v.sub(center, v.Vector(150, -150)), v.Vector(300, 100), | ||
"Press Enter To Start", | ||
content.fetch().Font("Sobiscuit") | ||
|
||
) | ||
|
||
def run(self): | ||
|
||
self.game.display.fill(c.Colours.BACKGROUND) | ||
|
||
self.title.render(self.game.display) | ||
self.prompts.render(self.game.display) | ||
|
||
keys = pygame.key.get_pressed() | ||
if keys[pygame.K_RETURN]: | ||
self.game.GameState = c.States.GAME |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters