Skip to content

Commit

Permalink
ingredients.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaxkr committed Aug 21, 2024
1 parent dcf0caf commit 2b65e08
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 14 deletions.
File renamed without changes.
28 changes: 27 additions & 1 deletion ingredients/handling-input.ts → ingredients/Handling Input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,31 @@ import PlayerBehavior from "./player.ts";
position in the game world.
Below is the implementation of the `Movement` behavior that handles player movement and firing based on input.
If you are using this.entity.transform.position.lookAt(this.inputs.cursor.world) you should ALWAYS do this before updating the transform position for the next frame.
This is correct:
const world = this.inputs.cursor.world;
if (!world) return;
// EXTREMELY IMPORTANT: Use the value of this.inputs.cursor.world before applying newPosition to the transform
const rotation = this.entity.transform.position.lookAt(world);
this.entity.transform.rotation = rotation;
// Apply the new position to the entity
this.entity.transform.position = newPosition;
This is wrong:
// Apply the new position to the entity
this.entity.transform.position = newPosition;
const world = this.inputs.cursor.world;
if (!world) return;
// EXTREMELY IMPORTANT: Use the value of this.inputs.cursor.world before applying newPosition to the transform
const rotation = this.entity.transform.position.lookAt(world);
this.entity.transform.rotation = rotation;
Please pay careful attention to this. It's tricky and important to remember when using cursor.world while also moving the entity and making it look at the cursor.
*/

export default class Movement extends Behavior {
Expand Down Expand Up @@ -83,9 +108,10 @@ export default class Movement extends Behavior {
}

// Rotate the entity to face the cursor's position

const world = this.inputs.cursor.world;
if (!world) return;

// EXTREMELY IMPORTANT: Use the value of this.inputs.cursor.world before applying newPosition to the transform
const rotation = this.entity.transform.position.lookAt(world);
this.entity.transform.rotation = rotation;

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,5 @@ export default class PlayerMovement extends Behavior {

this.entity.transform.position = this.entity.transform.position.add(velocity);

const cursorPos = this.inputs.cursor.world;
if (cursorPos) {
this.entity.transform.rotation = this.entity.pos.lookAt(cursorPos);
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 4 additions & 9 deletions ingredients/_basic-structure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import { MAP_BOUNDARY } from './_constants.ts'
class Movement extends Behavior {
// the speed of the player
speed = 5.0
// example value
anotherValue = 42.0
// the current velocity of the player
velocity = Vector2.ZERO

Expand All @@ -40,7 +42,8 @@ class Movement extends Behavior {

onInitialize(): void {
// definevalue calls make the public class variables visible in the inspector GUI and also sync over the network
this.defineValue(Movement, 'speed')
// define multiple values at once by passing them as more arguments. do not pass a list.
this.defineValues(Movement, 'speed', 'anotherValue')
this.defineValue(Movement, 'velocity', { type: Vector2Adapter })
}

Expand Down Expand Up @@ -71,13 +74,5 @@ class Movement extends Behavior {
newPosition.y = -MAP_BOUNDARY
if (newPosition.y + halfHeight >= MAP_BOUNDARY) newPosition.y = MAP_BOUNDARY

// make the entity this behavior is attached to face the player
const world = this.inputs.cursor.world
if (!world) return

const rotation = this.entity.transform.position.lookAt(world)
this.entity.transform.rotation = rotation

this.entity.transform.position = newPosition
}
}
37 changes: 37 additions & 0 deletions ingredients/combine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import os
import json

def collect_files():
current_dir = os.getcwd()
file_dict = {}

for filename in os.listdir(current_dir):
if os.path.isfile(filename):
file_path = os.path.join(current_dir, filename)
file_name_without_ext = os.path.splitext(filename)[0]
print(file_name_without_ext)

if (file_name_without_ext == 'combine' or file_name_without_ext == 'file_contents'):
continue

try:
with open(file_path, 'r', encoding='utf-8') as file:
file_contents = file.read()
file_dict[file_name_without_ext] = file_contents
except Exception as e:
print(f"Error reading file {filename}: {str(e)}")

return file_dict

def create_js_dictionary(file_dict):
js_dict = json.dumps(file_dict, indent=2)
js_output = f"const fileContents = {js_dict};"

with open('file_contents.js', 'w', encoding='utf-8') as js_file:
js_file.write(js_output)

print("JavaScript dictionary has been created in 'file_contents.js'")

if __name__ == "__main__":
file_dict = collect_files()
create_js_dictionary(file_dict)
12 changes: 12 additions & 0 deletions ingredients/file_contents.js

Large diffs are not rendered by default.

0 comments on commit 2b65e08

Please sign in to comment.