Product: Tetris2P AI
Sprint Summary

Daily Objectives

Notes

What’s my deliverable? A useable game engine, with a library of template objects for example.

What’s the default behavior for the ColliderPhysics update loop?

How does user input interact with the Collider Physics?
Example Case: user holds down right button to move a player object forward (to the right)

Physics engine will only apply to super flat 2d? Like a sidescroller. Won’t be relevant to any other game? Maybe we should let the player determine what happens at each update. To clarify, the physics engine will only apply to a flat 2d space, but it can still be drawn to a different look. In how many types of games would creating this physics space do anything? Mostly just side scroller and platforms. (side 2d perspective action games). BUT, we still want to do some allocations for these games. We can add a rigidbody check to the end? Maybe it’ll help if we write some sample code.

class Player extends gameObject {
	constructor(world) {
		this.body = this.createAABB(x, y, width, height)
		this.body.setAnchor(world)
	}

	update(delta) {
if ("left" in keystate) {
	this.body.moveLeft(5);
}
if ("right" in keystate) {
	this.body.moveRight(5);
}		
		If ("space" in keystate) {
			this.jump();
		}
}
}

So some issues I’m having is when should I check collisions? Physics should be checked preemptively before setting new positions. Triggers should be checked onCall. If I wanted to check if I’ve been hit by an enemy:

We can have a checkCollisions(aabb) function call at the top of the update. The function will check for collisions between that aabb and objects on respective layers. When a collision is detected with another aabb, the caller aabb, can add itself to a collision list to the other aabb’s list. checkCollisions will add newfound collisions to collisions already detected, and return that list.

when/where do we check gravity and collisions? How are most character controllers scripted? They have colliders for ‘isGrounded’ and ‘isTouchingCeiling’ which are checked at the BEGINNING. If you want a colliderTrigger to trigger, we let the objects move towards each so you can actually trigger them. We don’t want colliderPhysics to trigger, so we want to PREVENT them from triggering. This can be done either by casting and checking before moving in that direction OR detecting the collision and resolving it after moving. WHICH ONE IS BETTER OR DO I DO BOTH? Let’s create a default, physicsCastAndMove object? What does it do:

Tell an object to move in a direction, if the new position collides with another physics object, then handle the collision accordingly. How do you handle bounce vs no bounce? Are we still assuming that the developer will write their own code for gravity? YES. So the user can write their own ‘applyGravity’ function for each object. The applyGravity or applyPhysics will be called at the end of the update function, and it’ll CastAndMove towards the appropriate direction

Let’s code the CastAndMove the function:

castAndMove(direction, distance) {
	this.setPos(new pos)
	this.checkCollisions()
	If (this.collisions) {
		// handle collision
		this.setPos(toGround)
	}
}

I wonder if there’s a fast way of checking collisions using linear algebra. I’ll look into that later.
But anyways, I don’t think I need to include gravity functions in the game engine. The developers can figure that out for themselves. So final answer: the developer can check for valid positions if/when they wanna move their characters. I’m just providing a template for the AABB, and my own example of how I’d implement gravity.

For the LAST TIME, what do I need to write.

  1. layers to a scene
  2. checkCollisions function (for everything on a layer)

I think that’s all I need actually. Does the engine need to do anything with the layers? What about drawing? I think we can add drawing layers and collisions tags. Each scene has an ordered list of layers, and have a dictionary of layer names mapped to lists of objects. The engine looks at the order and dictionary and calls draw functions based on the layers. The checkCollisions function will check an object with any/desired tagLists. So each object will have a dictionary mapping ‘tag names’ to list of collisions.

I’ve added drawing layers. The developer can make their own AABB lists to check for collisions. When would the found collisions function be reset? It’s supposed to be reset at every update loop. Maybe I should just leave it out for now?]
I added the checkCollisions function. So I guess I’ve done my job? What’s after that? I should probably make some demo templates. I should take a sprite sheet and render it. I can use this link.

Objectives Completed

Plans for Tomorrow