Author Topic: Moves a point linearly in any direction  (Read 127 times)

eleusmario

  • Administrator
  • Newbie
  • *****
  • Posts: 12
    • View Profile
Moves a point linearly in any direction
« on: November 27, 2017, 06:34:30 AM »
Function to move a point from an initial line, initial column to an end line, final column, great for creating games to fire in any direction, the function was based on the line generation algorithm at https://www.tutorialspoint.com/computer_graphics/line_generation_algorithm.htm:

Code: [Select]
Window PointSize = 10

Shoot(5, 5, 20, 70) 'Shoot from initial Line, initial Column to final line, final column

EndProgram

Function Shoot(L1 Integer, C1 Integer, L2 Integer, C2 Integer)
  Var DL Integer, DC Integer
  Var Steps Integer, LIncrement Decimal, CIncrement Decimal
  Var L Decimal, C Decimal, V Integer
 
  L = L1; C = C1

  If L2 > L1
    DL = L2 - L1
  Else
    DL = L1 - L2
  EndIf 
  If C2 > C1
    DC = C2 - C1
  Else
    DC = C1 - C2
  EndIf 

  If DL > DC
    Steps = DL
  Else
    Steps = DC
  EndIf 

  LIncrement = DL / Steps
  CIncrement = DC / Steps

  If L1 > L2; Lincrement = Lincrement * (-1); EndIf
  If C1 > C2; Cincrement = Cincrement * (-1); EndIf

  V = 0
  While V < Steps
    Cls
    L += LIncrement
    C += CIncrement
 
    Point L, C, Blue
    Wait Events
    V++
  Loop
EndFunction

Randal

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Moves a point linearly in any direction
« Reply #1 on: November 28, 2017, 06:35:34 AM »
Do you feel like Logic Basic will be used for game making someday? I know there are lots of libraries out there but I also know that you are developing this from scratch so it may all be native code. It's a curiosity.

So far I haven't done much. We've been moving from place to place for over a month and finally settled and I have a permanent place. So I brought up LB and thought I would play with it again when I came across this piece of code. I think it would be fun to create a mini game in LB. :)
Maybe it's just a bunch of stuff that happens. -- Homer Simpson

eleusmario

  • Administrator
  • Newbie
  • *****
  • Posts: 12
    • View Profile
Re: Moves a point linearly in any direction
« Reply #2 on: December 01, 2017, 04:30:05 AM »
Hello Randal,

Yes, I plan to create a complete game in Logic Basic, perhaps with the collaboration of other LB users, I will soon be posting the code in this section.