Product: Tetris2P AI
Sprint Summary

Daily Objectives

Notes

If we’re creating clickable objects that are positioned/anchored to a ‘world’ space rather than a canvas, I think it would be a good idea to precalculate where the object would also appear in reference to the canvas. It’ll also be useful for the draw loop as well.

So for positioning and drawing, there’s two things you can do:

  1. Anchored to the Canvas (UI Elements)
  2. Anchored to a Parent
    • Which is anchored to a Parent
    • Which is eventually anchored to the Canvas

So we can have a world map, that is anchored to a canvas. Moving the world map around the canvas will move all the gameObjects inside the world map.

Inb4 I need to add sprite sheet rendering to the to do list. Also I wanna make the ball move left and right and jump, but that’s for later w/ the fizix engine.

BUT the first things first, we need to decide how clicking objects will work.

  1. Click event handler triggers → sets a click variable with position in a key/input library.
  2. On update loop, clickable objecs check if click entry exists
    • Clickable object checks coordinates to see if they’ve been clicked
    • If clicked, then set click variable in key/input library to false - optional if needed/necessary
  3. On exit update loop, set click entry to false

Should I separate the dictionaries for mouse clicks or combine them with the keyState dictionary. Oh I still need to allow for holding down the mouse button, heck. Let’s make two different dictionaries, one for mouseEvents, another for keyStates.
mouseMove gives a way of determining the last position the mouse was in. For now I’ll ignore potential issues so I can make a little progress.
To make:

  1. gameObject with print onclick function
  2. draggable gameObject
  3. gameObject with switchScene onclick function

How do I draw a rectangle from a min, max thing? Alright, I’ve drawn the rectangle, now I need to give it access to inputs. I want to delete all entries of the mouseEvents dictionary after an update. Is there anything that I shouldn’t delete? I think we should leave mousemove probably? Oh, I forgot to account for offsets!

So, clicking and checking for mouse events is functional. Something that I want to include is how do you make it easier to check if a key is newly pressed? Presses occur when you move your mouse up! So maybe I should make a keyEvents dictionary thats meant to be interfaced. Add the key to the keyEvents dict on a keyUp event, along with duration? Is duration relevant here?

So use keyState for ‘onmousedown’ functions and ‘keyPress’ for ‘onmouseup’ functions!!! Haha wow so convoluted but hopefully not really :)

So I think input processing is fine now, I can do a little bit of reformatting and cleaning up later on. Should I make the draggable gameObject now?

Let’s outline the flow of the action:

  1. Onmousdown: set object’s state to ‘being dragged’
  2. While object state = ‘being dragged’,
    • Move object to last mousemove point

Hmm, I need to figure out the interaction between the mousemove event and dragging. At what point should I assume an object is no longer being dragged? And then list the edge/bug cases

  1. Mouseup
    • If i click off the screen, while dragging, mouseup will never trigger. This is actually kinda common though I think? If you tab back in, the object will still follow your cursor. You can click on the screen again to trigger the mouseup event. (just make sure to disable other mousedown events while in the dragging state)
    • What if I’m drawing on a screen? It’ll keep drawing on the screen while my mouse isn’t down.
  2. Mouseout

The only ways of remembering information right now are by saving state, and the last mouseover position.

I’m back from my coffee break, about to go on another coffee break. Where did I leave off from? I’m preemptively assuming the click and drag functions will fall apart, since it depends on a mouseup function to stop. Switching windows or tabs prevents the mouseup function from happening, so what can I do to prevent the issue? If mouseenter occurs without mouseleave occuring? We can test and see if mouseleave happens when you alt tab.

Before I forget there’s two different possibly desired behaviors for mousemove:

I think we should assume the former, and let the developer execute the second one only if they want (keep a prevPosition variable in the gameObject code rather than engine code)

So from what I’m writing above, I’m assuming the next goal is to create a draggable element, or draw on the canvas. This is still part of the ‘make clickable elements’ thing from the daily goals.

I can drag it around now, but I want the AABB to be moved relative to where I clicked! So, I should save the point at where I clicked, and then move relative to that? I should find the offset during the mousedown event.

SceneSwitching is next :)
So when you switch scene, you want to make sure the sceneSwitch happens at the end of the update loop, cause the current scene’s update loop might mess with the new scene’s variables or loose track of pointers with the this.scene.engine switch. This was actually the easiest part, its working fine already cool :thumbs_up:

What’s next (for the game engine)?

Btw add a mutable global variable space within the engine object.

Don’t forget to break things into the short term to stay focused I guess. It’s fine to be short sighted sometimes for the sake of getting things done :)

Let’s break game objects into necessary but optional pieces:

  1. 2d physics body
  2. clickable body
  3. rendering and positioning
  4. update script

The first 3 items can all have different positions, but they all must have the same anchor point. So I think the 3 items are all relevant to the objects base position. That base position will be relative to the object’s parent’s base position instead. How do I go around implementing that now? I think we should do more work writing into the base gameObject class. How do include and exclude clickable objects and rigid bodies when necessary/unnecessary? I can just make true/false variables whether its made on initializing.

Also, I need to make a change so that, ‘clicks’ are only registered on clickAABB’s only if mouseup and mousedown happened on the same target. I can’t determine that from the game engine though, so it has to go into the gameObject script. So what needs to happen provided an object is clickable:

  1. If mousedown event occurs, check if pointInAABB
    • set mousedown variable to true
  2. If mouseup event occurs, check mousedown variable
    • If true, then set a ‘clicked’ variable to true
    • Then reset mousedown variable to false

Hmm, how/where do I include code to process the events for objects? Normally, every object would have a ‘begin’ function. Also I haven’t figured out how child objects should be updated. My original assumption was that the developers include a for loop to update their children within their own for loop, but I’m not sure if that’s good practice? Wait oh, I think it’s a fair assumption to have them call their own children update functions, since some of the will attach the child variables using object specific references.
Example: a tetrisGridObject will have a reference to its active piece using:

Rather than creating a new tetromino object and appending it to a:

Going off this logic, I’d like to avoid adding ancestry related code that developers might forget to include. Meaning, I don’t want to make the the developer create a chain for ‘begin’ and ‘end’ functions. The only script that always runs for all objects will be the update and maybe draw function.

The developer is just gonna have to add a: checkClicks() function at the top of the update function if they want clicks to work? To reiterate, the issue is that for clicks to register, mousedown and mouseup events have to occur on top of the objects AABB. If the developer only checks for the mouseup() event occurring, there’s no where to check for the mousedown event. I could make the checkClick function check for mousedown events when mouseup events aren’t occuring, but that would betray logical nomenclature and I don’t know conditionals for when developers check for clicks.

I think the best move would be to force the developer to include an ‘allowClickDetection’ function call at the top with the AABB as a parameter. When does isClicked get set to false when we actually detect a click? We can do that at the top of the function. The isClicked variable should only be set for one update loop. I forgot to reset the this.mousedown variable when you mouseup outside of the aabb.

It’s working :D
I should change the ‘createClickableArea’ to ‘createAABB’ instead. Done.

Now, should I differentiate, the uh mouse clicks? Apparently, left, right, scroll clicks all trigger the mousedown and mouseup events. Should I do this now? I’ll write this onto the backburner for now. Also for now, I’ll at least prevent the context menu from appearing.

So uh, what do I do now? I can either:

  1. Continue cleaning code
  2. Start the physics 2d engine
  3. Separate the mouse inputs
  4. Work on position anchors?
  5. Work on sprite and image rendering

(not discounting the other to do stuff, I’m debating what to do immediately next)

Objectives Completed