Author Topic: Slow-Motion  (Read 6579 times)

gwal

  • Regular
  • **
  • Posts: 69
  • Game Progress: Outer Space / Items
    • View Profile
Slow-Motion
« on: 2005-12-25, 08:36:36 PM »
 Recently when I was working on my game's script, I decided that it would be cool if by pressing the control key, then the player could use 'slow motion' for a few seconds. Right now the script slows down the frame rate, and increases the speed of the player sprite. (So everything else moves slow, but the player is only slowed down a little.) It also subtracts your slo-mo power from the internet. What I'm trying to do is have it subtract 1 from the slo-mo power each frame, but right now it subtracts it all at once. I tried the WaitForFrame line, but it didn't seem to work. Is there any way to do this? This is the code I'm using.

Code: [Select]
Sub Player_OnControllerMove(OldActions, NewActions)
       If (Not OldActions) And NewActions And ACTION_BUTTON3 Then DoFireButton5
End Sub

'slow motion'
Sub DoFireButton5()
 If ProjectObj.GamePlayer.InvQuantityOwned(7) <= 1 Then Exit Sub
 If ProjectObj.GamePlayer.InvQuantityOwned(7) > 1 Then
   ProjectObj.GamePlayer.FrameRateLimit = 30
   ProjectObj.GamePlayer.rMap.SpriteTemplates("player").MoveSpeed = 5
   LoseSloMo     
   ProjectObj.GamePlayer.FrameRateLimit = 60
   ProjectObj.GamePlayer.rMap.SpriteTemplates("player").MoveSpeed = 3
 End If
End Sub

Sub LoseSloMo
 ProjectObj.GamePlayer.InvQuantityOwned(7) = ProjectObj.GamePlayer.InvQuantityOwned(7) - 1
  If ProjectObj.GamePlayer.InvQuantityOwned(7) <= 1 Then Exit Sub
  If ProjectObj.GamePlayer.InvQuantityOwned(7) > 1 Then
    LoseSloMo
  End If
End Sub

HostObj.SinkObjectEvents ProjectObj.GamePlayer, "Player"
HostObj.ConnectEventsNow()
ProjectObj.GamePlayer.Play 16


Note: Between OnControllerMove and slow motion there is more code for shooting, and other things which are generated by the scripting wizard. Since I don't think they would have any effect on the slow motion, i didn't include them.

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: Slow-Motion
« Reply #1 on: 2005-12-27, 10:04:50 AM »
Well, that would call all of those at once, of course.  Instead, you should check each frame (in onAfterMoveSprites) if they are in "Slow-Motion" mode (have a variable set when they press the button and unset it as soon as they run out of the inventory) and if they are, then subtract one from the inventory.  If the inventory reaches 0 then reset the "Slow-Motion" variable.  It would be something like this:

Code: [Select]
Dim SlowMo
SlowMo = false

Sub Player_OnControllerMove(OldActions, NewActions)
       If (Not OldActions) And NewActions And ACTION_BUTTON3 Then
               SlowMo = True
               ProjectObj.GamePlayer.FrameRateLimit = 30
               ProjectObj.GamePlayer.rMap.SpriteTemplates("player").MoveSpeed = 5
       End If
End Sub

Sub Player_OnAfterMoveSprites()
       if SlowMo then
               ProjectObj.GamePlayer.InvQuantityOwned(7) = ProjectObj.GamePlayer.InvQuantityOwned(7) - 1
               if  ProjectObj.GamePlayer.InvQuantityOwned(7) <= 1
                       ProjectObj.GamePlayer.InvQuantityOwned(7) = 1
                       SlowMo = false
                       ProjectObj.GamePlayer.FrameRateLimit = 60
                       ProjectObj.GamePlayer.rMap.SpriteTemplates("player").MoveSpeed = 3
               end if
       end if
End Sub

HostObj.SinkObjectEvents ProjectObj.GamePlayer, "Player"
HostObj.ConnectEventsNow()
ProjectObj.GamePlayer.Play 16

Note, I haven't tested this, but it may very well work.
Edward Dassmesser

gwal

  • Regular
  • **
  • Posts: 69
  • Game Progress: Outer Space / Items
    • View Profile
