-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Brand new object system #38
Labels
Comments
Are you sure it absolutely must be implemented in scope of current milestone? |
class Transform(object):
"""t"""
required = True
def __init__(self, pos=None, rot=None, scale=None):
self._pos = pos or Point()
self._rot = rot or Point()
self._scale = scale or Point(1, 1, 1)
class GameObject(object):
"""t"""
default_components = [Transform]
components = default_components[:]
def __init__(self, transform=None):
self.add_component(transform or Transform())
def add_component(self, component):
"""t"""
self.components.append(component) |
@dispatch(Ship, Projectile)
def on_collision(ship, projectile):
ship.apply_damage(projectile.damage)
@dispatch(EnemyShip, EnemyShip)
def on_collision(ship1, ship2):
pass |
It's shame that we cannot construct function in runtime. It would be very nice to just have something like |
diff --git a/xoinvader/menu.py b/xoinvader/menu.py
index 16e0710..eb8d801 100644
--- a/xoinvader/menu.py
+++ b/xoinvader/menu.py
@@ -41,6 +41,62 @@ class PauseMenuState(State):
KEY.N: lambda: self.notify("This is test notification"),
})
+ def key_event_map(self):
+ # Under the hood
+ # self._events = EventHandler(self, self.key_event_map)
+ # dispatch(event)
+ # if action == call-app then getattr(application.get_current(), target)(*args, **kwargs)
+ # if action == call-self then getattr(self, target)(*args, **kwargs)
+ # if action == call then parse()
+ {
+ "type": "State",
+ "name": "PauseMenuState",
+ "init": {
+ "objects": [
+ {"class": "TextWidget", "args": ([4, 4], "Pause")},
+ {"class": "MenuItemWidget", "args": ([10, 10], "Continue")},
+ {"class": "MenuItemWidget", "args": ([10, 11], "Quit")},
+ ],
+ },
+ "key-event-map": {
+ "KEY.ESCAPE": {
+ "action": "call-app",
+ "target": "stop",
+ },
+ "KEY.R": {
+ "action": "call-self",
+ "target": "notify",
+ "args": "This is test notification",
+ },
+ "KEY.N": {
+ "action": "trigger-state",
+ "target": "InGameState",
+ },
+ },
+ "scripts": [
+ {
+ "name": "notify.py",
+ "id": "{fdfdfdf}",
+ },
+ ],
+ }
def notify(self, text, pos=Point(15, 15)):
self.add(
PopUpNotificationWidget( |
👍 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
THIS IS DRAFT
Abstract
This
time not came yet, but some changes we need to do in order to unblock further development.We need to design and implement as simple as possible object system that will fit to our needs for this time.
We have ships and backgrounds that have Surface to render. We have projectiles that looks like not good designed lists of coordinates...
Design
GameObject and State
GameObject
is recursive data structure that have position in world coordinates if it is not part of another object, otherwise it has local coordinates as offset to parent object.GameObject
can hold subobjects of typeGameObject
with own colliders, animations, sprites.State
as implemented now is a scene, that holds game objects and does all interations with them in loop when this state is active.State
can hold many instances ofGameObject
.Appllication and States
Application
holds one or moreState
s and executes current state.State
can be used in one time.IOLoop
3 methods of currentState
object:events()
,update(dt)
, andrender()
.Event-based messaging
State
has it's own message queue to provide messaging between objects and maybe even whole engine subsystems.Application
can have dedicated queue for something.GameObject
can put event into queue via it'sState
.EventHandler
ofState
pops all events from queue and process them onevents
stage of theState
.Game-specific implementation examples
Ship
Weapon
Collision detection
The text was updated successfully, but these errors were encountered: