Re: Vertical Problems

new topic     » goto parent     » topic index » view thread      » older message » newer message

On Wed, 20 Sep 2000 16:14:54 -0700, Paul Kerslake wrote:

>I've drawn a -smirk- tank at the bottom of the screen and I;m trying to
>get the turret to move. The down (d) movement works but the  up (u)
>movement does not stop. What am I doing wrong? Also, is there a way to
>stop the line from "growing" and simply have it's angle change? Thanks.

The answer to your first question is: check your logic.  (you had a '>'
where you should have had a '<')  but to simplify somewhat, I'd do
something like this:

include graphics.e
include get.e
integer gmode,desc
gmode=graphics_mode(19)

atom lengthh,reach,uright,lleft
  lengthh = 20
  reach   = 30
  uright  = 185
  lleft   = 185

draw_line(1,{{lengthh,uright},{reach,lleft}})

while 1 do
    desc=wait_key()
    if desc='u' then
      if lleft > 175 then
        draw_line(0,{{lengthh,uright},{reach,lleft}})
        lleft -= 1
        draw_line(1,{{lengthh,uright},{reach,lleft}})
      end if
    elsif desc='d' then
      if lleft < 195 then
        draw_line(0,{{lengthh,uright},{reach,lleft}})
        lleft+=1
        draw_line(1,{{lengthh,uright},{reach,lleft}})
      end if
    elsif desc='q' then
        gmode = graphics_mode(-1)
        abort(1)
    end if
end while
-------------------------------------------------------------------

To answer your second question, I'd do something like this:

include graphics.e
include get.e
include misc.e

integer gmode,desc
gmode=graphics_mode(19)

integer angle, radius
  angle = 0
  radius = 10
sequence origin
  origin = { 20, 185 }

function deg2rad( integer angle_deg )
  return angle_deg * PI / 180
end function

procedure draw_turret( integer color, integer angl )
  sequence pt2
  atom rad

  rad = deg2rad( 90 + angl )

  pt2 = { origin[1] + radius*sin( rad ), origin[2] + radius*cos( rad ) }
  draw_line( color, {origin, pt2} )
end procedure

draw_turret( 1, 0 )

while 1 do
    desc=wait_key()
    if desc='d' then
      if angle > -45 then
        draw_turret( 0, angle )
        angle -= 5
        draw_turret( 1, angle )
      end if
    elsif desc='u' then
      if angle < 45 then
        draw_turret( 0, angle )
        angle += 5
        draw_turret( 1, angle )
      end if
    elsif desc='q' then
        gmode = graphics_mode(-1)
        abort(1)
    end if
end while
-----------------------------------------------------------

Good Luck!
 Brian

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu