Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - ragingmime

Pages: [1]
1
Script / Re: mouse aiming and shooting script
« on: 2006-06-20, 09:29:20 PM »
If you need more of the gory details on how to get mouse aiming/shooting working, check out this thread that I started when I had some problems with a Megaman Fangame that I'd been working on.

2
Script / waiting in script/special functions
« on: 2006-03-04, 09:44:28 PM »
I'm setting up a special function that, when a player collides with an enemy, will replace the player with a "hurt" sprite (which won't collide with enemies), wait for a few seconds, and then switch back to the player sprite. Is there any way to implement this waiting period in special functions or script? (I mean, I guess I could just put a for loop or a counting function that executes every frame in the script, but there's got to be a more elegant solution than that.

[edit]: I've been poking around in the code reference, and I came across the OnFrameStart event. I've got the framerate capped, so I guess I could increment a variable every frame, and when the player gets hit I could store the current frame number. Once the difference between the current and stored frame number reaches X, I could switch back. But that's (relatively) slow and inelegant. (Plus, having a variable that constantly increases forever would probably crash the game if it were left on long enough, so that's probably not a good idea). Am I missing something that's right in my face, or should I go ahead and start coding what I've described?

Thanks in advance.

3
Script / Re: Mouse Aiming/sthooting
« on: 2006-02-11, 12:14:04 AM »
Thanks! I've edited your code to simplify it a little and to make it work within the shooting script:

Code: [Select]
Function GetStateDeltas(DX, DY)
     With ProjectObj.GamePlayer
        cX = .rMap.MapLayer(1).Sprite(AimSpriteIdx).X    'Or, alternatively, this could just be cX = X and cY=Y if calling from a MouseDown event
        cY = .rMap.MapLayer(1).Sprite(AimSpriteIdx).Y    'This is assuming that the crosshairs is on a layer with a scrollrate of 0 in both directions
        pX = .PlayerSprite.X - .MapScrollX - .rMap.ViewLeft    'I'm not sure if this is entirely correct, but what I'm trying to do is get the distance the player
        pY = .PlayerSprite.Y - .MapScrollY - .rMap.ViewTop   'is from the edge of the screen, not the edge of the map, so that the distance to the crosshairs is correct
    End With
    DistToReticleX = cX - pX
    DistToReticleY = cY - pY
    'calculate the hypotenuse of the triangle (the other sides being thedx and thedy) so that we can find the cosine and sine of the angle that's opposite to the hypotenuse - i.e. the angle between the player and the reticle. The hypotenuse, then, is the line between the player and the targeting reticle.
    hypot = sqr(DistToReticleX * DistToReticleX + DistToReticleY * DistToReticleY)
    'get cosine
    DX = DistToReticleX/hypot
    DY = DistToReticleY/hypot
 End Function

This code makes the mouse button shoot:
Code: [Select]
Sub Display_MouseDown(Button, Shift, X, Y)
   Dim NewSpr, DX, DY
   If nShot1Count >= 3 Then Exit Sub
   Set NewSpr = ProjectObj.GamePlayer.rMap.SpriteDefs("bullet").MakeInstance
   Set arBtn1Shots(nShot1Count) = NewSpr
   nShot1Count = nShot1Count + 1
   With ProjectObj.GamePlayer.PlayerSprite
      .rDef.rLayer.AddSprite HostObj.AsObject(NewSpr)
      nExpectCount = nExpectCount + 1
      NewSpr.X = .X + (.Width - NewSpr.Width) / 2
      NewSpr.Y = .Y + (.Height - NewSpr.Height) / 2
      GetStateDeltas DX, DY
      NewSpr.DX = DX * NewSpr.rDef.Template.MoveSpeed
      NewSpr.DY = DY * NewSpr.rDef.Template.MoveSpeed
      If NewSpr.rDef.Template.StateCount = 36 Then NewSpr.CurState = RectToPolarState(DX, DY)
   End With
End Sub

Thanks again for all your help! In case you're curious, this is what I'm working on. You can see a screenshot here.

