Skip to content

Commit

Permalink
feat: update to v0.0.10
Browse files Browse the repository at this point in the history
  • Loading branch information
Gugustinette committed Oct 22, 2024
1 parent 5a80e49 commit 9424f37
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 48 deletions.
54 changes: 27 additions & 27 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
"preview": "vite preview"
},
"devDependencies": {
"@fibbojs/3d": "^0.0.9",
"@fibbojs/core": "^0.0.9",
"@fibbojs/devtools": "^0.0.9",
"@fibbojs/event": "^0.0.9",
"@fibbojs/3d": "^0.0.10",
"@fibbojs/core": "^0.0.10",
"@fibbojs/devtools": "^0.0.10",
"@fibbojs/event": "^0.0.10",
"typescript": "^5.2.2",
"vite": "^5.2.0",
"vite-plugin-top-level-await": "^1.4.4",
Expand Down
8 changes: 4 additions & 4 deletions src/classes/Character.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ export default class Character extends FFBX {

initRigidBody(options?: FRigidBodyOptions) {
super.initRigidBody({
position: { x: 0, y: 0.25, z: 0 },
scale: { x: 0.25, y: 0.25, z: 0.25 },
positionOffset: { x: 0, y: 0.25, z: 0 },
scaleOffset: { x: -1.5, y: -1.5, z: -1.5 },
...options,
})
}

initSensor(options?: FRigidBodyOptions) {
super.initSensor({
...options,
position: { x: 0, y: 0.25, z: 0 },
scale: { x: 0.5, y: 0.5, z: 0.5 },
positionOffset: { x: 0, y: 0.25, z: 0 },
scaleOffset: { x: -1.3, y: -1.8, z: -1.3 },
})
}
}
22 changes: 9 additions & 13 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import RAPIER from '@dimforge/rapier3d'
import { FAmbientLight, FComponentEmpty, FCuboid, FDirectionalLight, FGameCamera, FScene } from '@fibbojs/3d'
import { FAmbientLight, FComponentEmpty, FCuboid, FDirectionalLight, FGameCamera, FRigidBodyType, FScene } from '@fibbojs/3d'
import { FKeyboard } from '@fibbojs/event'
import { fDebug } from '@fibbojs/devtools'
import './style.css'
Expand All @@ -17,52 +16,49 @@ import Character from './classes/Character'
fDebug(scene)

// Add directional light to represent the sun
scene.addLight(new FDirectionalLight(scene, {
new FDirectionalLight(scene, {
position: { x: 20, y: 20, z: 0 },
color: 0xFFFFFF,
intensity: 2,
}))
})
// Add ambient light
scene.addLight(new FAmbientLight(scene, {
new FAmbientLight(scene, {
color: 0x404040,
intensity: 20,
}))
})

// Create a death zone
const deathZone = new FComponentEmpty(scene, {
position: { x: 0, y: -20, z: 0 },
scale: { x: 100, y: 1, z: 100 },
})
deathZone.initCollider()
scene.addComponent(deathZone)

// Create a ground
const ground = new FCuboid(scene, {
position: { x: 0, y: -0.1, z: 0 },
scale: { x: 15, y: 0.1, z: 15 },
})
ground.initRigidBody({
rigidBodyType: RAPIER.RigidBodyType.Fixed,
rigidBodyType: FRigidBodyType.FIXED,
})
ground.setColor(0x348C31)
scene.addComponent(ground)

// Create a character
const character = new Character(scene)
scene.addComponent(character)

// Attach a camera to the character
scene.camera = new FGameCamera({ target: character })
scene.camera = new FGameCamera(scene, { target: character })

// Add collision events
character.onCollisionWith(deathZone, () => {
console.log('Character fell into the death zone!')
character.setPosition({ x: 0, y: 10, z: 0 })
character.transform.position = { x: 0, y: 10, z: 0 }
})

// Create keyboard
const keyboard = new FKeyboard(scene)
keyboard.onKeyDown('p', () => {
character.setPosition({ x: 0, y: 5, z: 0 })
character.transform.position = { x: 0, y: 5, z: 0 }
})
})()

0 comments on commit 9424f37

Please sign in to comment.