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

New Extension: Mouse Speed. #1715

Open
wants to merge 92 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
4411e1c
New Extension: Mouse Speed.
hammouda101010 Oct 8, 2024
956f7d8
fixed bugs
hammouda101010 Oct 8, 2024
f2a39a7
fixed format i think
hammouda101010 Oct 8, 2024
d0127eb
added image
hammouda101010 Oct 8, 2024
a16698e
added to list
hammouda101010 Oct 8, 2024
d0d7ada
moar stuff
hammouda101010 Oct 8, 2024
0860278
even more stuff
hammouda101010 Oct 8, 2024
9069954
fix
hammouda101010 Oct 8, 2024
bfecd8f
modified stuff
hammouda101010 Oct 8, 2024
be893df
blah
hammouda101010 Oct 8, 2024
5422e91
a
hammouda101010 Oct 8, 2024
8621a8a
resized the image are you happy now
hammouda101010 Oct 8, 2024
62684dc
amogus
hammouda101010 Oct 8, 2024
ccf3668
ok
hammouda101010 Oct 8, 2024
9b2d7ad
changed a bit the image
hammouda101010 Oct 8, 2024
580da6f
added new block
hammouda101010 Oct 9, 2024
6eb1c1d
added mouse limit
hammouda101010 Oct 9, 2024
66a5836
you can remove limits now.
hammouda101010 Oct 9, 2024
53d4cdf
fixed stuff
hammouda101010 Oct 9, 2024
ef61a52
added label and grammar fix
hammouda101010 Oct 9, 2024
33d8212
added another label
hammouda101010 Oct 9, 2024
4d3fed0
fixed format
hammouda101010 Oct 9, 2024
81589db
added sprite speed
hammouda101010 Oct 9, 2024
92f1922
removed sprites stuff
hammouda101010 Oct 9, 2024
0f17904
lint fix
hammouda101010 Oct 9, 2024
168f038
:skull:
hammouda101010 Oct 9, 2024
27ad71d
No More Mouse Speed, turbowarp modding implementat …
hammouda101010 Oct 10, 2024
0450e78
stuff
hammouda101010 Oct 10, 2024
2db4071
added error check
hammouda101010 Oct 10, 2024
cacf338
add find mod block
hammouda101010 Oct 10, 2024
3187601
tiny syntax error
hammouda101010 Oct 10, 2024
9dbd602
stuff
hammouda101010 Oct 10, 2024
afa561f
error detection but better
hammouda101010 Oct 10, 2024
0aca342
revert changes
hammouda101010 Oct 10, 2024
9f3876d
updated extensions.json
hammouda101010 Oct 10, 2024
a4923c3
renamed extension
hammouda101010 Oct 10, 2024
9bbc7fe
added menu
hammouda101010 Oct 10, 2024
c4ec18c
WARNING: loud srpelo alert
hammouda101010 Oct 10, 2024
aa87db4
import & export mods placeholder
hammouda101010 Oct 10, 2024
78af097
neutralized some constants
hammouda101010 Oct 10, 2024
f01c3bd
fixed format
hammouda101010 Oct 11, 2024
80e41e3
commit
hammouda101010 Oct 11, 2024
70d3a8f
added stuff
hammouda101010 Oct 11, 2024
311bb48
commit
hammouda101010 Oct 11, 2024
d87624b
added block icon
hammouda101010 Oct 11, 2024
e4983af
commit
hammouda101010 Oct 11, 2024
f70c65c
no problem
hammouda101010 Oct 11, 2024
b2ec17e
commented vm
hammouda101010 Oct 11, 2024
b142c3b
added inline image
hammouda101010 Oct 11, 2024
12520b4
added modpack feature
hammouda101010 Oct 11, 2024
b28652e
updated warning
hammouda101010 Oct 11, 2024
2f74c0a
commit
hammouda101010 Oct 11, 2024
435dcbf
added credit
hammouda101010 Oct 11, 2024
70f9af5
asset manager stuff
hammouda101010 Oct 11, 2024
e84880a
added load mod block
hammouda101010 Oct 11, 2024
ec678fc
updated ISSprite function
hammouda101010 Oct 11, 2024
4e46c8e
:skull::skull::skull:
hammouda101010 Oct 11, 2024
cbcaa4c
thanks for chat gpt to fix this, nobody was here t
hammouda101010 Oct 12, 2024
c5ff4b5
fixed linting
hammouda101010 Oct 12, 2024
26a72c4
chat gpt sucks
hammouda101010 Oct 12, 2024
b2f985e
fix
hammouda101010 Oct 12, 2024
be2e82c
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
hammouda101010 Oct 12, 2024
2ae516d
fixed format
hammouda101010 Oct 12, 2024
19dcd4f
wtf
hammouda101010 Oct 12, 2024
4e22dbf
FIXED STUFF
hammouda101010 Oct 12, 2024
5aeac1a
a
hammouda101010 Oct 12, 2024
92a72ff
a
hammouda101010 Oct 12, 2024
c42561c
cool
hammouda101010 Oct 12, 2024
e106567
FINALLY managed to make it work!
hammouda101010 Oct 12, 2024
c9981e0
new logo (unfinished)
hammouda101010 Oct 14, 2024
98e5783
Merge branch 'master' into master
hammouda101010 Oct 15, 2024
dac05fa
cool
hammouda101010 Oct 16, 2024
ab66338
hidden turbomodz extension
hammouda101010 Oct 16, 2024
cd7ea8f
runtime values is now object
hammouda101010 Oct 16, 2024
eb74766
added runtime values
hammouda101010 Oct 16, 2024
aafa761
updated files code, old one aged like milk
hammouda101010 Oct 16, 2024
9a8962e
runtime block added
hammouda101010 Oct 16, 2024
f37731a
stuff
hammouda101010 Oct 17, 2024
27d0d46
added stuff
hammouda101010 Oct 17, 2024
3a52e28
added mod prefix to sprites
hammouda101010 Oct 17, 2024
3625f60
Merge branch 'TurboWarp:master' into master
hammouda101010 Oct 17, 2024
db3dee2
help me
hammouda101010 Oct 17, 2024
7f6eb37
added runtime options loading
hammouda101010 Oct 17, 2024
83e271d
github committed die
hammouda101010 Oct 17, 2024
165d31c
improved runtime values block
hammouda101010 Oct 17, 2024
5622e20
go commit die
hammouda101010 Oct 17, 2024
4622077
stuffy
hammouda101010 Oct 17, 2024
7160e95
added more reporters
hammouda101010 Oct 18, 2024
675857e
Update turbomodz.js
hammouda101010 Oct 28, 2024
fb415c5
removed turbomodz from main branch
hammouda101010 Oct 28, 2024
78070dc
Merge branch 'TurboWarp:master' into master
hammouda101010 Oct 28, 2024
e66051f
Merge branch 'master' into master
hammouda101010 Nov 3, 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
48 changes: 48 additions & 0 deletions docs/Hammouda101010/mousespeed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Mouse Speed
This extension lets you get the speed of the mouse.

## "mouse speed"
```scratch
mouse speed :: #38c3e5 reporter
```
This block constantly returns the speed of the mouse
## "is mouse faster than ()?"
```scratch
is mouse faster than ()? :: #38c3e5 boolean
```
This block checks if the mouse speed is greater than the value. In other terms, if the mouse is faster than the value.

## Usage:

Basic Example:
```scratch
when green flag clicked
forever
if <is mouse faster than (50)? :: #38c3e5> then // checks if mouse faster than value
say[ouch, that hurts!]
else
say(mouse speed :: #38c3e5) //otherwise, returns mouse speed
```

Swiping Example:
```scratch
define explode
... // insert code here
change [score v] by [1]
delete this clone

when green flag clicked
set [score v] to [0]
forever
wait[5] seconds
create clone of [myself v]

when i start as a clone // simple code
point in direction(pick random [-180] to [180])
forever
move [5] steps
if on edge, bounce
if <<touching [mouse pointer v] > and <is mouse faster than (50)? :: #38c3e5>> then // checks if mouse faster than value
Explode
```

204 changes: 204 additions & 0 deletions extensions/Hammouda101010/mousespeed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
// Name: Mouse Speed
// ID: hammouda101010mousespeed
// Description: Get The Speed of the Mouse.
// By: Hammouda101010 <https://scratch.mit.edu/users/hammouda101010/>
// License: MIT

(function (Scratch) {
"use strict";

if (!Scratch.extensions.unsandboxed) {
throw new Error("Mouse Speed must run unsandboxed, silly");
}
// Block Icons
const blocksIcon =
"data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHdpZHRoPSIxMzkuNjk1NDQiIGhlaWdodD0iMTM5LjY5NTQ0IiB2aWV3Qm94PSIwLDAsMTM5LjY5NTQ0LDEzOS42OTU0NCI+PGcgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoLTE3MC4xNTIyOCwtMT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Zz48IS0tcm90YXRpb25DZW50ZXI6NjkuNjY4MjkwMDAwMDAwMDE6NjkuODQ3NzItLT4=";

// Scratch's VM
const vm = Scratch.vm;
const runtime = vm.runtime;

class MouseSpeed {
constructor() {
this.mouseX = 0; // Current mouse X position
this.mouseY = 0; // Current mouse Y position
this.lastX = 0; // Previous mouse X position
this.lastY = 0; // Previous mouse Y position
this.lastTime = performance.now(); // Last time the mouse was updated
this.speed = 0; // Speed of the mouse
this.limit = null; //Mouse's speed limit
this.tolerance = 50; // Tolerance of the mouse's speed
this.prevTime = null;
this.prevX = null;
this.prevY = null;

// Bind this to the event listener to track mouse movement
vm.renderer.canvas.addEventListener(
"mousemove",
this.handleMouseMove.bind(this)
);

// Start a continuous update interval to constantly track mouse speed
setInterval(() => this.updateMouseSpeed(), 50); // Updates every 50ms
}

getInfo() {
return {
id: "mousespeed",
name: "Mouse Speed",
menuIconURI: menuIcon,
blockIconURI: blocksIcon,
docsURI: "https://extensions.turbowarp.org/Hammouda101010/mousespeed",
color1: "#38C3E5",
color2: "#33A5C1",
blocks: [
{
opcode: "getMouseSpeed",
blockType: Scratch.BlockType.REPORTER,
text: "mouse speed",
},
{
opcode: "mouseFaster",
blockType: Scratch.BlockType.BOOLEAN,
text: "is mouse faster than [SPEED]?",
arguments: {
SPEED: {
type: Scratch.ArgumentType.NUMBER,
defaultValue: 50,
},
},
},
{
opcode: "mouseTolerance",
blockType: Scratch.BlockType.COMMAND,
text: "set mouse speed tolerance to [TOLERANCE]",
arguments: {
TOLERANCE: {
type: Scratch.ArgumentType.NUMBER,
defaultValue: 50,
},
},
},
{
blockType: Scratch.BlockType.LABEL,
text: "Mouse Speed Limit",
},
{
opcode: "mouseLimit",
blockType: Scratch.BlockType.COMMAND,
blockIconURI: limitIcon,
text: "set mouse speed limit to [LIMIT]",
arguments: {
LIMIT: {
type: Scratch.ArgumentType.NUMBER,
defaultValue: 100,
},
},
},
{
opcode: "mouseLimitRemove",
blockType: Scratch.BlockType.COMMAND,
blockIconURI: noLimitIcon,
text: "remove mouse speed limit",
},
{
blockType: Scratch.BlockType.LABEL,
text: "Hats & Events",
},
{
opcode: "whenMouseFaster",
blockType: Scratch.BlockType.HAT,
text: "when mouse is faster than [SPEED]",
arguments: {
SPEED: {
type: Scratch.ArgumentType.NUMBER,
defaultValue: 50,
},
},
},
],
};
}

// Handles Mouse Speed
handleMouseMove(event) {
this.mouseX = event.clientX;
this.mouseY = event.clientY;
}

//Updates Mouse Speed:
updateMouseSpeed() {
const currentTime = performance.now();
const timeElapsed = (currentTime - this.lastTime) / 1000; // Time in seconds

if (timeElapsed > 0) {
const dx = this.mouseX - this.lastX;
const dy = this.mouseY - this.lastY;

// Calculate the distance traveled by the mouse
const distance = Math.sqrt(dx * dx + dy * dy);

// Calculate speed in pixels per second
this.speed = distance / timeElapsed;
}

// Update the last known mouse position and time
this.lastX = this.mouseX;
this.lastY = this.mouseY;
this.lastTime = currentTime;
}

clamp(num, min, max) {
return Math.min(Math.max(num, min), max);
}

//The Extension Blocks

getMouseSpeed() {
//Gets Mouse Speed
if (this.limit === null) {
return Math.round(this.speed / this.tolerance); // Return the rounded speed
} else {
return this.clamp(
Math.round(this.speed / this.tolerance),
0,
this.limit
); // Return the limited rounded speed
}
}
mouseFaster(args) {
// Checks if mouse speed is greater than the SPEED arg
return this.getMouseSpeed() > args.SPEED;
}

mouseTolerance(args) {
//sets the mouse's tolerance
this.tolerance = args.TOLERANCE;
}

mouseLimit(args) {
this.limit = args.LIMIT;
}

mouseLimitRemove() {
this.limit = null;
}

whenMouseFaster(args) {
return this.getMouseSpeed() > args.SPEED;
}
}

runtime.on("BEFORE_EXECUTE", () => {
runtime.startHats("mousespeed_whenMouseFaster");
});

Scratch.extensions.register(new MouseSpeed());
})(Scratch);
1 change: 1 addition & 0 deletions extensions/extensions.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[
// This file supports comments
"Hammouda101010/mousespeed",
"lab/text",
"stretch",
"gamepad",
Expand Down
Binary file added images/Hammouda101010/mousespeed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading