Fortress Level Blog
A blog about the Fortress level of the Castle game.
flowchart TD
A[Game Engine loads GameLevelFortress] --> B[Constructor runs]
B --> C[Initialize gameEnv reference]
C --> D[Setup scytheSpawnTimer & scytheSpawnInterval]
D --> E[Load level music]
E --> F[Define background, player, NPC, barrier data]
F --> G[Create game object classes]
G --> H[GameEnvBackground]
G --> I[Player]
G --> J[Npc]
G --> K[Barrier]
H --> L[Objects instantiated in game environment]
I --> L
J --> L
K --> L
L --> M[Game Loop begins]
M --> N[GameLevelFortress.update called every frame]
N --> O[Increment scytheSpawnTimer]
O --> P{Timer >= scytheSpawnInterval?}
P -- No --> M
P -- Yes --> Q[Generate 1–10 scythes randomly]
Q --> R[spawnScythe]
R --> S[Create new Scythe]
S --> T[Add scythe to gameEnv.gameObjects]
T --> U[Append scythe.canvas to DOM container]
U --> V[Scythe.update runs every frame]
V --> W[Check NPC collision]
W --> X{Hit NPC?}
X -- Yes --> Y[Set _hittingNPC = true & Scythe stops moving]
X -- No --> Z[Move along elliptical arc path]
Z --> AA{Path completed?}
AA -- Yes --> AB[Destroy scythe & Remove from gameObjects & Remove canvas]
AA -- No --> AC[Rotate scythe sprite]
AC --> AD[Check player collision]
AD --> AE{Player hit?}
AE -- Yes --> AF[Destroy scythe & Call showEndScreen]
AE -- No --> V
Key Features
- OOP (Nested Inheritance)
- The Scythe class inherits from the Enemy class, which inherits from the charecter class, and so on…
- Custom Collision Detection
- The scythe detects collisions with the NPC and the player
- Iterables & Data Structures
- Arrays of sprites (the scythes)
- Objects (sprite data)
- Game Loop (See mermaid diagram)
- Handles movement, drawing, and collision detection every frame
- Event Handling
- Player can move, interact, etc.
- Keyboard input for player movement and interaction
- Conditionals, Loops, other simple programming concepts
- Level integration, custom game classes, etc.
File Structure
All code is in /assets/js/castleGame.
/assets/js/castleGame/GameLevelFortress> main file/assets/js/castleGame/castleFortress.md> Markdown file to view the game/assets/js/castleGame/custom/EndScreen.js> Displays an end screen upon winning/assets/js/castleGame/custom/Scythe.js> A special kind ofEnemythat can attack
Challenge
Fortress Game
Lines: 1
Characters: 0
Game Status: Not Started