-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: sounds, enemies, rotation, better movements and others
- Loading branch information
Showing
22 changed files
with
667 additions
and
156 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { FScene, FSprite, FComponentEmpty } from '@fibbojs/2d' | ||
import Character from "../Character.ts"; | ||
|
||
export default class Bloc extends FSprite { | ||
topSensor: FComponentEmpty | ||
audio= new Audio('maiojs/assets/oof.mp3') | ||
|
||
public constructor(scene: FScene, position: { x: number, y: number }) { | ||
super(scene, { | ||
texture: 'bloc.png', | ||
position: position | ||
}) | ||
|
||
this.topSensor = new FComponentEmpty(this.scene, { | ||
position : { | ||
x: this.position.x, | ||
y: this.position.y + 0.2 | ||
} | ||
}) | ||
|
||
this.initSensorAndCollider() | ||
this.initCollision() | ||
this.addToScene() | ||
} | ||
|
||
initSensorAndCollider() { | ||
this.topSensor.initSensor() | ||
this.initCollider() | ||
this.initSensor({ | ||
'scale': {x: 0.8, y: 0.2}, | ||
'position': {x: 0, y: -0.5}, | ||
}) | ||
} | ||
|
||
initCollision() { | ||
this.topSensor.onCollisionWith(Character, ({component}) => { | ||
const character = component as Character | ||
if(!character.controller.jumpAvailable) { | ||
character.controller.jumpAvailable = true | ||
} | ||
}) | ||
|
||
this.onCollisionWith(Character, ({component}) => { | ||
this.audio.play() | ||
const character = component as Character | ||
character.controller.yVelocity = 0 | ||
this.scene.removeComponent(this) | ||
this.scene.removeComponent(this.topSensor) | ||
}) | ||
} | ||
|
||
addToScene() { | ||
this.scene.addComponent(this) | ||
this.scene.addComponent(this.topSensor) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { FScene } from '@fibbojs/2d' | ||
import { FSprite } from '@fibbojs/2d' | ||
import Generator from "./Generator.ts"; | ||
import Character from "../Character.ts"; | ||
|
||
export default class TubeGenerator extends Generator { | ||
texture = 'tube.png' | ||
|
||
public constructor(scene: FScene, character: Character) { | ||
super(scene, character) | ||
} | ||
|
||
public generate(position: { x: number, y: number }, scale: { x: number, y: number }) { | ||
super.generate(position, scale) | ||
let tube = new FSprite(this.scene, { | ||
texture: this.texture, | ||
position, | ||
scale: {x: 1, y: 1} | ||
}) | ||
|
||
|
||
tube.initCollider() | ||
tube.initSensor({ | ||
'scale': {x: 0.8, y: 0.2}, | ||
'position': {x: 0, y: -0.5}, | ||
}) | ||
|
||
this.scene.addComponent(tube) | ||
|
||
tube.onLoaded(() => { | ||
tube.scaleX = scale.x | ||
tube.scaleY = scale.y | ||
|
||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { FCamera, FComponent, FScene } from '@fibbojs/2d' | ||
|
||
export interface CameraOptions { | ||
constY: number | ||
target: FComponent | ||
zoom: number | ||
} | ||
|
||
export class Camera extends FCamera { | ||
target: FComponent | ||
constY: number | ||
zoom: number | ||
|
||
constructor(scene: FScene, options: CameraOptions) { | ||
super(scene) | ||
this.target = options.target | ||
this.constY = options.constY || 0 | ||
this.zoom = options.zoom || 1 | ||
} | ||
|
||
onFrame(_delta: number): void { | ||
// Move the camera to the target | ||
this.scene.viewport.moveCenter( | ||
this.target.transform.position.x * 100 + this.position.x * 100, | ||
this.constY * 100 | ||
) | ||
} | ||
|
||
__ON_CAMERA_ADDED_TO_SCENE_PLEASE_DO_NOT_CALL_THIS_BY_HAND__(): void { | ||
// Disable all plugins on the pixi viewport | ||
this.scene.viewport.plugins.pause('drag') | ||
this.scene.viewport.plugins.pause('pinch') | ||
this.scene.viewport.plugins.pause('wheel') | ||
this.scene.viewport.plugins.pause('decelerate') | ||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import RAPIER from '@dimforge/rapier2d' | ||
import {FController, FShapes} from '@fibbojs/2d' | ||
import type { FControllerOptions, FScene } from '@fibbojs/2d' | ||
import BasicEnemy from "../enemy/BasicEnemy.ts"; | ||
|
||
export interface CustomControllerOptions extends FControllerOptions { | ||
/** | ||
* The speed of the character. | ||
*/ | ||
speed?: number | ||
|
||
positionInitial: { x: number, y: number } | ||
|
||
positionFinal: { x: number, y: number } | ||
|
||
component: BasicEnemy | ||
} | ||
|
||
/** | ||
* @description Custom controller | ||
* @category Character | ||
*/ | ||
export class EnemyController extends FController { | ||
/** | ||
* The speed of the character. | ||
*/ | ||
speed: number | ||
|
||
positionInitial: { x: number, y: number } | ||
|
||
positionFinal: { x: number, y: number } | ||
|
||
compteur: number = 0 | ||
|
||
component: BasicEnemy | ||
|
||
/** | ||
* The scene where the character is. | ||
*/ | ||
scene: FScene | ||
|
||
|
||
/** | ||
* The character controller that will be used to move the character. | ||
*/ | ||
characterController: RAPIER.KinematicCharacterController | ||
|
||
constructor(scene: FScene, options: CustomControllerOptions) { | ||
super(options) | ||
|
||
this.component = options.component | ||
|
||
this.positionInitial = options.positionInitial | ||
this.positionFinal = options.positionFinal | ||
|
||
// Define default values | ||
const DEFAULT_OPTIONS = { | ||
speed: options.speed, | ||
} | ||
|
||
// Apply default options | ||
options = { ...DEFAULT_OPTIONS, ...options } | ||
// Validate options | ||
if (!options.speed) | ||
throw new Error('FibboError: FCharacter requires speed option') | ||
|
||
// Store options | ||
this.scene = scene | ||
this.speed = options.speed | ||
|
||
|
||
// The gap the controller will leave between the character and its environment | ||
const offset = 0.01 | ||
// Create the character controller | ||
this.characterController = scene.world.createCharacterController(offset) | ||
|
||
// Initialize a sensor | ||
this.component.initSensor({ | ||
shape: FShapes.SQUARE, | ||
scale: { x: 1, y: 1 }, | ||
}) | ||
} | ||
|
||
onFrame(delta: number): void { | ||
// Get the corrected movement | ||
const mouvement = Math.sin(this.compteur) | ||
this.compteur += delta | ||
|
||
this.component.setPosition({ | ||
x: this.component.position.x + mouvement * delta * this.speed, | ||
y: this.component.position.y | ||
}) | ||
this.component.sensor?.rigidBody.setTranslation({ x: this.component.position.x, y: this.component.position.y }, true) | ||
|
||
this.component.topSensor.sensor?.rigidBody.setTranslation({ x: this.component.position.x, y: this.component.position.y + 0.5 }, true) | ||
} | ||
} |
Oops, something went wrong.