Skip to content

Commit

Permalink
Added stuff for player state and updated instructions in fighter README.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chukobyte committed May 19, 2021
1 parent 16865b1 commit fc1fc19
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 9 deletions.
Empty file added assets/__init__.py
Empty file.
Empty file.
14 changes: 14 additions & 0 deletions assets/game_projects/fighter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Empty file.
12 changes: 6 additions & 6 deletions assets/game_projects/fighter/scenes/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down Expand Up @@ -151,7 +151,7 @@
]
},
{
"name": "Walk",
"name": "walk",
"speed": 100,
"frames": [
{
Expand Down Expand Up @@ -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": [
{
Expand Down Expand Up @@ -428,7 +428,7 @@
]
},
{
"name": "Walk",
"name": "walk",
"speed": 100,
"frames": [
{
Expand Down
Empty file.
6 changes: 3 additions & 3 deletions assets/game_projects/fighter/src/fight_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions assets/game_projects/fighter/src/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Empty file.
14 changes: 14 additions & 0 deletions assets/game_projects/fighter/src/state/figher_game_state.py
Original file line number Diff line number Diff line change
@@ -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
46 changes: 46 additions & 0 deletions assets/game_projects/fighter/src/state/fighter_frame_state.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit fc1fc19

Please sign in to comment.