Post new topic    
Page «  1, 2, 3, 4, 5, 6  »
Slime Knight
Send private message
 
 PostFri Dec 19, 2014 12:48 am
Send private message Reply with quote
I've once again swum ut beyond my depth... Hurr
I'm attempting a few things in this project, One is to display a player score, the next is to have a gun powerup for player use, the last is one that I thought I had gotten working, but hadn't. Getting the Esc key to instantly run the game over command, thus exiting the game without showing the player menu.

... so while typing this I figured out the score issue I was having... A winner is me.

The next one is the bigger one. Having a gun powerup that will make it so pressing space bar will fire a projectile that will travel in a straight line in the direction the player was facing when they fired it. That will, when it hits a valid target NPC will run a script to remove said NPC (either with a delete NPC script, or a tag set, haven't decided yet) and increment the score by an amount.

I realize that this is probably a bit tricky. I was trying to use scripts from Space InvadeOHRs, but I'm wondering if I should scrap that and just try to build some from the ground up.

I feel like can achieve this with scripts to create and move slices, though I am a novice with slices. It seems that I could make a script that would be triggered by a key press. Something that would check tags or inventory to see if the powerup is there and has ammo. If so, the script would create either a a walkabout slice of the projectile, or create a rectangle at 2x2 pixels (or something) and remove one unit of ammo. (prob an inventory item)

After the slice is created, it would move until it left the screen or hit a valid target, at which point it would disappear. Could something like this be achieved with the "Move Slice to" command? Perhaps implementing a pixel by pixel, or tile by tile check to see if the slice occupies the same space as the enemy target...

I know this is all very convoluted sounding, and I'm not familiar enough with the scripting commands to probably make much sense. One of the reasons I'm typing these queries out is that it helps me organize my thoughts and clear my thinking. (as I said, while typing I figured out the score issue)

In any case, as always any help (tips, advice, comments, death threats, etc.) would be appreciated. If not, then have a nice night anyway Grin
Metal King Slime
Send private message
 
 PostFri Dec 19, 2014 5:32 am
Send private message Reply with quote
There's a lot of good ways to do this, slices are basically the perfect tool for the job. And if you can get even a little good with 'em, you'll have a leg up on damn naar everyone when it comes to doin cool stuff! Two commands that TMC and RMSephy have turned me onto recently is SetSliceVelocity and FindCollidingSlice.

Set Slice Velocity lets you tell a certain slice to start moving in a certain direction at a certain speed indefinitely, which is basically perfect for shots. Find Colliding Slice lets you specify a certain parent slice, and checks to see if a given slice is colliding with any of that first slice's children. So if all of your enemies are parented to a slice called "Enemies", you could do something like

Code:

#Creates a variable and sets it to the slice ID of the enemy that our shot
#has hit, or 0 if nobody's been hit. In a game, I'd probably check this
#for each shot.
variable (HitHelper)
HitHelper := FindCollidingSlice (Enemies,Shot)

#If you hit something...
If (HitHelper)
then (
        #Free the slice you hit
        FreeSlice (HitHelper)
        )


Though obviously in a real game and not an example on a forum you'd want to do some kind of cool explosion effect rather than just making the thing suddenly vanish. Presumably you'd want to make your shot disappear too, or maybe you'd want to let your shot keep on truckin and rack up a sweet multi-kill. If you wanted, you could even parent that enemy slice to a new parent, something like "DyingDudes" so that it wouldn't keep getting hit while it exploded, and would let you apply all of your death animation effects later on at once. But I'm gettin ahead of myself!

This is another great trick you might use, a secret hiding in plain sight: NextSibling. Using this, you can cycle through every child of a certain slice and do all kinds of stuff pretty quick. Like, say that DyingDudes slice I talked about, you could go through every slice that's in its death throes, advance its animation a step each tick, and then free the slice after it'd had its dramatic send off. I don't know if it was TMC or James or who who put that tutorial in there, but it's powerful, powerful magic and whoever came up with it is elligible for wizard-hood. Or you could go through all your enemies and make them try to chase the hero. Or you could go through all your shots for your FindCollidingSlice thing.

One thing you shouldn't try to do (And again, this is TMC's advice to me that I'm passing on, because I did it this way and he freaked) is use two of those NextSibling kind of loops and the "SliceCollide" command to try to manually find every colliding slice. Apparently FindCollidingSlice works at a baser, faster level of the engine than an equal number of "SliceCollides" and there will be a definite performance drop.

And my final advice, and hopefully I'm not pilin too much on you at once or gettin you too confused or anything, because the last thing I want to do is turn away someone enthusiastic about doing cool stuff instead of boring old RPGs, is that you should use rectangle slices for your collisions, even if you put a sprite on top of them for prettiness sake. Why? Because I think (And I could be wrong) that "Collision" for slices is detected only by the size of the slice, so a Walkabout Slice would be a 20x20 square, even if you've only drawn a 2x2 square in the middle, which means that it would "Collide" with a slice while it was still hitting air in the eyes of the player. Using a rectangle (Or a container maybe, now that I think of it) will let you fine tune collisions so that they match up more closely with when the sprites are actually overlapping. Like the hitboxes on the debug of a fighting game, if you've ever seen that.

Best of luck! Keep asking questions, and keep on typing to figure stuff out. It always helps more when you type it out "for real" to otehr people rather than just talking to the wall, it seems.
Slime Knight
Send private message
 
 PostFri Dec 19, 2014 3:05 pm
Send private message Reply with quote
Wow, that's a lot to take in at one time! Fortunately, I find all of it quite encouraging!

I appreciate all the information, and links that you posted. I spend a lot of tie scanning, or word-searching through the Plotscripting dictionary, but not knowing exactly what it is I'm looking for. So it's great when someone knows a specific code, or command and is able to pinpoint it!

It seems like the scripts you have posted, and linked to will allow e to do pretty much exactly what I'm looking for (and then some!). The game I'm designing should be a good testing ground for trial and error with this since it is so primitive (sprites abruptly disappearing, or simply freezing in place after a hit is what I'm looking for)

Before I get rambling on too much, I'll simply once again say Thank you! For the help as well as the encouragement. A lot of times when I post here, I"m afraid that I'm annoying people with dumb questions, but mostly people seem quite willing to help.

I'll update in a bit with info on progress, and most likely, more dumb questions! Hurr
Slime Knight
Send private message
 
 PostSat Dec 20, 2014 3:31 am
Send private message Reply with quote
Okay... So, I've been trying some stuff out and attempting to wrap my brain around working with slices. I've checked out some other threads for ideas, as well as reading through the plotscripting dictionary to try and familiarize myself with some of the functions

I attempted to try out some scripting, and came up with this...

Code:

plotscript, fireshot, begin
variable(bullet, sl)
bullet := create rect (2, 2, 2),
put slice (0, hero x, hero y),
if (hero direction (me) ==right)
then
set slice velocity (bullet, 2, 0,75),
(play sound (21,false,false))
end


This is obviously still in progress, and if I'm being an idiot, or an completely on the wrong track, feel free to let me know. I'm still pretty fuzzy on slices, having only ever used them in the walktall scripts which are very basic. Trying to learn about slice handles, collections, etc, and how they relate to one another.

Anyhow, though I'm frustrated at my lack of knowledge, and slow pace of learning, I'm still plugging along. If I get too stuck, I can do an initial version of my game with no projectiles, but It would be so much cooler to know how to do it.

And again, thanks to all you wonderful Slimes!
Metal King Slime
Send private message
 
 PostSat Dec 20, 2014 6:47 am
Send private message Reply with quote
Lookin good so far! My only warning is, if your game is going to be bigger than one screen (Which given your Atari 2600 goal, might not be the case) then you're going to run into the same problem using HeroX and HeroY as in this thread and can use the same solution James posted in there.
Red Slime
Send private message
 
 PostSat Dec 20, 2014 8:12 am
Send private message Reply with quote
Some really cool ideas. Maybe you could release as stand-alone game?
Metal King Slime
Send private message
 
 PostSat Dec 20, 2014 9:28 am
Send private message Reply with quote
dantedynamite wrote:
Some really cool ideas. Maybe you could release as stand-alone game?


What do you mean? Don't you think that's why he's asking the questions in the first place?
Metal King Slime
Send private message
 
 PostSat Dec 20, 2014 10:05 am
Send private message Reply with quote
Comments on that fireshot script:

Firstly, there's no reason to put commas at the end of each line (they are ignored). Second, you need to put ( or 'begin' after 'then'. It looks like you slotted in "set slice velocity" in the wrong place.

Slice positions are always measured in pixels rather than tiles. "hero x/y" returns the hero position in tiles. You want to use the "hero pixel x/y" commands instead.

Finally, the first argument to "put slice" shoudl be "bullet", not 0.
Liquid Metal Slime
Send private message
 
 PostSat Dec 20, 2014 7:08 pm
Send private message Reply with quote
Gizmog wrote:
Code:

#Creates a variable and sets it to the slice ID of the enemy that our shot
#has hit, or 0 if nobody's been hit. In a game, I'd probably check this
#for each shot.
variable (HitHelper)
HitHelper := FindCollidingSlice (Enemies,Shot)

#If you hit something...
If (HitHelper)
then (
        #Free the slice you hit
        FreeSlice (HitHelper)
        )



It seems I'm trying to do the exact same thing so I might as well join this threads conversation.

Regarding the code I quoted above, how do I go about assigning a rectangle slice in the form of a child to each of my enemy sprites? I have all my guard enemies drawn in the form of hero sprites and patrolling around my map as individual NPC instances. I'll try to look for some tutorials in the mean time.

In short I have 4 enemy NPC's on my map and want to apply an invisible rectangle (hit box) to each of them, thus when the bullet collides with the hit box that NPC will die.

EDIT: I have since made the hitboxes and lined them up with my enemies so that hitbox1 lines up with NPC(0), hitbox2 with NPC(1)...etc... I'm really struggling to get this collision thing working though.

My hitboxes are parented to "get NPC slice (0), (1), (2)..."
My Bullets are parented to walkabout layer, if that helps.
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
⍠ C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
Slime Knight
Send private message
 
 PostSat Dec 20, 2014 11:10 pm
Send private message Reply with quote
Hey, you're doing better than me! V

At least you've got some bullets firing, I'm still working on that. as it is now, one of my scripts is causing another to go into an infinite loop (that's the error anyway)

SheamKennedy, I checked out your scripts from the other thread, and I think they will be helpful to me in my endeavors. If I could just figure out these slice functions. For whatever reason, the whole concept of working with slices hasn't clicked yet.
Slime Knight
Send private message
 
 PostSun Dec 21, 2014 2:07 am
Send private message Reply with quote
Ahhh... my favorite part of the day. Annoying TMC, (and other users) with my bad coding!... sigh

I'm still trying to add a gun powerup to my game, but I'm having... trouble... anyway, on to my nonsense.


Code:
plotscript, ending, begin #a map autorun script for each screen in
                                             #the game used for checking the amount
                                             #of levers pulled, 6 to win.
   stop sound (18),
   wait (3)

   while (lever >5) do (titlescreen)

   if (key is pressed (key:Esc))then (exit) #still having trouble
                                                                 #with bypassing the menu
   while (check tag (12)== true)             
   do                                            #tag 12 is set on by having
      (shootabullet)                    #the ammo item in your inventor
   wait (2)
end

   
plotscript, exit, begin
   wait (3), game over
end

#I tried adjusting Sheamkennedy's scripts to use
#with my projectile mechanics, as it is now, it does some
#very bizarre things. sometimes giving errors,
#firing projectiles without the key being pressed,
#It deletes multiple inventory items when I want it
#to only delete one per shot.
#I'm hopeful that I've just made some stupid mistakes again
#But after trying on my own all day, I decided I should
#just ask the slimes

plotscript, shootabullet, begin
   variable(sl, isshooting, bullet)
   if(key is pressed(key:space)) then(
      if(isShooting <> 1) then(
         isShooting := 1
         if(hero direction (me)== right) then(
            bullet := create rect (2, 2, 2)
            put slice (bullet, hero pixel x, hero pixel y)
            set slice velocity x (bullet, -20, 10)
            set slice velocity y (bullet, 0, 10)
               (play sound (21,false,false))
            delete item (item:shell, 1)
            isShooting := 0
            exit script
         )
      )
      if(hero direction (me)== left) then(
         bullet := create rect (2, 2, 2)
         put slice (bullet, hero pixel x, hero pixel y)
         set slice velocity x (bullet, -20, 10)
         set slice velocity y (bullet, 0, 10)
            (play sound (21,false,false))
         delete item (item:shell, 1)
         isShooting := 0
         exit script
      )
   )

   if(hero direction (me)== up) then(
      bullet := create rect (2, 2, 2)
      put slice (bullet, hero pixel x, hero pixel y)
      set slice velocity x (bullet, 0, 10)
      set slice velocity y (bullet, -20, 10)
         (play sound (21,false,false))
      delete item (item:shell, 1)
      isShooting := 0
      exit script
   )
   if(hero direction(me)== down) then(
      bullet := create rect (2, 2, 2)
      put slice (bullet, hero pixel x, hero pixel y)
      set slice velocity x (bullet, 0, 10)
      set slice velocity y (bullet, 20, 10)
         (play sound (21,false,false))
      delete item (item:shell, 1)
      isShooting := 0
      exit script
   )
   isShooting := 0

end

Metal King Slime
Send private message
 
 PostSun Dec 21, 2014 3:10 am
Send private message Reply with quote
I've never thought about how to do this with NPCs before, so I'm gonna be making it up as I go along. What you're going to want is something really smooth and elegant to check all of them at once. To my eye, that means cycling through everything using the NextSibling family of commands. Because of that, parenting them to the NPC's Slice component might not be the best idea in the world.

Go to your map with the enemies and hit Ctrl+F4 to open up the Slice Debug menu. There'll be a container in there called "walkabout layer", and inside there'll be a bunch of containers with "WalkaboutSpriteComponent" slices inside of them. Presumably there'll be some with hitboxes in there also, and those are gonna be your NPCs. The rest are gonna be the heroes. That means we can differentiate one from the other, which is good!

What I'd do is add a lookup code to your hitbox slice. If you're loading a slice collection and parenting that to your NPC Slices, then open up the Slice Collection editor in custom, find your hitbox collection, go down to lookup and set something up. Don't forget to export your .hsi after!

If you're using the CreateContainer/Rectangle/Whatever commands, you're still going to have to set up a lookup code in the editor and export your HSI. Don't forget to include it in your scripts! After you've done that, tack in a SetSliceLookup for the hitbox. While you're at it, throw in a SetSliceExtra and set the Zeroth extra value to the number of the NPC you're gonna parent it to. That'll make things easier later!

So right now, the code is gonna look something like...
Code:

script,MakeHitbox,WhichNPC,begin

Hitbox := CreateContainer (8,8)

#We probably don't want our hitbox on the upper left corner of the NPC..
CenterSlice (Hitbox)

SetSliceLookup (HitBox,sli:ImAHitBox)
SetSliceExtra (HitBox,0,WhichNPC)
setparent (Hitbox,GetNPCSlice (WhichNPC))


and after we run it once for all of our NPCs (Who hopefully each have a distinct ID! TMC is gonna yell at me for not doing NPC References, but I don't understand how they work. For the sake of this example, we're going to assume there's only one copy of each NPC we want to blow up. One of NPC 1, One of NPC 2, etc. I'm also not sure what's going to happen when we destroy the NPC! It's gonna be an adventure, it's gonna be fun.) then we're gonna have NPCs with hitboxes runnin around. But what about when they need to hit something?

Okay, so now we're going to cycle through all of our NPCs. Now, we have to be careful because presumably not all of our NPCs have hitboxes, and as far as the engine is concerned, the HeroWalkabout is the same as the NPC walkabout. We'd start with like...

Code:

script,HitStuff,begin
variable (WhichVictim)
variable (VictimBox)
#Finds the first NPC in the walkabout layer..
WhichVictim := firstchild (lookup slice(sl:walkabout layer))

#Checks all of the NPCs in the walkabout layer..
while (WhichVictim)
do (
 
 #If the current NPC has a hitbox...
  WhichBox := lookupslice (sli:ImAHitBox,WhichVictim)
  if (WhichBox)
 
  #See if anything is hitting it!
  then (CollisionCheck (WhichBox))

  #Next victim, please! If there's no victim, then WhichVictim will be 0,
  #and 0 means false, and the While Loop will close.
  WhichVictim := NextSibling (WhichVictim)

  #Fun fact: Because there's no wait in this while loop, it'll check all of them SUPER FAST
  )
)

end

script,CollisionCheck,WhoCollided,begin
if (SliceCollide (WhoCollided,PlayerShot))
then (
   #Remember how we wrote down what NPC the slice was parented to?
   #This is why! We check that now and blow that NPC the F up
    DestroyNPC (GetSliceExtra (WhoCollided,0))
  )
end


That's... something what it'd look like. There's a lot of problems with this, it's assuming there's only one shot to be checked, which may not be a bad assumption. Ideally we'd have this three ring circus of

Code:


while (whatever)
do (
     CheckPlayerInput
     MoveStuff
     CheckCollisions/Interactions
     VisualStuff 
     wait (1)
     )


Where we could have a bunch of while loops that'd see what the player wants done, move the player and NPCs accordingly, see if anyone is somewhere they aren't supposed to be and put 'em back, see if anything needs to explode and mark them accordingly, set everyone to their new visual appearance, and then wait (1) just that one time so that, in the players perspective, everything updates just once a tick and it's all super smooth and cool. We're obviously a little bitp ast that point, so I'm willing to throw bad money after good.

Now, if we were clever, we could parent a container to the WalkaboutLayer, let's call it "Shots". And when you add a shot, you'd parent it to Shots instead of the walkabout layer, because the walkabout layer is its grandparent and the whole thing should add up about the same. And then instead of "if (SliceCollide (WhoCollided,Shot))" we could do "if (FindCollidingSlice (Shots,WhoCollided)" to check EVERY shot, of which there could be many.

I'm tired, I'm confused, this post was way too long but hopefully it'll help a little. I'm worried about the "WaitForSlice" in the shooting script, because I can't imagine it's a good idea to hold up the rest of the script while the shot moves. I'm worried about a few other things that I don't remember.
Metal King Slime
Send private message
 
 PostSun Dec 21, 2014 3:21 am
Send private message Reply with quote
Urkelbot666 wrote:
Ahhh... my favorite part of the day. Annoying TMC, (and other users) with my bad coding!... sigh

I'm still trying to add a gun powerup to my game, but I'm having... trouble... anyway, on to my nonsense....

AND A WHOLE BUNCH OF OTHER STUFF


My first suggestion would be to change
Code:
KeyIsPressed (Whatever)


to

Code:
KeyVal (Whatever) >> 1)


KeyVal is usually better than KeyIsPressed because you can control what situation you want to check for. KeyIsPressed would return true each tick, about 18 times a second. That can make it trigger faster than you really want. KeyVal > 1 means that they key has either been pressed and released in the same tick, or has been newly pressed in this tick, but was not being pressed previously/not being held down/etc. so it doesn't repeat so many times. That could be doing some of it.

It's hard to tell though. If something's giving errors, knowing what the errors are is very important to solving the problem. What kind of errors? What is the script supposed to do and what is happening instead?
Slime Knight
Send private message
 
 PostSun Dec 21, 2014 5:01 pm
Send private message Reply with quote
Haha, re-reading my last post, I see that it was really quite vague... I'll try to elaborate.

I've gone between Key is Pressed (wait(x), and keyval a few times, but I realize that Keyval is what I should be using, thank you
==========================================
Scripts;
Code:

plotscript, ending, begin

   stop sound (18),
   wait (3)

   while (lever >5) do (titlescreen),


   if (keyval(key:Esc)>>1)then (exit)
   while (check tag (12)== true)
   do
   (shootabullet)   

end


Ending -autorun script for each map which checks an incrementing variable.

-If its condition is met, player wins. (currently running the titlescreen script)

-Additionally, I have a keyval >>1 check for the (esc) key to quit playing.

-Additionally, this script stops a looping sound which may have been playing from a previous screen

-Lastly, This script checks if (tag 12) is on, if so, this script is to run the Shootabullet script (Tag 12) is set on by having the "ammo" item in one's inventory.

Known errors:
-Pressing (esc) still brings up the playing menu.
-Entering a new screen with (Tag 12) on crashes the game


Code:

plotscript, shootabullet, begin
variable(sl, isshooting, bullet)
    if(keyval(key:space)>>1) then(
        if(isShooting <> 0) then(
          isShooting := 1
            if(hero direction (me)== right) then(
       bullet := create rect (2, 2, 2)
       put slice (bullet, hero pixel x, hero pixel y)
            set slice velocity x (bullet, 20, 10)
            set slice velocity y (bullet, 0, 10) 
       (play sound (21,false,false)) 
       delete item (item:shell, 1)
            isShooting := 0
            exit script
          ) )
etc...


ShootaBullet
-Runs if (tag 12) is on.
-When Key (currently "space") is pressed the direction the hero is facing is checked.

-a 2x2 rectangle (bullet) is created

-the bullet will shoot in the direction the player is facing

-The bullet will continue indefinitely, flying offscreen

-(to be implemented) -If the bullet hits an enemy, the Enemy's (NPC is there) tag is set to off, so the enemy is gone, but will return in that
screen if revisited (will be added to "ending" script.

-A shot firing sound will play

-One "ammo" item is deleted from the player's inventory


Known errors:
-Entering a new screen with (tag 12) on causes the game to freeze after about 1 step

-Error will appear, Choosing to ignore the error leaves a black screen until a key is pressed, bringing the error up again.



-NEW DEVELOPMENT-

While (tag 12) is on, and the player goes to a North screen

-the error does NOT appear. However as soon as the player appears in the north room, a bullet automatically fires north without (space) being pushed

-Additionally, all four "ammo" items obtained from getting the "Gun" powerup are deleted from the inventory.

Code:

plotscript,steps2, begin
   play sound (20, false, false),
   setup score

Steps2
- This is an each step script used for playing a footstep sound and updating the player's score

-No known errors, but included since it is also running at the time the game freezes

=====================================
I think that's everything that is going on as of right now.
I'll provide any relevant additional information as I discover it.
Again, thank you for your help and patience to this point, it is greatly appreciated.
Metal King Slime
Send private message
 
 PostSun Dec 21, 2014 6:07 pm
Send private message Reply with quote
I'm confused as hell here. Are you saying the script actually works sometimes? It looks like as soon as Lever is greater than 5, the game returns to the title screen, which would prevent anything too bad from happening. But with "while (CheckTag (12))", it looks like as soon as Tag 12 is on, the game is going to go into a death spiral of checking for spacebar, at the expense of doing anything else, hence your error.

Try opening up the Tag Debug editor (F4), use the + - keys to get down to Tag 12, and then hit Ctrl + to turn it on, if it isn't already. I have no idea how auto-run scripts work, so I have no idea if this is trigger every tick or not, but to me it looks like it's only going to fire once, and it's firing once every time you go to a map. So, the first time you go to a map where Tag 12 is true, kerblooie! I think you're doing the while loops wrong.

What it might look like instead is..

Code:

StopSound (18)


#While the lever is less than 5, check all of our commands.
while (Lever >> 5)
do (
     if (KeyVal (Key:Esc) >> 1) then (exit)

    if (CheckTag (12) == true)
    then (ShootABullet)

   #This is the most important of the script. Without it, the game will check
   #if the Escape key has been pressed, and Tag 12 FOREVER, without
   #ever doing anything like.. letting the player move around or showing
   #all the pretty pictures.
    wait (1)
 
   #So long as lever is less than 5, the commands in this Do Bubble will
   #Will repeat until Lever is no longer less than 5
   )

#Thus, if the script is reading this bit, Lever is greater than 5 and the
#time for looping is over and we can do what we wanted to happen when
#Lever is greater than 5
TitleScreen


Basically, a while loop only works if the condition is true when you check. It's like if you say to someone "Hey, while you're in the kitchen, make me a sandwich". If they're not in the kitchen, you're not gonna get a sandwich. And if they ARE in the kitchen, you never told them to leave the kitchen and bring you the sandwich so you can eat it, so they're gonna be stuck in there makin sandwiches forever.

Also, dunno if you were reading the other thread too, but I posted there about how ShootABullet is going to be a pain to tweak later on and I think you're close enough to having something workable that it might be an issue soon.


EDIT: Oh, and as for your menu problem, I'm afraid I don't understand. Do you want the menu to open up sometimes when you hit escape? Or is the escape key always supposed to end the game?
Display posts from previous:
Page «  1, 2, 3, 4, 5, 6  »