Commit Graph

50 Commits

Author SHA1 Message Date
3cf1d19c4d Use ComponentMappers everywhere else 2020-02-01 21:51:54 +04:00
84a353cfd2 Rename tag compontents to make it obvious they're for tagging 2020-02-01 21:15:57 +04:00
f4508fa0da Utilize a PLAYER tag and ASTEROIDS group
User PLAYER tag for access to the player entity
Use ASTEROIDS group to count how many asteroids there are
2020-02-01 20:40:39 +04:00
d8cabf4549 Support Entity tagging 2020-02-01 20:34:37 +04:00
f8f7868398 Add entity grouping. 2020-02-01 20:21:34 +04:00
749e378a03 Add constructors to Components, useful for more terse entity creation 2020-02-01 17:04:06 +04:00
69d5caf24d Move all ComponentMappers to Components as public static constants 2020-02-01 16:05:12 +04:00
6ae11ef2d3 ECS refactoring (breaks game code)
- Remove requirement of an Engine instance in ComponentMapper instances,
as the Engine from the entity passed to get() can be used. Allows for
static initialization of ComponentMappers.

- Store instances of ComponentMapper in a static Map within the
ComponentMapper class itself, rather that inside of Engine.

- Name bit/bits consistently. Some cases of bits were renamed to bit,
such as ComponentType getBits() is now getBit(). Change usage of Mask to
just Bits for consistency.

- Modify access modifiers and field finality where appropriate

- Add comments to public methods in Engine
2020-02-01 15:55:54 +04:00
cc53757a37 Don't activate/deactivate/remove entities when not needed 2020-01-31 21:31:33 +04:00
b389cb9c2b Add afterburner. 2020-01-31 21:30:33 +04:00
06d6a9630c Add new font 2020-01-31 20:27:53 +04:00
26049488ae Scale world units from banana units (800x600) to something smaller.
Let's just call them meters.

Get rid of Viewport and handle world scaling based on screen height:
- Keep world height at a constant 10 meters and scale width according
to screen dimensions.

Add uiSpriteBatch used for rendering UI elements at appropriate scale
2020-01-31 20:25:49 +04:00
5f846f00b0 Have entity.remove() set active = false
Removes the need to check if an entity hasn't been removed prior to
processing.
2020-01-31 13:00:24 +04:00
fa809148a7 Add GameDataComponent which holds current game's data (score, lives, etc)
Now more like an actual game. Score, lives, and when you die, you get
respawned. If you die rnough times, you Game Over, and your lives and
score are reset. Each time you get 10000 points, you gain a life!

Add GameMode enum
Add GameDataSystem which manipulates the current game data based on events.
Add GameDataRenderSystem which renders the current game data.

Add AsteroidHitEvent and PlayerDeathEvent which are are fired when an
asteroid is destroyed or the player is killed, respectively.

Add SpriteBatch to Graphics
2020-01-30 23:59:58 +04:00
c3b806f79f Various changes and fixes.
Set dirty = true in setVertices()

Correct Viewport worldWidth/worldHeight assignment

Optimize imports + various formatting

Remove html project
2020-01-30 16:37:27 +04:00
de942c44aa Add DecayComponent and DecaySystem
Add DecayComponent to debris entities so they disappear after while.

decayTimer set to a random value between 0.5 and 2.5 seconds.
2020-01-30 15:34:49 +04:00
c969b87eca Add ColliderComponent and add it to entities that can be collided with.
Only entities with ColliderComponent will be checked for collisions.

Also, don't check collisions with inactive/removed entities.
2020-01-30 14:03:47 +04:00
3b1c075102 Implement asteroids breaking apart
Rename createPlayerDebris -> createDebris to make it clear it's not only
for the player entity.

Add Constants.ASTEROID_SPAWN_COUNT

Slow down asteroids, tweak sizing
2020-01-30 13:37:52 +04:00
d140959fdc Tweaks to player debris creation
Reduced explosion direction variation and max angular velocity so it's
more apparent that the lines were from the original ship.

Removed subtraction then adding back of player position from getLineModels

Formatting + comments.
2020-01-29 13:10:35 +04:00
0d323a69bc Add player debris 2020-01-29 04:02:14 +04:00
f083a40682 Add random slow rotation to asteroids. 2020-01-29 04:01:03 +04:00
3ffb274e8d Add angularVelocity to VelocityComponent
Use it to control player rotation.
2020-01-28 23:03:45 +04:00
3918f8c1f5 Add Model interface to be used for ModelComponent instead of Polygon
Allows shapes other than Polygons to be used a Model
Add PolygonModel and LineModel implementations
2020-01-28 17:58:12 +04:00
b9e63dea26 Fixed angle wrapping math.
When rotation was < 0, we were subtracting it from 360, which was
producing a number larger than 360. We should have been adding it to 360,
not subtracting.

Moved angle wrapping math to a separate function.
2020-01-28 15:17:38 +04:00
01c6a777cb Process entities only if they are active and not removed 2020-01-27 18:35:55 +04:00
042282646b Spawn + shoot asteroids
* Add AsteroidSpawningSystem which adds asteroids to the game at a regular
  interval up to a set limit.
* Add EventFactory for generating entity-specific Collision events
* Detect asteroids being shot with BulletAsteroidCollisionEvent
* Add DEBUG output to creating entities
* New getPointAlongPolygon utils function
2020-01-27 14:39:39 +04:00
e6356e4210 Update AsteroidFactor to use rand from Constants
Made its members private, small changes to generation method.
2020-01-27 14:39:36 +04:00
97e79b93ea Add isRemoved() and toString() to Entity 2020-01-27 13:19:36 +04:00
f366c4b808 Simply entity refreshing.
Consolidate toRemove, toEnable toDisable into toRefresh, move logic of
whether an entity should be added or removed to an EntitySystem into
EntitySystem.

Entities now have a systemBits member which represents which
systems they're currently a part of and is used by the refresh() logic
in EntitySystem.

Adding or removing components from an entity after it has been created
and activated will now add or remote the entity from relevant systems.
2020-01-27 11:55:55 +04:00
83223e5dc2 Move Entity management to new EntityManager class to clean up Engine 2020-01-27 01:35:51 +04:00
82828ff05d Add has() method to ComponentMapper
Some other minor changes:
* Made ComponentType final + package-private
* Made Entity and ComponentType id protected to allow direct access from
  Engine
* Made ComponentType bits protected to allow direct access from Entity
* Made Entity componentBIts protected to allow direct access from
  ComponentMapper and EntitySystem
2020-01-26 16:00:06 +04:00
bd37d4fc65 Reuse removed entities - prevents massive entity component arrays.
Assign each entity a uniqueId as well as their regular ID. The uniqueID
of an entity is always difference from past or present active entities.
2020-01-26 12:48:27 +04:00
5d9d49971f Add BaseSystem which all systems (entity processing or not) extend from 2020-01-26 04:11:48 +04:00
28dbff3d16 Delete bullets when they leave the screen 2020-01-25 17:55:23 +04:00
b9148c028d Add CollisionSystem 2020-01-25 17:26:44 +04:00
74ba61ee53 Add EntityFactory, player can now shoot bullets
Add DEBUG Constant + rendering of FPS when true
2020-01-25 17:26:04 +04:00
087b53564f maxVelocity = Float.MAX_VALUE by default 2020-01-25 17:21:14 +04:00
5eed818cc3 It makes more sense for Component to be an interface 2020-01-25 15:51:06 +04:00
f44f34b3de Add ComponentMapper for faster retrieval of entity components 2020-01-25 15:34:58 +04:00
d97c956607 Cleanup of ListenerRegistry 2020-01-25 14:03:50 +04:00
90e5ff36e7 Move entity processing loop to systems
Store cache of interested entities in each system.

Perform entity activation, deactivation and removal outside of the update
loop.

Instead of throwing an exception when trying to get a Component from
ComponentBag that is out of range, just return null. This is to allow
systems to try getting a Component it isn't registered for.

Fixed ComponentType.isTypeInMask
2020-01-25 13:56:35 +04:00
d8b82c4fee Fix screen wrapping math
Rather than place entities directly on the screen edge boundary, add the
distance they were beyond the screen edge.

Store aabb in ModelComponent for use by multiple systems.
2020-01-25 13:18:38 +04:00
22fc504619 Add Event/Listener framework to common/ecs 2020-01-25 00:18:16 +04:00
83113f3afd Rotate at a frame time dependent rate (300 degrees / second) 2020-01-25 00:18:16 +04:00
3d9b62d455 Add screen wrapping system
Move model position/rotation updating to movement system
2020-01-25 00:17:14 +04:00
d7c55d72e3 Set up ECS on GameScreen: register components and systems, add player 2020-01-24 17:24:08 +04:00
6fb664adaf Add player/model components + input/render systems 2020-01-24 16:05:13 +04:00
e38b538a1e Add movement/acceleration/velocity components + movement system 2020-01-24 16:05:13 +04:00
89a7bc031c Add beginnings of game code. 2020-01-24 16:05:08 +04:00
909b50b47d Add base project files. 2020-01-24 12:03:04 +04:00