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

Username:   Password: 
 RegisterRegister   
 glitch in game, code flawed?!
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
ZeroPaladn




PostPosted: Fri Dec 02, 2005 10:14 am   Post subject: glitch in game, code flawed?!

im making a little shooting game just for the hell of it, and i got the movement, and the health/heat done. The problem is the laser. what i want it to do is you shoot it, then it moves independantly of the "cannon", which is fixed by assigning the cuttent y value to a new value, and the laser moves along that value ONLY. when i try it out, its bugs, and player 2 gets a massive speed boost (which is not suposed to happen) and the laser stays at the default coordinate (which is 15 when yous tart, because of my wall collision detection.)

hers the code.
code:

View.Set ("graphics:600;450,position:center;center,nobuttonbar")

const heatshot := 12
const speedshot := 5
const maxhp := 100
var font : int := 0
var chars : array char of boolean
var heat1, heat2 : int := 0
var hp1, hp2 : int := 100
var y1, y2, lasery1, lasery2 : int := 0
var laser1, laser2 : boolean := false
font := Font.New ("sans serif:14:bold")

proc cannons
    Input.KeyDown (chars)
    if chars (KEY_UP_ARROW) then
        y2 += 1
    elsif chars (KEY_DOWN_ARROW) then
        y2 -= 1
    end if
    if chars ('w') then
        y1 += 1
    elsif chars ('s') then
        y1 -= 1
    end if
    if y2 > 335 then
        y2 -= 1
    elsif y2 < 15 then
        y2 += 1
    end if
    if y1 > 335 then
        y1 -= 1
    elsif y1 < 15 then
        y1 += 1
    end if
    Draw.FillOval (0, y1, 15, 15, 43)
    Draw.FillBox (0, y1 - 2, 20, y1 + 2, 43)
    Draw.FillOval (maxx, y2, 15, 15, brightgreen)
    Draw.FillBox (maxx, y2 - 2, maxx - 20, y2 + 2, brightgreen)
    if chars (KEY_CTRL) then
        laser1 := true
    end if
    if chars (' ') then
        laser2 := true
    end if
end cannons

proc bars
    Draw.Box (25, maxy - 25, 225, maxy - 50, black)
    Draw.FillBox (26, maxy - 26, 24 + (hp1 * 2), maxy - 49, 43)
    Draw.Box (maxx - 25, maxy - 25, maxx - 225, maxy - 50, black)
    Draw.FillBox (maxx - 26, maxy - 26, maxx - 24 - (hp2 * 2), maxy - 49, brightgreen)
    Font.Draw ("Health", 100, maxy - 43, font, black)
    Font.Draw ("Health", maxx - 150, maxy - 43, font, black)
    Draw.Box (25, maxy - 55, 225, maxy - 80, black)
    Draw.FillBox (26, maxy - 56, 224, maxy - 79, brightblue)
    Draw.Box (maxx - 25, maxy - 55, maxx - 225, maxy - 80, black)
    Draw.FillBox (maxx - 26, maxy - 56, maxx - 224, maxy - 79, brightblue)
end bars

proc lasers
    if laser1 = true then
        heat1 -= heatshot
        lasery1 := y1
        for i : maxx .. 0 by speedshot
        cannons
            Draw.Line (i, lasery1, i - 20, lasery1, brightgreen)
            if i <= 0 then
                laser1 := false
            end if
        end for
    end if
    if laser2 = true then
        heat2 -= heatshot
        lasery2 := y2
        for o : 0 .. maxx by speedshot
        cannons
            Draw.Line (o, lasery2, o + 20, lasery2, 43)
            if o >= maxx then
                laser2 := false
            end if
        end for
    end if
end lasers

View.Set ("offscreenonly")
loop
    cls
    Draw.Box (maxx, maxy, 0, 0, black)
    Draw.Line (maxx, 350, 0, 350, black)
    cannons
    lasers
    bars
    View.Update
    delay (5)
end loop


thanks in advance.
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Fri Dec 02, 2005 10:30 am   Post subject: (No subject)

first of all it's
Turing:

        for decreasing i : maxx .. 0


then as you call cannons from inside that for loop, you check for movement without delays for that many steps.

you also don't need an if statement to tell when the forloop is done, just place it outside of the loop
Turing:

        for decreasing i : maxx .. 0 by speedshot
        % cannons
            Draw.Line (i, lasery1, i - 20, lasery1, brightgreen)
        end for

        laser1 := false

Also your lazer1 and lazer2 loops are separate, so while one is firing, another one can't
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
ZeroPaladn




PostPosted: Fri Dec 02, 2005 11:53 am   Post subject: (No subject)

oops Embarassed thanks tony, ill fix those.
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  [ 3 Posts ]
Jump to:   


Style:  
Search: