2727 const nekoContainer = document . createElement ( "div" ) ;
2828 const nekoFile = "/Assets/SubScripts/OnekoJS/Assets/oneko.gif"
2929
30- // Adjustable Variables:
31- const nekoSpeed = 37 ;
32- const nekoScaling = 4 ;
30+ // >>> Adjustable Variables - START <<<
31+
32+ // Speed and Scale:
33+ const nekoSpeed = 60 ;
34+ const nekoScaling = 6 ;
35+
36+ // Behavior:
3337 const nekoSleep = 100 ;
3438 const nekoMinDistance = 48 ;
3539 const randomIdleEventDelay = 10 ;
3640 const randomIdleEventOffset = 200 ;
3741 const sleepyOffset = 8 ;
3842 const maxSleepTime = 192 ;
3943 const maxIdleAnimationTime = 9 ;
44+ const minWallDistance = 16 ;
4045 const minWallDistanceToScratch = 32 ;
41-
46+
47+ // Start-Position:
48+ const ranomStartPositon = true ;
49+ const nekoStartPosX = 32 ;
50+ const nekoStartPosY = 32 ;
51+
52+ // >>> Adjustable Variables - END <<<
53+
4254 // Nekos Position:
43- let nekoPosX = 32 ;
44- let nekoPosY = 32 ;
55+ let nekoPosX = 0 ;
56+ let nekoPosY = 0 ;
4557
4658 // Mouse Position:
4759 let mousePosX = 0 ;
132144
133145 // INITIALIZER: ####################################################################################################
134146 function init ( ) {
147+ // Start-Position:
148+ setStartPosition ( )
149+
135150 // Configuring Container:
136151 nekoContainer . id = "oneko" ;
137152 nekoContainer . ariaHidden = true ;
152167
153168 // Add event Lisitener with "Lambda" method to Update Script-Global Mouse position:
154169 document . addEventListener ( "mousemove" , function ( event ) {
155- mousePosX = event . clientX ;
156- mousePosY = event . clientY ;
170+ updateMousePosition ( event . clientX , event . clientY )
157171 } ) ;
158172
173+ // Fix StartUp Position so it can be freely defined (As long as the mouse-move event has not fired the known mouse position is 0, 0):
174+ updateMousePosition ( nekoPosX , nekoPosY )
175+
159176 // Enforce Size with scaling (Double DIV causes to many issues):
160177 window . addEventListener ( 'load' , updateDivScale ) ;
161178 window . addEventListener ( 'resize' , updateDivScale ) ;
233250 nekoPosY -= ( diffY / distance ) * currentScaledNekoSpeed ;
234251
235252 // Keep distance to window Border (Fixes of-screen when resizing):
236- nekoPosX = Math . min ( Math . max ( 16 , nekoPosX ) , window . innerWidth - 16 ) ;
237- nekoPosY = Math . min ( Math . max ( 16 , nekoPosY ) , window . innerHeight - 16 ) ;
253+ nekoPosX = Math . min ( Math . max ( 16 , nekoPosX ) , window . innerWidth - minWallDistance ) ;
254+ nekoPosY = Math . min ( Math . max ( 16 , nekoPosY ) , window . innerHeight - minWallDistance ) ;
238255
239256 // Set Neko Position:
240257 nekoContainer . style . left = `${ nekoPosX - 16 } px` ;
350367 nekoContainer . style . transform = `scale(${ adjustedScale } )` ; // Backticks to turn value into String.
351368 currentScaledNekoSpeed = adjustedNekoSpeed
352369 }
370+
371+ // Define START-Position on screen by fixed value or random:
372+ function setStartPosition ( ) {
373+ // At random:
374+ if ( ranomStartPositon == true ) {
375+ // Get Viewport-Size:
376+ const width = window . innerWidth ;
377+ const height = window . innerHeight ;
378+
379+ // Page Limits:
380+ const maxX = width - minWallDistance ;
381+ const maxY = height - minWallDistance ;
382+
383+ // Generate random Pos:
384+ const x = Math . random ( ) * maxX ;
385+ const y = Math . random ( ) * maxY ;
386+
387+ // Position Oneko:
388+ nekoPosX = x
389+ nekoPosY = y
390+ } else { // Static:
391+ nekoPosX = nekoStartPosX
392+ nekoPosY = nekoStartPosY
393+ }
394+ }
395+
396+ // Updates the Position of the Mouse on screen (In function so it can be offset for start Position):
397+ function updateMousePosition ( myPosX , myPosY ) {
398+ mousePosX = myPosX ;
399+ mousePosY = myPosY ;
400+ }
353401 } ;
354402} ) ( ) ;
0 commit comments