Pyxes is a library that adds functionality and structure to pygame, you can still use all your pygame code but with less of a lot boilerplate code!
from pyxes import Game
game = Game()
game.run()
game = Game(width = 640, height = 480, bg_color = Colors['black'], bg_alpha = 255, title = 'Title', cursor = True, fps = 60, quit_on_escape = False, default_scene = Scene())
print(self.title)
game.set_title('My Game Title')
game.set_icon('icon.png')
print(self.icon_path) # icon file path
print(self.icon_image) # icon pygame.image
print(game.width, game.height)
game.set_size(1280, 720)
game.bg_color = (123, 255, 100) # default is (0, 0, 0) (black)
game.bg_alpha = 128 # default is 255
All update, drawing and event functions will be paused, except Scene events.
print(game.pause)
game.set_pause(True) # can be True or False, by default is False
game.toggle_pause()
print(game.fullscreen)
game.set_fullscreen(False) # can be True or False, by default is True
game.toggle_fullscreen()
print(game.fps)
game.set_fps(30)
print(self.cursor)
game.set_cursor_visibility(False) # can be True or False, by default is True
game.toggle_cursor_visibility()
game.hidde_cursor()
game.show_cursor()
print(game.delta_time)
game.screenshot() # default screenshots directory is 'screenshots/'
game.screenshot('my_screenshots')
game.screenshot(os.path.join(__file__, 'my_screenshots'))
game.quit_on_escape = True # can be True or False, by default is False
The 'print_name' function is executed for the current scene and all game objects actives.
game.custom_event('print_name', 'Lullaby')
class Player (GameObject):
def print_name(self, name):
print(f'My name is: {name}')
from pyxes import Game, Scene
class MainScene (Scene):
def load(self):
print('main scene loaded!')
game = Game()
game.set_scene('main', MainScene())
game.run()
my_scene = Scene() # instancing a base scene
game.add_scene('scene_name', my_scene) # add scene to game.scenes
game.change_scene('scene_name') # change the active/current scene
game.set_scene('scene_name', my_scene) # a shortcut for add_scene and change_scene
game.get_active_scene()
game.remove_scene('scene_name') # delete a scene
game.reset_scene() # reset current scene
my_scene = Scene(ignore_pause = False)
class MainScene (Scene):
def __init__(self):
super().__init__()
def load(self):
print('main scene loaded!')
def update(self)
print('main scene loop.', self.game.delta_time)
active_scene = game.get_active_scene()
active_scene.reset()
This function will be executed automatically when a GameObject is created.
active_scene = game.get_active_scene()
active_scene.sort_game_objects_by_z()
my_scene = Scene(ignore_pause = True)
or
class MyScene (Scene):
def load(self):
self.ignore_pause = True
my_scene = MyScene()
from pyxes import Game, Scene, GameObject
class Player (GameObject):
def key_down(self, event, keyname):
if keyname == 'w': self.y -= 10
if keyname == 'a': self.x -= 10
if keyname == 's': self.y += 10
if keyname == 'd': self.x += 10
class MainScene (Scene):
def load(self):
self.add_game_object('player', Player())
game = Game(default_scene=MainScene())
game.run()
MyObject = GameObject(x = 0, y = 0, z = 0, width = 10, height = 10, color = Colors['white'], alpha = 255, tags = [], gui = False, ignore_pause = False, active = True, visible = True)
game.get_active_scene().instant_game_object(MyObject)
active_scene = game.get_active_scene()
player = GameObject()
active_scene.add_game_object('player', player) # create a GameObject with 'player' name
active_scene.instant_game_object(player) # create a GameObject without specifying a name
active_scene.remove_game_object('player') # remove GameObject by name
player = active_scene.get_game_object('player')
class MyGameObject (GameObject):
def __init__(self):
super().__init__()
def load(self):
print(self.id, 'my-gameobject loaded!')
def update(self)
print(self.name, 'my-gameobject scene loop.', self.game.delta_time)
player = GameObject(x=0, y=0, z=0)
or
player.x = 25
player.y = 25
player.set_z(1)
player = GameObject(color=(255, 255, 255))
or
player.color = Colors['red']
player = GameObject(aplha=128)
or
player.alpha = 128
player = GameObject(width=25, height=25)
or
player.set_size(25, 25) # width, height
or
player.width = 50
player.height = 25
GameObjects has 'gui' enabled will be fixed in the window.
GUI = GameObject(width=200, height=50, gui=True)
player.reset()
active_scene.instant_game_object(GameObject(tags=['enemy']))
enemies = active_scene.get_game_objects_by_tag('enemy')
player.add_tag('player')
player.remove_tag('player')
if player.has_tag('player'):
print(player, 'is a player!')
print(player.get_tags())
player.visible = False # by default is True
player.active = False # by default is True
player.ignore_pause = True # by default is False
print(player.z)
player.set_z(10)
Events for Scenes and GameObjects.
key_down
key_up
mouse_down
mouse_up
mouse_motion
mouse_wheel
joy_axis_motion
joy_button_down
joy_button_up
quit
fullscreen
resize
expose
focus
on_pause
on_collide
on_click
class MainScene (Scene):
def key_down(self, event, key_name):
if key_name == 'p': self.game.toggle_pause()