-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
157 additions
and
126 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,123 +1,109 @@ | ||
package JukeBox | ||
import LinkedList | ||
import TimerUtils | ||
import Players | ||
import SyncSimple | ||
import ClosureTimers | ||
|
||
class Music | ||
int spellid | ||
string path | ||
real duration | ||
string name | ||
|
||
construct(int id, string path) | ||
construct(int id, string path, real duration) | ||
this.spellid = id | ||
this.path = path | ||
this.name = path.substring(path.lastIndexOf("\\") + 1, path.lastIndexOf(".")) | ||
let p = ALL_PLAYERS.getFirst() | ||
if localPlayer == p | ||
GetSoundFileDuration(path).sync(p) syncedDur -> | ||
duration = syncedDur / 1000 | ||
this.duration = duration | ||
|
||
function play() returns Music | ||
PlayThematicMusic(path) | ||
return this | ||
|
||
|
||
class JukeRequest | ||
player juker | ||
int id | ||
Music music | ||
|
||
construct(player p, int id) | ||
construct(player p, Music music) | ||
this.juker = p | ||
this.id = id | ||
this.music = music | ||
|
||
|
||
public JukeBox jukeBox | ||
LinkedList<Music> musics | ||
constant musics = new LinkedList<Music>() | ||
|
||
public class JukeBox | ||
let requests = new LinkedList<JukeRequest>() | ||
let randomQueue = new LinkedList<int>() | ||
let jukeTimer = getTimer() | ||
let randomQueue = new LinkedList<Music>() | ||
|
||
var lastWasRequest = false | ||
|
||
Music currentMusic | ||
|
||
construct() | ||
jukeTimer.setData(this castTo int) | ||
for n = 0 to 3 | ||
for i = 0 to musics.size() | ||
if (i * GetRandomInt(1,7)) mod 2 == 0 | ||
randomQueue.addtoStart(i) | ||
else | ||
randomQueue.add(i) | ||
CallbackSingle cb = null | ||
|
||
function playNextMusic() | ||
StopMusic(false) | ||
// If request in queue, play it | ||
if requests.size() > 0 | ||
lastWasRequest = true | ||
let req = requests.pop() | ||
currentMusic = musics.get(req.id) | ||
currentMusic = req.music.play() | ||
printTimed("Jukebox: Playing |cff84DE52" + currentMusic.name + "|r as requested by " + req.juker.getNameColored(), 10) | ||
destroy req | ||
else if randomQueue.size() > 0 | ||
let id = randomQueue.pop() | ||
currentMusic = musics.get(id) | ||
if currentMusic == null | ||
playNextMusic() | ||
return | ||
printTimed("Jukebox: Playing |cff84DE52" + currentMusic.name + "|r", 10) | ||
randomQueue.addtoStart(id) | ||
lastWasRequest = false | ||
if currentMusic != null | ||
PlayMusic(currentMusic.path) | ||
jukeTimer.start(currentMusic.duration + 0.01, () -> onMusicCallback()) | ||
else | ||
StopMusic(false) | ||
jukeTimer.start(60, () -> onMusicCallback()) | ||
// Play next random music | ||
lastWasRequest = false | ||
if randomQueue.size() == 0 | ||
randomQueue.addAll(musics) | ||
randomQueue.shuffle() | ||
currentMusic = randomQueue.pop().play() | ||
printTimed("Jukebox: Playing |cff84DE52" + currentMusic.name + "|r", 10) | ||
|
||
if cb != null | ||
destroy cb | ||
cb = doAfter(currentMusic.duration + 1) -> | ||
cb = null | ||
playNextMusic() | ||
|
||
function checkSpell(int id) | ||
int idx = 0 | ||
for music from musics.staticItr() | ||
for music in musics | ||
if music.spellid == id | ||
let p = GetTriggerUnit().getOwner() | ||
for req from requests.staticItr() | ||
for req in requests | ||
if req.juker == p | ||
printTimedToPlayer("You already have a track in the jukebox!", 10, p) | ||
printTimedToPlayer("You already have a track queued in the jukebox!", 10, p) | ||
return | ||
|
||
printTimed("The Track |cff84DE52" + music.name + "|r has been queued by " + p.getNameColored(), 10) | ||
requests.add(new JukeRequest(p, idx)) | ||
printTimed("The Track |cff84DE52" + music.name + "|r has been requested by " + p.getNameColored(), 10) | ||
requests.add(new JukeRequest(p, music)) | ||
if requests.size() == 1 and not lastWasRequest | ||
jukeTimer.start(0.5, () -> onMusicCallback()) | ||
playNextMusic() | ||
return | ||
idx++ | ||
|
||
function onMusicCallback() | ||
(GetExpiredTimer().getData() castTo JukeBox).playNextMusic() | ||
|
||
init | ||
musics = new LinkedList<Music>() | ||
musics.add(new Music('A03T', "Sound\\Music\\mp3Music\\Doom.mp3")) | ||
musics.add(new Music('0000', "Sound\\Music\\mp3Music\\Human1.mp3")) | ||
musics.add(new Music('0000', "Sound\\Music\\mp3Music\\Human2.mp3")) | ||
musics.add(new Music('A03L', "Sound\\Music\\mp3Music\\HumanX1.mp3")) | ||
musics.add(new Music('0000', "Sound\\Music\\mp3Music\\Orc1.mp3")) | ||
musics.add(new Music('0000', "Sound\\Music\\mp3Music\\Orc2.mp3")) | ||
musics.add(new Music('0000', "Sound\\Music\\mp3Music\\Orc3.mp3")) | ||
musics.add(new Music('0000', "Sound\\Music\\mp3Music\\OrcX1.mp3")) | ||
musics.add(new Music('A02R', "Sound\\Music\\mp3Music\\PursuitTheme.mp3")) | ||
musics.add(new Music('A03P', "Sound\\Music\\mp3Music\\SadMystery.mp3")) | ||
musics.add(new Music('0000', "Sound\\Music\\mp3Music\\Tension.mp3")) | ||
musics.add(new Music('A03U', "Sound\\Music\\mp3Music\\TragicConfrontation.mp3")) | ||
musics.add(new Music('0000', "Sound\\Music\\mp3Music\\Undead1.mp3")) | ||
musics.add(new Music('0000', "Sound\\Music\\mp3Music\\Undead2.mp3")) | ||
musics.add(new Music('A03O', "Sound\\Music\\mp3Music\\PH1.mp3")) | ||
musics.add(new Music('A03M', "Sound\\Music\\mp3Music\\ArthasTheme.mp3")) | ||
musics.add(new Music('0000', "Sound\\Music\\mp3Music\\BloodElfTheme.mp3")) | ||
musics.add(new Music('A03S', "Sound\\Music\\mp3Music\\War2IntroMusic.mp3")) | ||
musics.add(new Music('A03Q', "Sound\\Music\\mp3Music\\Credits.mp3")) | ||
musics.add(new Music('0000', "Sound\\Music\\mp3Music\\Comradeship.mp3")) | ||
musics.add(new Music('A03N', "Sound\\Music\\mp3Music\\DarkAgents.mp3")) | ||
musics.add(new Music('0000', "Sound\\Music\\mp3Music\\IllidansTheme.mp3")) | ||
musics.add(new Music('0000', "Sound\\Music\\mp3Music\\LichKingTheme.mp3")) | ||
musics.add(new Music('A03R', "Sound\\Music\\mp3Music\\NagaTheme.mp3")) | ||
jukeBox = new JukeBox() | ||
doAfter(0.1) -> | ||
musics.add(new Music('A03T', "Sound\\Music\\mp3Music\\Doom.mp3", 66.125)) | ||
musics.add(new Music('0000', "Sound\\Music\\mp3Music\\Human1.mp3", 273.032)) | ||
musics.add(new Music('0000', "Sound\\Music\\mp3Music\\Human2.mp3", 236.983)) | ||
musics.add(new Music('A03L', "Sound\\Music\\mp3Music\\HumanX1.mp3", 284.646)) | ||
musics.add(new Music('0000', "Sound\\Music\\mp3Music\\Orc1.mp3", 311.954)) | ||
musics.add(new Music('0000', "Sound\\Music\\mp3Music\\Orc2.mp3", 313.496)) | ||
musics.add(new Music('0000', "Sound\\Music\\mp3Music\\Orc3.mp3", 282.706)) | ||
musics.add(new Music('0000', "Sound\\Music\\mp3Music\\OrcX1.mp3", 324.953)) | ||
musics.add(new Music('A02R', "Sound\\Music\\mp3Music\\PursuitTheme.mp3", 86.537)) | ||
musics.add(new Music('A03P', "Sound\\Music\\mp3Music\\SadMystery.mp3", 84.515)) | ||
musics.add(new Music('0000', "Sound\\Music\\mp3Music\\Tension.mp3", 19.540)) | ||
musics.add(new Music('A03U', "Sound\\Music\\mp3Music\\TragicConfrontation.mp3", 72.264)) | ||
musics.add(new Music('0000', "Sound\\Music\\mp3Music\\Undead1.mp3", 303.507)) | ||
musics.add(new Music('0000', "Sound\\Music\\mp3Music\\Undead2.mp3", 309.242)) | ||
musics.add(new Music('A03O', "Sound\\Music\\mp3Music\\PH1.mp3", 281.582)) | ||
musics.add(new Music('A03M', "Sound\\Music\\mp3Music\\ArthasTheme.mp3", 122.295)) | ||
musics.add(new Music('0000', "Sound\\Music\\mp3Music\\BloodElfTheme.mp3", 144.552)) | ||
musics.add(new Music('A03S', "Sound\\Music\\mp3Music\\War2IntroMusic.mp3", 81.136)) | ||
musics.add(new Music('A03Q', "Sound\\Music\\mp3Music\\Credits.mp3", 83.017)) | ||
musics.add(new Music('0000', "Sound\\Music\\mp3Music\\Comradeship.mp3", 124.927)) | ||
musics.add(new Music('A03N', "Sound\\Music\\mp3Music\\DarkAgents.mp3", 64.950)) | ||
musics.add(new Music('0000', "Sound\\Music\\mp3Music\\IllidansTheme.mp3", 108.006)) | ||
musics.add(new Music('0000', "Sound\\Music\\mp3Music\\LichKingTheme.mp3", 79.193)) | ||
musics.add(new Music('A03R', "Sound\\Music\\mp3Music\\NagaTheme.mp3", 87.1877)) | ||
jukeBox = new JukeBox() |
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
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
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,44 @@ | ||
package BounceTest | ||
|
||
public function calculateNormal(vec2 pointA, vec2 pointB, vec2 pointC) returns vec2 | ||
let vectorAB = pointB - pointA | ||
let vectorAC = pointC - pointA | ||
|
||
// Calculate the cross product of AB and AC (only Z component since we're in 2D) | ||
let crossProductZ = vectorAB.x * vectorAC.y - vectorAB.y * vectorAC.x | ||
|
||
// Determine the normal based on the cross product sign | ||
vec2 normal | ||
if crossProductZ > 0 | ||
normal = vec2(-vectorAB.y, vectorAB.x) // Left normal | ||
else | ||
normal = vec2(vectorAB.y, -vectorAB.x) // Right normal | ||
|
||
// Normalize the normal vector | ||
return normal.norm() | ||
|
||
public function reflectVelocity(vec2 velocity, vec2 normal, real reboundFactor) returns vec2 | ||
// Calculate the dot product of velocity and normalized normal | ||
let dotProduct = velocity.dot(normal) | ||
|
||
// Calculate the reflection vector | ||
var reflection = velocity - (2 * dotProduct * normal) | ||
|
||
// // Calculate the cosine of the angle between vel3 and nor3 | ||
// let cosAngle = dotProduct / (velocity.length() * normal.length()) | ||
|
||
// print(cosAngle.toString()) | ||
// // Check if the angle is very small (cosAngle close to 1 means angle close to 0) | ||
// if (cosAngle > 0.5) // Adjust this threshold based on your needs | ||
// // For nearly parallel, reduce the reflection magnitude | ||
// reflection *= 0.5 // Example: reduce the reflection's magnitude | ||
|
||
// Apply the rebound factor | ||
let reflectedVelocity = reflection * reboundFactor | ||
|
||
return reflectedVelocity | ||
|
||
@Test function test() | ||
calculateNormal(vec2(0, 0), vec2(1, 0), vec2(0, 0.5)).assertEquals(vec2(0, 1.0)) | ||
print(calculateNormal(vec2(0, 0), vec2(1, 0), vec2(0, 0.5)).toString()) | ||
print(reflectVelocity(vec2(0.5, -0.5), calculateNormal(vec2(0, 0), vec2(1, 0), vec2(0, 0.5)), 1.).toString()) |
Oops, something went wrong.