From c66412945922d07cb2d44e2b98f494a6bf3f6877 Mon Sep 17 00:00:00 2001 From: Brychan Dempsey Date: Thu, 6 May 2021 14:22:22 +1200 Subject: [PATCH] Update 'README.md' --- README.md | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cdd6bd6..4ada081 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,58 @@ # JavaECS-Docs -Documentation for the Java Entity-Component-System \ No newline at end of file +## *Documentation for the Java Entity-Component-System* + +Traditional game-engine designs typically follow the standard functional or object-oriented design paradigms. + +Functional-paradigm games focus on a 'this-then-that' model, e.g. + +***Simple Driving Game*** + +``` py +turn = GetTurn() +TurnCar(turn) +if IsCollided(): # and other checks + GameOver() +else: + DrawNextFrame() + turn = GetTurn() +``` + +Such a system works well for some game-designs; it is simplistic and follows a deterministic sequence of steps. But it lacks scalability and extensibility. +An Object-Oriented approach could be used instead: +``` py +# Create a base-class that is a vehicle, with basic properties: +class Vehicle: + position = [x,y] + IsCrashed = False + def CalcTurn(): + pass + def IsCollided(): + pass + +# Create the PlayerVehicle class which extends Vehicle to include the player input method +class PlayerVehicle(Vehicle): + def GetPlayerInput(): + pass + +def GameLoop(): + vehicles[] = GetAllVehichles() + allCollided = False + while not allCollided: + for v in vehicles: + turnAmount + if v is PlayerVehicle: + turnAmount = v.GetPlayerInput() + else: + turnAmount = v.CalcTurn() + v.TurnVehicle() + if v.IsCollided(): + v.IsCrashed = True + anyNotCollided = False + for v in vehicles: + if v.IsCrashed = False: + anyNotCollided = True + break + + +```