Posted: Sun May 15, 2011 2:44 pm Post subject: Making an Etch-A-Sketch?
I am trying to make an Etch-A-Sketch program for school and I got it to make lines with the arrow keys however, I want to make it so that it makes lines only when you click a button then stop making line when you click it again. Right now it always makes lines.
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<View.Set ("graphics")
var x, y, radius : int
x := 200
y := 100
radius:=15
Draw.FillOval (x, y, radius, radius, red)
var chars : array char of boolean
View.Set ("offscreenonly")
loop
Input.KeyDown (chars)
if chars (KEY_UP_ARROW) then
y+=2
Draw.FillOval (x, y, radius, radius, red)
elsif chars (KEY_RIGHT_ARROW) then
x+=2
Draw.FillOval (x, y, radius, radius, red)
elsif chars (KEY_LEFT_ARROW) then
x-=2
Draw.FillOval (x, y, radius, radius, red)
elsif chars (KEY_DOWN_ARROW) then
y-=2
Draw.FillOval (x, y, radius, radius, red)
end if
View.Update
Time.Delay (5)
end loop>
Sponsor Sponsor
mirhagk
Posted: Sun May 15, 2011 2:52 pm Post subject: RE:Making an Etch-A-Sketch?
So have you checked out any of the mouse commands, i'd suggest going into the Turing help file, and doing a search for mouse.
Tony
Posted: Sun May 15, 2011 2:56 pm Post subject: RE:Making an Etch-A-Sketch?
did you mean to ask a question in there somewhere? If so, please fill out the provided template next time.
code:
if <button-is-pressed> then
% draw the line
else
% don't draw the line
end if
Posted: Sun May 15, 2011 2:58 pm Post subject: RE:Making an Etch-A-Sketch?
What I really mean, is how do I make my circle move without making a line?
Tony
Posted: Sun May 15, 2011 3:11 pm Post subject: Re: RE:Making an Etch-A-Sketch?
vdemons @ Sun May 15, 2011 2:58 pm wrote:
What I really mean, is...
Nice, now we are getting somewhere.
As you move the circle, you'd need to clear the screen from the circle's previous location. I imagine that right now you do that by drawing a piece of a "line" on top.
The two basic approaches are either:
- re-draw the entire screen as it was before.
- draw some minimal changes on top.
Posted: Sun May 15, 2011 3:16 pm Post subject: RE:Making an Etch-A-Sketch?
...and how would I do that, the only way I know of doing that is to use "cls" but it erases the entire screen!
Tony
Posted: Sun May 15, 2011 3:20 pm Post subject: RE:Making an Etch-A-Sketch?
That's one way. Then you would need to re-draw the entire screen, as it was before (less the moving non-drawing circle). Meaning that you'd have to remember what was on the screen, somehow.
Posted: Sun May 15, 2011 3:56 pm Post subject: RE:Making an Etch-A-Sketch?
hmm... Well, the space requirement is the only real reason I would've suggested it, having a large for loop when you dont need it seems to slow down things a lot... or at least in bigger games.