Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How do you make a shield in a fighting game?
- Pixel1up
-
Scratcher
9 posts
How do you make a shield in a fighting game?
I've been working on a Super Smash Bros./Scott Pilgrim type fighting game. I was trying to make he shield work in a test project, but then I realized I had no idea how to. I wanted it to break when the size was too small, and stun you. Which works fine, but if you hold down space, it doesn't. Also, I didn't know how to make it so you gain back shield over time.
Here's the script I had, if you need the project to see it it's here:
https://scratch.mit.edu/projects/1023543846/
Here's the script I had, if you need the project to see it it's here:
https://scratch.mit.edu/projects/1023543846/
when green flag clicked
set size to (500) %
forever
if <key [space] pressed?> then
show
go to [character]
repeat until <not <key [space] pressed?>>
change size by (-3)
if <(size) < [125]> then
hide
broadcast [shieldbreak]
end
end
else
hide
end
end
- invalidaccess
-
Scratcher
100+ posts
How do you make a shield in a fighting game?
what do you mean by “ a shield” ? like a power zone or something?
- Koamodo975
-
Scratcher
1000+ posts
How do you make a shield in a fighting game?
I'm assuming you want a Smash Bros-esque shield, where the shield is a sort of bubble that shrinks until it guardbreaks. To do this, you should create a variable (I'll call it ‘defence’), and use this code(I'm using c as my key 'cause that feels natural):
when green flag clickedThis should work. Lemme know if it messes up and I'll see what I can do.
forever
go to [player v]
set size to (defence)
if <<key [c v] pressed?> and <(defense) > [1]>> then
show
else
hide
if <(defence) < [100]> then
change [defence v] by (1)
end
end
if <key [c v] pressed?> then
change [defence v] by (-1)
if <touching attacks? ::sensing> then
handle defense code ::movement
change [defence v] by (-5)
end
end
if <(defense) < [1]> then
handle guardbreak code
hide // or you could add a guard-breaking animation if you want
end
- Pixel1up
-
Scratcher
9 posts
How do you make a shield in a fighting game?
Maybe just a way to delay it so you can't spam it though..
- Koamodo975
-
Scratcher
1000+ posts
How do you make a shield in a fighting game?
Just add another variable, (I'll call it ‘blockcooldown’), and, in a separate script:
when green flag clicked
forever
if <key [c v] pressed?> then
wait until <not <key [c v] pressed?>>
set [blockcooldown v] to (20)
end
end
// In the main script:
when green flag clicked
forever
go to [player v]
set size to (defense)
if <<<key [c v] pressed?> and <(defense) > [1]> >and <(blockcooldown) < [1]>> then
show
else
hide
if <(defense) < [100]> then
change [defense v] by (1)
end
end
if <<<key [c v] pressed?> and <(defense) > [1]> >and <(blockcooldown) < [1]>> then
change [defense v] by (-1)
if <touching attacks? ::sensing> then
handle defense code ::movement
change [defense v] by (-5)
end
end
if <(defense) < [1]> then
handle guardbreak code
hide
end
if <(blockcooldown) > [0]> then
change [blockcooldown v] by (-1)
end
- Discussion Forums
- » Help with Scripts
-
» How do you make a shield in a fighting game?