
-----------------------------------
UnTiteled
Sat Jan 16, 2010 12:56 pm

health subtraction...please help
-----------------------------------
What is it you are trying to achieve?
i am trying to make my health decrease work (whenever you or the enemy is hit by a blast you subtract 10 hp) 
but for some reason it wont work


What is the problem you are having?
it doesnt want to work, ive been weorking on the health alone for 3 days trying to figure out why


Describe what you have tried to solve this problem
in three days i tryed alot of things like inserting other code or changing my current code


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)


const GROUND_HEIGHT := 120
const RUN_SPEED := 10
const JUMP_SPEED := 30
const GRAVITY := 2


var manfig1 := Pic.FileNew ("stand.gif")
var manfig2 := Pic.FileNew ("face.gif")
var monsterfig2 := Pic.FileNew ("monster_face.gif")
var monster := Pic.FileNew ("monster.gif")

var ypos := 750
var xpos := 150

var chars : array char of boolean
var position := 1000

var posx, posy : int
var velx, vely : real

var hp2 := 100

posx := 20
velx := 0
posy := 400
vely := 0




setscreen ("graphics:max;max")

colourback (70)
cls
locate (15, 20)
put "___________.__"
locate (16, 20)
put "\\__    ___/|  |__   ____ "
locate (17, 20)
put "  |    |   |  |  \\_/ __ \\ "
locate (18, 20)
put "  |    |   |   Y  \\  ___/ "
locate (19, 20)
put "  |____|   |___|  /\\___  >"
locate (20, 20)
put "                \\/     \\/ "
locate (21, 20)
put "   _____  .__         .__                   .__          __  "
locate (22, 20)
put "  /  _  \\ |  |   ____ |  |__   ____   _____ |__| _______/  |_ "
locate (23, 20)
put " /  /_\\  \\|  | _/ ___\\|  |  \\_/ __ \\ /     \\|  |/  ___/\\   __\"
locate (24, 20)
put "/    |    \\  |_\\  \\___|   Y  \\  ___/|  Y Y  \\  |\\___ \\  |  |  "
locate (25, 20)
put "\\____|__  /____/\\___  >___|  /\\___  >__|_|  /__/____  > |__|  "
locate (26, 20)
put "        \\/          \\/     \\/     \\/      \\/        \\/ "

put "Instructions: Move with the 'up, down, left, and right buttons', shoot with the space bar"
put ""
put "On the first day, God created the Heavens and The earth..."
put "On the sixth day, God created the creatures of the earth, and with them"
put "came a soul devouring beast, once the humans were put on the earth, so"
put "did the demon start to hunt for souls"
put ""
put "your quest iss to defeat these demons and save the world from darkness"
put "hit any key to begin"
Input.Pause
colourback (white)
colour (white)
cls






locate (16, 20)
colour (black)

put " _______________"
locate (17, 20)
put "|prepare        |"
locate (18, 20)
put "|to             |"
locate (19, 20)
put "|be destroyed.  |"
locate (20, 20)
put "| ______________|"
locate (21, 20)
put "|/"
Pic.Draw (manfig2, 120, 240, picMerge)
Pic.Draw (manfig1, 50, 50, picMerge)
drawline (0, GROUND_HEIGHT, maxx, GROUND_HEIGHT, blue)
locate (41, 10)
put "hit any key to continue"
Input.Pause

locate (16, 90)
put " _______________"
locate (17, 90)
put "|               |"
locate (18, 90)
put "|GRAAAWWWWRRRRR |"
locate (19, 90)
put "|______________ |"
locate (20, 90)
put "               |/"
Pic.Draw (monsterfig2, 790, 250, picMerge)
locate (41, 10)
Pic.Draw (monster, position, 60, picMerge)
View.Set ("offscreenonly")
loop


    colour (black)
    colourback (white)
    cls
    locate (16, 20)
    put " _______________"
    locate (17, 20)
    put "|prepare        |"
    locate (18, 20)
    put "|to             |"
    locate (19, 20)
    put "|be destroyed.  |"
    locate (20, 20)
    put "| ______________|"
    locate (21, 20)
    put "|/"
    Pic.Draw (manfig2, 120, 240, picMerge)
    Pic.Draw (manfig1, 50, 50, picMerge)
    drawline (0, GROUND_HEIGHT, maxx, GROUND_HEIGHT, blue)
    locate (41, 10)

    locate (16, 90)
    put " _______________"
    locate (17, 90)
    put "|               |"
    locate (18, 90)
    put "|GRAAAWWWWRRRRR |"
    locate (19, 90)
    put "|______________ |"
    locate (20, 90)
    put "               |/"
    Pic.Draw (monsterfig2, 790, 250, picMerge)
    locate (41, 10)
    Pic.Draw (monster, position, 60, picMerge)
    position := position - 1

    delay (15)
    View.Update
    cls
    exit when position = 750
end loop
locate (5, 50)
put "press s to start..."
Input.Pause

var pic2 := Pic.FileNew ("darkblast.gif")
var monster2 := Pic.FileNew ("monster.gif")
var pic := Pic.FileNew ("fireball2.gif")
View.Set ("offscreen")

loop
    loop

var box1_x1, box1_y1, box1_x2, box1_y2 : int
var box2_x1, box2_y1, box2_x2, box2_y2 : int
        var y := posx
        var x := posy






        Input.KeyDown (chars)
        if chars ('q') then
            exit
        end if


        if chars (KEY_LEFT_ARROW) then
            velx := -RUN_SPEED
        elsif chars (KEY_RIGHT_ARROW) then
            velx := RUN_SPEED
        else
            velx := 0
        end if


        if chars (KEY_UP_ARROW) and posy = GROUND_HEIGHT then
            vely := JUMP_SPEED
        end if











        Pic.Draw (monster2, 750, 60, picMerge)
        Pic.Draw (pic2, ypos, xpos, picMerge)
        ypos := ypos - 1
        delay (3)
        if ypos = -80 then
            ypos := 750
            exit
        end if



        Input.KeyDown (chars)
        if chars (' ') then
            loop
            put "enemy:health  ",hp2,"/100"  



box1_x1 := y
box1_y1 := x
box1_x2 := y + 60
box1_y2 := x + 60
box2_x1 := 780
box2_y1 := 40
box2_x2 := 840
box2_y2 := 225

        drawbox (box1_x1, box1_y1, box1_x2, box1_y2, 9)
        drawbox (box2_x1, box2_y1, box2_x2, box2_y2, 12)


        box1_x1 += 1
        box1_x2 += 1
        if box1_x2 = box2_x1 and box1_y2 > box2_y1 then
            hp2 := hp2 - 10

        end if



                Input.KeyDown (chars)
                if chars ('q') then
                    exit
                end if


                if chars (KEY_LEFT_ARROW) then
                    velx := -RUN_SPEED
                elsif chars (KEY_RIGHT_ARROW) then
                    velx := RUN_SPEED
                else
                    velx := 0
                end if


                if chars (KEY_UP_ARROW) and posy = GROUND_HEIGHT then
                    vely := JUMP_SPEED
                end if



                Pic.Draw (manfig1, posx, posy, picMerge)


                drawline (0, GROUND_HEIGHT, maxx, GROUND_HEIGHT, blue)

                vely -= GRAVITY
                posx += round (velx)
                posy += round (vely)


                if posy < GROUND_HEIGHT then
                    posy := GROUND_HEIGHT
                    vely := 0
                end if




                delay (35)
                View.Update
                cls

                if posx < 0 then
                    posx := -1
                elsif posx > 600 then
                    posx := 600
                end if

                Pic.Draw (pic, y, x, picMerge)

                y += 5

                if y > 760 then
                    y := -10

                    exit
                end if





                Pic.Draw (monster2, 750, 60, picMerge)
                Pic.Draw (pic2, ypos, xpos, picMerge)
                ypos := ypos - 1
                delay (3)
                if ypos = -80 then
                    ypos := 750

                end if






            end loop
        end if



        ypos := ypos - 1
        delay (3)
        if ypos = -80 then
            ypos := 750

        end if



        vely -= GRAVITY
        posx += round (velx)
        posy += round (vely)


        if posy < GROUND_HEIGHT then
            posy := GROUND_HEIGHT
            vely := 0
        end if




        Pic.Draw (manfig1, posx, posy, picMerge)


        drawline (0, GROUND_HEIGHT, maxx, GROUND_HEIGHT, blue)

        delay (35)


        if posx < 0 then
            posx := -1
        elsif posx > 600 then
            posx := 600
        end if
        View.Update
        cls










    end loop

    ypos := ypos - 1
    delay (3)
    if ypos = -80 then
        ypos := 750

    end if





end loop

Please specify what version of Turing you are using
4.1.1

-----------------------------------
UnTiteled
Sat Jan 16, 2010 12:58 pm

RE:health subtraction...please help
-----------------------------------
oops i posted the code wrong somehow

-----------------------------------
UnTiteled
Sun Jan 17, 2010 9:03 am

RE:health subtraction...please help
-----------------------------------
never mind to whoever was thinking of posting i got it

-----------------------------------
qmanjr5
Mon Jan 18, 2010 8:58 am

RE:health subtraction...please help
-----------------------------------
Make a procedure/process called "hit".
Make it so whenever an enemy hits you, it runs that procedure.
In the procedure put "hp-x" x=however many HP you want to be taken away.