4
Script / Re: Mouse Aiming/sthooting
« on: 2006-02-08, 09:47:18 PM »
I'm going to pass the x and y coordinates of the reticle to the shooting function. That function will use trigonometry and the x and y coordinates to determine the angle at which the projectile should be shot (i.e., angle = inverse tangent of y/x). So it does create a sprite (a bullet) relative to the "aim" sprite, but it only uses variables that have been defined within the script to do so.

The main reason that I want to put the "aim" sprite on its own layer is so that it won't scroll with the rest of the sprites. That way, it'll only move if the user moves the mouse. Will I take a performance hit for that?

Restarting the level uses a special function defined in the windowed map dialogue, not the full-screen editor. Maybe that's why OnSpecialEvent doesn't get triggered when I restart.

5
Script / Re: Mouse Aiming/sthooting
« on: 2006-02-08, 07:20:21 PM »
Durnurd, you are my hero. Thanks a million.

There are still a few quirks (e.g. if you restart the level, you'll have to make sure to run FindAim again), but otherwise it works beautifully. I'm thinking about putting aim on its own layer, which should solve all the problems. (By the way, for anyone who wants to use the themselves, make sure to remove the parentheses on the line with the "for" or else GameDev will get angry).

I have crosshairs! Hooray!

6
Script / Re: Mouse Aiming/sthooting
« on: 2006-02-08, 04:00:16 PM »
Okay, I get it. Thanks!

The crosshairs now move with the mouse with this code:
Code: [Select]
Sub Display_MouseMove(Button, Shift, X, Y)
With ProjectObj.GamePlayer
.rMap.MapLayer(0).Sprite(14).X = X + .MapScrollX - .rMap.ViewLeft
.rMap.MapLayer(0).Sprite(14).Y = Y + .MapScrollY - .rMap.ViewTop
End With
End Sub
                   
HostObj.SinkObjectEvents CurrentDisplay, "Display"
HostObj.SinkObjectEvents ProjectObj.GamePlayer, "Player"
HostObj.ConnectEventsNow()

The problem I'm running into now is that when I kill an enemy, the index of my crosshairs sprite changes (there's one less sprite, so it becomes #13 instead of #14) and "I get a subscript out of range." Is there any way to find the index of a given sprite and plug that in instead of hard-coding the number? I poked around in the documentation and found a way of doing the reverse - i.e. getting the sprite definition's name if you have the index - but that doesn't help me, becasue the index is variable while the name is (I assume) static.

Any suggestions? Thanks a lot... you guys are amazingly helpful!

7
Script / Re: Mouse Aiming/sthooting
« on: 2006-02-08, 12:49:28 PM »
Are sprite definitions the same thing as templates? I thought that, at least within the GameDev editor, both sprite templates and specific sprites are named. Are sprites within the editor technically sprite definitions (because you could create multiple sprites with script?) If that's the case, could I refer to the sprite definition by name and then refer to index 0 of that sprite defintion to get the sprite that I see in the editor? How would I do that?

If I'm controlling a sprite with script, do I have to make an instance of the sprite within the script? If I want to get at a sprite that's already there (i.e. initial instance is checked and it exists in the game even without the script running), how do I reference it/figure out its index? (I only see a field for the name in the GameDev editor). Would it be considered a sprite definition, a sprite, or something else?

Sorry to be a pain about this, it's just that this object hierarchy is a little confusing. You guys have been really helpful - thanks again!

8
Script / Re: Mouse Aiming/sthooting
« on: 2006-02-07, 06:36:31 PM »
Okay, I did that and I got the proper error messages. Now, I'm getting another error message and I think the problem is in how I'm referring to the sprites. I guess the sprite is owned by the layer within the map, not by the map as I have it.

The code right now is:

Code: [Select]
#Split == Runtime script (Number 1) ============

Sub Display_MouseMove(Button, Shift, X, Y)
With ProjectObj.GamePlayer
.rMap.Sprite("aim").X = X + .MapScrollX - .rMap.ViewLeft
.rMap.Sprite("aim").Y = Y + .MapScrollY - .rMap.ViewTop
End With
End Sub

But apparently Sprite is owned by Layer. Layer isn't owned by rMap, becuase using .rMap.rLayer.Sprite gives me an error, as does PlayerSprite.rDef.rLayer.Sprite. I've read the reference, but apparently I'm just not understanding something.

Thanks for all your help; I really appreciate it.

9
Script / Re: Mouse Aiming/sthooting
« on: 2006-02-07, 01:52:21 PM »
Thanks; that was probably part of the problem. It seems like the event still isn't being triggered, though, because I can put all kinds of garbage in Display_MouseMove and never get an error:
Code: [Select]

' ===== Initialization Script (Number 0) =======
Sub Player_OnPlayInit()
HostObj.StartScript=1
HostObj.StartScript=2
End Sub

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

#Split == Runtime script (Number 1) ============
'Modified by ragingmime

Sub Display_MouseMove(Button, Shift, X, Y)
With ProjectObj.GamePlayer.rMap
sdfsddsfsa
.Sprite("aim").X = X + .MapScrollX - .rMap.ViewLeft
.Sprite("aim").X = X /0
.Sprite("aim").Y = Y + .MapScrollY - .rMap.ViewTop
End With
End Sub
                   
HostObj.SinkObjectEvents CurrentDisplay, "Display"
HostObj.SinkObjectEvents ProjectObj.GamePlayer, "Player"
HostObj.ConnectEventsNow()

Script number 2 is a shooting script, which runs fine.

Do you see anything else I might be doing wrong? Thanks for all your great help.

10
Script / Re: Mouse Aiming/sthooting
« on: 2006-02-06, 03:50:06 PM »
Thanks! Yep, that does help: now I'm not getting any error messages when I start the game.

The crosshairs sprite (called "aim," using the template "aimtemp" and on the path "aimpath") still isn't moving, though. I've made sure that it's set as an initial instance, that the control is set to "simple (scripted)", that its movement speed is at the maximum (although I'm not sure that matters), etc. The crosshairs sprite appears when the script isn't running, but it of course doesnt' move. When the game is run with the script, the crosshairs sprite still appears but it also doesn't move when I move the mouse. The code right now is:


#Split == Runtime script (Number 1) ============
'Modified by ragingmime

Sub CurrentDisplay_MouseMove(Button, Shift, X, Y)
With ProjectObj.GamePlayer.rMap
.Sprite("aim").X = X + .MapScrollX - .rMap.ViewLeft
.Sprite("aim").Y = Y + .MapScrollY - .rMap.ViewTop
End With
End Sub
                   
HostObj.SinkObjectEvents CurrentDisplay, "Display"
HostObj.SinkObjectEvents ProjectObj.GamePlayer, "Player"
HostObj.ConnectEventsNow()


Can you see anything else that I'm doing wrong?

Thanks a lot!

11
Script / Mouse Aiming/sthooting
« on: 2006-02-05, 03:48:40 PM »
I've set up the wizard-based shooting script in my game, and I'm trying to find a way to use it to let the player aim and shoot with the mouse, a la Abuse.

I've been trying to use the mouse input sample script to make crosshairs that the player can move with the mouse, but the script doesn't work. I get the error "Object Variable or With Block variable not set" when I include this line:
HostObj.SinkObjectEvents CurrentDisplay, "Display"
What's going on? Here's the rest of the script:

Sub CurrentDisplay_MouseMove(Button, Shift, X, Y)
With ProjectObj.GamePlayer
ProjectObj.GamePlayer.rMap.SpriteDefs("aim").X = X + .MapScrollX - .rMap.ViewLeft
ProjectObj.GamePlayer.rMap.SpriteDefs("aim").Y = Y + .MapScrollY - .rMap.ViewTop
End With
End Sub


Also, I don't understand the point of the initialization script area of this sample. It has a connecteventsnow line when there's already a connecteventsnow line in the runtime script. Is this sample from an older version of the game maker? Am I missing something there?

Thanks in advance.

Pages: [1]