Post new topic    
Page «  1, 2, 3, 4, 5, 6  »
Slime Knight
Send private message
 
 PostWed Jan 14, 2015 11:56 pm
Send private message Reply with quote
Thank you very much, Bob the Hamster! I've successfully implemented the scripts you graciously offered, and things seem to be running smoothly, and I don't to worry about my numbered slice handle changing!
Grin
Liquid Metal Slime
Send private message
 
 PostThu Jan 15, 2015 2:49 am
Send private message Reply with quote
@Bob the Hamster:
Hey thanks for the help. The collision detection is still not recognizing a hit between the hitbox and bullet unfortunately.

Here's the latest code in full. I made all the changes suggested plus a few little changes for personal preference but nothing that should have any effect on the collision. Let me know if you need to look at the slice tree or anything else.


Code:

include, plotscr.hsd
include, scancode.hsi
include, gun.hsi

#GLOBALS
global variable (1, isShooting)
global variable (2, hitbox)
global variable (3, Bullet)

#_____________________________________________
plotscript, Map Auto Run, begin

variable (collection)
collection := load slice collection(1)
 
  #Guard 1
  #Define and parent the hitbox
  hitbox:= lookup slice(sli:Hitbox1, collection)
  setparent (hitbox, GetNPCSlice (0))
  #Position the hitbox
  set slice edge x (hitbox, edge:top, 2)
  set slice edge y (hitbox, edge:top, -2)

  #While map is running perform this loop
  While (true) do(
 
    #This checks if projectile is colliding, then kills corresponding NPC
    checkCollisions
   
  wait(1) 
  )
 
end

#_____________________________________________ 
plotscript, On Keypress Handler, begin

variable (collection)

if(key is pressed(key:X)) then(
    if(isShooting <> 1) then(
      isShooting := 1
          if(hero direction == right) then(
            collection := load slice collection(0)
            Bullet := lookup slice(sli:Bullet1, collection)
            set parent(Bullet, get hero slice (0))
            set slice velocity x (Bullet, 20, 10)
            set slice velocity y (Bullet, 0, 10)
            center slice (Bullet)
            isShooting := 1
            wait for slice(Bullet)
            free slice(Bullet)
            isShooting := 0
            exit script
          )
          if(hero direction == left) then(
            collection := load slice collection(0)
            Bullet:= lookup slice(sli:Bullet1, collection)
            set parent(Bullet, get hero slice (0))
            set slice velocity x (Bullet, -20, 10)
            set slice velocity y (Bullet, 0, 10)
            center slice (Bullet)
            isShooting := 1
            wait for slice(Bullet)
            free slice(Bullet)
            isShooting := 0
            exit script
          )
          if(hero direction == up) then(
            collection := load slice collection(0)
            Bullet:= lookup slice(sli:Bullet1, collection)
            set parent(Bullet, get hero slice (0))
            set slice velocity x (Bullet, 0, 10)
            set slice velocity y (Bullet, -20, 10)
            center slice (Bullet)
            isShooting := 1
            wait for slice(Bullet)
            free slice(Bullet)
            isShooting := 0
            exit script
          )
          if(hero direction == down) then(
            collection := load slice collection(0)
            Bullet:= lookup slice(sli:Bullet1, collection)
            set parent(Bullet, get hero slice (0))
            set slice velocity x (Bullet, 0, 10)
            set slice velocity y (Bullet, 20, 10)
            center slice (Bullet)
            isShooting := 1
            wait for slice(Bullet)
            free slice(Bullet)
            isShooting := 0
            exit script
          )
          isShooting := 0
        )
    )
end

#_____________________________________________
script, checkCollisions, begin
  variable(b, h)
  b := lookup slice(sli:Bullet1)
  h := lookup slice(sli:Hitbox1)
  if (b && h)  then(
    if (SliceCollide (b, h)) then(
      destroy NPC (0)
      play sound (1, false, true)
    )
  )   
end

⊕ 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
Metal King Slime
Send private message
 
 PostThu Jan 15, 2015 3:28 am
Send private message Reply with quote
I think your problem is the "wait for slice". That means the script is holding everything and waiting for the bullet to have moved before it does any other checks... and unfortunately once the bullet has moved, you're freeing its slice, never giving it a time to check.
Liquid Metal Slime
Send private message
 
 PostThu Jan 15, 2015 5:17 am
Send private message Reply with quote
Gizmog wrote:
I think your problem is the "wait for slice". That means the script is holding everything and waiting for the bullet to have moved before it does any other checks... and unfortunately once the bullet has moved, you're freeing its slice, never giving it a time to check.


That makes since. I'll play around with this tomorrow. I may have to use a timer to wait a set period of time to free the bullet slice in that case but I can figure that out probably. Thanks.
⊕ 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
Metal King Slime
Send private message
 
 PostThu Jan 15, 2015 5:32 am
Send private message Reply with quote
No problem! A timer sounds like a great way to handle the problem.
Liquid Metal Slime
Send private message
 
 PostFri Jan 16, 2015 2:47 pm
Send private message Reply with quote
Gizmog wrote:
No problem! A timer sounds like a great way to handle the problem.


Hey thanks. I have confirmed that the wait is in fact the problem. The current code I have is messy and not working as desired but the NPC is dying upon collision with the bullet which is good. I'll keep cleaning up the code this weekend and if I need any more hope I'll post about it.

A big thanks to everyone who helped out with this problem. Especially Gizmog though since he put up with my constant onslaught of questions.
⊕ 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
Metal King Slime
Send private message
 
 PostFri Jan 16, 2015 3:11 pm
Send private message Reply with quote
That's what I'm here for.
Liquid Metal Slime
Send private message
 
 PostSun Jan 18, 2015 7:57 pm
Send private message Reply with quote
I'm happy to say that things are working out! I made a little basic tutorial thingy here:

http://www.slimesalad.com/forum/viewgame.php?t=6467

In a basic situation this works great. I will now have to transfer the code over to my actual game and get it working with embiggened characters which I saw you guys talking about a little earlier in the forum. I think I can handle this now but will let you know if any questions arise.
⊕ 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
Metal King Slime
Send private message
 
 PostSun Jan 18, 2015 9:58 pm
Send private message Reply with quote
Lookin' good! I notice that if you take a shot and then change directions really quick, you kind of "steer" the shot, which is a very Atari 2600 touch. I can think of a few shooting games that used that to very interesting effect. Hope you don't have any trouble importing it into your real game, looking really forward to that.
Liquid Metal Slime
Send private message
 
 PostMon Jan 19, 2015 5:17 am
Send private message Reply with quote
Gizmog wrote:
Lookin' good! I notice that if you take a shot and then change directions really quick, you kind of "steer" the shot, which is a very Atari 2600 touch. I can think of a few shooting games that used that to very interesting effect. Hope you don't have any trouble importing it into your real game, looking really forward to that.


I actually noticed that too. I plan to make my projectiles in the form of throwing stars or something so I think this may be a neat effect. Definitely unintentional but desirable.
⊕ 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
 
 PostMon Jan 19, 2015 11:27 pm
Send private message Reply with quote
Awesome! Thanks for including the script files with notations! I may compare this to what I've been using and see if I can improve my game Grin (hoping to have a self contained version of my "retro" game up before next month)

Great work!
Slime Knight
Send private message
 
 PostWed Jan 21, 2015 12:24 am
Send private message Reply with quote
I was toying with the idea of adding a "mode B" to the game I'm working on. This would be simpler, use only one screen, a hero, several NPCs(all the same walkabout graphic), and a projectile.

The format is; the player controls a monster at the top of the screen moving only laterally. pushing space drops slime from the monster at approaching baddies, thus destroying them. (a little like atari kaboom, except the player is firing at NPCs instead of the reverse)

I've got the basic shooting working, but my hit detection isn't functioning. At the moment, my projectiles sail right through my NPCs with no effect.

This script seems to work;
Code:

plotscript, mode2shoot, begin
variable (slime)
while (kills<<10)
do
(
variable(sl)
if(keyval (key:space)>>0)

then
(           
       slime := load walkabout sprite (23, 0)
       put slice (slime, hero pixel x, hero pixel y)
            set slice velocity x (slime, 0, 30)
            set slice velocity y (slime, 15, 20) 
       (play sound (32,false,false)) 
)(wait (4))
)
end


This script replaces the hero sprite with a larger one, generates enemies, and runs the hit detection script. this seems to be at least partially working from what I've been able to tell.

Code:

plotscript, bigfly, begin

variable(hero, sl, picsl, picnum, npid)
   hero:= 0
   picnum:= 5

   sl := get hero slice(  npid  )
   picsl :=lookup slice(sl:walkabout sprite component, sl)
   replace hero sprite(picsl, picnum)

while (kills<<10)
do (wait (15)
create NPC (1,3,9,right)
create npc (2, 5,9,right)
wait (15)
create npc (3,4,9,left)
create npc (4,1,9,left)
(slimehit)
Wait(1)
)
end


This is my hit detection script that doesn't seem to be working. I'm not sure about whether the variables are necessary, or if I ought to be using global variables. In any case my slime projectile fires and passes through my NPCs. Perhaps I'm using the wrong slice commands. (beardo is the enemy)

Code:


plotscript, slimehit, begin
variable (beardo1, beardo2, slime)
beardo1 := lookup slice (sl:walkabout sprite component, get NPC slice (1))
beardo2 := lookup slice (sl:walkabout sprite component, get NPC slice (2))

slime := lookup slice (sli:slime)
if (slice collide (slime, beardo1) == true)
then (destroy npc (1))
else if
(slice collide (slime, beardo2) == true)
then (destroy npc (2))
end


