mima-engine 0.1.4__py3-none-any.whl → 0.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of mima-engine might be problematic. Click here for more details.

Files changed (80) hide show
  1. mima/__init__.py +1 -1
  2. mima/backend/pygame_assets.py +15 -9
  3. mima/backend/pygame_audio.py +5 -2
  4. mima/backend/pygame_backend.py +255 -57
  5. mima/backend/pygame_camera.py +63 -0
  6. mima/backend/pygame_events.py +331 -85
  7. mima/collision.py +182 -111
  8. mima/engine.py +155 -15
  9. mima/maps/tiled/tiled_map.py +3 -3
  10. mima/maps/tiled/tiled_tileset.py +1 -0
  11. mima/maps/tilemap.py +78 -15
  12. mima/maps/tileset.py +8 -2
  13. mima/maps/transition_map.py +6 -8
  14. mima/mode_engine.py +80 -0
  15. mima/objects/animated_sprite.py +23 -15
  16. mima/objects/attributes.py +3 -0
  17. mima/objects/creature.py +64 -25
  18. mima/objects/dynamic.py +30 -8
  19. mima/objects/effects/colorize_screen.py +22 -6
  20. mima/objects/effects/debug_box.py +124 -0
  21. mima/objects/effects/light.py +21 -30
  22. mima/objects/effects/show_sprite.py +39 -0
  23. mima/objects/effects/walking_on_grass.py +25 -7
  24. mima/objects/effects/walking_on_water.py +17 -6
  25. mima/objects/loader.py +24 -13
  26. mima/objects/projectile.py +21 -6
  27. mima/objects/sprite.py +7 -8
  28. mima/objects/world/color_gate.py +5 -2
  29. mima/objects/world/color_switch.py +12 -6
  30. mima/objects/world/container.py +17 -8
  31. mima/objects/world/floor_switch.py +8 -4
  32. mima/objects/world/gate.py +8 -5
  33. mima/objects/world/light_source.py +11 -9
  34. mima/objects/world/logic_gate.py +8 -7
  35. mima/objects/world/movable.py +72 -28
  36. mima/objects/world/oneway.py +14 -9
  37. mima/objects/world/pickup.py +10 -5
  38. mima/objects/world/switch.py +28 -25
  39. mima/objects/world/teleport.py +76 -55
  40. mima/scene_engine.py +19 -20
  41. mima/scripts/command.py +16 -2
  42. mima/scripts/commands/change_map.py +23 -4
  43. mima/scripts/commands/equip_weapon.py +23 -0
  44. mima/scripts/commands/give_item.py +5 -3
  45. mima/scripts/commands/move_map.py +9 -9
  46. mima/scripts/commands/parallel.py +16 -3
  47. mima/scripts/commands/present_item.py +7 -5
  48. mima/scripts/commands/screen_fade.py +30 -12
  49. mima/scripts/commands/serial.py +30 -7
  50. mima/scripts/commands/set_spawn_map.py +6 -3
  51. mima/scripts/commands/show_choices.py +16 -7
  52. mima/scripts/commands/show_dialog.py +110 -3
  53. mima/scripts/script_processor.py +41 -20
  54. mima/states/game_state.py +2 -0
  55. mima/states/memory.py +28 -0
  56. mima/states/quest.py +2 -3
  57. mima/types/keys.py +48 -0
  58. mima/types/mode.py +4 -10
  59. mima/types/player.py +9 -0
  60. mima/types/position.py +13 -0
  61. mima/types/tile_collision.py +11 -0
  62. mima/types/window.py +44 -0
  63. mima/usables/item.py +1 -0
  64. mima/util/colors.py +5 -0
  65. mima/util/constants.py +6 -0
  66. mima/util/functions.py +27 -0
  67. mima/util/input_defaults.py +109 -0
  68. mima/util/runtime_config.py +234 -30
  69. mima/util/trading_item.py +20 -0
  70. mima/view/camera.py +160 -19
  71. mima/view/mima_mode.py +612 -0
  72. mima/view/mima_scene.py +225 -0
  73. mima/view/mima_view.py +12 -0
  74. mima/view/mima_window.py +153 -0
  75. {mima_engine-0.1.4.dist-info → mima_engine-0.2.0.dist-info}/METADATA +4 -2
  76. mima_engine-0.2.0.dist-info/RECORD +128 -0
  77. {mima_engine-0.1.4.dist-info → mima_engine-0.2.0.dist-info}/WHEEL +1 -1
  78. mima/view/scene.py +0 -322
  79. mima_engine-0.1.4.dist-info/RECORD +0 -114
  80. {mima_engine-0.1.4.dist-info → mima_engine-0.2.0.dist-info}/top_level.txt +0 -0
