GLBasic forum

Main forum => GLBasic - en => Topic started by: shawn on 2011-Jan-28

Title: sprite movement pattern and mouse controls
Post by: shawn on 2011-Jan-28
Hello, I have my first couple of questions. Hopefully they aren't too stupid.

Lets say I have a sprite moving from left to right, how can I get it to go in a wavy pattern rather than just straight? I just want a slight movement up and down, nothing drastic.

The other question is about mouse input. I want to have a ship controlled by the mouse but I want to limit the speed so that every mouse is the same, as well as the same speed as keyboard controls. I'm sure I have seen it on the forums somewhere but I can't find it now.
Title: Re: sprite movement pattern and mouse controls
Post by: matchy on 2011-Jan-28
A1: Take the SIN of the X to wavy move. Same thing here with draw a line:
Code (glbasic) Select

// draw sine wave in a rectangle
FUNCTION draw_wave: pos_x,pos_y,wave_w,wave_h, step_x, length
LOCAL wave_x,wave_y, last_x,last_y, x1,y1, x2,y2

FOR wave_x=0 TO INTEGER(wave_w/1) STEP step_x
wave_y=INTEGER(wave_h/2)+SIN(wave_x*length)*wave_h/3
IF last_x>0
x1=pos_x+last_x
x2=pos_x+wave_x
y1=pos_y+last_y
y2=pos_y+wave_y
DRAWLINE x1+1,y1+1, x2+1,y2+1, RGB(0,255,0) //shadow
DRAWLINE x1,y1, x2,y2, RGB(0,0,255)
ENDIF
last_x=wave_x
last_y=wave_y
NEXT
ENDFUNCTION
Title: Re: sprite movement pattern and mouse controls
Post by: shawn on 2011-Jan-28
Thank you matchy, got the movement working like a treat!  =D