Product: Tetris2P AI
Sprint Summary

Notes

hey aha, let’s jump straight into the tetris + game framework thing

Game Engine Files:
Scene Files:
Game Object Files:

I should code up intended usage for the engine and then pop off from there.
I’m not really focusing haha heck
OK does the engine do anything different between games? No it shouldn’t I think. So I can move all the code interfacing with MainLoop into that module.

First issue!
We’re passing class methods into MainLoop to be called later! This doesn’t work cause they exist in different spaces so ‘this’ isn’t defined in the methods!
THIS variable is set by the context its invoked
Wow that’s actually super stupid
Wait nvm this is where the bind function comes in handy, i learned this in React lmao
this.draw = this.draw.bind(this);

Heck me what do i do next now
What do I have now again.

I have an object class that runs the MainLoop program. What else does is it do besides run the MainLoop? It’s supposed to draw and update a scene. Also its supposed to handle scene transitions.
Alright let’s make a scene now to draw! Just make it a blank scene with a colored background.

Before that though:

  1. Color the current background (using engine draw method)
  2. Make it a fixed smaller size
  3. Center it in the screen Just as a reminder: (0,0) of the canvas refers to the TOP LEFT
    But kk I did that. Now time to make first example scene. Gonna reference yesterday’s notes on what to make
    But first I’m gonna make another scene that just draws a background, and maybe a moving ball Or maybe make the background color a component?

What differentiates scenes from each other? I’m having trouble picturing how everything interacts with each other. In Unity you don’t code anything into the Scene object. What do you do with it then? Scene’s just hold an ordered hierarchy of objects.

So Scene’s are just gameObject containers. The scene renders them in the order they’re provided. Kk that makes sense SO how does the developer add objects to it? You can instantiate it with a set objects. But the objects might need references to each other, so when do they get instantiated?

Make another loop in scene constructor to add object relationships?

Also separate prefab things dude! There objects that need to be instantiated when the scene opens up. I only need to instantiate objects that are present at the beginning of the scene!!! The only thing you need to write for a new scene, is the instantiation function. What happens in the instantiation function? You create your initial objects and add initial game references.

How does Unity do it again?
Prefabs vs GameObjects
GameObjects are instantiated at the start. Prefabs are used later after instantiation to create additional GameObjects.
When GameObjects are gonna be created from Prefabs during runtime, you can pass in all the object references during/right after instantiation. Example, when you make a new tetromino, you can pass in the grid as a parameter to the construction function, so it has a reference of it.

Can I get an example for tetris at least?
If we have a scene for multiplayer, we can instantiate a match object, then a player object, then add that player object to the match object. Yes, nice, very cool sounds like a plan. SO, the only unique thing about each Scene is the function you use when the scene loads in. Note that this occurs separately from instantiation, unless I’m want to change how scene switches work. I want to instantiate/create all the scene objects, and then pass in the list to the game engine. OR, should I pass a list of the scene classes instead and have everything run during construction?

Let’s discuss advantages and disadvantages of both? First why would I want to have the scene objects instantiated first?
Btw Scenes can determine to which scene they want to transition into, but not really what transitions into them. I can implement something like that, but maybe for once I get there. I’m basically creating a state machine? OH, ok yeah I think it’s better to just, not have them instantiated initially. Why? If you want to make a game based on levels, you don’t want to instantiate all the levels from the beginning right? It’s more of just a memory concern.

Its crazy how little code I’m actually writing haha
Ok, how does scene switching work? There needs to be some sort of reference/callable function. I think we can have all gameObjects have a reference to the actual scene, and the scene calls a switchScene function using its reference to the engine.

First example I’m gonna do is make a background game object and a bouncing ball game object. I’m not trying to do anything physics based but it doesn’t hurt to accommodate for it.

Ok I also have to figure out the relationship and components. GameObjects generally have several components. I feel like I can leave it up to the developer to write their own components.

Ay nice i have a working prototype! Apparently the way you check for clicks is by:

  1. Adding onclick and dbclick event triggers to the canvas
  2. The canvas knows where the coordinates of the click
  3. Check the position of clickable objects in game code
    • Sounds kinda inefficient, but it works if you don’t have too many elements?

The issue with this however, is incorporating it into a draw loop? Hmm, I guess we can set an onclick/dbclick function to the canvas object and have it set variables in the engine. The clickable objects can check by themselves whether there’s a click or not and perform action. The ‘click’ variable will reset to false at the end of an update loop. I think I can leave mouse clicks out for a different time though. For now we focus on keyboard inputs!
The main idea issue I want to make sure I have down first is separating short and long presses. I’ll just write some pseudo code?

if hold == false and keydown:  
	shortpressaction()  
	Hold = true;  
	startholdTimer; 
if hold == true and keyup:  
	// end short press  
	Hold = false;  
if hold == true and keydown:  
	if startholdtimer > 1s;  
		performholdAction()  
	Else:  
		Holdtimer += delta;

Ok, cool sounds fine. Also you can use two different time variables, one time variable to represent how long you need to hold a key down for it to become a long press, and another variable to determine at what interval to perform a holdaction once you’ve determined the key is being held down.

For most double click key presses, you can set a timer to determine the interval from when you last pressed the same key. Wow it feels like I did a good amount of work today :)

Objectives Completed

Plans for Tomorrow