Any thoughts would be appreciated. To be honest, I'm actually pleased that I've even gotten things to work as much as they are here (No Errors! V )
Metal King Slime
Send private message
 
 PostWed Jan 21, 2015 1:11 am
Send private message Reply with quote
The problem is right here:
Code:

beardo1 := lookup slice (sl:walkabout sprite component, get NPC slice (1))
beardo2 := lookup slice (sl:walkabout sprite component, get NPC slice (2))


GetNPCSlice returns a handle to a slice, so you can just write

Code:

beardo1 := GetNPCSlice (1)
BearDo2 := GetNPC2Slice (2)


No need for the lookup stuff.

Also, dunno if it'll be a problem or not, but your script only checks BearDo2 if BearDo1 isn't being hit. If both of them are hit at the same time, it might only recognize the first one.

EDIT: Wait.. more problems. Re-reading.

EDIT EDIT: There's more than one copy of NPC 1 and 2, right? If that's the case, you're going to need to iterate through all the copies of each kind. The easiest way to do that is gonna be

1) Find out how many NPCs of each type there are with NPCCopyCount

2) Check each copy using a For Loop and NPCReference to count through each one and see what it's doin

It sounds very complicated, but it's actually pretty simple once you get your loop set up right, and can allow for some very elaborate effects. I think it'll look something like..

Code:

#How many copies of this NPC there are
variable (HowManyEnemies)
HowManyEnemies := NPCCopyCount (1)

#The slice handle of the NPC in question
variable (EnemiesSlice)

#The required variable for the For Loop
variable (EnemyLooper)

#Note that the for loop is counting to the NPCCount minus one. That's
#because 0 is a valid NPC Reference!
#
#IE: if we have 10 enemies, they're enemies 0-9. If we tried to check
#ten enemies, 1-10, we'd be in trouble.

for (EnemyLooper,0,HowManyEnemies --1)
do (
 #If you've never used a for loop before, basically,
 #it does this stuff in the do block and then increments EnemyLooper
 #by 1 and does it again until it reaches the value we said,         
 #HowManyEnemies --1
 
 #Check the dictionary for how to make them go backwards and count
 #by fives and other cool variations
 EnemiesSlice := GetNPCSlice (NPCReference (1,EnemyLooper))
 
 if ( SliceCollide (lookupslice (Sli:Slime),EnemiesSlice) )
 then ( DestroyNPC (NPCReference (1,EnemyLooper) ) )
 
 #Because this is gonna run a finite number of times, we don't need a
 #wait (1), and they'll all happen in the same tick
 )


I'm not sure if destroying the NPC in the middle is gonna be a problem or not, but I doubt it. If it is, there's ways around that. Also not exactly sure I'm getting this code right, but something close to this. Also just noticed that it might act goofy if there's no copies of NPC 1. Should probably throw a check on there to make sure there's actually enemies like a...

Code:

if (HowManyEnemies)
then (
 for ...
 )


EDIT EDIT EDIT: And another problem, those

Code:

wait (15)


In your loop mean that it's only gonna check the collision like... every 2 seconds. Plenty of time for a shot to travel right through something. You're going to want to do something like..

Code:

plotscript, bigfly, begin

variable(hero, sl, picsl, picnum, npid)
   hero:= 0
   picnum:= 5

   sl := get hero slice(  npid  )
   picsl :=lookup slice(sl:walkabout sprite component, sl)
   replace hero sprite(picsl, picnum)

variable (MonsterTime)

while (kills<<10)
do (
 if (MonsterTime == 15)
 then (
  create NPC (1,3,9,right)
  create npc (2, 5,9,right)
 )
 if (MonsterTime == 30)
 then (
  create npc (3,4,9,left)
  create npc (4,1,9,left)
 )
 (slimehit)

#Bump the timer up a notch every tick and set it to 0 if it gets too high
increment (MonsterTime,1)
if (MonsterTime == 31)
then (MonsterTime := 0)
Wait(1)
)
end


You gotta be real careful with waits in a looping script like this, because they can throw off the timing of the rest of the loop.
Slime Knight
Send private message
 
 PostWed Jan 21, 2015 3:01 am
Send private message Reply with quote
Wow! Thanks for that quick and thorough response Grin I skimmed through the code you posted a few times, and it seems like you've touched upon pretty much everything I'm trying to do, and more!

If (more likely WHEN, haha) I run into any trouble I can't figure out on my own, I'll post again. But I think that everything here will get this mini-game running in pretty good order, and with my code a little neater as well. Again, I really appreciate the effort you've put into helping me out with stuff.
Metal King Slime
Send private message
 
 PostWed Jan 21, 2015 3:16 am
Send private message Reply with quote
Helping with plotscripts is my favorite thing to do. All of the fun of solving the mystery, none of the pressure of actually making a game. Win-win! Glad to do it!
Display posts from previous:
Page «  1, 2, 3, 4, 5, 6  »