Re: Slow-Motion
« Reply #2 on: 2005-12-27, 04:23:38 PM »
OK, so I implemented the changes in the script, but right now when I press the control key, it goes into slow motion and it won't stop. Also, the slomo item isn't being subtracted. (But then again, the player has 150 of it on a small bar so maybe I just can't see it). I'm not sure where to go from here.

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: Slow-Motion
« Reply #3 on: 2005-12-27, 07:28:34 PM »
try changing

Code: [Select]
Sub Player_OnAfterMoveSprites()
       if SlowMo then

to

Code: [Select]
Sub Player_OnAfterMoveSprites()
       if SlowMo = True then
Edward Dassmesser

gwal

  • Regular
  • **
  • Posts: 69
  • Game Progress: Outer Space / Items
    • View Profile
Re: Slow-Motion
« Reply #4 on: 2005-12-31, 12:00:41 AM »
Ok, I would have replied earlier, but I've been on vacation. I added the changes and when I started up the game, it wouldn't work untill I changed:
Code: [Select]
If  ProjectObj.GamePlayer.InvQuantityOwned(7) <= 1to
Code: [Select]
If  ProjectObj.GamePlayer.InvQuantityOwned(7) <= 1 ThenThis made perfect sense to me. However, changing these two lines still hasn't fixed the problem, and I'm not sure what to do now. Right now the game goes into slomo fine, but then it won't stop. Sorry if I sound annoying, but although I've been using gamedev for a while, I don't know too much about scripting.

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Slow-Motion
« Reply #5 on: 2005-12-31, 09:01:01 AM »
If you show inventory item number 8 on the screen (this is what InvQuantityOwned(7) from script refers to because the script starts at 0, but the player dialog starts at 1), can you see the quantity going down?

gwal

  • Regular
  • **
  • Posts: 69
  • Game Progress: Outer Space / Items
    • View Profile
Re: Slow-Motion
« Reply #6 on: 2005-12-31, 02:01:33 PM »
No. Item #8 (in the inventory, so it's #7 in the script), is already being displayed on the screen as a small vertical bar. The quantity on the screen isn't changing.

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Slow-Motion
« Reply #7 on: 2005-12-31, 02:22:37 PM »
What is the value that it's "stuck" at?  Some relatively large positive value?  Can you estimate?  (10? 100? 1000? 10000?)

gwal

  • Regular
  • **
  • Posts: 69
  • Game Progress: Outer Space / Items
    • View Profile
Re: Slow-Motion
« Reply #8 on: 2005-12-31, 02:26:23 PM »
Well, the player starts out with 150 slow motion. (max and initial quantity, though the max quantity of the slow motion can be increased throughout the game). Since I can't see a change in the bar when I activate slow motion, I'm guessing it's either at 150 or 149.

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: Slow-Motion
« Reply #9 on: 2005-12-31, 09:13:01 PM »
Is there any function that automatically replenishes the slowmotion?  or anything like that that may be affecting it?
Edward Dassmesser

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Slow-Motion
« Reply #10 on: 2005-12-31, 11:29:31 PM »
If you don't already have it, try adding "Option Explicit" as the first line of the script.  It will force all your variables to be declared thereby ensuring that all your variables are typed/spelled correctly.  Did you copy/paste the script or type it manually?  Maybe if you increase the max quantity to 300 or so you can tell if something is automatically constantly increasing the inventory quantity (it should stay below 150 right?)

gwal

  • Regular
  • **
  • Posts: 69
  • Game Progress: Outer Space / Items
    • View Profile
Re: Slow-Motion
« Reply #11 on: 2006-01-01, 12:47:04 PM »
First of all, to answer Durnurd's question, there is no function right now that replenishes the slomotion power.
I changed the max quantity of slomo power to 300, but when I go into slow motion, I still can't see a difference in the inventory.
Yes, the script was copy/pasted.
I added Option Explicit to the top of the script, but now when I try to play the game two error messages pop up. The first one says:
Error Playing Map: tried to draw text when no drawing surface is available
The second message says: Script stopped at line 120 at character 4: variable is undefined: 'SloMo'.
Line 120 is the line after OnAfterMoveSprites.
Code: [Select]
Sub Player_OnAfterMoveSprites
   If SlowMo = True Then

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Slow-Motion
« Reply #12 on: 2006-01-01, 09:03:23 PM »
Well, according to the error message, it says "SloMo" and not "SlowMo"  Check the code very carefully to see if there is a discrepancy in the variable name.

gwal

  • Regular
  • **
  • Posts: 69
  • Game Progress: Outer Space / Items
    • View Profile
Re: Slow-Motion
« Reply #13 on: 2006-01-01, 10:49:34 PM »
That was the problem. I changed everything which said slomo in some form or another to SlowMo, and it works fine now!
Thanks for all the help.  8)