Ooops
March 05, 2021, 07:33:18 AM
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email
?
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Like stats
Home
Forum
Help
Search
Gallery
Login
Register
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
Graphics
»
[bb] Filled Circle in 2 dimensional array by Pakz [ 1+ years ago ]
« previous
next »
Print
Pages: [
1
]
Go Down
Author
Topic: [bb] Filled Circle in 2 dimensional array by Pakz [ 1+ years ago ] (Read 402 times)
BlitzBot
Jr. Member
Posts: 1
Total likes: 0
[bb] Filled Circle in 2 dimensional array by Pakz [ 1+ years ago ]
«
on:
June 29, 2017, 12:28:39 AM »
Title :
Filled Circle in 2 dimensional array
Author :
Pakz
Posted :
1+ years ago
Description :
I was reading the Java Gaming forum and saw a post with some useful code in it. I was code for the fog of war feature. It drew filled circles on coordinates in the map. I did not know how to do this yet. I used to create a circle with data statements and then check true or false for getting the circle shape. The method in the code below uses some math to create a filled circle. It can have a set radius.
I made a small example around it. This example can also be tweaked to becoming a map generator to
Code :
Code: BlitzBasic
; Filled circle in 2 dimensional array
; By Rudy van Etten in 2014
Graphics
640
,
480
,
32
,
2
SetBuffer
BackBuffer
(
)
SeedRnd
MilliSecs
(
)
Const
mapwidth =
39
Const
mapheight =
29
Const
tilewidth =
16
Const
tileheight =
16
Dim
map
(
mapwidth,mapheight
)
Type
point
Field
x,y,radius,radmod
End Type
makepoint
(
3
)
Repeat
Cls
If
KeyDown
(
1
)
=
True
Then
End
Dim
map
(
mapwidth,mapheight
)
For
this.point=
Each
point
mapcircle
(
thisx,thisy,this
adius
)
this
adius = this
adius + this
admod
If
this
adius >
9
Then
this
admod = -
1
If
this
adius <
2
Then
this
admod =
1
Next
drawmap
(
)
Flip
For
i=
0
To
100
Delay
1
If
KeyDown
(
1
)
=
True
Then
End
Next
Forever
End
Function
mapcircle
(
x1,y1,radius
)
For
y2=-radius
To
radius
For
x2=-radius
To
radius
If
(
y2*y2+x2*x2
)
<= radius*radius+radius*
0.8
x3 = x1+x2
y3 = y1+y2
If
x3>=
0
And
y3>=
0
And
x3<=mapwidth
And
y3<=mapheight
map
(
x3,y3
)
=
1
End If
End If
Next
Next
End Function
Function
makepoint
(
num
)
For
i=
0
To
num
this.point =
New
point
thisx =
Rand
(
mapwidth
)
thisy =
Rand
(
mapheight
)
If
Rand
(
0
,
1
)
=
1
this
admod =
1
Else
this
admod = -
1
End If
this
adius =
Rand
(
1
,
9
)
Next
End Function
Function
drawmap
(
)
For
y=
0
To
mapheight
For
x=
0
To
mapwidth
If
map
(
x,y
)
=
0
Color
0
,
0
,
0
ElseIf
map
(
x,y
)
=
1
Color
255
,
255
,
255
End If
Rect
x*tilewidth,y*tileheight,tilewidth,tileheight,
True
Next
Next
End Function
Comments :
none...
Logged
Print
Pages: [
1
]
Go Up
« previous
next »
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
Graphics
»
[bb] Filled Circle in 2 dimensional array by Pakz [ 1+ years ago ]
SimplePortal 2.3.6 © 2008-2014, SimplePortal