Skip to content

Commit

Permalink
Merge pull request #9 from Minigrim0/V2.1
Browse files Browse the repository at this point in the history
V2.1
  • Loading branch information
Minigrim0 authored Sep 1, 2021
2 parents 9d20580 + e6e900b commit bc86e45
Show file tree
Hide file tree
Showing 108 changed files with 1,182 additions and 453 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ A clear and concise description of what you expected to happen.
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- OS: [e.g. Linux]
- Version [e.g. 22]

**Additional context**
Expand Down
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:
Expand Down
Binary file added .meta/github_preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .meta/screenshots/ingame.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .meta/screenshots/mainmenu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions Editor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import tkinter
import logging

import pygame
import pygame.locals
Expand All @@ -8,6 +9,8 @@
from models.game_options import GameOptions
from models.screen import Screen

logging.basicConfig(level=logging.WARNING)

pygame.init()

options = GameOptions.getInstance()
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# Stromtrays
<p>
<img src="https://deepsource.io/gh/Minigrim0/Stormtrays.svg/?label=active+issues&show_trend=true&token=9zXI6PGE43X7aVUJL0rgA6Qf)](https://deepsource.io/gh/Minigrim0/Stormtrays/?ref=repository-badge" alt="deepsource status" title="deepsource status" />
<img src="https://deepsource.io/gh/Minigrim0/Stormtrays.svg/?label=active+issues&show_trend=true&token=9zXI6PGE43X7aVUJL0rgA6Qf" alt="deepsource status" title="deepsource status" />
<img src="https://github.com/Minigrim0/Stormtrays/actions/workflows/linting.yml/badge.svg" alt="github action status" title="itch.io build and push" />
</p>

<img src=".meta/screenshots/ingame.png" alt="in game screenshot" title="In Game Screenshot" />

<p>
A tower defense game written in python with <a href="https://pygame.org"><img src=".meta/pygame.png" height=20 alt="pygame" title="pygame" /></a>
</p>
Expand Down
6 changes: 6 additions & 0 deletions Stormtrays.py
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 removed UI/assets/images/grid.png
Binary file not shown.
85 changes: 85 additions & 0 deletions UI/components/animated_selectable.py
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
63 changes: 63 additions & 0 deletions UI/components/animated_selector.py
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)
4 changes: 2 additions & 2 deletions UI/components/credits.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json

import logging
import pygame as pg

from models.game_options import GameOptions
Expand Down Expand Up @@ -48,7 +48,7 @@ def _buildCategory(self, category_data: dict):
elif isinstance(element, str):
self._buildElementFromString(element)
else:
print("Unhandled", type(element))
logging.warning(f"Unhandled {type(element)}")

def _buildTitle(self, title: str):
"""Builds the title of a caegory"""
Expand Down
40 changes: 19 additions & 21 deletions UI/menus/editor.py → UI/components/gui/editor_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,55 +13,53 @@ def __init__(self, level):
self.vert_line = pygame.Surface((1, const.WINDOW_WIDTH))
self.hori_line = pygame.Surface((const.WINDOW_WIDTH, 1))

options = GameOptions.getInstance()
self.fond = pygame.image.load(const.fond).convert_alpha()
self.QGImg = pygame.image.load(options.fullPath("images", "QuestGiverF1.png")).convert_alpha()
self.buttons = {}

self.fond_Edit = None
self._build(level)

def _build(self, level):
"""Builds the Editor's UI"""
options = GameOptions.getInstance()
for index, (key, tile) in enumerate(level.tiles.items()):
self.buttons[key] = Button(
(const.WINDOW_WIDTH + 10 + (74 * (index % 2)), 10 + (74 * (index // 2))),
(64, 64),
image=tile.editor_image
)

self.buttons = {}
self.buttons["c1"] = Button((const.WINDOW_WIDTH + 10, 10), (64, 64), level.tiles["c1"].image[1])
self.buttons["t2"] = Button((const.WINDOW_WIDTH + 10, 74), (64, 64), level.tiles["t2"].image[1])
self.buttons["t1"] = Button((const.WINDOW_WIDTH + 10, 138), (64, 64), level.tiles["t1"].image[1])
self.buttons["x1"] = Button((const.WINDOW_WIDTH + 85, 10), (64, 64), level.tiles["x1"].image[1])
self.buttons["p1"] = Button((const.WINDOW_WIDTH + 85, 74), (64, 64), level.tiles["p1"].image[1])
self.buttons["v1"] = Button((const.WINDOW_WIDTH + 85, 138), (64, 64), level.tiles["v1"].image[1])
self.buttons["k1"] = Button((const.WINDOW_WIDTH + 5, 228), (192, 64), level.tiles["k1"].image[1])
self.buttons["QG"] = Button((const.WINDOW_WIDTH + 10, 292), (64, 64), self.QGImg)
self.buttons["eraseButton"] = Button(
(const.WINDOW_WIDTH + 2, const.WINDOW_HEIGHT - 45),
(80, 30),
pygame.image.load(const.efface).convert_alpha(),
image=pygame.image.load(options.fullPath("images", "buttons/erase.png")).convert_alpha(),
)
self.buttons["changeBackgroundButton"] = Button(
(const.WINDOW_WIDTH + 6, const.WINDOW_HEIGHT - 100),
(72, 44),
pygame.image.load(const.Mini_Fond).convert_alpha(),
image=pygame.image.load(options.fullPath("images", "buttons/change_background.png")).convert_alpha(),
)
self.buttons["saveButton"] = Button(
(const.WINDOW_WIDTH + 96, const.WINDOW_HEIGHT - 50),
(40, 40),
pygame.image.load(const.sauve).convert_alpha(),
image=pygame.image.load(options.fullPath("images", "buttons/save.png")).convert_alpha(),
)
self.buttons["loadButton"] = Button(
(const.WINDOW_WIDTH + 96, const.WINDOW_HEIGHT - 100),
(40, 40),
pygame.image.load(const.ouvrir).convert_alpha(),
image=pygame.image.load(options.fullPath("images", "buttons/open.png")).convert_alpha(),
)

self.right_panel.fill((189, 83, 64))
self.right_panel.fill((128, 0, 0))
self.vert_line.fill((0, 0, 0))
self.hori_line.fill((0, 0, 0))

self.QGPos = (0, 0)

def draw(self, screen):
"""Draws the UI on the screen"""
for i in range(1, const.tabx):
screen.blit(self.vert_line, (i * 64, 0))
screen.blit(self.hori_line, (0, i * 64))

screen.blit(self.right_panel, (const.WINDOW_WIDTH, 0))
for button in self.buttons.values():
for _name, button in self.buttons.items():
button.draw(screen)

def update(self, event):
Expand Down
File renamed without changes.
Loading

0 comments on commit bc86e45

Please sign in to comment.