Jeran

Howdy! I make things!

Cohost is goign to be my one stop shot for just dumping all my current hyperfixations, and the random things I make as a result of them!


# Define a function to generate and show a random number
def swing():
    result=0
    tempDamage=0;
    defenseAmount=0;
    #decide if we hit the enemy
    if(random.randint(0,accuracy.get())  >=  random.randint(0,enemy_evasion.get())):
        #decide if the hit has magic embued damage
        if(random.randint(0,max_value)  <=  weapon_elemental_chance.get()):
            print("the weapon sparkles with magics!")
            playsound(magicHitSound)
            elementalHit=1;
        else:
            playsound(hitSound)
            elementalHit=0;
        #decide if it is a critical hit or not
        if(random.randint(0,max_value)  <=  critical_chance.get()):
            print("crit!")
            criticalHit=2;
        else:
            criticalHit=1;
        #calculate the regular damage.
        tempDamage=1+Fuzz(attack.get()*((1+(2*weapon_level.get()/max_value)))) ##damage
        #print("attack damage is ",tempDamage)
        defenseAmount=tempDamage-(max(tempDamage-enemy_armor.get(),0)*max(.01,(1-(enemy_defense.get()/max_value)))) 
        result=max(tempDamage-enemy_armor.get(),0)*max(.01,(1-(enemy_defense.get()/max_value))) ##resistances
        
        result=result+(elementalHit*Fuzz(weapon_elemental_power.get()) * (1-(enemy_elemental_type_resistances.get()/max_value)))#elemental damage and resistance
        result=int(result*criticalHit) #crit bonus

    else:
        playsound(missSound)
        result="Miss!"
    


    #process results.
    if(result!="Miss!"):
        enemy_hp.set(enemy_hp.get()-result);
    if(enemy_hp.get()<=0):
        print("BAAAAAUGH. you killed it!");
        playsound("death.wav")
        #add experience, and level up if needed.
        experience.set(experience.get()+enemy_level.get());
        if(experience.get()>=level.get()):
            playsound("levelup.wav")
            experience.set(experience.get()-level.get());#it takes as much exp to level up as your current level.
            level.set(level.get()+1)#incriment by one (i know that if you manage to level up more than once, then it would take another kill to flush the banked levels)
        ###reset the enemy by picking a new level of difficulty, a new health amount, and setting its max, and current HP.    
        enemy_level.set(random.randrange(1,10))
        enemy_max_HP.set(random.randrange(1,10*enemy_level.get()));
        enemy_hp.set(enemy_max_HP.get())
    testHealth=int(healthBarSize*(enemy_hp.get()/enemy_max_HP.get()))
    pb1['value']=testHealth#update the health bar, by getting the health percentage, and multiplying it by the bar size to get progress
    print(result, "attack:", tempDamage, " defended:",defenseAmount,"health"+str(testHealth));

the nice thing about this tho, is that i have been actually learning how to use Tkinter, and it seems.... fun? im horrible at front end, so this is a revelation for me.


You must log in to comment.