@@ -3,7 +3,7 @@ from ...types.direction import Direction
3
3
  from ...types.graphic_state import GraphicState
4
4
  from ...types.nature import Nature
5
5
  from ...types.object import ObjectType
6
- from ...util.constants import ONEWAY_ACTIVATION_DELAY, TILE_HEIGHT, TILE_WIDTH
6
+ from ...util.constants import ONEWAY_ACTIVATION_DELAY
7
7
  from ..animated_sprite import AnimatedSprite
8
8
  from ..dynamic import Dynamic
9
9
 
@@ -22,10 +22,11 @@ class Oneway(Dynamic):
22
22
  jump_vy: float,
23
23
  width: float,
24
24
  height: float,
25
+ tilemap,
25
26
  dyn_id=-1,
26
27
  name="Oneway",
27
28
  ):
28
- super().__init__(name, px, py, dyn_id)
29
+ super().__init__(px, py, name, tilemap, dyn_id)
29
30
  self.sprite = AnimatedSprite(
30
31
  tileset_name,
31
32
  image_name,
@@ -36,8 +37,8 @@ class Oneway(Dynamic):
36
37
  self.type = ObjectType.ONEWAY
37
38
  self.graphic_state = graphic_state
38
39
  self.facing_direction = facing_direction
39
- self.sprite.width = int(width * TILE_WIDTH)
40
- self.sprite.height = int(height * TILE_HEIGHT)
40
+ self.sprite.width = int(width * self.engine.rtc.tile_width)
41
+ self.sprite.height = int(height * self.engine.rtc.tile_height)
41
42
 
42
43
  self.hitbox_px, self.hitbox_py = 0.0, 0.0
43
44
  self.hitbox_width, self.hitbox_height = 1.0, 1.0
@@ -50,6 +51,7 @@ class Oneway(Dynamic):
50
51
  self.activation_delay: float = ONEWAY_ACTIVATION_DELAY
51
52
  self.triggered: bool = False
52
53
  self.cooldown: float = 0.0
54
+ self.target = None
53
55
 
54
56
  if jump_vx < 0:
55
57
  self.jump_vx = jump_vx - 1
@@ -88,15 +90,16 @@ class Oneway(Dynamic):
88
90
  self.timer -= elapsed_time
89
91
 
90
92
  # Activation countdown reached 0 and the jump is initiated.
91
- if self.timer <= 0.0:
93
+ if self.timer <= 0.0 and self.target is not None:
92
94
  self.engine.script.add_command(
93
- CommandOnewayMove(target, self.jump_vx, self.jump_vy)
95
+ CommandOnewayMove(self.target, self.jump_vx, self.jump_vy)
94
96
  )
95
97
  self.cooldown = 2.0
96
98
 
97
99
  # Reset the triggered flag so it has to be activated again
98
100
  # by interaction
99
101
  self.triggered = False
102
+ self.target = None
100
103
 
101
104
  def on_interaction(self, target, nature=Nature.WALK):
102
105
  if target.type == ObjectType.PLAYER and nature == Nature.WALK:
@@ -134,6 +137,7 @@ class Oneway(Dynamic):
134
137
  return False
135
138
 
136
139
  self.triggered = True
140
+ self.target = target
137
141
  if self.timer <= 0.0:
138
142
  self.timer = self.activation_delay
139
143
 
@@ -141,11 +145,11 @@ class Oneway(Dynamic):
141
145
 
142
146
  return False
143
147
 
144
- def draw_self(self, ox: float, oy: float):
145
- self.sprite.draw_self(self.px - ox, self.py - oy)
148
+ def draw_self(self, ox: float, oy: float, camera_name: str = "display"):
149
+ self.sprite.draw_self(self.px - ox, self.py - oy, camera_name)
146
150
 
147
151
  @staticmethod
148
- def load_from_tiled_object(obj, px, py, width, height):
152
+ def load_from_tiled_object(obj, px, py, width, height, tilemap):
149
153
  oneway = Oneway(
150
154
  px=px,
151
155
  py=py,
@@ -162,6 +166,7 @@ class Oneway(Dynamic):
162
166
  jump_vy=obj.get_float("jump_vy"),
163
167
  width=width,
164
168
  height=height,
169
+ tilemap=tilemap,
165
170
  dyn_id=obj.object_id,
166
171
  name=obj.name,
167
172
  )
@@ -8,8 +8,10 @@ from ..effects.walking_on_water import WalkingOnWater
8
8
 
9
9
 
10
10
  class Pickup(Dynamic):
11
- def __init__(self, px: float, py: float, item_name: str, dyn_id=-1):
12
- super().__init__("Pickup", px, py, dyn_id)
11
+ def __init__(
12
+ self, px: float, py: float, item_name: str, tilemap, dyn_id=0
13
+ ):
14
+ super().__init__(px, py, "Pickup", tilemap, dyn_id)
13
15
  self.type: ObjectType = ObjectType.PICKUP
14
16
  self.item = self.engine.get_item(item_name)
15
17
  self.collected = False
@@ -25,9 +27,10 @@ class Pickup(Dynamic):
25
27
  if self.collected:
26
28
  return False
27
29
 
28
- if target.type == ObjectType.PLAYER:
30
+ pl = target.get_player()
31
+ if pl.value > 0:
29
32
  if self.item.on_interaction(target):
30
- if self.engine.give_item(self.item):
33
+ if self.engine.give_item(self.item, pl):
31
34
  self.collected = True
32
35
  return True
33
36
  else:
@@ -35,7 +38,7 @@ class Pickup(Dynamic):
35
38
 
36
39
  return False
37
40
 
38
- def draw_self(self, ox: float, oy: float):
41
+ def draw_self(self, ox: float, oy: float, camera_name: str = "display"):
39
42
  if self.collected:
40
43
  return
41
44
 
@@ -45,6 +48,7 @@ class Pickup(Dynamic):
45
48
  (self.py - oy + 0.7) * self.item.sprite_height,
46
49
  0.2875 * self.item.sprite_width,
47
50
  BLACK,
51
+ camera_name,
48
52
  )
49
53
 
50
54
  self.engine.backend.draw_partial_sprite(
@@ -55,6 +59,7 @@ class Pickup(Dynamic):
55
59
  self.item.sprite_oy * self.item.sprite_height,
56
60
  self.item.sprite_width,
57
61
  self.item.sprite_height,
62
+ camera_name,
58
63
  )
59
64
 
60
65
  def _handle_terrain(self, elapsed_time: float):
@@ -5,7 +5,6 @@ from ...types.direction import Direction
5
5
  from ...types.graphic_state import GraphicState
6
6
  from ...types.nature import Nature
7
7
  from ...types.object import ObjectType
8
- from ...util.constants import TILE_HEIGHT, TILE_WIDTH
9
8
  from ..animated_sprite import AnimatedSprite
10
9
  from ..dynamic import Dynamic
11
10
 
@@ -21,14 +20,15 @@ class Switch(Dynamic):
21
20
  facing_direction: Direction,
22
21
  graphic_state: GraphicState,
23
22
  initial_signal=True,
24
- dyn_id=-1,
23
+ tilemap=None,
24
+ dyn_id=0,
25
25
  name="Switch",
26
26
  ):
27
27
  assert graphic_state in [GraphicState.OPEN, GraphicState.CLOSED], (
28
28
  f"graphic_state of Switch {name}{dyn_id} must be either 'open'"
29
29
  f" or 'closed', but it {graphic_state}"
30
30
  )
31
- super().__init__(name, px, py, dyn_id)
31
+ super().__init__(px, py, name, tilemap, dyn_id)
32
32
 
33
33
  self.sprite = AnimatedSprite(
34
34
  tileset_name,
@@ -62,13 +62,15 @@ class Switch(Dynamic):
62
62
  elapsed_time, self.facing_direction, self.graphic_state
63
63
  )
64
64
 
65
- def draw_self(self, ox: float, oy: float):
65
+ def draw_self(self, ox: float, oy: float, camera_name: str = "display"):
66
66
  if not self.visible:
67
67
  # print(f"{self.name} is not visible")
68
68
  return
69
- self.sprite.draw_self(self.px - ox, self.py - oy)
69
+ self.sprite.draw_self(self.px - ox, self.py - oy, camera_name)
70
70
 
71
71
  def on_interaction(self, target: Dynamic, nature: Nature):
72
+ # if target.is_player().value > 0:
73
+ # print(f"{target.is_player()} talked to me({self.name})")
72
74
  if (
73
75
  nature == Nature.TALK
74
76
  and target.type == ObjectType.PLAYER
@@ -113,26 +115,26 @@ class Switch(Dynamic):
113
115
  for listener in self.listeners:
114
116
  listener.on_interaction(self, nature)
115
117
 
116
- if (
117
- not self.send_initial_signal
118
- and abs(self.engine.player.px - self.px)
119
- < (self.engine.backend.render_width // (TILE_WIDTH * 2))
120
- and abs(self.engine.player.py - self.py)
121
- < (self.engine.backend.render_height // (TILE_HEIGHT * 2))
122
- ):
123
- print(
124
- (
125
- self.engine.player.px - self.px,
126
- self.engine.player.py - self.py,
127
- ),
128
- (
129
- self.engine.backend.render_width // (TILE_WIDTH * 2),
130
- self.engine.backend.render_height // (TILE_HEIGHT * 2),
131
- ),
132
- )
118
+ # if (
119
+ # not self.send_initial_signal
120
+ # and abs(self.engine.player.px - self.px)
121
+ # < (self.engine.backend.render_width // (TILE_WIDTH * 2))
122
+ # and abs(self.engine.player.py - self.py)
123
+ # < (self.engine.backend.render_height // (TILE_HEIGHT * 2))
124
+ # ):
125
+ # print(
126
+ # (
127
+ # self.engine.player.px - self.px,
128
+ # self.engine.player.py - self.py,
129
+ # ),
130
+ # (
131
+ # self.engine.backend.render_width // (TILE_WIDTH * 2),
132
+ # self.engine.backend.render_height // (TILE_HEIGHT * 2),
133
+ # ),
134
+ # )
133
135
 
134
136
  @staticmethod
135
- def load_from_tiled_object(obj, px, py, width, height):
137
+ def load_from_tiled_object(obj, px, py, width, height, tilemap):
136
138
  switch = Switch(
137
139
  px=px,
138
140
  py=py,
@@ -146,12 +148,13 @@ class Switch(Dynamic):
146
148
  obj.get_string("facing_direction", "south").upper()
147
149
  ],
148
150
  initial_signal=obj.get_bool("initial_signal", True),
151
+ tilemap=tilemap,
149
152
  dyn_id=obj.object_id,
150
153
  name=obj.name,
151
154
  )
152
155
 
153
- switch.sprite.width = int(width * TILE_WIDTH)
154
- switch.sprite.height = int(height * TILE_HEIGHT)
156
+ switch.sprite.width = int(width * Switch.engine.rtc.tile_width)
157
+ switch.sprite.height = int(height * Switch.engine.rtc.tile_height)
155
158
 
156
159
  ctr = 1
157
160
  while True:
@@ -1,4 +1,5 @@
1
1
  from __future__ import annotations
2
+
2
3
  import logging
3
4
  from typing import List, Optional
4
5
 
@@ -12,8 +13,7 @@ from ...types.direction import Direction
12
13
  from ...types.graphic_state import GraphicState
13
14
  from ...types.nature import Nature
14
15
  from ...types.object import ObjectType
15
- from ...util.colors import RED
16
- from ...util.constants import TILE_HEIGHT, TILE_WIDTH
16
+ from ...types.player import Player
17
17
  from ..animated_sprite import AnimatedSprite
18
18
  from ..dynamic import Dynamic
19
19
 
@@ -38,13 +38,18 @@ class Teleport(Dynamic):
38
38
  relative: bool = False,
39
39
  sliding: bool = False,
40
40
  vertical: bool = False,
41
+ tilemap=None,
41
42
  dyn_id: int = -1,
42
43
  name="Teleport",
43
44
  ):
44
- super().__init__(name, px, py, dyn_id)
45
+ super().__init__(px, py, name, tilemap, dyn_id)
45
46
 
46
47
  self.sprite = AnimatedSprite(
47
- tileset_name, image_name, sprite_name, graphic_state, facing_direction
48
+ tileset_name,
49
+ image_name,
50
+ sprite_name,
51
+ graphic_state,
52
+ facing_direction,
48
53
  )
49
54
 
50
55
  self.type = ObjectType.TELEPORT
@@ -68,7 +73,10 @@ class Teleport(Dynamic):
68
73
  self.sfx_on_trigger: str = ""
69
74
 
70
75
  def update(self, elapsed_time: float, target: Optional[Dynamic] = None):
71
- self.sprite.update(elapsed_time, self.facing_direction, self.graphic_state)
76
+ self.triggered = False
77
+ self.sprite.update(
78
+ elapsed_time, self.facing_direction, self.graphic_state
79
+ )
72
80
 
73
81
  def on_interaction(self, target: Dynamic, nature: Nature):
74
82
  if nature == Nature.SIGNAL:
@@ -81,91 +89,101 @@ class Teleport(Dynamic):
81
89
  if self.has_sprite and not self.visible:
82
90
  return False
83
91
 
92
+ pt = target.get_player()
84
93
  if (
85
94
  nature == Nature.WALK
86
- and target.type == ObjectType.PLAYER
87
- and not self.engine.teleport_triggered
95
+ and pt != Player.P0
96
+ and not self.engine.is_teleport_active(pt)
88
97
  ):
89
- self.engine.teleport_triggered = True
98
+ self.engine.trigger_teleport(True, pt)
90
99
  dst_px = self.dst_px
91
100
  dst_py = self.dst_py
92
101
  dst_vx = 0
93
102
  dst_vy = 0
94
103
 
95
104
  dst_vx, dst_vy = Direction.to_velocity(self.teleport_direction)
96
-
97
- # if self.relative:
98
- # if self.vertical:
99
- # dst_py += target.py
100
- # else:
101
- # dst_px += target.px
102
-
105
+ # self.sliding = False
103
106
  if self.sliding:
104
107
  if dst_vx != 0:
105
108
  dst_py = target.py
106
109
  elif dst_vy != 0:
107
110
  dst_px = target.px
108
111
 
109
- self.engine.script.add_command(
110
- CommandMoveMap(
111
- self.dst_map_name,
112
- target,
113
- dst_px,
114
- dst_py,
115
- dst_vx,
116
- dst_vy,
117
- )
118
- )
119
- else:
120
- if self.triggered:
121
- return False
112
+ # self.engine.script.add_command(
113
+ # CommandMoveMap(
114
+ # new_map_name=self.dst_map_name,
115
+ # obj=target,
116
+ # target_px=dst_px,
117
+ # target_py=dst_py,
118
+ # vx=dst_vx,
119
+ # vy=dst_vy,
120
+ # players=[pt],
121
+ # )
122
+ # )
123
+ # else:
124
+ if self.triggered:
125
+ return False
122
126
 
123
- new_direction = target.facing_direction
124
- if self.invert_exit_direction:
125
- new_direction = Direction((target.facing_direction.value + 2) % 4)
127
+ new_direction = target.facing_direction
128
+ if self.invert_exit_direction:
129
+ new_direction = Direction(
130
+ (target.facing_direction.value + 2) % 4
131
+ )
126
132
 
127
- self.engine.script.add_command(
128
- CommandSerial(
133
+ cmd = CommandSerial(
134
+ [
135
+ CommandScreenFade(),
136
+ CommandParallel(
129
137
  [
130
- CommandScreenFade(),
131
- CommandParallel(
132
- [
133
- CommandChangeMap(self.dst_map_name, dst_px, dst_py),
134
- CommandSetFacingDirection(target, new_direction),
135
- CommandScreenFade(fadein=True),
136
- ]
138
+ CommandChangeMap(
139
+ self.dst_map_name, dst_px, dst_py
137
140
  ),
138
- ],
139
- )
140
- )
141
- if self.sfx_on_trigger:
142
- self.engine.audio.play_sound(self.sfx_on_trigger)
141
+ CommandSetFacingDirection(target, new_direction),
142
+ CommandScreenFade(
143
+ fadein=True, map_name=self.dst_map_name
144
+ ),
145
+ ]
146
+ ),
147
+ ]
148
+ )
149
+ cmd.set_players([pt])
150
+ self.engine.script.add_command(cmd)
151
+
152
+ if self.sfx_on_trigger:
153
+ self.engine.audio.play_sound(self.sfx_on_trigger)
143
154
 
144
- self.triggered = True
155
+ self.triggered = True
145
156
  return True
146
157
 
147
158
  return False
148
159
 
149
- def draw_self(self, ox: float, oy: float):
160
+ def draw_self(self, ox: float, oy: float, camera_name: str = "display"):
150
161
  if not self.visible:
151
162
  self.engine.backend.draw_circle(
152
- (self.px + 0.5 - ox) * TILE_WIDTH,
153
- (self.py + 0.5 - oy) * TILE_HEIGHT,
154
- 0.5 * TILE_WIDTH,
155
- RED,
163
+ (self.px + 0.5 - ox) * self.engine.rtc.tile_width,
164
+ (self.py + 0.5 - oy) * self.engine.rtc.tile_height,
165
+ 0.5 * self.engine.rtc.tile_width,
166
+ self.engine.rtc.color_red,
167
+ camera_name,
156
168
  )
157
169
  return
158
170
 
159
171
  if self.has_sprite:
160
- self.sprite.draw_self(self.px - ox, self.py - oy)
172
+ self.sprite.draw_self(self.px - ox, self.py - oy, camera_name)
161
173
 
162
174
  @staticmethod
163
- def load_from_tiled_object(obj, px, py, width, height) -> List[Teleport]:
175
+ def load_from_tiled_object(
176
+ obj, px, py, width, height, tilemap
177
+ ) -> List[Teleport]:
164
178
  sprite_name = obj.get_string("sprite_name")
165
179
  tileset_name = obj.get_string("tileset_name")
166
180
  image_name = obj.get_string("tileset_name")
167
- graphic_state = GraphicState[obj.get_string("graphic_state", "closed").upper()]
168
- facing_direction = Direction[obj.get_string("facing_direction", "south").upper()]
181
+ graphic_state = GraphicState[
182
+ obj.get_string("graphic_state", "closed").upper()
183
+ ]
184
+ facing_direction = Direction[
185
+ obj.get_string("facing_direction", "south").upper()
186
+ ]
169
187
  target_map = obj.get_string("target_map", "map1_c1")
170
188
  invert_exit_direction = obj.get_bool("invert_exit_direction")
171
189
  relative = obj.get_bool("relative", False)
@@ -209,6 +227,7 @@ class Teleport(Dynamic):
209
227
  relative=relative,
210
228
  sliding=sliding,
211
229
  vertical=False,
230
+ tilemap=tilemap,
212
231
  dyn_id=obj.object_id,
213
232
  name=obj.name,
214
233
  )
