comedot Documentation

repository·develop·Indexed 19 days ago

https://github.com/invadingoctopus/comedot

An all-in-one 2D game framework for Godot 4.8+ featuring a component-based architecture. It provides a library of components, UI elements, and templates for genres such as platformers, RPGs, and shooters, utilizing an opinionated ECS-inspired approach to facilitate rapid development.

Tokens
10.6K
Snippets
3
Records
57
Agent score
67%

What's inside comedot

  1. Implement player and AI input control

    develop

    The InputComponent serves as a shared control-input state for players, AI, or demo sources. Other components read or modify movement, actions, and input signals from this component instead of handling raw InputEvents directly.

    Common Control Patterns:

    • Asteroids-style: Use AsteroidsControlComponent for unified spaceship/tank control (turning, thrusting, braking) instead of combining separate turning and thrust components.
    • Platformer Movement: Use JumpComponent (handles vertical velocity via CharacterBody2D.up_direction) in conjunction with PlatformerPhysicsComponent (for gravity and air friction).
    • Climbing: Use ClimbComponent to enable platformer climbing inside Area2D nodes like ladders or ropes.
    • Mouse/Joystick Aiming: Use AimingCursorComponent for reticle control (right-stick or mouse) or MouseRotationComponent to rotate an entity toward the pointer.
  2. Manage entity stats and modifiers

    develop

    Use these components to handle data and resource management:

    • StatsComponent: Stores and indexes an entity's Stat resources (health, ammo, XP) by name and UID.
    • StatModifierComponent: Modifies Stat resources over time using a child Timer (e.g., regeneration or mana drain).
    • StatModifierOnDeathComponent: Modifies Stat resources when the entity's HealthComponent reaches death (e.g., awarding XP or score).
  3. Use the core Entity script

    develop

    The Entity script is the foundation of the system. It is used with a default Node2D scene and provides the following capabilities:

    • Manages component installation and lookup.
    • Handles lifecycle notifications.
    • Provides cached shortcuts to the primary area, body, sprite, and camera nodes.
    • Provides deletion helpers.
  4. Understand the Comedot ECS approach

    develop

    Comedot uses an opinionated Entity-Component-System (ECS) inspired framework for 2D games. Unlike traditional ECS, it avoids complex 'systems' logic in favor of a Node-based workflow:

    • Entities: Regular Godot Nodes used to represent gameplay objects.
    • Components: Regular Godot Nodes attached to Entities that handle specific gameplay mechanics (movement, combat, inventory, etc.).

    You build gameplay by attaching components to entities and tweaking their exported properties in the Inspector. This allows you to mix Comedot components with your own custom scripts or other Godot addons seamlessly.

  5. Implement turn-based gameplay components

    develop

    For turn-based systems, use the following components:

    • Core Logic: TurnBasedComponent is the abstract base for components processed during begin, execute, and end turn phases by a TurnBasedEntity.
    • Movement:
      • TurnBasedTileBasedControlComponent: Moves a turn-based Entity through TileBasedPositionComponent when it is its turn.
      • TurnBasedTileBasedGravityComponent (Experimental): Provides pseudo-gravity for TileBasedPositionComponent entities using a Timer.
      • TurnBasedTileBasedPlatformerControlComponent (Experimental): A turn-based, tile-based platformer control layer.
    • Visuals/UI:
      • TurnBasedAnimationComponent: Plays animations in response to turn-based signals.
      • TurnBasedCounterComponent: A debug component that displays the current turn number and phase.
      • TurnBasedStateUIComponent (Experimental): A master UI component for showing TurnBasedEntity and TurnBasedCoordinator state.
  6. Configure projectile and hitscan weapons

    develop

    Comedot provides several ways to handle weaponry:

    • GunComponent: A cooldown-based projectile weapon. It includes an editable gun sprite, pivot, and bullet emission point. It processes unhandled input so UI can intercept firing.
    • BulletlessGunComponent: A cooldown-based weapon that applies instant damage at a target position instead of spawning projectiles. Best used with DamageComponent and aiming components for towers or hitscan attacks.
    • BulletModifierComponent: Modifies projectile Entities emitted by a GunComponent (e.g., changing damage or adding visual effects). Requirement: This must run after the GunComponent.
  7. Understand the relationship between Entities and Components

    develop

    In Comedot, Entities serve primarily as "scaffolding" or base containers. They manage lifecycle notifications, component installation, and provide shortcuts to common nodes (like primary areas, bodies, or sprites).

    To implement specialized gameplay behavior, you should use Components. Entities provide the structure, while Components provide the logic. For more details on logic implementation, refer to the Components Catalog.md.

  8. Configure gameplay via Gameplay Resources

    develop

    Comedot uses specialized Resource classes to define gameplay data and mechanics:

    • Ability: Represents a selectable action or skill, optionally with StatCost and target requirements.
    • Stat: Represents integer values like health, ammo, or XP.
    • StatCost: Represents the cost (in Stats) for interactions or abilities.
    • InventoryItem: Represents an item held in an InventoryComponent.
    • Upgrade: Represents permanent or repeatable upgrades and their costs.
    • TextSequence: A collection of text entries for dialogue or tutorials.
    • StateMachine: Implements a simple StringName state list with allowed transitions.
  9. Manage visual feedback and animations

    develop

    Use these components to drive Entity visuals:

    • Directional Animations:
      • OverheadAnimationComponent: Drives directional AnimatedSprite2D (e.g., idleN, walkSE) from overhead movement input.
      • PlatformerAnimationComponent: Drives AnimatedSprite2D based on CharacterBodyComponent and InputComponent state.
      • NodeFacingComponent: Rotates an Entity or Node2D to face a target (useful for aiming).
    • Status and Feedback:
      • HealthVisualComponent (Experimental): Provides visual feedback for HealthComponent changes (healing/damage).
      • DamageVisualComponent (Experimental): Provides visual feedback for actual damage received.
      • StatsVisualComponent: Emits TextBubbles and UI feedback when selected Stats change.
      • BlinkPauseComponent: Temporarily pauses and blinks an Entity (useful for spawn delays or death effects).
      • HideWhenStationaryComponent: Hides an Entity when movement input is idle and shows it when movement resumes.
  10. Implement combat damage with DamageComponent and DamageReceivingComponent

    develop

    To implement a standard combat system, use a pair of components:

    1. DamageComponent: An Area2D hitbox that applies damage. It supports optional faction filtering and hit chance.
    2. DamageReceivingComponent: An Area2D hurtbox that accepts hits from a DamageComponent and forwards the damage to a HealthComponent. It also supports faction filtering.

    Variants:

    • DamageRayComponent: A DamageComponent variant using RayCast2D to report only the first physics contact in a frame.
    • DamageRepeatingComponent: A timer-based DamageComponent variant for hazards or turrets that repeatedly damage opposing receivers in contact.
    • DamageOverTimeComponent: Adds timed, repeated damage to a DamageReceivingComponent without requiring continuous collision contact (e.g., poison or burn).
  11. Use Area2D for collision detection

    develop

    Comedot offers different ways to handle Area2D signals depending on your requirements:

    • One-off Detection: Use AreaCollisionComponent to detect Areas, PhysicsBody2Ds, or TileMapLayers without maintaining a persistent contact list.
    • Persistent Contact Tracking: Use AreaContactComponent when you need to track all Areas, PhysicsBody2Ds, or TileMapLayers currently touching the component's Area2D (a live contact list).
    • TileMap Specifics: Use TileCollisionComponent to report collisions specifically with TileMapLayers and the involved cell coordinates.
    • Automated Reactions: Use ModifyOnCollisionComponent to add/remove nodes/components or remove the entity entirely when specific Area2D collision criteria are met (e.g., projectile impacts).
  12. Implement ability and targeting systems

    develop

    To create an ability-based system, compose the following components:

    • AbilityComponent: Stores the gameplay abilities (skills, spells) an entity can perform. Use with StatsComponent for cost management.
    • AbilityControlComponent: Converts input actions into AbilityComponent.performAbility() calls. It automatically creates an AbilityTargetingComponentBase subclass if the ability requires a target.
    • AbilityTargetableComponent: Marks an entity as a valid target. Requires a Node2D-style component node to receive mouse events.
    • AbilityTargetingComponentBase: An abstract base for components that prompt an entity to choose a target.
    • AbilityReactionComponent: An AbilityTargetableComponent subclass that runs Payload reactions after the entity is chosen as a target (e.g., for 'talk' or 'activate' commands).