Skip to content

Commit

Permalink
feat(main): ✨ Added a new demo for testing smth
Browse files Browse the repository at this point in the history
ISN'T FINISHED YET
  • Loading branch information
Tsunami014 (Max) authored and Tsunami014 (Max) committed Dec 29, 2024
1 parent 872d673 commit 7cc9e95
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 11 deletions.
2 changes: 1 addition & 1 deletion BlazeSudio/graphics/graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def _Event(self, event: pygame.event.Event):
def _DrawAft(self):
"""
This function is called every time *just before* the screen is drawn. This could be used for things to be drawn on top of all the other GUI elements.
To draw something *behind* the other elements, use `_DrawBef()`.
To draw something *behind* the other elements, use `_Tick()`.
This function can also be used for events that happen after everything else.
"""
Expand Down
Binary file added demoFiles/sampleTileset.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
73 changes: 63 additions & 10 deletions demos.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,58 @@ def load(slf):

Main()()

def TsetCollDemo():
from BlazeSudio.graphics import Screen, Loading, options as GO, GUI
from functools import partial
import pygame

tset = pygame.image.load('demoFiles/sampleTileset.png')

class Main(Screen):
def getTile(self, idx):
if idx is None:
return
self.poly = None
self.tile = tset.subsurface((idx*32, 0, 32, 32))

@Loading.decor
def calcPoly(slf, self):
self.poly = [(0, 0), (32, 0), (32, 32), (0, 32)]

def __init__(self):
self.getTile(0)
super().__init__()

def _LoadUI(self):
self.layers[0].add('Main')

PCTOP = GO.PNEW((0.5, 0), (1, 0), (True, False))
self.scale = GUI.NumInputBox(self, PCTOP, 100, GO.RNONE, start=None, empty=1, min=1, max=30, placeholder='Scale by size', decimals=2)
chooser = GUI.DropdownButton(self, PCTOP, ['Tile %i'%i for i in range(tset.get_width()//32)], func=lambda i: self.getTile(i))

goBtn = GUI.Button(self, GO.PCBOTTOM, GO.CGREEN, 'Go!', func=partial(self.calcPoly, self))

self['Main'].extend([
self.scale,
chooser,
goBtn
])

def _Tick(self):
scale = self.scale.get()

def outPos(x, y):
center_x = (self.size[0] - 32 * scale) / 2
center_y = (self.size[1] - 32 * scale) / 2
return (x * scale + center_x, y * scale + center_y)

self.WIN.blit(pygame.transform.scale(self.tile, (32*scale, 32*scale)), outPos(0, 0))

if self.poly is not None:
pygame.draw.polygon(self.WIN, (0, 0, 0), [outPos(*p) for p in self.poly], 4)

Main()()

# GENERATION STUFF

def TWorldsDemo():
Expand Down Expand Up @@ -651,26 +703,27 @@ def cmd(cmdd):
cmds.append(command)

label('Node generator [image]:')
button('Node Editor Demo', NodeEditorDemo, )
button('Node Editor Demo', NodeEditorDemo, )

label('Graphics [graphics] / [game]:')
button('Graphics Demo', GraphicsDemo, )
button('Lorem Ipsum Graphics Demo', LoremGraphicsDemo, )
button('Theme Playground Demo', ThemePgDemo, True)
button('Graphics Demo', GraphicsDemo, )
button('Lorem Ipsum Graphics Demo', LoremGraphicsDemo, )
button('Theme Playground Demo', ThemePgDemo, True)

# TODO: Sound editor demo
label('Collisions [collisions]:')
button('Collisions Demo', CollisionsDemo, )
button('DEBUG Collisions Demo', lambda: CollisionsDemo(True), )
button('Collisions Demo', CollisionsDemo, )
button('DEBUG Collisions Demo', lambda: CollisionsDemo(True), )

# Broken generation stuff
#button('Generate World Demo', TWorldsDemo, )
#button('Generate Terrain Demo', TTerrainGenDemo, )
#button('Generate World Demo', TWorldsDemo, )
#button('Generate Terrain Demo', TTerrainGenDemo, )


label('Misc stuff:')
button('Wrap Demo [game]', WrapDemo, )
button('Wrap Basic Demo [game]', WrapBasicDemo, )
button('Wrap Demo [game]', WrapDemo, )
button('Wrap Basic Demo [game]', WrapBasicDemo, )
button('Tileset Collision Demo [game]', TsetCollDemo, )

if has_tk:
root.after(1, lambda: root.attributes('-topmost', True))
Expand Down

0 comments on commit 7cc9e95

Please sign in to comment.