@@ -247,6 +266,7 @@ class Teleport(Dynamic):
247
266
  relative=relative,
248
267
  sliding=sliding,
249
268
  vertical=True,
269
+ tilemap=tilemap,
250
270
  dyn_id=obj.object_id,
251
271
  name=obj.name,
252
272
  )
@@ -278,6 +298,7 @@ class Teleport(Dynamic):
278
298
  relative=relative,
279
299
  sliding=sliding,
280
300
  vertical=vertical,
301
+ tilemap=tilemap,
281
302
  dyn_id=obj.object_id,
282
303
  name=obj.name,
283
304
  )
mima/scene_engine.py CHANGED
@@ -5,6 +5,7 @@ from .states.game_state import GameState
5
5
  from .types.keys import Key as K
6
6
  from .types.mode import Mode
7
7
  from .types.nature import Nature
8
+ from .types.player import Player
8
9
  from .view.scene import Scene
9
10
 
10
11
 
@@ -25,12 +26,10 @@ class MimaSceneEngine(MimaEngine):
25
26
  self._scenes: Dict[str, Scene] = {}
26
27
  self._current_scene: Scene
27
28
 
28
- self.all_games: Dict[str, GameState] = {}
29
- self.current_game: str = ""
30
29
  self.save_timer_reset = 1.0
31
30
  self._save_timer = self.save_timer_reset
32
- self.teleport_triggered: bool = False
33
- self.dialog_active: bool = False
31
+ # self.teleport_triggered: bool = False
32
+ # self.dialog_active: bool = False
34
33
 
35
34
  def on_user_create(self):
36
35
  return True
@@ -58,19 +57,23 @@ class MimaSceneEngine(MimaEngine):
58
57
 
59
58
  return True
60
59
 
61
- def change_map(self, map_name: str, px: float, py: float):
62
- type_string = (
63
- self.get_map(map_name).get_string("type", "local").upper()
64
- )
65
- if type_string == "WORLD":
66
- type_string = "WORLD_MAP"
67
- if type_string == "LOCAL":
68
- type_string = "LOCAL_MAP"
69
- mode = Mode[type_string]
60
+ def load_scene(self):
61
+ self.scene_stack
62
+
63
+ # def load_scene(self, map_name: str, px: float, py: float):
64
+ # type_string = (
65
+ # self.get_map(map_name).get_string("type", "local").upper()
66
+ # )
67
+ # if type_string == "WORLD":
68
+ # type_string = "WORLD_MAP"
69
+ # if type_string == "LOCAL":
70
+ # type_string = "LOCAL_MAP"
71
+ # mode = Mode[type_string]
70
72
 
71
- self.scene_stack.append(mode)
72
- self._scenes[self.scene_stack[-1]].change_map(map_name, px, py)
73
- # print(self.scene_stack)
73
+ # self.scene_stack.append(mode)
74
+ # self._scenes[self.scene_stack[-1]].load_scene()
75
+ # # self._scenes[self.scene_stack[-1]].change_map(map_name, px, py)
76
+ # # print(self.scene_stack)
74
77
 
75
78
  @property
76
79
  def scene(self) -> Scene:
@@ -80,7 +83,3 @@ class MimaSceneEngine(MimaEngine):
80
83
  @property
81
84
  def previous_scene(self) -> Scene:
82
85
  return self._scenes[self.scene_stack[-2]]
83
-
84
- @property
85
- def game_state(self) -> GameState:
86
- return self.all_games[self.current_game]
mima/scripts/command.py CHANGED
@@ -1,6 +1,8 @@
1
1
  from __future__ import annotations
2
2
 
3
- from typing import TYPE_CHECKING
3
+ from typing import TYPE_CHECKING, List, Optional
4
+
5
+ from ..types.player import Player
4
6
 
5
7
  if TYPE_CHECKING:
6
8
  from ..engine import MimaEngine
@@ -9,10 +11,13 @@ if TYPE_CHECKING:
9
11
  class Command:
10
12
  engine: MimaEngine
11
13
 
12
- def __init__(self):
14
+ def __init__(self, players: Optional[List[Player]] = None):
13
15
  self.started: bool = False
14
16
  self.completed: bool = False
15
17
  self.uninterruptible: bool = False
18
+ self.players: List[Player] = (
19
+ players if (players is not None and players) else [Player.P0]
20
+ )
16
21
 
17
22
  def start(self):
18
23
  pass
@@ -20,5 +25,14 @@ class Command:
20
25
  def update(self, elapsed_time: float):
21
26
  pass
22
27
 
28
+ def can_complete(self, force: bool = False) -> bool:
29
+ if self.uninterruptible and not force:
30
+ return False
31
+
32
+ return True
33
+
23
34
  def finalize(self):
24
35
  pass
36
+
37
+ def set_players(self, players: List[Player]):
38
+ self.players = players
@@ -1,15 +1,34 @@
1
+ from typing import List, Optional
2
+
3
+ from ...types.player import Player
1
4
  from ..command import Command
2
5
 
3
6
 
4
7
  class CommandChangeMap(Command):
5
- def __init__(self, map_name: str, spawn_px: float, spawn_py):
6
- super().__init__()
8
+ def __init__(
9
+ self,
10
+ map_name: str,
11
+ spawn_px: float,
12
+ spawn_py,
13
+ players: Optional[List[Player]] = None,
14
+ ):
15
+ if players is None:
16
+ players = [Player.P1]
17
+
18
+ super().__init__(players)
7
19
 
8
20
  self._map_name: str = map_name
9
21
  self._spawn_px: float = spawn_px
10
22
  self._spawn_py: float = spawn_py
11
23
 
12
24
  def start(self):
13
- self.engine.scene_stack.pop()
14
- self.engine.change_map(self._map_name, self._spawn_px, self._spawn_py)
25
+ self.engine.get_view().unload_map(self.players[0])
26
+ self.engine.get_view().load_map(
27
+ self._map_name, self._spawn_px, self._spawn_py, self.players[0]
28
+ )
29
+ # self.engine.change_map(self._map_name, self._spawn_px, self._spawn_py)
15
30
  self.completed = True
31
+
32
+ def finalize(self):
33
+ self.engine.trigger_teleport(False, self.players[0])
34
+ self.engine.trigger_player_collision(False, self.players[0])
@@ -0,0 +1,23 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import TYPE_CHECKING, Optional
4
+
5
+ from ..command import Command
6
+
7
+ if TYPE_CHECKING:
8
+ from ...objects.creature import Creature
9
+ from ...types.weapon_slot import WeaponSlot
10
+ from ...usables.weapon import Weapon
11
+
12
+
13
+ class CommandEquipWeapon(Command):
14
+ def __init__(self, weapon: Weapon, creature: Creature, slot: WeaponSlot):
15
+ super().__init__()
16
+
17
+ self._weapon: Weapon = weapon
18
+ self._target: Creature = creature
19
+ self._slot: WeaponSlot = slot
20
+
21
+ def start(self):
22
+ self._target.equip_weapon(self._slot, self._weapon)
23
+ self.completed = True
@@ -14,11 +14,13 @@ class CommandGiveItem(Command):
14
14
 
15
15
  self._item_name: str = item_name
16
16
 
17
- if dynamic is None:
18
- dynamic = self.engine.player
17
+ # if dynamic is None:
18
+ # dynamic = self.engine.player
19
19
 
20
20
  self._dynamic: Dynamic = dynamic
21
21
 
22
22
  def start(self):
23
- self.engine.give_item(self._item_name)
23
+ # if self._dynamic is None:
24
+ # self._dynamic = self.engine.get_player(self.players[0])
25
+ self.engine.give_item(self._item_name, self.players[0])
24
26
  self.completed = True