Baconthulu: How does the attacking work?

Ask and answer questions about making games and related topics. Unrelated topics go in that other forum.

Moderators: marionline, SDHawk

Post Reply
User avatar
sheamkennedy
Liquid Metal Slime
Posts: 1110
Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:

Baconthulu: How does the attacking work?

Post by sheamkennedy »

This is targeted at Bob. I was just wondering if you used a built in check trigger the sword slash script or if you are checking a bunch of conditions in a while-loop to see if the player is facing the enemy and simultaneous holding the directional button towards the enemy?
⊕ 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
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7658
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

Hmmm... I'll have to check the script...

It is more the latter. I am not using a built in check, but I am also not using a check in a while loop. Instead I use an "on keypress" script.

I have an on-keypress script that includes the following:

Code: Select all

  while(true) do( # hack loop so we can use "break"
    if(keyval(key:up)>1)    then(hero motion(up),    break)
    if(keyval(key:right)>1) then(hero motion(right), break)
    if(keyval(key:down)>1)  then(hero motion(down),  break)
    if(keyval(key:left)>1)  then(hero motion(left),  break)
...

The "hero motion" script checks to see if it is okay for the hero to either move or attack, and if so, runs "hero motion action"

Code: Select all

script, hero motion, d, begin
  if(hero is aligned) then(
    if(hero atk frames == 0) then(
      hero motion action(d)
    )
  )
end
Then the "hero motion action" script contains checks to see if there is an enemy to attack or an npc to talk to:

Code: Select all

script, hero motion action, d, begin
  variable(ref)
  ref := get monster ahead of hero(d)
  if(is attackable(ref)) then(
    hero attack monster(ref)
  )
  if(is talker(ref)) then(
    if(current textbox == -1) then(
      talker action for this map(ref)
    )
  )
end
Hero movement is the default movement, it is not scripted, although it is triggered with the same keypresses.

I hope that helps! :)
Last edited by Bob the Hamster on Fri Jan 12, 2018 3:52 pm, edited 1 time in total.
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7658
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

I should also mention that I have seriously considered changing it to make Bob auto-attack any enemy that is one tile away. I think that would pair nicely with touch-controls, so if I make a future update after the click-to-walk feature for heroes is finished, I might change the way attacking works.

If I did that, I would probably leave the existing keypress code exactly as it is (adding click-to-walk would not mean removing keyboard control) but I would add either a while loop or a 1-tick timer that checks for nearby enemies and attacks them.
User avatar
sheamkennedy
Liquid Metal Slime
Posts: 1110
Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:

Post by sheamkennedy »

Thanks!

I kind of prefer how you actively have to be running in to the enemy to attack, it makes it so you can't just leave the game running and allow enemies to make their way towards you. I think if you make the game touch screen then you should also add some sort of idling mechanic to deter the player from idling for too long. Maybe they fall asleep and are super vulnerable to the next attack or something like that.

Also what's the best way of checking hero alignment? I assume I just check that hero x == hero pixel x/20 and that hero y == hero pixel y/20...
Last edited by sheamkennedy on Sun Jan 14, 2018 9:39 am, edited 1 time in total.
⊕ 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
Post Reply