Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3 Stylish and useful extensions. #1746

Open
wants to merge 37 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
079c8a0
Create tsete.txt
Eaielectronic Nov 5, 2024
8192690
Add files via upload
Eaielectronic Nov 5, 2024
e08a5de
Delete extensions/Eaielectronic/tsete.txt
Eaielectronic Nov 5, 2024
62452cd
Rename Finger mutli-mobile to Finger-mutli-mobile.js
Eaielectronic Nov 5, 2024
c418acf
Rename Fps-returne to Fps-returne.js
Eaielectronic Nov 5, 2024
ef61a2e
Rename Login page to Login-page.js
Eaielectronic Nov 5, 2024
48d84fb
Update Login-page.js
Eaielectronic Nov 5, 2024
42ad742
Update ScrollingTextBubble.js
Eaielectronic Nov 5, 2024
a73cd31
Update Login-page.js
Eaielectronic Nov 5, 2024
c854e96
Update Fps-returne.js
Eaielectronic Nov 5, 2024
a5e821f
Update Finger-mutli-mobile.js
Eaielectronic Nov 5, 2024
1e0a04b
Update Finger-mutli-mobile.js
Eaielectronic Nov 5, 2024
43330b3
Update Fps-returne.js
Eaielectronic Nov 5, 2024
fc3218e
Update Login-page.js
Eaielectronic Nov 5, 2024
17a62a5
Update ScrollingTextBubble.js
Eaielectronic Nov 5, 2024
34ba4b1
Create teste.txt
Eaielectronic Nov 5, 2024
32f7557
Create teste
Eaielectronic Nov 5, 2024
e8782c4
Add files via upload
Eaielectronic Nov 5, 2024
c7d180d
Delete images/Eaielectronic/Finger-mutli-mobile.svg
Eaielectronic Nov 5, 2024
211311d
Delete images/Eaielectronic/Finger-mutli-mobile2.svg
Eaielectronic Nov 5, 2024
09d0c3e
Delete images/Eaielectronic/teste
Eaielectronic Nov 5, 2024
a0e03c0
Delete images/Eaielectronic/teste.txt
Eaielectronic Nov 5, 2024
3907f16
Add files via upload
Eaielectronic Nov 5, 2024
ae418c5
Delete images/Eaielectronic/Finger-mutli-mobile2.svg
Eaielectronic Nov 5, 2024
b786216
Add files via upload
Eaielectronic Nov 5, 2024
aa36118
Update ScrollingTextBubble.js.svg
Eaielectronic Nov 5, 2024
d6f8ba3
Update Login-page.svg
Eaielectronic Nov 5, 2024
84f3ba2
Update Finger-mutli-mobile.svg
Eaielectronic Nov 5, 2024
a60c18c
Delete images/Eaielectronic/ScrollingTextBubble.js.svg
Eaielectronic Nov 5, 2024
acf6920
Delete images/Eaielectronic/Login-page.svg
Eaielectronic Nov 5, 2024
b4151aa
Add files via upload
Eaielectronic Nov 5, 2024
f4531fc
Update Fps-returne.js
Eaielectronic Nov 5, 2024
bdb3d5d
Update Login-page.js
Eaielectronic Nov 5, 2024
b2a48bc
Update ScrollingTextBubble.js
Eaielectronic Nov 5, 2024
77cc15c
Update ScrollingTextBubble.js
Eaielectronic Nov 5, 2024
c9d1d4d
Update ScrollingTextBubble.js
Eaielectronic Nov 5, 2024
5b74dc3
apply prettier
Eaielectronic Nov 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
172 changes: 172 additions & 0 deletions extensions/Eaielectronic/Finger-mutli-mobile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
// Name: Finger ios/android
// ID: multiTouchDetection
// Description: Detect multiple fingers on mobile devices. Unlike sensing+ works on all mobile devices.
// By: Eaielectronic
// By: SERPENT1867 <https://scratch.mit.edu/users/serpent1867/+
// License: MPL-2.0
(function (Scratch) {
"use strict";

class MultiTouchDetection {
constructor() {
// Stocke les coordonnées des touches (jusqu'à 10 doigts)
this.touches = Array(10).fill({ x: 0, y: 0 });

// Écoute les événements tactiles
this.setupTouchListeners();
}

getInfo() {
return {
id: "multiTouchDetection",
name: "Multi-Touch Detection",
blocks: [
{
opcode: "isTouchingFinger",
blockType: Scratch.BlockType.BOOLEAN,
text: "is touching finger?",
filter: [Scratch.TargetType.SPRITE],
},
{
opcode: "getTouchX",
blockType: Scratch.BlockType.REPORTER,
text: "touch [INDEX] X position",
arguments: {
INDEX: {
type: Scratch.ArgumentType.NUMBER,
defaultValue: 1,
},
},
filter: [Scratch.TargetType.SPRITE],
},
{
opcode: "getTouchY",
blockType: Scratch.BlockType.REPORTER,
text: "touch [INDEX] Y position",
arguments: {
INDEX: {
type: Scratch.ArgumentType.NUMBER,
defaultValue: 1,
},
},
filter: [Scratch.TargetType.SPRITE],
},
// Nouveau bloc pour la position X d'un doigt touchant un sprite
{
opcode: "getTouchXOnSprite",
blockType: Scratch.BlockType.REPORTER,
text: "touch X position on sprite?",
filter: [Scratch.TargetType.SPRITE],
},
// Nouveau bloc pour la position Y d'un doigt touchant un sprite
{
opcode: "getTouchYOnSprite",
blockType: Scratch.BlockType.REPORTER,
text: "touch Y position on sprite?",
filter: [Scratch.TargetType.SPRITE],
},
],
};
}

// Détection si un doigt touche le sprite
isTouchingFinger(args, util) {
const spriteBounds = util.target.getBounds();

// Vérifie si au moins un doigt touche le sprite
for (let i = 0; i < this.touches.length; i++) {
const touch = this.touches[i];
if (
spriteBounds.left <= touch.x &&
touch.x <= spriteBounds.right &&
spriteBounds.bottom <= touch.y &&
touch.y <= spriteBounds.top
) {
return true;
}
}
return false;
}

// Fonction qui configure les écouteurs d'événements tactiles
setupTouchListeners() {
const convertToScratchCoords = (touch) => {
const canvas = Scratch.renderer.canvas; // Récupère le canvas de Scratch
const rect = canvas.getBoundingClientRect(); // Récupère la position du canvas
const scratchX = ((touch.clientX - rect.left) / rect.width) * 480 - 240;
const scratchY = 180 - ((touch.clientY - rect.top) / rect.height) * 360;
return { x: scratchX, y: scratchY };
};

const touchHandler = (event) => {
// Met à jour les coordonnées des doigts dans le tableau
for (let i = 0; i < event.touches.length && i < 10; i++) {
const touch = event.touches[i];
const { x, y } = convertToScratchCoords(touch);
this.touches[i] = { x, y };
}

// Réinitialise les positions restantes si moins de doigts
for (let i = event.touches.length; i < 10; i++) {
this.touches[i] = { x: 0, y: 0 };
}
};

window.addEventListener("touchstart", touchHandler);
window.addEventListener("touchmove", touchHandler);
window.addEventListener("touchend", touchHandler);
}

// Obtenir la position X du toucher d'un doigt donné
getTouchX(args) {
const index = Math.max(0, Math.min(9, args.INDEX - 1)); // Limite à 10 doigts
return this.touches[index].x;
}

// Obtenir la position Y du toucher d'un doigt donné
getTouchY(args) {
const index = Math.max(0, Math.min(9, args.INDEX - 1)); // Limite à 10 doigts
return this.touches[index].y;
}

// Nouveau: Obtenir la position X d'un doigt touchant un sprite
getTouchXOnSprite(args, util) {
const spriteBounds = util.target.getBounds();

// Cherche le premier doigt touchant le sprite et renvoie sa position X
for (let i = 0; i < this.touches.length; i++) {
const touch = this.touches[i];
if (
spriteBounds.left <= touch.x &&
touch.x <= spriteBounds.right &&
spriteBounds.bottom <= touch.y &&
touch.y <= spriteBounds.top
) {
return touch.x;
}
}
return 0; // Retourne 0 si aucun doigt ne touche le sprite
}

// Nouveau: Obtenir la position Y d'un doigt touchant un sprite
getTouchYOnSprite(args, util) {
const spriteBounds = util.target.getBounds();

// Cherche le premier doigt touchant le sprite et renvoie sa position Y
for (let i = 0; i < this.touches.length; i++) {
const touch = this.touches[i];
if (
spriteBounds.left <= touch.x &&
touch.x <= spriteBounds.right &&
spriteBounds.bottom <= touch.y &&
touch.y <= spriteBounds.top
) {
return touch.y;
}
}
return 0; // Retourne 0 si aucun doigt ne touche le sprite
}
}

Scratch.extensions.register(new MultiTouchDetection());
})(Scratch);
77 changes: 77 additions & 0 deletions extensions/Eaielectronic/Fps-returne.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Name: FPS returne
// ID: fpsbasedreturn
// Description: allows you to create games that run at the same speed, even if the FPS changes.
// By: Eaielectronic
// By: SERPENT1867 <https://scratch.mit.edu/users/serpent1867/>
// License: MPL-2.0
(function (Scratch) {
"use strict";
class FPSBasedReturn {
constructor() {
this.previousTime = null; // Pour stocker l'heure de la dernière frame
this.fpsValue = 30; // Initialiser avec une valeur par défaut (30 FPS)
}

getInfo() {
return {
id: "fpsbasedreturn",
name: "FPS Based Return",
blocks: [
{
opcode: "getFPSMultiplier",
blockType: Scratch.BlockType.REPORTER,
text: "FPS multiplier (based on [REFERENCE] FPS",
arguments: {
REFERENCE: {
type: Scratch.ArgumentType.NUMBER,
defaultValue: 30,
},
},
},
{
opcode: "getCurrentFPS",
blockType: Scratch.BlockType.REPORTER,
text: "current FPS",
},
],
};
}

// Méthode pour obtenir le delta time et calculer une fois les FPS
calculateFPS() {
const currentTime = performance.now();

if (this.previousTime === null) {
this.previousTime = currentTime;
return; // Attendre jusqu'à la prochaine frame pour calculer le delta time
}

let deltaTime = (currentTime - this.previousTime) / 1000; // Convertir en secondes
this.previousTime = currentTime;

if (deltaTime > 1 / 30) {
deltaTime = 1 / 30; // Limiter à 30 FPS max pour éviter des pics
}

this.fpsValue = 1 / deltaTime; // Calculer les FPS actuels
}

// Méthode pour retourner le FPS actuel
getCurrentFPS() {
this.calculateFPS(); // Mettre à jour le FPS
return this.fpsValue; // Retourner la valeur des FPS actuels
}

// Méthode pour calculer le multiplicateur en fonction des FPS
getFPSMultiplier(args) {
const referenceFPS = args.REFERENCE; // FPS de référence choisi par l'utilisateur
const fps = this.getCurrentFPS(); // Obtenir les FPS actuels

const multiplier = referenceFPS / fps; // Le rapport par rapport au FPS de référence
return multiplier;
}
}

// Enregistrer l'extension dans TurboWarp
Scratch.extensions.register(new FPSBasedReturn());
})(Scratch);
Loading