-
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 #9 from Minigrim0/V2.1
V2.1
- Loading branch information
Showing
108 changed files
with
1,182 additions
and
453 deletions.
There are no files selected for viewing
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
2 changes: 1 addition & 1 deletion
2
.github/workflows/linting.yml → .github/workflows/linting_build_push.yml
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: Lint and push to itchio | ||
name: Lint, Build executables and push to itchio | ||
|
||
on: | ||
push: | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -1,8 +1,14 @@ | ||
import logging | ||
|
||
import pygame | ||
|
||
from models.stormtrays import Stormtrays | ||
|
||
logging.basicConfig(level=logging.WARNING) | ||
|
||
logging.info("Initializing pygame") | ||
pygame.init() | ||
|
||
logging.info("launching game") | ||
stormtrays = Stormtrays.getInstance() | ||
stormtrays.run() |
Binary file not shown.
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,85 @@ | ||
import pygame as pg | ||
|
||
from models.game_options import GameOptions | ||
from UI.components.image_animation import ImageAnimation | ||
|
||
|
||
class AnimatedSelectable: | ||
"""An animated selectable image""" | ||
|
||
def __init__( | ||
self, position: tuple, name: str, size: tuple = (256, 256), | ||
initial_animation: str = "idle", selection_animation: str = "attack" | ||
): | ||
self.animations: {str: ImageAnimation} = {} | ||
self.position: tuple = position | ||
self.current_animation: str = initial_animation | ||
self.initial_animation: str = initial_animation | ||
self.selection_animation: str = selection_animation | ||
self.selected: bool = False | ||
self.name: str = name | ||
self.size: tuple = size | ||
|
||
self.name_display: pg.Surface = None | ||
self._build() | ||
|
||
def _build(self): | ||
"""Builds the name surface""" | ||
options = GameOptions.getInstance() | ||
self.name_display = options.fonts["MedievalSharp-xOZ5"]["20"].render(self.name, 1, (255, 255, 255)) | ||
|
||
def _endSelectAnimation(self): | ||
"""Callback for the selection animation to restart the initial one""" | ||
self.current_animation = self.initial_animation | ||
self.animations[self.selection_animation].reset() | ||
|
||
def addAnimation( | ||
self, animation_name: str, animation: ImageAnimation, is_initial: bool = False, is_selection: bool = False | ||
): | ||
"""Adds an animation to the executable | ||
Args: | ||
animation_name (str): The name of the new animation | ||
animation (ImageAnimation): The ImageAnimation | ||
is_initial (bool, optional): Whether to set the animation as initial. Defaults to False. | ||
is_selection (bool, optional): Whether to set the animation as selection animation. Defaults to False. | ||
""" | ||
self.animations[animation_name] = animation | ||
self.animations[animation_name].play() | ||
if is_initial or animation_name == self.initial_animation: | ||
self.initial_animation = animation_name | ||
if is_selection or animation_name == self.selection_animation: | ||
self.selection_animation = animation_name | ||
self.animations[self.selection_animation].setCallback(self._endSelectAnimation) | ||
|
||
def update(self, timeElapsed): | ||
"""Updates the selectable's animations""" | ||
self.animations[self.current_animation].update(timeElapsed) | ||
|
||
def draw(self, screen, offset: tuple = (0, 0)): | ||
"""Draws the selectable on the screen""" | ||
position = tuple(map(lambda i, j: i + j, self.position, offset)) | ||
self.animations[self.current_animation].draw(screen, position) | ||
if self.selected: | ||
pg.draw.rect(screen.fenetre, (255, 255, 255), pg.Rect(position, (256, 256)), width=2) | ||
screen.blit( | ||
self.name_display, | ||
(position[0] + 128 - self.name_display.get_size()[0]//2, position[1]) | ||
) | ||
|
||
def select(self): | ||
"""Sets the selectable as selected and plays the selection animation""" | ||
self.selected = True | ||
self.current_animation = self.selection_animation | ||
self.animations[self.current_animation].play() | ||
|
||
def unselect(self): | ||
"""Sets the selectable as unselected""" | ||
self.selected = False | ||
|
||
def click(self, event_pos, offset: tuple = (0, 0)): | ||
"""Returns true if the position overlap the selectable""" | ||
position = tuple(map(lambda i, j: i + j, self.position, offset)) | ||
if position[0] < event_pos[0] < position[0] + self.size[0]: | ||
return position[1] < event_pos[1] < position[1] + self.size[1] | ||
return False |
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,63 @@ | ||
import pygame as pg | ||
|
||
from UI.components.animated_selectable import AnimatedSelectable | ||
from UI.components.image_animation import ImageAnimation | ||
|
||
|
||
class AnimatedSelector: | ||
"""A list of animated selectable items""" | ||
|
||
def __init__(self, position, size, selectable_size: tuple = (256, 256)): | ||
self.elements: list(AnimatedSelectable) = [] | ||
self.position = position | ||
self.size = size | ||
self.selectable_size = selectable_size | ||
|
||
@property | ||
def _selected(self) -> AnimatedSelectable: | ||
"""Returns the selected AnimatedSelectable""" | ||
for element in self.elements: | ||
if element.selected: | ||
return element | ||
return None | ||
|
||
@property | ||
def selected_name(self) -> AnimatedSelectable: | ||
"""Returns the name of the selected selectable""" | ||
for element in self.elements: | ||
if element.selected: | ||
return element.name | ||
return None | ||
|
||
def update(self, timeElapsed): | ||
"""Updates the selectables""" | ||
for selectable in self.elements: | ||
selectable.update(timeElapsed) | ||
|
||
def draw(self, screen): | ||
"""Draws the selector on the screen""" | ||
for selectable in self.elements: | ||
selectable.draw(screen, offset=self.position) | ||
|
||
def handleEvent(self, event): | ||
"""Handles user events""" | ||
if event.type == pg.MOUSEBUTTONDOWN and event.button == 1: | ||
selected_element = self._selected | ||
for element in self.elements: | ||
if element != selected_element and element.click(event.pos, offset=self.position): | ||
selected_element.unselect() | ||
element.select() | ||
|
||
def addElement(self, name, animations: dict): | ||
"""Adds a selectable to the selector""" | ||
position = ( | ||
(len(self.elements) % 2) * self.selectable_size[0], | ||
(len(self.elements) // 2) * self.selectable_size[1] | ||
) | ||
selectable = AnimatedSelectable(position, name=name) | ||
for animation_name, animation in animations.items(): | ||
image_animation = ImageAnimation(initial_data=animation, image_size=self.selectable_size) | ||
selectable.addAnimation(animation_name, image_animation) | ||
if len(self.elements) == 0: | ||
selectable.selected = True | ||
self.elements.append(selectable) |
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
File renamed without changes.
Oops, something went wrong.