Two buttons at once
Author |
Message |
andyman
|
Posted: Sun Dec 07, 2003 10:31 am Post subject: Two buttons at once |
|
|
I've been trying to create to buttons for my program. One will start a new game and the other will continue your file if it previously exists. Then when one is clicked the other button will disappear. I'm using version 3.1.1 and no I our school won't get the newer version. Here's my program so far:
code: | % setscreen ("graphics:400;600:sxga")
setscreen ("nocursor")
var fontQ : int := Font.New ("Rockwell:16")
var fontID : int := Font.New ("Rockwell:20")
var fn : string
var intnum : int
var mousex, mousey, mouseb : int
mousewhere (mousex, mousey, mouseb)
function mouseover (x1, y1, x2, y2 : int) : boolean
var mousex, mousey, mouseb : int
mousewhere (mousex, mousey, mouseb)
if mousex >= x1 and mousex <= x2 then
if mousey >= y1 and mousey <= y2 then
result true
end if
end if
result false
end mouseover
procedure button (x1, y1, x2, y2, p1, p2 : int, c : string)
loop
var mousex, mousey, mouseb : int
mousewhere (mousex, mousey, mouseb)
if mouseover (x1, y1, x2, y2) then
drawfillbox (x1, y1, x2, y2, grey)
drawline (x1, y2, x2, y2, 25)
drawline (x1, y1, x1, y2, 25)
drawline (x1, y1, x2, y1, 30)
drawline (x2, y1, x2, y2, 30)
Font.Draw (c, x1 + p1, y1 + p2, fontQ, black)
if mouseb = 1 and mouseover (x1, x2, y1, y2) then
drawfillbox (x1, y1, x2, y2, 104)
drawline (x1, y2, x2, y2, blue)
drawline (x1, y1, x1, y2, blue)
drawline (x1, y1, x2, y1, black)
drawline (x2, y1, x2, y2, black)
Font.Draw (c, x1 + p1, y1 + p2, fontQ, yellow)
delay (100)
cls
exit
end if
else
drawfillbox (x1, y1, x2, y2, grey)
drawline (x1, y2, x2, y2, 30)
drawline (x1, y1, x1, y2, 30)
drawline (x1, y1, x2, y1, 25)
drawline (x2, y1, x2, y2, 25)
Font.Draw (c, x1 + p1 - 1, y1 + p2, fontQ, black)
end if
delay (10)
end loop
end button
process button1 (x1, y1, x2, y2, p1, p2 : int, c : string)
button (x1, y1, x2, y2, p1, p2, c)
cls
Font.Draw ("Enter your name", 80, 580, fontID, black)
Font.Draw ("to start your own file", 60, 560, fontID, black)
locatexy (0, 540)
get fn : *
open : intnum, fn, put
end button1
process buttons2 (x1, y1, x2, y2, p1, p2 : int, c : string)
button (x1, y1, x2, y2, p1, p2, c)
cls
Font.Draw ("Hi Enter your name", 80, 580, fontID, black)
Font.Draw ("to start your own file", 60, 560, fontID, black)
locatexy (0, 540)
get fn : *
end buttons2
fork button1(50, 350, 150, 375, 11, 3, "New Game")
fork buttons2(200, 350, 300, 375, 18, 3, "Continue")
|
If there's a way to fix it or make it better, I would appreciate it. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Dan
|
Posted: Sun Dec 07, 2003 3:00 pm Post subject: (No subject) |
|
|
it whould probly be easyer to uses the GUI buttons for this but GUI is buggy and a pain to lrean some times.
the main porblm with your progam is all the forks and process. i hate thous. this progame can be done better with out them by modfing your fuctions a bit:
code: |
% setscreen ("graphics:400;600:sxga")
setscreen ("nocursor")
var fontQ : int := Font.New ("Rockwell:16")
var fontID : int := Font.New ("Rockwell:20")
var fn : string
var intnum : int
var mousex, mousey, mouseb : int
mousewhere (mousex, mousey, mouseb)
function mouseover (x1, y1, x2, y2 : int) : boolean
var mousex, mousey, mouseb : int
mousewhere (mousex, mousey, mouseb)
if mousex >= x1 and mousex <= x2 then
if mousey >= y1 and mousey <= y2 then
result true
end if
end if
result false
end mouseover
function button (x1, y1, x2, y2, p1, p2 : int, c : string) : boolean
var mousex, mousey, mouseb : int
var flag : boolean := false
mousewhere (mousex, mousey, mouseb)
if mouseover (x1, y1, x2, y2) then
flag := true
drawfillbox (x1, y1, x2, y2, grey)
drawline (x1, y2, x2, y2, 25)
drawline (x1, y1, x1, y2, 25)
drawline (x1, y1, x2, y1, 30)
drawline (x2, y1, x2, y2, 30)
Font.Draw (c, x1 + p1, y1 + p2, fontQ, black)
if mouseb = 1 and mouseover (x1, x2, y1, y2) then
drawfillbox (x1, y1, x2, y2, 104)
drawline (x1, y2, x2, y2, blue)
drawline (x1, y1, x1, y2, blue)
drawline (x1, y1, x2, y1, black)
drawline (x2, y1, x2, y2, black)
Font.Draw (c, x1 + p1, y1 + p2, fontQ, yellow)
delay (100)
cls
result true
end if
else
drawfillbox (x1, y1, x2, y2, grey)
drawline (x1, y2, x2, y2, 30)
drawline (x1, y1, x1, y2, 30)
drawline (x1, y1, x2, y1, 25)
drawline (x2, y1, x2, y2, 25)
Font.Draw (c, x1 + p1 - 1, y1 + p2, fontQ, black)
end if
result false
end button
procedure button1 ()
cls
Font.Draw ("Enter your name", 80, 580, fontID, black)
Font.Draw ("to start your own file", 60, 560, fontID, black)
locatexy (0, 540)
get fn : *
open : intnum, fn, put
end button1
procedure button2 ()
cls
Font.Draw ("Hi Enter your name", 80, 580, fontID, black)
Font.Draw ("to start your own file", 60, 560, fontID, black)
locatexy (0, 540)
get fn : *
end button2
procedure buttons ()
loop
if button (50, 350, 150, 375, 11, 3, "New Game") then
button1 ()
elsif button (200, 350, 300, 375, 18, 3, "Continue") then
button2 ()
end if
delay (10)
end loop
end buttons
buttons()
|
i think this will do what you whont better |
Computer Science Canada
Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more! |
|
|
|
|
|
|