Other A challange or too easy: Spiders web!

Mark Read

Well-Known Member
Licensed User
Longtime User
I need to be able to draw a spiders web (roughly) starting from the middle of the screen and stopping well before the borders of the screen.

I have no idea how I should program this or is it even possible in B4A?

Hints, tips or code would be very welcome.
Regards
Mark
 

Mark Read

Well-Known Member
Licensed User
Longtime User
Okay, thanks Erel. Now I know its possible but I have no idea where to start. Can someone give a few pointers?
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
Its an idea for a shoot-m-up game. The bad guys would come from the center of the web and move along the strands. The good guy moves around the outer ring and shoots the bad guys and collects ammo for example. The games starts with maybe three triangles and works up to a complex web form each level.....
I just need some idea how to generate the web. Tricky would also be how to control the movement only on the strands.

Thanks
 

Attachments

  • spidersWeb1.gif
    spidersWeb1.gif
    11.7 KB · Views: 154
Upvote 0

derez

Expert
Licensed User
Longtime User
web.png


Not exactly but close...

B4X:
Sub Globals
Dim cnvs As Canvas
Dim m As Int = 15
Dim n As Int = 7
Dim alfa As Double = -360 / m
Dim dr As Double 
Dim cx As Int = 50%x
Dim cy As Int = 50%y
End Sub

Sub Activity_Create(FirstTime As Boolean)
cnvs.Initialize(Activity)
End Sub

Sub Activity_Resume
draw
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub draw
Dim r As Double = 50%y
For i = 0 To m-1
    cnvs.DrawLine(cx, cy,cx + r*SinD(i * alfa),cy+ r*CosD(i * alfa) ,Colors.white,2)
Next
r = 0
dr = 50%x / m / n
Dim angle As Double = 0
Do While r <= 50%x
    cnvs.DrawLine(cx+r*SinD(angle),cy+r*CosD(angle),cx+(r+dr)*SinD(angle+alfa),cy+(r+dr)*CosD(angle+alfa),Colors.White,2)
    angle = angle + alfa
    r = r+dr
Loop
Activity.Invalidate
End Sub

By the way - real webs are spiral like the one above:
images
 
Last edited:
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
@derez, this is great but as you said not exactly what I mean.

I will try to explain: Level 1 would start something like the attached picture. The blue dots are the bad guys. They come from the center and can only move outwards until they reach the limit of the "web", then they can move around it. The red dot is the good guy, he can only move around the outside of the "web". Each further level adds a triangle and a bad guy. The code to generate the web must have a variable which I can increment each level to increase the complexity and it should not be a spiral. Hope this is clear

I think I also need to "remember" where the web is to enable the correct movement??
Regards
Mark
 

Attachments

  • game.jpg
    game.jpg
    15.8 KB · Views: 150
Upvote 0

derez

Expert
Licensed User
Longtime User
B4X:
Sub draw
Dim r As Double = 50%y
For i = 0 To m-1
    cnvs.DrawLine(cx, cy,cx + r*SinD(i * alfa),cy+ r*CosD(i * alfa) ,Colors.white,2)
Next
dr = 50%x / n
For i = 1 To n-1
    r = i * dr
    For j = 0 To m-1
        cnvs.DrawLine(cx+r*SinD(j*alfa),cy+r*CosD(j*alfa),cx+r*SinD((j+1)*alfa),cy+r*CosD((j+1)*alfa),Colors.White,2)
    Next
Next
Activity.Invalidate
End Sub

The rest of the game is for you to plan...
The complexity of the web is controlled by m and n.
upload_2014-3-14_10-9-8.png
 
Last edited:
Upvote 0
Top