Castle Paradox Forum Index Castle Paradox

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Gamelist   Review List   Song List   All Journals   Site Stats   Search Gamelist   IRC Chat Room

Side Scroller Help
Goto page 1, 2, 3, 4  Next
 
Post new topic   Reply to topic    Castle Paradox Forum Index -> HELP!
View previous topic :: View next topic  
Author Message
TwinHamster
♫ Furious souls, burn eternally! ♫




Joined: 07 Mar 2004
Posts: 1352

PostPosted: Fri Mar 13, 2009 2:11 pm    Post subject: Side Scroller Help Reply with quote

So after playing quite a bit of Timpoline and seeing Spoonweaver release Tim-Tim, I decided to give this side-scroller thing a spin.

Browsed through Moogle's SS101 articles and essentially popped the third article's script straight into the game.

Figured it was pretty smooth, so I tried adding my own code to make a simple melee-attack.

This is the modification in the [do game] script found in the SS101:
(I'm not sure if this is the best way to put it, but...)

Code:

script, do game, begin

...

#Attacks
   if(key is pressed (key:z))
   then(
   hero-speed := 0
   if(hero-vy == 0)
   then(
   #Ground:
   if(hero-direction==right)
   then(
   setheropicture(me, 7)
   set hero direction (me, right)
   set hero frame (me, 1)
   wait (1)
   set hero direction (me, down)
   create npc (99, herox(me), heroy(me), down)
   set npc frame (99, 1)
   put npc (99, hero pixel x (me) + 20, hero pixel y (me))
   wait (5)
   destroy npc (99)
   set hero picture (me, 4)
   set hero direction (me, up)
   )
   else(
   setheropicture(me, 7)
   set hero direction (me, right)
   set hero frame (me, 0)
   wait (1)
   set hero direction (me, down)
   create npc (99, herox(me), heroy(me), down)
   set npc frame (99, 0)
   put npc (99, hero pixel x (me) -- 20, hero pixel y (me))
   wait (5)
   destroy npc (99)
   set hero picture (me, 4)
   set hero direction (me, up)
   )
   
   )
   hero-speed := 25
   )

end


By pressing the [z] key, the hero stops moving and thrusts a spear in the direction he's facing.



And I'm pretty proud of myself so far.
Unfortunately, there are a few things I'd like to get sorted out first.

[1] Adding the wait-commands tells the entire loop to wait for the animation to finish and freezes all of the game until the wait passes.
This seems like a neat effect, but is there a way I can prevent this from happening?

[2] Also, when the game first starts up, the hero isn't animated when running (the frames don't cycle).
This happens regardless of the changes I make to [do game].

Much obliged.
Back to top
View user's profile Send private message Send e-mail AIM Address
Camdog




Joined: 08 Aug 2003
Posts: 606

PostPosted: Fri Mar 13, 2009 2:54 pm    Post subject: Reply with quote

