Untitled

mail@pastecode.io avatar
unknown
plain_text
20 days ago
2.4 kB
4
Indexable
Never
#Fighter1 code 
from mblock import event
import time
wait_time=0.03
inputR='right arrow'
inputL='left arrow'
inputH='m'
health='P1Health'
EnemyName='Fighter2'
message='Hit2'
@event.greenflag
def on_greenflag():
    sprite.set_variable(health, 100)
    sprite.set_costume('Idle')
    while True:
        if sprite.is_keypressed(inputR):
            move(13)
        if sprite.is_keypressed(inputL):
            move(-13)
        if sprite.is_keypressed(inputH):
            hit()
        if sprite.get_variable(health)<=0:
            sprite.set_costume('die')
            sprite.say(EnemyName+' Wins')
            time.sleep(2)
            sprite.stop_all()

@event.received('Hit1')
def on_received():
    sprite.set_variable(health, sprite.get_variable(health)-5)

def move(direction):
    sprite.change_x_by(direction)
    sprite.set_costume('Walk1')
    time.sleep(wait_time)
    sprite.set_costume('walk2')
    time.sleep(wait_time)
    sprite.set_costume('walk3')
    time.sleep(wait_time)
    sprite.set_costume('Idle')
def hit():
    if sprite.distance_to(EnemyName)<=20:
        sprite.broadcast(message)
    sprite.play('Crunch')
    sprite.set_costume('Hit')
    time.sleep(0.1)
    sprite.set_costume('Idle')



#Fighter 2 code  
from mblock import event
import time

wait_time=0.03
inputR='d'
inputL='a'
inputH='c'
health='P2Health'
EnemyName='Fighter'
message='Hit1'

@event.greenflag
def on_greenflag():
    sprite.set_variable(health, 100)
    sprite.set_costume('Idle')
    while True:
        if sprite.is_keypressed(inputR):
            move(13)
        if sprite.is_keypressed(inputL):
            move(-13)
        if sprite.is_keypressed(inputH):
            hit()
        if sprite.get_variable(health)<=0:
            sprite.set_costume('die')
            sprite.say(EnemyName+' Wins')
            time.sleep(2)
            sprite.stop_all()



@event.received('Hit2')
def on_received():
    sprite.set_variable(health, sprite.get_variable(health)-5)


def move(direction):
    sprite.change_x_by(direction)
    sprite.set_costume('Walk1')
    time.sleep(wait_time)
    sprite.set_costume('walk2')
    time.sleep(wait_time)
    sprite.set_costume('walk3')
    time.sleep(wait_time)
    sprite.set_costume('Idle')

def hit():
    if sprite.distance_to(EnemyName)<=20:
        sprite.broadcast(message)
    sprite.play('Crunch')
    sprite.set_costume('Hit')
    time.sleep(0.1)
    sprite.set_costume('Idle')





    


Leave a Comment