GlovePIE:Invisible Fish

From WiiLi

Jump to: navigation, search

Fishing with a wiimote.

/*                  Invisible Fish v1.1
***********************************************************
*                 Created by Rhys Legault                 *
*                 rhyslegault@hotmail.com                 *
*             Last Modified: February 28th, 2007          *
***********************************************************
*  Feel free to use, modify and redistribute this script  *
***********************************************************
*
*  About:
*  This script is a virtual fishing script for the wiimote.  There is no visual
*  component to this script (other than the LEDs). Feel free to make a flash
*  game etc. based off of this script if you like.
*
*  Requires: 1 Wiimote + 1 Nunchuk
*
*  Controls:
*  Press and hold Wiimote.B
*  Bring the wiimote up and over your shoulder
*  Bring the wiimote forward with some speed and release Wiimote.B to release the line
*  Let the line go out and once it hits the water wait for a bite
*  Flick the wiimote to get a fish on the line
*  Reel in using the nunchuk
*  Watch out for the fish to pull back or gets too far away as the line can snap
*  The debug shows the line distance
*  The LEDs show you the line strength - the faster they flash the more likely it will break
*
*  Line snap = Contant 4 LEDs
*  Caught = All 4 LEDs flash on and off
*  Wait 10 seconds and try again
*
*  Note:  Code is ugly. I just kind of started adding things here and there until
*  I finished.  All things seem to work for me.  I just wanted to get the basic idea done.
*
*/

if Wiimote.B && var.LineBreak = false && var.OnHook = false && var.InAir = false && var.InWater = false
   if Wiimote.gy < 0
      if var.ReachBack = false
          var.Rumble = 80
          var.ReachBack = true
      else
         if Wiimote.gy < var.MaxThrow then var.MaxThrow = Wiimote.gy
      endif
   endif
else

   if var.ReachBack
      if var.GetAngle = false
         if var.Count < 5
            if Wiimote.gy > var.Angle then var.Angle = Wiimote.gy
            var.Count++
         else
            var.MaxThrow = abs(var.MaxThrow + 1)
            var.GetAngle = true
         endif
      else
         var.Released = true
      endif
   endif
endif

if var.Released
   var.Distance = (var.MaxThrow + var.Angle) * 200
   if var.Distance > 1800 then var.Distance = 1700
   var.Rumble = var.Distance
   var.Count = 0
   var.MaxThrow = 0
   var.Angle = 0
   var.ReachBack = false
   var.GetAngle = false
   var.InAir = true
   var.LineStrength = 100
   var.Released = false
endif

if var.OnHook

   if var.LineStrength <= 0 || var.Distance >= 1800
      var.Rumble = 50
      var.LineBreak = true
      var.OnHook = false
   else
      if var.Distance <=0
      var.Rumble = 100
      var.Caught = true
      var.OnHook = false
      endif
   endif

   if true
      var.BiteWait = (RandomRange(3000,10000) - (3 * var.FishSize))
      wait var.BiteWait ms
      var.FishFighting = true
      var.BiteWait = (RandomRange(100,2000) + var.FishSize)
      wait var.BiteWait ms
      var.FishFighting = false
   endif

   if var.FishFighting = false
      if (Wiimote.Nunchuk.gy < -0.5, Wiimote.Nunchuk.gy >1) || (Wiimote.Nunchuk.gz < -1, Wiimote.Nunchuk.gz > 1)
         var.Distance = var.Distance - 10
         var.LineStrength = var.LineStrength - var.FishSize/50
         var.Rumble = 20
         wait 20ms
      else
         if var.LineStrength <= 100 then var.LineStrength = var.LineStrength + 3
      endif
   else
      var.Distance = var.Distance + var.FishSize/50
      if var.LineStrength >= 10 then var.LineStrength = var.LineStrength - var.FishSize/50
      if (Wiimote.Nunchuk.gy < -0.5, Wiimote.Nunchuk.gy >1) || (Wiimote.Nunchuk.gz < -1, Wiimote.Nunchuk.gz > 1)
         var.Distance = var.Distance + var.FishSize/20
         var.LineStrength = var.LineStrength - var.FishSize/50
      endif
      var.Rumble = RandomRange(20,300)
   endif
endif

if var.Caught
   Say ("Yippie")
   wait 10s
   var.Distance = 0
   var.Caught = false
endif

if var.LineBreak
   Say ("Snap")
   wait 10s
   var.Distance = 0
   var.LineBreak = false
endif

//Waiting for fish
if var.InWater
   //Flick
   if Wiimote.gy > 1.5 && Wiimote.gz < -1
      var.Flick = true
      var.Rumble = Wiimote.gy + abs(Wiimote.gz < -1) * 100
      wait 25ms
      var.Flick = false
      wait 200ms
   endif

   if var.Bite = false
      wait RandomRange(1000,6000) ms
      var.FishSize = RandomRange(20,300)
      var.Rumble = var.FishSize
      var.Bite = true
   else
      var.BiteCount++
      if var.BiteCount <= 10
         if var.Flick = true
            if var.FishSize < 50
               var.FishType = "Goldfish"
            elseif var.FishSize < 100
               var.FishType = "Perch"
            elseif var.FishSize < 150
               var.FishType = "Bass"
            elseif var.FishSize < 200
               var.FishType = "Trout"
            elseif var.FishSize < 250
               var.FishType = "Pike"
            else
               var.FishType = "Salmon"
            endif
            var.BiteCount = 0
            var.OnHook = true
            var.InWater = false
            var.Bite = false
         endif
      else
        var.Bite = false
        var.BiteCount = 0
      endif
   endif
endif

//Leds
if var.Caught
   Wiimote.Leds = 15
   wait 100ms
   Wiimote.Leds = 0
   wait 100ms
elseif var.LineBreak
   Wiimote.Leds = 15
elseif var.OnHook
   if var.LineStrength > 0
      Wiimote.Leds = 6
      wait var.LineStrength ms
      Wiimote.Leds = 9
      wait var.LineStrength ms
   endif
elseif var.InWater
   Wiimote.Leds = 15
elseif var.InAir
   var.LedWait = var.Distance/8
   Wiimote.Leds = 1
   wait var.LedWait ms
   Wiimote.Leds = 3
   wait var.LedWait ms
   Wiimote.Leds = 7
   wait var.LedWait ms
   Wiimote.Leds = 15
   wait (var.LedWait*2 ms)
   Wiimote.Leds = 7
   wait var.LedWait ms
   Wiimote.Leds = 3
   wait var.LedWait ms
   Wiimote.Leds = 1
   wait var.LedWait ms
   var.InAir = false
   var.InWater = true
elseif var.ReachBack
   Wiimote.Leds = 6
else
   Wiimote.Leds = 0
endif

if var.Rumble > 0
   Wiimote.Rumble = true
   wait var.Rumble ms
   Wiimote.Rumble = false
   var.Rumble = 0
endif

if var.Caught
   debug = "Congratulations! You caught a " + var.FishType
elseif var.LineBreak
   debug = "Sorry, the line broke. Try Again."
else
   debug = "Distance: " + var.Distance
endif
Personal tools
Online Casino - best online casino reviews.
Facebook Developers - facebook applications, facebook developers, facebook development, social network application development and viral widget social media strategy