It's hard to tell why the hero isn't animating without all the code (not sure if moogle's example stuff does that or not), but you should be able to get the hero to animate by adding this line to your loop:

Code:
set hero frame(me, hero frame(me),xor,1)


Of course, this will make the hero switch frames continuously. You'd need to add a conditional to make it happen only during movement, or however you want to work it.

As for the waiting stuff, the answer is to remove the wait statements. Of course, if you want the attack animation to persist for longer than a single tick, you'll need another way of tracking animation length. The easiest way to do it (off the top of my head) would probably be to define a global variable that you can set to true or false to determine if you update the hero picture. Just put a conditional around your loop where you change the hero picture depending on what direction they move:

Code:
if (updateAnimation) then(
  #update animation
)


Then, whenever your player attacks you can fire off a timer for however long you want the animation to last:

Code:
plotscript, turn on animation, begin
  updateAnimation := true
end

#later, in your attack code
  if (key is pressed(key:z)) then(
    #do your attack stuff
    updateAnimation := false

    set timer (1, 10, 1, @turn on animation)
  )


That will make your attack animation last 10 ticks.
Back to top
View user's profile Send private message
Spoon Weaver




Joined: 18 Nov 2008
Posts: 421
Location: @home

PostPosted: Fri Mar 13, 2009 2:56 pm    Post subject: Reply with quote

well the trick i used in order to have waiting and yet not wait is this.

first, i get a global variable.

then, I have the loop decrement the variable if it is higher then 0.

next, I have the if statement that creates the action to set the global variable to a certain number.

Finally, i have stuff happen as the variable gets smaller.


hope this helps




EDIT: yea what camdog said
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Moogle1
Scourge of the Seas
Halloween 2006 Creativity Winner
Halloween 2006 Creativity Winner



Joined: 15 Jul 2004
Posts: 3377
Location: Seattle, WA

PostPosted: Fri Mar 13, 2009 3:31 pm    Post subject: Reply with quote

Quote:
Also, when the game first starts up, the hero isn't animated when running (the frames don't cycle).


Regarding animation, are you using the latest SS101? Unless you've grabbed part 1 or part 2, the hero should be animating. You mentioned you popped the third article's script into the game; I'm curious why you didn't go further.

You say "when the game first starts up." Does the problem fix itself later?

As others have mentioned, you need to handle the attack one frame at a time. Maybe something like:

Code:
if (key is pressed(key:z) && hero-attack == 0) then (
  hero-attack := 10
)
if (hero-attack >> 0) then (
 # show attack frame and check if you're killing anything
 # you might want to do something to prevent the player from just holding down attack
 hero-attack -= 1
)


(edit) now that I reread what everyone else said, I feel a little redundant
_________________
Back to top
View user's profile Send private message Visit poster's website AIM Address
TwinHamster
♫ Furious souls, burn eternally! ♫




Joined: 07 Mar 2004
Posts: 1352

PostPosted: Fri Mar 13, 2009 4:18 pm    Post subject: Reply with quote

I'm having some trouble understanding how the timers work and where the attack frames fit in.
This is going to come out terribly messy and I am already sorry.

With Camdog's advice, I have remodeled the attack coding so that:

After pressing the attack key,
the hero shows his first attack frame for 5 ticks
After the timer runs out, the second frame is supposed to be shown.

Code:

script, do game, begin
  variable(playing)
  variable(hero can jump)
  playing := true

  # Let's do The Loop!
  while (playing) do (
 
  if (updateAnimation) then(
  #Chooong!
 
  set hero direction (me, down)
   play sound (0, false, true)
   create npc (99, herox(me), heroy(me), down)
   set npc frame (99, 1)
   put npc (99, hero pixel x (me) + spear-direction, hero pixel y (me))
   wait (5)
   destroy npc (99)
   set hero picture (me, 4)
   set hero direction (me, up)
   updateAnimation := false

      hero-speed := 25
      hero can jump:=true
  #update animation
  )
 
 
    # Accept player input
    if (key is pressed(key:esc)) then (playing := false)
    if (key is pressed(key:right)) then (
      hero-direction := right
      hero-vx += hero-speed
    )
    if (key is pressed(key:left)) then (
      hero-direction := left
      hero-vx -= hero-speed
    )
   
   #Attacks
   if(key is pressed (key:Ctrl) && hero-vy == 0)
   then(
   hero can jump:=false
   hero-speed := 0

   if(hero-direction==right)
   then(
   spear-direction := 20
   
    #do your attack stuff
   
   setheropicture(me, 7)
   set hero direction (me, right)
   set hero frame (me, 1)

   )
   else(
   
   spear-direction := -20
   setheropicture(me, 7)
   set hero direction (me, right)
   set hero frame (me, 0)

   )
   
   updateAnimation := false

    set timer (1, 5, 1, @turn on animation)
   )
...
end


Unfortunately, I wasn't sure how to use a timer to get the second frame to show up and ended using a wait(5).
I tried inserting a 'turn off animation' script, which basically set the global variable [updateAnimation] false after the second frame, but that ended up endlessly looping without showing the second attack frame.

Interestingly,
attacking while the hero is moving results in him stopping and then sliding for a little bit before showing his first attack frame. This is neat.

Holding down the attack button makes the hero also hold his attack until you let go of the key. I planned to have a charging attack, but this is also kind of cool.

Thanks for the replies so far.

[Edit] Actually, I've realized that it would probably be much easier to just give the attack 1 frame for now.
Back to top
View user's profile Send private message Send e-mail AIM Address
Spoon Weaver




Joined: 18 Nov 2008
Posts: 421
Location: @home

PostPosted: Fri Mar 13, 2009 4:31 pm    Post subject: Reply with quote

perhaps this can explain the technique a little better.




Code:
script, do game, begin
  variable(playing)
  variable(hero can jump)
  playing := true

  # Let's do The Loop!
  while (playing) do (
 
  if (updateAnimation) then(
  #Chooong!
 
  set hero direction (me, down)
 

... blah blah blah


   #Attacks
   if(key is pressed (key:Ctrl) && hero-vy == 0)
   then(
   hero can jump:=false
   hero-speed := 0

   if(hero-direction==right)
   then(
   spear-direction := 20
   
    #do your attack stuff


#------V set the variable V

   attacktimer:=20

#------^ set the variable ^


   setheropicture(me, 7)
   set hero direction (me, right)
   set hero frame (me, 1)

   )
   else(
      [b]attacktimer:=20[/b]
   spear-direction := -20
   setheropicture(me, 7)
   set hero direction (me, right)
   set hero frame (me, 0)

   )
   
   )


#------V use the variable V

if (attack timer>>0) then (decrement (attack timer)
if (atacktimer==15) then (#animamtion 2)
if (atacktimer==10) then (#animamtion 3)
if (atacktimer==5) then (#animamtion 4)
if (atacktimer==1) then (#end animation and restore to normal)



#------^ use the variable ^
...
end
Back to top
View user's profile Send private message Send e-mail Visit poster's website
TwinHamster
♫ Furious souls, burn eternally! ♫




Joined: 07 Mar 2004
Posts: 1352

PostPosted: Fri Mar 13, 2009 6:29 pm    Post subject: Reply with quote

Spoonweaver wrote:
A very useful tip


Oh, that's actually pretty clever!
After twisting the script around, it appears to work okay.

Thanks! I'll surely be back for more soon.

[Edit]

Regarding the lack of animation frames,

I found that it was the result of my slowing down the max x-velocity which threw it off track and led to the script only showing one frame.
I've tweaked so that it just alternates between the two frames each tick of movement.
Back to top
View user's profile Send private message Send e-mail AIM Address
Spoon Weaver




Joined: 18 Nov 2008
Posts: 421
Location: @home

PostPosted: Fri Mar 13, 2009 7:09 pm    Post subject: Reply with quote

cool. good luck on your game. Happy
Back to top
View user's profile Send private message Send e-mail Visit poster's website
TwinHamster
♫ Furious souls, burn eternally! ♫




Joined: 07 Mar 2004
Posts: 1352

PostPosted: Fri Mar 13, 2009 7:59 pm    Post subject: Reply with quote

Current Problem: Resolved!

Moving to other maps;
I've made some npcs serve as door so that activating them sends you to another map.
However, upon ascending to the next plane, the hero will plummet through the ground into the oblivions teleport to a completely wrong position after teleporting to the proper one.

Is there a way to get him to recognize the new wall-blocks beneath him?

[Edit] Oh, the problem seems to be that the [put hero] command in the main looping script activates and sends the hero to the pixel position that he should have been in, instead of where I want him to be.

Multiplying the desired position by 200 to get [hero-x] and [hero-y] fixes the problem pretty well.


Last edited by TwinHamster on Fri Mar 13, 2009 8:17 pm; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail AIM Address
Moogle1
Scourge of the Seas
Halloween 2006 Creativity Winner
Halloween 2006 Creativity Winner



Joined: 15 Jul 2004
Posts: 3377
Location: Seattle, WA

PostPosted: Fri Mar 13, 2009 8:09 pm    Post subject: Reply with quote

You've got to reset his hero-x and hero-y on arriving at a new map.

I am in the middle of writing this article.
_________________
Back to top
View user's profile Send private message Visit poster's website AIM Address
Spoon Weaver




Joined: 18 Nov 2008
Posts: 421
Location: @home

PostPosted: Fri Mar 13, 2009 9:36 pm    Post subject: Reply with quote

that was a tricky problem. I sort of fudged the results a little. I ran into a problem that activated other NPC's while i was using the doors, still not sure what caused this. but it is why you always blink when using doors in tim tim and why you can't pick up items while blinking. Wink
Back to top
View user's profile Send private message Send e-mail Visit poster's website
TwinHamster
♫ Furious souls, burn eternally! ♫




Joined: 07 Mar 2004
Posts: 1352

PostPosted: Sat Mar 14, 2009 2:02 pm    Post subject: Reply with quote

Okay, additional enemy types.
I couldn't quite figure out all of this article, so that severely limits my ability to add more enemies. (Pretty much paced enemies)

I see that the [do enemies] script cycles between [first enemy id] and [last enemy id] to check if their instances are on the screen.
After the check, enemies on the screen are processed. Good stuff.

But [process enemy] has completely lost me.

On first glance, I figured that increasing [last enemy id] and adding another [case] to the [switch] in [process enemy] was all that I needed, but I have apparently been doing this wrong.

If someone could shove me in the right direction, that would be great :D
Back to top
View user's profile Send private message Send e-mail AIM Address
Moogle1
Scourge of the Seas
Halloween 2006 Creativity Winner
Halloween 2006 Creativity Winner



Joined: 15 Jul 2004
Posts: 3377
Location: Seattle, WA

PostPosted: Sat Mar 14, 2009 3:10 pm    Post subject: Reply with quote

That sounds right to me, but I'm not looking at the script right now. Can you paste your [process enemies]?
_________________
Back to top
View user's profile Send private message Visit poster's website AIM Address
TwinHamster
♫ Furious souls, burn eternally! ♫




Joined: 07 Mar 2004
Posts: 1352

PostPosted: Sat Mar 14, 2009 4:25 pm    Post subject: Reply with quote

The new enemy case is actually working now, but only for one instance at a time.

Do I need to make modifications to [do enemies] for it to pick up the rest of them?

[Edit] Okay, so a single enemy #1 (the new kind) is only processed when there is a copy of enemy #0 (the goomba) present on the map.

Here's my [process enemy]
The new enemy-type is on the upper half of it.
For now, it is a simple paced-enemy that is not affected by gravity.
Thanks

Code:

script, process enemy, npc, begin
  switch(get npc id(npc)) do (
 
   case(enemy:batter) do(
   #Make the Batter fly! No effect from gravity.
   if (npc direction(npc) == left) then (
      put npc(npc, npc pixel x(npc) -- goomba walk speed, npc pixel y(npc))
      if (npc can left(npc) == false) then (set npc direction(npc, right))
     ) else (
      if (npc direction(npc) == right) then (
        put npc(npc, npc pixel x(npc) + goomba walk speed, npc pixel y(npc))
        if (npc can right(npc) == false) then (set npc direction(npc, left))
      )
   else (
        # Run down the time until we delete the enemy
        set npc extra(npc, extra 1, npc extra(npc, extra 1) -- 1)
        if (npc extra(npc, extra 1) == 0) then (
         destroy npc(npc)
         exit returning(0) # Quit out of this script
        )
      )
   
   )
   
   if(hero hurting == 0)
     then(
     if ((hero-x / 10) -- npc pixel x(npc) << 20 &&
        npc pixel x(npc) -- (hero-x / 10) << 20 &&
        (hero-y / 10) -- npc pixel y(npc) << 20 &&
        npc pixel y(npc) -- (hero-y / 10) << 20 &&
        npc direction(npc) <> down)
        then (
      # Hero got hit!
        hurt hero
     )
     )
    
     if ((npc pixel y(npc) == npc pixel y (99)) && ( (20 >> (npc pixel x (99) -- npc pixel x (npc))) && ((npc pixel x (99) -- npc pixel x (npc)) >> -20)) )
     then (
        # Lance hits foe!
        set npc direction(npc, down)
        set npc extra(npc, extra 1, corpse time)
        )
   
   )
   
   case(enemy:goomba) do (
     # Make our goomba walk
     set npc frame(npc, enemy anim / 2)
     if (npc direction(npc) == left) then (
      put npc(npc, npc pixel x(npc) -- goomba walk speed, npc pixel y(npc))
      if (npc can left(npc) == false) then (set npc direction(npc, right))
     ) else (
      if (npc direction(npc) == right) then (
        put npc(npc, npc pixel x(npc) + goomba walk speed, npc pixel y(npc))
        if (npc can right(npc) == false) then (set npc direction(npc, left))
      ) else (
        # Run down the time until we delete the enemy
        set npc extra(npc, extra 1, npc extra(npc, extra 1) -- 1)
        if (npc extra(npc, extra 1) == 0) then (
         destroy npc(npc)
         exit returning(0) # Quit out of this script
        )
      )
     )
     put npc(npc, npc pixel x(npc), npc pixel y(npc) + npc extra(npc, extra 2) / 10)
     if (npc can fall(npc)) then (
      set npc extra(npc, extra 2, npc extra(npc, extra 2) + gravity)
      if (npc extra(npc, extra 2) >> hero-max-vy) then (set npc extra(npc, extra 2, hero-max-vy))
     ) else (
      set npc extra(npc, extra 2, 0)
     )
    
     # Check for hero collisions
     if(hero hurting == 0)
     then(
     if ((hero-x / 10) -- npc pixel x(npc) << 20 &&
        npc pixel x(npc) -- (hero-x / 10) << 20 &&
        (hero-y / 10) -- npc pixel y(npc) << 20 &&
        npc pixel y(npc) -- (hero-y / 10) << 20 &&
        npc direction(npc) <> down)
        then (
      # Collision! Check if hero fell onto goomba.
        hurt hero
     )
     )
    
     #Check for SPEARS
     if ((npc pixel y(npc) == npc pixel y (99)) && ( (20 >> (npc pixel x (99) -- npc pixel x (npc))) && ((npc pixel x (99) -- npc pixel x (npc)) >> -20)) )
     then (
        # Goomba dies
        set npc direction(npc, down)
        set npc extra(npc, extra 1, corpse time)
        )
   )
  )
end
Back to top
View user's profile Send private message Send e-mail AIM Address
Moogle1
Scourge of the Seas
Halloween 2006 Creativity Winner
Halloween 2006 Creativity Winner



Joined: 15 Jul 2004
Posts: 3377
Location: Seattle, WA

PostPosted: Sat Mar 14, 2009 4:46 pm    Post subject: Reply with quote

This is my fault.

Quote:
count := npc copy count(enemy:goomba) -- 1 # count goes from 0..n-1


Replace [enemy:goomba] with i and you'll be just fine.
_________________
Back to top
View user's profile Send private message Visit poster's website AIM Address
Display posts from previous:   
Post new topic   Reply to topic    Castle Paradox Forum Index -> HELP! All times are GMT - 8 Hours
Goto page 1, 2, 3, 4  Next
Page 1 of 4

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group