Math Problem
Blitz3D Forums/Blitz3D Programming/Math Problem
| ||
Hello! Im currently trying to code a new enemy for my 2d space shooter game. It should be a chain that osciallte from left to right. Hope this graphic helps you to understand what i want to to. I tought it should be possible with Sin/Cos Commands. But it won't work the way i want it to. Here is the code: Graphics 800,600 SetBuffer BackBuffer() While Not KeyDown(1) Cls tt=tt+1 If tt>360 Then tt=0 For i=0 To 50 Plot 400+Sin(tt)*i,50+i*10+Cos(tt)*i Next Line 400,50,400,600 ;Axis Flip Wend |
| ||
something like that ?Graphics 800,600 SetBuffer BackBuffer() While Not KeyDown(1) If KeyHit(57) Then typ = typ +1 typ = typ Mod 2 Cls tt=tt+1 ;If tt>360 Then tt=0 ;modulo is better ... i think tt = tt Mod 360 For i=0 To 50 Select typ Case 0 ;like that ? x = 400 + Sin(tt) * 400 Case 1 ;or like that ? x = 400 + Sin(tt+((i/50.0)*360)) * 400 End Select y = 50+i*10 Plot x,y Next Line 400,50,400,600 ;Axis Text 10,10,"Hit space to switch type" Flip Wend |
| ||
Hello, thank you for your post. But your code event doesn't that what I want to :-) The left-right movment is correct, but i think in a chain that swings each part also moves a little bit up and down. Imagine you hold a chain, than all parts move like on a path of a circle I think. Do you know what i mean? |
| ||
Graphics 800,600 SetBuffer BackBuffer() d=1 i=-90 While Not KeyDown(1) Cls i=i+d For o=1 To 100 Step 10 Plot 400+Sin(i)*o,300+Cos(i)*o Next If Abs(i)=90 Then d=-d Line 400,0,400,600 ;Axis Flip Wend and Graphics 800,600 SetBuffer BackBuffer() d=2 i=-90 o#=10 Cls Line 400,0,400,600 While Not KeyDown(1) i=i+d o#=o#+0.05 Plot 400+Sin(i)*o#,300+Cos(i)*o# If Abs(i)>=90 Then d=-d Flip Wend or Graphics 800,600 SetBuffer BackBuffer() d#=80 i#=-90 o#=10 Cls Line 400,0,400,600 While Not KeyDown(1) i#=i#+d#/o# o#=o#+0.1 Plot 400+Sin(i#)*o#,300+Cos(i#)*o# If Abs(i#)>=90 Then d#=-d# Flip Wend |
| ||
Hey, cool... this looks much better, but still one problem ;) when the direct change the speed should getting slower and after direction it should accelerate again. i've tried it that way, and i think it will work this way. Anyway, thank you very much for the help, and if you still have improvements it would be great if you post it here :-) Graphics 800,600 SetBuffer BackBuffer() d#=1 i#=0 While Not KeyDown(1) Cls Text 10,10,i Text 10,30,d i=i+d For o=1 To 100 Step 10 Plot 400+Sin(i)*o,300+Cos(i)*o Next If i>45 Then d=d-0.01 If i<-45 Then d=d+0.01 If d>1 Then d=1 If d<-1 Then d=-1 Line 400,0,400,600 ;Axis Flip Wend |
| ||
something like this thenGraphics 800,600 SetBuffer BackBuffer() d=20 i#=-90 Cls While Not KeyDown(1) a#=(1/Abs(i)*d) If a#>1 Then a#=1 i#=i#+a# Cls Line 400,0,400,600 Plot 400+Sin(i#)*50,300+Cos(i#)*50 If Abs(i)>=90 Then d=-d Text 0,0,1/Abs(i#)*d Flip Wend |
| ||
If you want correct pendule physics try this:Graphics 800,600 SetBuffer BackBuffer() d=1 i#=-90 s#=0 While Not KeyDown(1) Cls s=s-Sin(i)*.01 s=s*.999 ;Slowing the speed i=i+s For o=1 To 100 Step 10 Plot 400+Sin(i)*o,300+Cos(i)*o Next Line 400,0,400,600 ;Axis Flip Wend |