
-----------------------------------
Blessing
Wed Jan 20, 2010 6:28 pm

Just need to work out the kinks of my program (aka, collision mechanics)
-----------------------------------
Hi there! I'm trying to figure out a couple of things, most importantly, how to make a sprite, collide with a box as well as why my buttons aren't working.


What is the problem you are having?

- I don't get it/It's not working

I've tried using a procedure vs a process to try and get it to create a button, but that doesn't work as both processes and procedures must be at the module level to work properly.

My code is nearly 300 lines, but I'll post it anyways :P



import GUI
var winID : int
winID := Window.Open ("nobuttonbar,position:truemiddle,centre,graphics:640;480")
var misslei : int := Pic.FileNew ("Misslea.bmp")
var missle : int := Sprite.New (misslei)
var text1 : int := Font.New ("Times New Roman:18:Bold")
var a, b, a2, b2, a3, c, clr, count, d, e, l, lives, msize, w, x, y : int
var yesnoplay, ynp2 : string
a2 := 0
b := 620
b2 := 640
a2 := 0
c := 33
clr := 218
count := 0
d := 30
l := 1
lives := 3
msize := 1
w := 0
x := 100
y := 100
process music
    play ("cdef1g 4gfed1c")
end music
fork music
for i : 0 .. 39
    RGB.SetColor (clr, 0, 0, i / 39)
    Font.Draw ("Wanna play? Put in a game code if you have one. ( y/n )", (maxx div 2) - (Font.Width ("Wanna play? Put in a game code if you have one. ( y/n )", text1) div 2), (maxy div 2) - 9,
        text1, clr)
    View.Update
    delay (50)
end for
get yesnoplay
if yesnoplay = "n" then
    put "That's a shame."
    delay (500)
end if
if yesnoplay = "y" then
    put "Good. here we go."
    delay (500)
elsif yesnoplay = "100%achievement" then
    delay (500)
    put "Wow! You beat the game?"
    delay (500)
    put "In that case... do you want to use the smaller missle? ( put '1' for big, and '2' for small )"
    get msize
    if msize = 1 then
        put "Okay, Have fun!!!"
    elsif msize = 2 then
        put "Okay, Have fun!!!"
    end if
end if
process music2
    play ("4cdef1g")
end music2
fork music2
loop
    d := d - 1
    colorback (d)
    delay (100)
    cls
    exit when d = 16
end loop
for i : 0 .. 39
    RGB.SetColor (clr, 0, 0, i / 39)
    Font.Draw ("Welcome to...", (maxx div 2) - (Font.Width ("Welcome to...", text1) div 2), (maxy div 2) - 9, text1, clr)
    View.Update
    delay (50)
end for
delay (1000)
for decreasing i : 39 .. 0
    RGB.SetColor (clr, 0, 0, i / 39)
    Font.Draw ("Welcome to...", (maxx div 2) - (Font.Width ("Welcome to...", text1) div 2), (maxy div 2) - 9, text1, clr)
    View.Update
    delay (50)
end for
cls
delay (1000)
for i : 0 .. 39
    RGB.SetColor (clr, 0, 0, i / 39)
    Font.Draw ("Explodin'", (maxx div 2) - (Font.Width ("Explodin'", text1) div 2), (maxy div 2) - 9, text1, clr)
    View.Update
    delay (50)
end for
delay (1000)
for decreasing i : 39 .. 0
    RGB.SetColor (clr, 0, 0, i / 39)
    Font.Draw ("Explodin'", (maxx div 2) - (Font.Width ("Explodin'", text1) div 2), (maxy div 2) - 9, text1, clr)
    View.Update
    delay (50)
end for
process music3
    play ("4gfed1c")
end music3
fork music3
loop
    d := d + 1
    colorback (d)
    delay (100)
    cls
    exit when d = 30
end loop
cls
if msize = 1 then
    misslei := Pic.FileNew ("Misslea.bmp")
    missle := Sprite.New (misslei)
elsif msize = 2 then
    misslei := Pic.FileNew ("missleb.bmp")
    missle := Sprite.New (misslei)
end if
randint (a, 50, 440)
var key : array char of boolean
process misslecontrol
    loop
        a2 := 0
        Input.KeyDown (key)
        if key (KEY_UP_ARROW) then
            y += 1
        end if
        if key (KEY_DOWN_ARROW) then
            y -= 1
        end if
        if key (KEY_RIGHT_ARROW) then
            x += 1
        end if
        if key (KEY_LEFT_ARROW) then
            x -= 1
        end if
        Sprite.Show (missle)
        Sprite.SetPosition (missle, x, y, true)
        delay (5)
        if x = 0 then
            x := 1
        end if
        if x = 640 then
            x := 639
        end if
        if y = 0 then
            y := 1
        end if
        if y = 480 then
            y := 479
        end if
    end loop
end misslecontrol
process levelup
    for i : 0 .. 39
        RGB.SetColor (clr, 0, 0, i / 39)
        Font.Draw ("Level Up!!!", (maxx div 2) - (Font.Width ("Level Up!!!", text1) div 2), (maxy div 2) - 9, text1, clr)
        View.Update
        delay (10)
    end for
    for decreasing i : 39 .. 0
        RGB.SetColor (clr, 0, 0, i / 39)
        Font.Draw ("Level Up!!!", (maxx div 2) - (Font.Width ("Level Up!!!", text1) div 2), (maxy div 2) - 9, text1, clr)
        View.Update
        delay (50)
    end for
end levelup
fork misslecontrol
loop
    if missle < b and missle < a and missle > b2 and missle > a2 then
        lives := lives - 1
    end if
    locate (1, 1)
    put "Level ", l
    locate (2, 1)
    put "Walls Passed ", count
    locate (3, 1)
    put "Lives; ", lives
    drawfillbox (b, a, b2, a2, grey)
    drawfillbox (b, a + 80, b2, 480, grey)
    b := b - 5
    b2 := b2 - 5
    drawfillbox (b + 20, 0, b2 + 20, 480, white)
    delay (c - 20)
    if b = 0 then
        count := count + 1
        drawfillbox (0, 0, 20, 480, white)
        b := 620
        b2 := 640
        randint (a, 50, 360)
    end if
    if count = 5 then
        fork levelup
        c := c - 1
        count := 0
        l := l + 1
    end if
    if l = 7 then
        put "WOW! I didn't think you'd make it this far..."
    end if
    if l = 8 then
        put "One last level...."
    end if
    exit when l = 9
end loop
cls
play ("4abcd1e 4edcdcbcb1a")
cls
for i : 0 .. 39
    RGB.SetColor (clr, 0, 0, i / 39)
    Font.Draw ("Wow... You won!", (maxx div 2) - (Font.Width ("Wow... You won!", text1) div 2), (maxy div 2) - 9, text1, clr)
    View.Update
    delay (10)
end for
cls
for decreasing i : 39 .. 0
    RGB.SetColor (clr, 0, 0, i / 39)
    Font.Draw ("Wow... You won!", (maxx div 2) - (Font.Width ("Wow... You won!", text1) div 2), (maxy div 2) - 9, text1, clr)
    View.Update
    delay (50)
end for
cls
for i : 0 .. 39
    RGB.SetColor (clr, 0, 0, i / 39)
    Font.Draw ("You've Unlocked a Smaller Missle!", (maxx div 2) - (Font.Width ("You've Unlocked a Smaller Missle!", text1) div 2), (maxy div 2) - 9, text1, clr)
    View.Update
    delay (10)
end for
cls
for decreasing i : 39 .. 0
    RGB.SetColor (clr, 0, 0, i / 39)
    Font.Draw ("You've Unlocked a Smaller Missle!", (maxx div 2) - (Font.Width ("You've Unlocked a Smaller Missle!", text1) div 2), (maxy div 2) - 9, text1, clr)
    View.Update
    delay (50)
end for
cls
for i : 0 .. 39
    RGB.SetColor (clr, 0, 0, i / 39)
    cls
    Font.Draw ("Next time you play enter the code ", (maxx div 2)
        - (Font.Width ("Next time you play enter the code ", text1) div 2), (maxy div 2) - 9, text1, clr)
    View.Update
    delay (10)
end for
cls
for decreasing i : 39 .. 0
    RGB.SetColor (clr, 0, 0, i / 39)
    Font.Draw ("Next time you play enter the code ", (maxx div 2)
        - (Font.Width ("Next time you play enter the code ", text1) div 2), (maxy div 2) - 9, text1, clr)
    View.Update
    delay (50)
end for
cls
for i : 0 .. 39
    RGB.SetColor (clr, 0, 0, i / 39)
    cls
    Font.Draw ("'100%achievement' to use the smaller missle.", (maxx div 2)
        - (Font.Width ("'100%achievement' to use the smaller missle.", text1) div 2), (maxy div 2) - 9, text1, clr)
    View.Update
    delay (10)
end for
cls
for decreasing i : 39 .. 0
    RGB.SetColor (clr, 0, 0, i / 39)
    Font.Draw ("'100%achievement' to use the smaller missle.", (maxx div 2)
        - (Font.Width ("'100%achievement' to use the smaller missle.", text1) div 2), (maxy div 2) - 9, text1, clr)
    View.Update
    delay (50)
end for

delay (500)
cls
Window.Close (winID)
loop
    exit when GUI.ProcessEvent
end loop


I'm using 4.1.1
