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

Username:   Password: 
 RegisterRegister   
 How can I get this healthbar to decrease properly... and one other question
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
XShotGunZX




PostPosted: Mon Jun 14, 2010 6:53 pm   Post subject: How can I get this healthbar to decrease properly... and one other question

What is it you are trying to achieve?
Well the main thing I want to achieve is to get the healthbar in my program to decrease properly, basically my program is sort of like the popular game brick breaker.. but instead of hitting a ball and hitting bricks, you have to catch balls that fall from the sky, and essentially your catching these balls to prevent them from hitting the earth (background pic) and if they hit the earth you lose health.

Also, if someone is feeling really helpful could you also answer...

How can I get the balls and healthbar to stop flickering, I used View.Set ("offscreenonly") and View.Update and I believe its in the correct place


What is the problem you are having?
Well, I have three different types of balls falling, a red one, a green one and a purple one, the red one works as its supposed to, removing 90 health from the health bar, the purple one removes 90 health on the first time, the green one does nothing throughout the whole program, the next time the purple one hits though, it, for some reason removes 180-270 health and it continues like that.

Describe what you have tried to solve this problem
I used whatever I learned in my computer studies class (not much lol, since I just started programming 5 months ago and we just learned about if statements, variables and rushed through mouse commands), I used the resources on compsci such as the FAQ to remove flickering but it did not work, and I looked through the turing reference but could not find anything.

Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Well here's my code, I know im using processes and I've also read that processes are bad.. so if the program is messing up due to that, or if you believe it will mess up due to that in the future.. what can I use instead to make the balls work?

Turing:


setscreen ("graphics:900;550,position:middle;centre,nobuttonbar,title:Brick Breaker")
var ch : string (1)
var x, x2, x3, x4, x5, y, y2, y3, Health : int
var i : int := 0
var xPos : int
var yPos : int
var button : int

Health := 900
x := 0
x2 := 0
x3 := 0
x4 := 0
x5 := 0
y := 525
y2 := 525
y3 := 525
randomize
randint (x5, 0, 900)
randint (x3, 0, 900)
randint (x4, 0, 900)

View.Set("offscreenonly")
var mypic : int := Pic.FileNew ("Earth Picture2.jpg")

process background
    loop
        Pic.Draw (mypic, 0, 0, picUnderMerge)
    end loop

end background
fork background

process redball
    loop
        loop
            drawfilloval (x3, y, 10, 10, 12)
            y := y - 2
            exit when y < 145
        end loop

        y := 525
        randint (x3, 0, 900)
        loop
            drawfilloval (x3, y, 10, 10, 12)
            y := y - 2
            exit when y < 145
        end loop
    end loop
end redball
fork redball

delay (500)

process greenball
    loop
        loop
            drawfilloval (x4, y2, 10, 10, brightgreen)
            y2 := y2 - 3
            exit when y2 < 145
        end loop

        y2 := 525
        randint (x4, 0, 900)
        loop
            drawfilloval (x4, y2, 10, 10, brightgreen)
            y2 := y2 - 3
            exit when y2 < 145
        end loop
    end loop
end greenball
fork greenball

delay (500)

process purpleball
    loop
        loop
            drawfilloval (x5, y3, 10, 10, purple)
            y3 := y3 - 5
            exit when y3 < 145
        end loop

        y3 := 525
        randint (x5, 0, 900)
        loop
            drawfilloval (x5, y3, 10, 10, purple)
            y3 := y3 - 5
            exit when y3 < 145
        end loop
    end loop
end purpleball
fork purpleball



process brick

    loop

        Mouse.Where (xPos, yPos, button)

        x := xPos + 1
        x2 := x + 120

        drawfillbox (x, 130, x2, 145, yellow)

        View.Update
        cls

    end loop

end brick
fork brick

Pic.Draw (mypic, 0, 0, picCopy)

View.Update

process health
loop
drawfillbox (0,0,Health,25,brightred)
if y < 146 or y2 < 146 or y3 < 146 then
Health := Health - 90
end if
end loop
end health
fork health




Please specify what version of Turing you are using
turing 4.1.1
Sponsor
Sponsor
Sponsor
sponsor
Monduman11




PostPosted: Mon Jun 14, 2010 7:19 pm   Post subject: RE:How can I get this healthbar to decrease properly... and one other question

umm i looked at your code and i dont see any hit detection for the green and purple balls all i see is for the red one. add the hit detection for the green and purple and see if it works. and i see that uve used lots or processes, my advice stay away from them cause they cause more trouble than they're worth, only thing they're good for is music
XShotGunZX




PostPosted: Mon Jun 14, 2010 7:27 pm   Post subject: Re: RE:How can I get this healthbar to decrease properly... and one other question

Monduman11 @ Mon Jun 14, 2010 7:19 pm wrote:
umm i looked at your code and i dont see any hit detection for the green and purple balls all i see is for the red one. add the hit detection for the green and purple and see if it works. and i see that uve used lots or processes, my advice stay away from them cause they cause more trouble than they're worth, only thing they're good for is music


if y < 146 or y2 < 146 or y3 < 146 then
Health := Health - 90


umm y is hit detection for red ball, y2 and y3 is for green and purple balls... and yea,

Well here's my code, I know im using processes and I've also read that processes are bad.. so if the program is messing up due to that, or if you believe it will mess up due to that in the future.. what can I use instead to make the balls work?


What can I use besides processes to make this program run properly XD?
Monduman11




PostPosted: Mon Jun 14, 2010 7:32 pm   Post subject: Re: RE:How can I get this healthbar to decrease properly... and one other question

XShotGunZX @ Mon Jun 14, 2010 7:27 pm wrote:
Monduman11 @ Mon Jun 14, 2010 7:19 pm wrote:
umm i looked at your code and i dont see any hit detection for the green and purple balls all i see is for the red one. add the hit detection for the green and purple and see if it works. and i see that uve used lots or processes, my advice stay away from them cause they cause more trouble than they're worth, only thing they're good for is music


if y < 146 or y2 < 146 or y3 < 146 then
Health := Health - 90


umm y is hit detection for red ball, y2 and y3 is for green and purple balls... and yea,

Well here's my code, I know im using processes and I've also read that processes are bad.. so if the program is messing up due to that, or if you believe it will mess up due to that in the future.. what can I use instead to make the balls work?


What can I use besides processes to make this program run properly XD?

um procedures are a good alternative to use instead of processes. and what you do with procedures is have one for your main stuff and then have one for the drawing of the balls and the hp bar. so in the first one put everything that is related with your movement, and hit detection stuff, and then just do another procedure for drawing and it makes your code look neater, and most importantly its more efficient
XShotGunZX




PostPosted: Tue Jun 15, 2010 4:24 pm   Post subject: Re: How can I get this healthbar to decrease properly... and one other question

well I tryed using procedures, didn't work out..

I still need help on this can someone help me
TerranceN




PostPosted: Tue Jun 15, 2010 5:27 pm   Post subject: RE:How can I get this healthbar to decrease properly... and one other question

I see from using processes you want to do two things at once. Unfortunately you can't, even with processes. All they do is run part of one process then a part of a different process, the problem is you cannot control the frequency or importance of each process, so one process may get a lot more parts run than another, seemingly at random.

Instead of trying to do two things at once, we can trick the user into thinking that we can. If we run everything in one big loop fast enough, it seems to the human eye that multiple things are happening at once. But we need a way to control how fast that loop goes or on some computers the game will be faster/slower. We can do this with Time.DelaySinceLast(delayTime:int). This will delay for (delayTime - time since last called) so if your game takes 10ms for one loop and you give Time.DelaySinceLast 30ms, it will delay 20ms. This will cap the speed the loop can go. Finally, (simple) procedures are just a way to group similar code together, for more look here. Here is an example of all this in practice:

Turing:
View.Set("grphics:500;500,offscreenonly,nobuttonbar,title:Example")

var isRunning : boolean := true
var x, y, v, x2, y2, v2 : int := 1

proc Update()
    y -= v
    y2 -= v2

    if (y < 0) then
        y := maxy
        x := Rand.Int(0, maxx)
        v := Rand.Int(5, 10)
    end if
   
    if (y2 < 0) then
        y2 := maxy
        x2 := Rand.Int(0, maxx)
        v2 := Rand.Int(5, 10)
    end if
end Update

proc Draw_()
    cls
   
    Draw.FillOval(x, y, 10, 10, red)
    Draw.FillOval(x2, y2, 10, 10, blue)
   
    View.Update()
end Draw_

loop
    Update()
   
    Draw_()

    Time.DelaySinceLast(33)
end loop


Hope that helps.
XShotGunZX




PostPosted: Tue Jun 15, 2010 6:09 pm   Post subject: Re: How can I get this healthbar to decrease properly... and one other question

Surprised yea that helps alot thanks! but there are a few parts I do not understand how to use correctly, can you tell me what they do so I can attempt to use your method in my program lol Smile, only reason im asking is that my teacher will think I did no work and copied all the code if I don't even know what some of my own code does...

code:

var isRunning : boolean := true
what is "isRunning" and :=true?

var x, y, v, x2, y2, v2 : int := 1
why do you put a :=1 after the variables : int?

proc Update ()
why the brackets with nothing inside?

y -= v
y2 -= v2
why is it -=? what does that do?

proc Draw_ ()
Why do you put an underscore and brackets here? why do you even put blank brackets XD

Time.DelaySinceLast (33)
and lastly I couldn't fully understand this.. can you explain this please and thank you :)
TheGuardian001




PostPosted: Tue Jun 15, 2010 6:34 pm   Post subject: Re: How can I get this healthbar to decrease properly... and one other question

XShotGunZX @ Tue Jun 15, 2010 6:09 pm wrote:

code:

var isRunning : boolean := true
what is "isRunning" and :=true?

var x, y, v, x2, y2, v2 : int := 1
why do you put a :=1 after the variables : int?

proc Update ()
why the brackets with nothing inside?

y -= v
y2 -= v2
why is it -=? what does that do?

proc Draw_ ()
Why do you put an underscore and brackets here? why do you even put blank brackets XD

Time.DelaySinceLast (33)
and lastly I couldn't fully understand this.. can you explain this please and thank you :)


isRunning is a variable. Give it whatever name you want, as long as you know what it represents. := true means that it is a boolean (turing will infer the type of the variable from the value you put in it), and that it is set to true (booleans are either true or false)

the := will give all the variables on that line a value of 1. This is basically just so that they don't accidentally get used before they have a value. You should generally always give your variables an initial value, even if it's an empty one (0 for ints, "" for strings, etc).

Brackets are considered to be good practice, since some other languages do actually require them. The underscore has no meaning, it's just a part of the procedure name.

y2 -= v2 is the same as y2 := y2 - v2. It's just a short from. It essentially means the first variable is equal to itself minus the second variable. Instead of having to re-write the variable you want to subtract from, Turing will understand that you want to subtract from whatever variable you are editing. This also works for +=, *=, and /=

Finally, Time.DelaySinceLast(milliseconds). Essentially what this does is ensure that at least (milliseconds) has passed since the last time Time.DelaySinceLast was called. If that amount of time hasn't passed, the program will wait until it has.
When you use delay(time), the program will wait for (time) milliseconds from when it gets to that delay. When you use Time.DelaySinceLast(time), it will wait for (time) milliseconds since the last time Time.DelaySinceLast or delay() was called, IE:

code:

put "Hello!"
delay(50) %waits 50 ms.
for i : 1 .. 50
    put "in a looooop."
end for
Time.DelaySinceLast(1000)
put "done"


Now, let's say that the for loop in that program takes 150 ms to run. Once the program gets to Time.DelaySinceLast, it will check how long it has been since the last delay was used (in this case, 150 ms). If it has been less than 1000 ms, it will wait for the remaining amount of time (in this case, it waits 850 ms,) so that the time between when the for loop starts and when "done" is put on the screen is at least one second.
Sponsor
Sponsor
Sponsor
sponsor
XShotGunZX




PostPosted: Tue Jun 15, 2010 6:58 pm   Post subject: Re: How can I get this healthbar to decrease properly... and one other question

ohhhh ok, I understand it now, well it seems that

var isRunning : boolean := true

does nothing in that program.. so I removed that and I changed all the terms to stuff that we learned and I understand.. so for now my program looks like this


code:

View.Set ("graphics:900;550,offscreenonly,nobuttonbar,title:Example")

var x, y, v, x2, y2, v2, x3, y3, v3, x4, y4, v4, x5, y5, v5 : int := 0
var mypic : int := Pic.FileNew ("Earth Picture2.jpg")

proc Update

    y := y - v
    y2 := y2 - v2
    y3 := y3 - v3
    y4 := y4 - v4
    y5 := y5 - v5

    if y < 146 then
        y := maxy
        randint (x, 0, maxx)
        randint (v, 5, 10)
    end if

    if y2 < 146 then
        y2 := maxy
        randint (x2, 0, maxx)
        randint (v2, 5, 10)
    end if

    if y3 < 146 then
        y3 := maxy
        randint (x3, 0, maxx)
        randint (v3, 5, 10)
    end if

    if y4 < 146 then
        y4 := maxy
        randint (x4, 0, maxx)
        randint (v4, 5, 10)
    end if

    if y5 < 146 then
        y5 := maxy
        randint (x5, 0, maxx)
        randint (v5, 5, 10)
    end if

end Update

proc Draw_
    cls

    Pic.Draw (mypic, 0, 0, picUnderMerge)
    drawfilloval (x, y, 10, 10, brightpurple)
    drawfilloval (x2, y2, 10, 10, blue)
    drawfilloval (x3, y3, 10, 10, green)
    drawfilloval (x4, y4, 10, 10, purple)
    drawfilloval (x5, y5, 10, 10, brightgreen)

    View.Update
end Draw_

loop
    Update

    Draw_

    Time.DelaySinceLast (33)
end loop


[size=12]Will it affect how the program will run overall if I changed stuff like Rand.Int (blabla) to randint (blabla) or is it just that those things are a different way that turing works like x -= y and x = x - y

and lastly, how would I go about adding the brick code into these procedures... I tried putting the code that makes the brick move into update and the code that draws the brick itself into draw_ and well.... it was a horrible result... I also tried putting the brick code into a seperate procedure and adding that into the loop... and it was messed up lol, sorry if im asking too many questions its just that im new to programming and I have no clue what im doing... heres the brick code by the way.

(The brick is the little box that catches the balls)
code:

    loop

        Mouse.Where (xPos, yPos, button)

        x := xPos + 1
        x2 := x + 120

        drawfillbox (x, 130, x2, 145, yellow)

        View.Update
        cls

    end loop
TerranceN




PostPosted: Tue Jun 15, 2010 8:15 pm   Post subject: RE:How can I get this healthbar to decrease properly... and one other question

The isRunning variable was going to be checked every time the loop went around so that you could set it to false in another procedure and exit the loop. I just forgot to add that part.

Putting the moving code into update and the drawing code into draw is the correct thing to do, what was horrible about it? Did you copy the View.Update and cls too (giving you two of each in the Draw_ procedure)? If you did, go line by line and think about what that would do.
XShotGunZX




PostPosted: Tue Jun 15, 2010 9:14 pm   Post subject: Re: RE:How can I get this healthbar to decrease properly... and one other question

TerranceN @ Tue Jun 15, 2010 8:15 pm wrote:
The isRunning variable was going to be checked every time the loop went around so that you could set it to false in another procedure and exit the loop. I just forgot to add that part.

Putting the moving code into update and the drawing code into draw is the correct thing to do, what was horrible about it? Did you copy the View.Update and cls too (giving you two of each in the Draw_ procedure)? If you did, go line by line and think about what that would do.


oh.....hehehehe... I made a stupid mistake.. I forgot to add a variable to the mouse position thats why it wasn't working.. haha I figured it out after trying to make the brick code work in a completely new program... yea.. ok.. basically I got everything now.. Very HappyVery HappyVery Happy

can you explain how the isRunning thing is supposed to work and what it would do for my program? btw thanks for all the help I really appreciate it Smile
Srlancelot39




PostPosted: Tue Sep 28, 2010 6:47 pm   Post subject: RE:How can I get this healthbar to decrease properly... and one other question

if you are running the graphics in a process, it may flash dispite the use of offscreenonly and View.Update.
TWizard




PostPosted: Mon Oct 04, 2010 11:47 pm   Post subject: RE:How can I get this healthbar to decrease properly... and one other question

Well answering the first question ask you could just set the damage as in:

var damage, health, x, x2, y, y2 : int

x := 0
x2 := 0
y := 0
y2 := 0
damage := 50
health := 400

if y = y2 and x = x2 then
health := health - damage
end if

Draw.Box (0,0,400,10,red)
drawfillbox (0,0,health,10,red)

If the would be any help to ye. I don't fully understand the concept of the game or your entire question so basically all I got from it was health bar and damage. Thats what I came up with so it may help or be totally unless.
TWizard




PostPosted: Mon Oct 04, 2010 11:57 pm   Post subject: RE:How can I get this healthbar to decrease properly... and one other question

var red_x, red_y : int

red _ y := 500
red_x := 200

proc Red_Ball
red_y := red_y - 1

if red _ y := 0 then
red_y := 500
end if
end Red_Ball

loop
delay (25)
cls
drawfilloval (red_x,red_y,10,10,red)
end loop

And that should help your process problem just put them in procedures then put them in one loop. At least thats what i understood from your question.
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  [ 14 Posts ]
Jump to:   


Style:  
Search: