From fc1fc19f9f8fdff52055064980349024aa1c2324 Mon Sep 17 00:00:00 2001 From: chukobyte Date: Wed, 19 May 2021 11:30:47 -0400 Subject: [PATCH] Added stuff for player state and updated instructions in fighter README. --- assets/__init__.py | 0 assets/game_projects/__init__.py | 0 assets/game_projects/fighter/README.md | 14 ++++++ assets/game_projects/fighter/__init__.py | 0 assets/game_projects/fighter/scenes/main.json | 12 ++--- assets/game_projects/fighter/src/__init__.py | 0 .../fighter/src/fight_simulator.py | 6 +-- assets/game_projects/fighter/src/init.py | 2 + .../fighter/src/state/__init__.py | 0 .../fighter/src/state/figher_game_state.py | 14 ++++++ .../fighter/src/state/fighter_frame_state.py | 46 +++++++++++++++++++ 11 files changed, 85 insertions(+), 9 deletions(-) create mode 100644 assets/__init__.py create mode 100644 assets/game_projects/__init__.py create mode 100644 assets/game_projects/fighter/__init__.py create mode 100644 assets/game_projects/fighter/src/__init__.py create mode 100644 assets/game_projects/fighter/src/state/__init__.py create mode 100644 assets/game_projects/fighter/src/state/figher_game_state.py create mode 100644 assets/game_projects/fighter/src/state/fighter_frame_state.py diff --git a/assets/__init__.py b/assets/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/assets/game_projects/__init__.py b/assets/game_projects/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/assets/game_projects/fighter/README.md b/assets/game_projects/fighter/README.md index 6f26e984..e1601749 100644 --- a/assets/game_projects/fighter/README.md +++ b/assets/game_projects/fighter/README.md @@ -8,8 +8,22 @@ A small project to prototype a fighting game and online play. * Move Left: Left Key * Move Right: Right Key +* Attack: Space #### Player Two * Move Left: A * Move Right: D + +#### General + +* Shake camera: G +* Camera zoom in: O +* Camera zoom out: P +* Camera move left: J +* Camera move right: L +* Camera move up: I +* Camera move down: K + +* Go back to title screen: ESC +* Exit game from title screen: ESC diff --git a/assets/game_projects/fighter/__init__.py b/assets/game_projects/fighter/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/assets/game_projects/fighter/scenes/main.json b/assets/game_projects/fighter/scenes/main.json index a2568cb8..0751a0d3 100644 --- a/assets/game_projects/fighter/scenes/main.json +++ b/assets/game_projects/fighter/scenes/main.json @@ -89,13 +89,13 @@ }, { "animated_sprite": { - "current_animation": "Idle", + "current_animation": "idle", "is_playing": true, "flip_x": false, "flip_y": false, "animations": [ { - "name": "Idle", + "name": "idle", "speed": 100, "frames": [ { @@ -151,7 +151,7 @@ ] }, { - "name": "Walk", + "name": "walk", "speed": 100, "frames": [ { @@ -366,13 +366,13 @@ }, { "animated_sprite": { - "current_animation": "Idle", + "current_animation": "idle", "is_playing": true, "flip_x": true, "flip_y": false, "animations": [ { - "name": "Idle", + "name": "idle", "speed": 100, "frames": [ { @@ -428,7 +428,7 @@ ] }, { - "name": "Walk", + "name": "walk", "speed": 100, "frames": [ { diff --git a/assets/game_projects/fighter/src/__init__.py b/assets/game_projects/fighter/src/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/assets/game_projects/fighter/src/fight_simulator.py b/assets/game_projects/fighter/src/fight_simulator.py index 963d3b9c..0a7b2e86 100644 --- a/assets/game_projects/fighter/src/fight_simulator.py +++ b/assets/game_projects/fighter/src/fight_simulator.py @@ -86,7 +86,7 @@ def _simulate_player_state( self, frame: int, player_state_data: PlayerStateData ) -> None: if player_state_data.player_input_buffer.is_empty(): - player_state_data.player_node.play(animation_name="Idle") + player_state_data.player_node.play(animation_name="idle") else: for input in player_state_data.player_input_buffer.get_frame_inputs( frame=frame @@ -96,11 +96,11 @@ def _simulate_player_state( ): if input == InputBuffer.Value.LEFT.value: player_state_data.player_node.add_to_position(Vector2.LEFT()) - player_state_data.player_node.play(animation_name="Walk") + player_state_data.player_node.play(animation_name="walk") # player_one_state_data.player_node.flip_h = True elif input == InputBuffer.Value.RIGHT.value: player_state_data.player_node.add_to_position(Vector2.RIGHT()) - player_state_data.player_node.play(animation_name="Walk") + player_state_data.player_node.play(animation_name="walk") # player_one_state_data.player_node.flip_h = False elif input == InputBuffer.Value.WEAK_PUNCH.value: # TODO: Implement weak punch diff --git a/assets/game_projects/fighter/src/init.py b/assets/game_projects/fighter/src/init.py index e5f2605c..5404adab 100644 --- a/assets/game_projects/fighter/src/init.py +++ b/assets/game_projects/fighter/src/init.py @@ -7,3 +7,5 @@ def _start(self) -> None: SceneTree.change_scene( scene_path="assets/game_projects/fighter/scenes/title_screen.json" ) + # player_state = PlayerState() + # print(player_state) diff --git a/assets/game_projects/fighter/src/state/__init__.py b/assets/game_projects/fighter/src/state/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/assets/game_projects/fighter/src/state/figher_game_state.py b/assets/game_projects/fighter/src/state/figher_game_state.py new file mode 100644 index 00000000..59380227 --- /dev/null +++ b/assets/game_projects/fighter/src/state/figher_game_state.py @@ -0,0 +1,14 @@ +from roll.node import Node + +from assets.game_projects.fighter.src.input_buffer import InputBuffer + +class FighterUIState: + def __init__(self): + self.text_label = None + + +class FighterGameState: + def __init__(self, node: Node, input_buffer: InputBuffer, fighter_ui_state: FighterUIState): + self.node = node + self.input_buffer = input_buffer + self.fighter_ui_state = fighter_ui_state diff --git a/assets/game_projects/fighter/src/state/fighter_frame_state.py b/assets/game_projects/fighter/src/state/fighter_frame_state.py new file mode 100644 index 00000000..a040ee18 --- /dev/null +++ b/assets/game_projects/fighter/src/state/fighter_frame_state.py @@ -0,0 +1,46 @@ +import json + +from roll.math import Vector2 + +# Roughing out player state data + +# These will be stored by frame +class AnimationState: + def __init__(self): + self.animation_name = "idle" + self.frame = 0 + + @property + def data(self) -> dict: + return {"animation_name": self.animation_name, "frame": self.frame} + + def __str__(self): + return json.dumps(self.data) + + def __repr__(self): + return json.dumps(self.data) + + +class FighterFrameState: + def __init__(self): + self.player = 1 + self.position = Vector2(0.0, 0.0) + self.inputs = ["l", "wp"] + self.animation = AnimationState() + self.state = "idle" + + @property + def data(self) -> dict: + return { + "player": self.player, + "position": {"x": self.position.x, "y": self.position.y}, + "inputs": self.inputs, + "animation": self.animation.data, + "state": self.state, + } + + def __str__(self): + return json.dumps(self.data, indent=4) + + def __repr__(self): + return json.dumps(self.data, indent=4)