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

Username:   Password: 
 RegisterRegister   
 Buttons
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Salman




PostPosted: Sat Jan 19, 2013 6:19 pm   Post subject: Buttons

What is it you are trying to achieve?
<Replace all the <> with your answers/code and remove the <>>


What is the problem you are having?
<Answer Here>


Describe what you have tried to solve this problem
<Answer Here>


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>

Turing:


<Add your code here>



Please specify what version of Turing you are using
<Answer Here>
Sponsor
Sponsor
Sponsor
sponsor
Panphobia




PostPosted: Sat Jan 19, 2013 6:32 pm   Post subject: RE:Buttons

?
Salman




PostPosted: Sat Jan 19, 2013 6:53 pm   Post subject: RE:Buttons

For some reason the buttons aren't showing anymore, can you tell me how i can show thoses, this is my code:

import GUI
var x2 := maxx div 2
var y2 := maxy div 2
const radius := 10
var speedx : int := -1
var speedy : int := 1
var font : int
var font2 : int
var movement1 : int := 0
var movement2 : int := 0
var keys : array char of boolean
var x := 175
var y := 0
colorback (black)
for i : 1 .. 25 %Counted loop makes the background stay black
for j : 1 .. 80
put " " ..
end for
end for
setscreen ("nocursor,offscreenonly")
font := Font.New ("Arial Black:18")
font2 := Font.New ("Arial Black:12")
Font.Draw ("Pong", 280, 320, font, red)

procedure startGame
cls

Draw.FillBox (0, 600, maxx, 360, brightred)
Draw.FillBox (0, 00, maxx, 45, brightred)
Draw.FillBox (0, 175 + movement1, 10, 225 + movement1, brightred)
Draw.FillBox (630, x + movement2, maxx, 225 + movement2, brightred)
Font.Draw ("Player 1 Score", 5, 385, font2, blue)
Font.Draw ("Player 2 Score", 500, 385, font2, blue)
Input.KeyDown (keys)
if keys ('w') then
Draw.FillBox (0, 175 + movement1, 10, 225 + movement1, brightred)
if movement1 <= 360 - 175 - 50 then
movement1 := movement1 + 2
end if
end if

if keys ('s') then
Draw.FillBox (0, 175 + movement1, 10, 225 + movement1, brightred)
if movement1 >= 45 - 175 then
movement1 := movement1 - 2
end if
end if

if keys (KEY_UP_ARROW) then
Draw.FillBox (630, 175 + movement2, maxx, 225 + movement2, brightred)
if movement2 <= 360 - 175 - 50 then
movement2 := movement2 + 2
end if
end if

if keys (KEY_DOWN_ARROW) then
Draw.FillBox (630, 175 + movement2, maxx, 225 + movement2, brightred)
if movement2 >= 45 - 175 then
movement2 := movement2 - 2
end if
end if

Draw.FillOval (x2, y2, radius, radius, brightblue)
x2 := x2 + speedx
if y2 + speedy + radius > 360 or y2 + speedy - radius < 45 then
speedy := speedy * -1
end if
y2:=y2+speedy
if y2 + speedy + radius > 175 + movement1 and y2 + speedy + radius < 225 + movement1 and x2 + speedx - radius < 10 then
speedx := speedx * -1
end if
if y2 + speedy + radius > 175 + movement2 and y2 + speedy - radius < 225 + movement2 and x2 + speedx - radius > 620 then
speedx := speedx * -1
end if
if y2 + speedy + radius <10 or y2 + speedy + radius>maxx then
Draw.FillOval (x2, y2, radius, radius, brightblue)
end if

end startGame
var startButton : int := GUI.CreateButton (maxx div 2 - 30, 60, 60, "Start Game", startGame)



procedure helpGame
cls
Font.Draw ("Refer to the instruction manual", 100, 320, font, red)
end helpGame
var helpButtom : int := GUI.CreateButton (maxx div 2 - 200, 60, 60, "Help", helpGame)

loop
startGame
View.Update
exit when GUI.ProcessEvent
end loop
Tony




PostPosted: Sat Jan 19, 2013 7:24 pm   Post subject: RE:Buttons

looks like you are clearing the screen after you process the buttons but before you draw them to the screen.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Salman




PostPosted: Sun Jan 20, 2013 1:30 pm   Post subject: RE:Buttons

where should i process the buttons?
Tony




PostPosted: Sun Jan 20, 2013 7:40 pm   Post subject: RE:Buttons

Good question. What are your choices? It would be before and after all the other major steps that your game is taking.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Salman




PostPosted: Sun Jan 20, 2013 10:16 pm   Post subject: RE:Buttons

Start game and help are the options
Tony




PostPosted: Mon Jan 21, 2013 1:22 am   Post subject: RE:Buttons

well, the help text is only drawn when you press the button, it doesn't really matter.

You game loop right now is something like
code:

loop
   clear screen
   move stuff
   draw stuff to screen
   process buttons
end loop


but because the loop repeats over and over, it doesn't really matter after the first frame. We can describe it starting from any other point, as long as we maintain the same order of events. It is often helpful to take "draw stuff" as the last step. So what you are doing is:

code:

loop
  process buttons
  clear screen
  move stuff
  draw stuff
end loop


Thus your choices are:
[1]clear screen[2]move stuff[3]draw stuff[4]

You currently decided to place the buttons into slot [1]. I'll let you think about what that means.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Sponsor
Sponsor
Sponsor
sponsor
Salman




PostPosted: Tue Jan 22, 2013 11:32 am   Post subject: RE:Buttons

I tried this, still doesn't work

import GUI
var x2 := maxx div 2
var y2 := maxy div 2
const radius := 10
var score1 : int := 0
var score2 : int := 0
var strScore1 : string := "0"
var strScore2 : string := "0"
var speedx : int := -1
var speedy : int := 1
var font : int
var font2 : int
var movement1 : int := 0
var movement2 : int := 0
var keys : array char of boolean
var x := 175
var y := 0
colorback (black)
for i : 1 .. 25 %Counted loop makes the background stay black
for j : 1 .. 80
put " " ..
end for
end for
setscreen ("nocursor,offscreenonly")
font := Font.New ("Arial Black:18")
font2 := Font.New ("Arial Black:12")
Font.Draw ("Pong", 280, 320, font, red)
procedure startGame %This procedure runs the game
cls
Draw.FillBox (0, 600, maxx, 360, brightred)
Draw.FillBox (0, 00, maxx, 45, brightred)
Draw.FillBox (0, 175 + movement1, 10, 225 + movement1, brightred)
Draw.FillBox (630, x + movement2, maxx, 225 + movement2, brightred)
Font.Draw ("Player 1 Score", 5, 385, font2, blue)
Font.Draw ("Player 2 Score", 500, 385, font2, blue)
Input.KeyDown (keys)
if keys ('w') then
Draw.FillBox (0, 175 + movement1, 10, 225 + movement1, brightred)
if movement1 <= 360 - 175 - 50 then
movement1 := movement1 + 2
end if
end if

if keys ('s') then
Draw.FillBox (0, 175 + movement1, 10, 225 + movement1, brightred)
if movement1 >= 45 - 175 then
movement1 := movement1 - 2
end if
end if

if keys (KEY_UP_ARROW) then
Draw.FillBox (630, 175 + movement2, maxx, 225 + movement2, brightred)
if movement2 <= 360 - 175 - 50 then
movement2 := movement2 + 2
end if
end if

if keys (KEY_DOWN_ARROW) then
Draw.FillBox (630, 175 + movement2, maxx, 225 + movement2, brightred)
if movement2 >= 45 - 175 then
movement2 := movement2 - 2
end if
end if
Font.Draw (strScore1, 5, 370, font2, blue)
Font.Draw (strScore2, 600, 370, font2, blue)

Draw.FillOval (x2, y2, radius, radius, brightblue)
x2 := x2 + speedx
y2 := y2 + speedy
if y2 + speedy + radius > 360 or y2 + speedy - radius < 45 then
speedy := speedy * -1
end if
if y2 + speedy + radius > 175 + movement1 and y2 + speedy + radius < 225 + movement1 and x2 + speedx - radius < 10 then
speedx := speedx * -1
end if
if y2 + speedy + radius > 175 + movement2 and y2 + speedy - radius < 225 + movement2 and x2 + speedx - radius > 620 then
speedx := speedx * -1
end if
%If statement used for scoring
if x2 + speedx + radius > 650 then %If the x value is greater than maxx, then a point is added to player 1
score1 := score1 + 1
strScore1 := intstr (score1)
speedx := 1
x2 := maxx div 2
y2 := maxy div 2
elsif x2 + speedx + radius < 0 then %if the x value is less than zero, then a point is added to player 2
score2 := score2 + 1
strScore2 := intstr (score2) %Converts score to string value
speedx := -1
x2 := maxx div 2
y2 := maxy div 2
end if
end startGame
procedure helpGame
Font.Draw ("Refer to the instruction manual", 100, 320, font, red)
end helpGame
loop
exit when GUI.ProcessEvent
var startButton : int := GUI.CreateButton (maxx div 2 - 30, 60, 60, "Start Game", startGame)
var helpButtom : int := GUI.CreateButton (maxx div 2 - 200, 60, 60, "Help", helpGame)
View.Update
end loop
loop
startGame
View.Update
end loop
Tony




PostPosted: Tue Jan 22, 2013 3:35 pm   Post subject: Re: RE:Buttons

Salman @ Tue Jan 22, 2013 11:32 am wrote:

loop
exit when GUI.ProcessEvent
var startButton : int := GUI.CreateButton (maxx div 2 - 30, 60, 60, "Start Game", startGame)
var helpButtom : int := GUI.CreateButton (maxx div 2 - 200, 60, 60, "Help", helpGame)
View.Update
end loop

Can you explain what your code is doing here?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Salman




PostPosted: Tue Jan 22, 2013 8:13 pm   Post subject: RE:Buttons

it creates the buttons, and the loop exits when gui.quit is called, whereupon GUI.ProcessEvent will return true and the loop will exit
Salman




PostPosted: Tue Jan 22, 2013 8:15 pm   Post subject: RE:Buttons

When, i run it just the buttons won't clear
Tony




PostPosted: Tue Jan 22, 2013 8:38 pm   Post subject: RE:Buttons

- how many buttons will it create (hint, it's more than 2)?
- when will the loop exit (that is, when will GUI.Quit be called)?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Salman




PostPosted: Tue Jan 22, 2013 8:59 pm   Post subject: RE:Buttons

It will create 2 buttons, the loop will exit when GUI.ProcessEvent
Salman




PostPosted: Tue Jan 22, 2013 9:17 pm   Post subject: RE:Buttons

I'm still confused with what to do
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 2  [ 22 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: