|
Post by Wayne Rayner on Jun 22, 2009 19:54:22 GMT -5
I have currently got my spaceship and the star on my game. I want the mouse to move the spaceship on click. Say you click on the star, the space ship moves to the star and collects it. How would I approch this.
|
|
|
Post by Nicky Peter Hollyoake on Jul 3, 2009 13:00:44 GMT -5
I ain't programmed in basic4gl for 3 months now, heres my kick at it. Dim Mouse(1) Dim ActivateSpaceship = FALSE Dim Spaceship(1) Dim Star(1)
Star(0) = RND() % TextCols() Star(1) = RND() % TextRows()
Spaceship(0) = RND() % TextCols() Spaceship(1) = RND() % TextRows()
ResizeText(50, 30) TextMode (TEXT_BUFFERED) SetTextScroll (FALSE)
While TRUE
CLS
Mouse(0) = Mouse_X() * TextCols() Mouse(1) = Mouse_Y() * TextRows()
if mouse_button (MOUSE_LBUTTON) and Mouse(0) = Star(0) and Mouse(1) = Star(1) then ActivateSpaceship = TRUE Endif if ActivateSpaceship Then if Spaceship(0) = Star(0) and Spaceship(1) = Star(1) then ActivateSpaceship = FALSE Star(0) = RND() % TextCols() Star(1) = RND() % TextRows() Else SpaceShip(0) = SpaceShip(0) - SGN(SpaceShip(0)-Star(0)) SpaceShip(1) = SpaceShip(1) - SGN(SpaceShip(1)-Star(1)) Endif Endif
'Text Locate Star(0), Star(1): Print "*" Locate Spaceship(0), Spaceship(1): Print "^"
DrawText() Sleep(75) Wend Fantastic job I think, and nicely use of SGN, it was that or more if/then/endif's... - Nicky Made a little demo using it, was bored. Dim Mouse(1) Dim ActivateSpaceship = FALSE Dim StarCounter = 0 Dim Tick Dim Spaceship(1) Dim Star(1)
Star(0) = RND() % TextCols() Star(1) = 1 + RND() % (TextRows() - 1)
Spaceship(0) = TextRows() / 2 Spaceship(1) = TextRows() / 2
ResizeText(50, 30) TextMode (TEXT_BUFFERED) SetTextScroll (FALSE)
Tick = TickCount()
While TRUE
CLS
Mouse(0) = Mouse_X() * TextCols() Mouse(1) = Mouse_Y() * TextRows()
if mouse_button (MOUSE_LBUTTON) and Mouse(0) = Star(0) and Mouse(1) = Star(1) then ActivateSpaceship = TRUE Endif if ActivateSpaceship Then if Spaceship(0) = Star(0) and Spaceship(1) = Star(1) then ActivateSpaceship = FALSE Star(0) = RND() % TextCols() Star(1) = 1 + RND() % (TextRows() - 1) StarCounter = StarCounter + 1 Else SpaceShip(0) = SpaceShip(0) - SGN(SpaceShip(0)-Star(0)) SpaceShip(1) = SpaceShip(1) - SGN(SpaceShip(1)-Star(1)) Endif Endif
'Text Color(255, 0, 0) : Locate 30, 0: Print "Stars:" ; StarCounter Color(255, 0, 255): Locate 0, 0: Print 60 - ((TickCount() - Tick) / 1000) Color(255, 255, 0): Locate Star(0), Star(1): Print "*" Color(0, 255, 255): Locate Spaceship(0), Spaceship(1): Print "^" if 60 - ((TickCount() - Tick) / 1000) < 0 Then END Endif
DrawText() Sleep(40) Wend How many stars can you get before the timer runs out. - Nicky
|
|
|
Post by Wayne Rayner on Jul 4, 2009 5:07:28 GMT -5
cool nicky it will help me with my strategy game thanks, I might even edit the code for the game a bit but awesome as I wish I could code as good as you. Also I might have to ask questions about some of the code.
thanks Wayne Rayner
|
|
|
Post by shadow008 on Jul 4, 2009 10:40:38 GMT -5
holy shit nicky!!! you still exist ?? and by the way, what does SGN do anyways
|
|