Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Seeking help for Health Bar for fighting game (Grade 11 Student)
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
MiniWade




PostPosted: Fri Jan 10, 2014 7:47 pm   Post subject: Seeking help for Health Bar for fighting game (Grade 11 Student)

What is it you are trying to achieve?
I am starting my final project for Grade 11 Computer Science,and am making a fightning game. I want to know how to make a health bar, as well as how to make it so that when the character gets hit, it loses health. As well as once a characters health gets all empty (no health remaining), the other person is victorious.


What is the problem you are having?
I don't know how to start it, not anything.


Describe what you have tried to solve this problem
I've looked online, but can't seek my answer.



Please note all I only have is my character moving left/right, attacking animation, defending animation. I have yet to create the second character, and this game is meant to be just multi-player. I know how to do the stuff for the second character. However, I just don't know about the whole health bar process. I want someone to help me learn it, with an example so I can understand. Note, I am still a beginner and will need bit more explanation then other fellow members. Thanks!
Turing:


%Final Assignment

%Working With Images
var picwalk : array 0 .. 4 of int
var picdefend : array 0 .. 6 of int
var picattack : array 0 .. 6 of int

var picback, picerase : int
var frame, charx, time1, time2, chary, walk : int
var letter : string (1)

%RETRIEVE AN IMAGE WALK
picwalk (0) := Pic.FileNew ("untitled-1 copy.bmp")
picwalk (1) := Pic.FileNew ("untitled-2 copy.bmp")
picwalk (2) := Pic.FileNew ("untitled-3 copy.bmp")
picwalk (3) := Pic.FileNew ("untitled-4 copy.bmp")
picwalk (4) := Pic.FileNew ("untitled-5 copy.bmp")

%RETRIEVE AN IMAGE DEFEND
picdefend (0) := Pic.FileNew ("untitled-1 copy.bmp")
picdefend (1) := Pic.FileNew ("untitled-6 copy.bmp")
picdefend (2) := Pic.FileNew ("untitled-7 copy.bmp")
picdefend (3) := Pic.FileNew ("untitled-8 copy.bmp")
picdefend (4) := Pic.FileNew ("untitled-9 copy.bmp")
picdefend (5) := Pic.FileNew ("untitled-10 copy.bmp")
picdefend (6) := Pic.FileNew ("untitled-11 copy.bmp")


%RETRIEVE AN IMAGE ATTACK
picattack (0) := Pic.FileNew ("untitled-1 copy.bmp")
picattack (1) := Pic.FileNew ("untitled-12 copy.bmp")
picattack (2) := Pic.FileNew ("untitled-13 copy.bmp")
picattack (3) := Pic.FileNew ("untitled-14 copy.bmp")
picattack (4) := Pic.FileNew ("untitled-15 copy.bmp")
picattack (5) := Pic.FileNew ("untitled-16 copy.bmp")
picattack (6) := Pic.FileNew ("untitled-17 copy.bmp")





% picback := Pic.FileNew ("holiday_street.gif")

%Constants
const keyLeft := chr (203)
const keyRight := chr (205)
const spacebar := chr (32)
const keyUp := chr (200)

%INITIIALIZE THE FRAMES ON SCREEN
setscreen ("graphics: 800, 600")

%Pic.Draw (picback, 0, 0, picCopy)
frame := 0
charx := 0
chary := 0
letter := ""
walk := 0


picerase := Pic.New (charx, 0, charx + 71, 145)
Pic.Draw (picwalk (frame), charx, 0, picMerge)
Pic.Draw (picdefend (frame), charx, 0, picMerge)
Pic.Draw (picattack (frame), charx, 0, picMerge)
time1 := Time.Elapsed

loop

    time2 := Time.Elapsed
    letter := ""
    if hasch then
        getch (letter)
       
        %Going through the frames, without stopping in between
        if letter = keyRight then
            walk := 1
        end if
        if letter = keyLeft then
            walk := 2
        end if
        if letter = keyUp then
            walk := 3
        end if
        if letter = spacebar then
            walk := 4
        end if
    end if

    %WALKING LEFT
    time2 := Time.Elapsed

    if (letter = keyRight or walk = 1) and time2 - time1 > 150 then

        %Erase the character
        Pic.Draw (picerase, charx, 0, picCopy)
        Pic.Free (picerase)

        %Update the cariable
        frame := frame + 2
        if frame > 4 then
            frame := 0
            walk := 0
        end if
        charx := charx + 15

        %Draw the image on the screen
        picerase := Pic.New (charx, 0, charx + 71, 145)
        Pic.Draw (picwalk (frame), charx, 0, picMerge)
        time1 := Time.Elapsed
    end if

    %WALKING RIGHT

    if (letter = keyLeft or walk = 2) and time2 - time1 > 150 then


        %Erase the character
        Pic.Draw (picerase, charx, 0, picCopy)
        Pic.Free (picerase)

        %Update the cariable
        frame := frame + 2
        if frame > 4 then
            frame := 0
            walk := 0
        end if
        charx := charx - 15

        %Draw the image on the screen
        picerase := Pic.New (charx, 0, charx + 71, 145)
        Pic.Draw (picwalk (frame), charx, 0, picMerge)
        time1 := Time.Elapsed
    end if

    %DEFENDING
    if (letter = keyUp or walk = 3) and time2 - time1 > 150 then

        %Erase the character
        Pic.Draw (picerase, charx, chary, picCopy)
        Pic.Free (picerase)

        %Update the cariable
        frame := frame + 1
        if frame > 6 then
            frame := 0
            walk := 0
        end if
        charx := charx + 0

        %Draw the image on the screen
        picerase := Pic.New (charx, 0, charx + 71, 145)
        Pic.Draw (picdefend (frame), charx, 0, picMerge)
        time1 := Time.Elapsed
    end if

    % ATTACKING
    if (letter = spacebar or walk = 4) and time2 - time1 > 150 then

        %Erase the character
        Pic.Draw (picerase, charx, chary, picCopy)
        Pic.Free (picerase)

        %Update the cariable
        frame := frame + 1
        if frame > 6 then
            frame := 0
            walk := 0
        end if
        charx := charx + 0

        %Draw the image on the screen
        picerase := Pic.New (charx, 0, charx + 100, 145)
        Pic.Draw (picattack (frame), charx, 0, picMerge)
        time1 := Time.Elapsed
    end if
end loop



Please specify what version of Turing you are using
Turing for Windows 4.1.1
Sponsor
Sponsor
Sponsor
sponsor
Raknarg




PostPosted: Fri Jan 10, 2014 8:43 pm   Post subject: RE:Seeking help for Health Bar for fighting game (Grade 11 Student)

For your health bar, you will have to keep track of a current health and maximum health variable. Basically, all you do is turn the health into a ratio and draw a box according to that ratio.

Let's say your health bar is normally a box 100 pixels long, and your maximum health is 25 points. At full health, you will make a box 100 pixels wide. Let's say you lose 4 points of health. 21/25 = 0.88, you you draw the box at 100*0.88 pixels, or 88 pixels.

Here' a quick example to show you how ratios work:

Turing:

setscreen ("offscreenonly")

var maxhp, hp : int := 35

loop
    exit when hp <= 0

    put "Current health points: ", hp, " / ", maxhp
    put "Health to max health ratio: ", hp / maxhp
    put "Health bar is 100 pixels wide. Draw it at ", round (100 * (hp / maxhp)), " pixels."

    Draw.FillBox (0, 30, round (100 * (hp / maxhp)), 50, 12)
    Draw.Box (0, 30, 100, 50, black)

    View.Update
    delay (400)
    cls

    hp -= 1
end loop


Tell me if this needs more explanation
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: