-
Notifications
You must be signed in to change notification settings - Fork 1
/
world_init.agc
155 lines (123 loc) · 3.6 KB
/
world_init.agc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// File: world_init.agc
// Created: 21-01-21
#include "noise.agc"
#include "core.agc"
#include "World_terrain.agc"
#include "World_light.agc"
type Vec2Data
X# as float
Y# as float
endtype
type Int2Data
X as integer
Y as integer
endtype
type ColorData
Red as integer
Green as integer
Blue as integer
endtype
type LightData
Pos as Int2Data
Range as integer
Color as ColorData
endtype
type BlockData
TypID as integer
ImageID as integer
SpriteID as integer
Color as ColorData
OldColor as ColorData
endtype
type WorldData
Block as BlockData[-1,-1]
Biome as integer[-1]
Height as integer[-1]
Light as LightData[-1]
endtype
#constant BLOCK_AIR 0
#constant BLOCK_DIRT 1
function World_Init(WorldSizeX,WorldSizeY,TileSize)
global WorldTileSize
WorldTileSize=TileSize
AtlasImageID=loadimage("images/Tiles32.png")
SetImageMagFilter(AtlasImageID,0)
global TileImageID as integer[15]
for Index=0 to TileImageID.length
TileImageID[Index]=LoadSubImage(AtlasImageID,"img"+str(Index))
next
global World as WorldData
World.Block.length=WorldSizeX
World.Biome.length=WorldSizeX
for BlockX=0 to World.Block.length
World.Block[BlockX].length=WorldSizeY
World.Biome[BlockX]=0 // I need a 1D Noise Function here
next BlockX
Noise_Init()
Noise_Seed(257)
Frecueny#=10.0
for BlockX=0 to World.Block.length
for BlockY=World.Block[0].length to 0 step -1
Noise#=0.5+Noise_Perlin2(BlockX/Frecueny#,BlockY/Frecueny#)
World.Block[BlockX,BlockY].TypID=round(Noise#)
World.Block[BlockX,BlockY].Color.Red=32
World.Block[BlockX,BlockY].Color.Green=32
World.Block[BlockX,BlockY].Color.Blue=32
next BlockY
Height=World_GetGroundHeight(BlockX)
World.Height.insert(Height)
next BlockX
ViewLeft=World_GetCameraLeftBound()
ViewTop=World_GetCameraTopBound()
ViewRight=World_GetCameraRightBound()
ViewBottom=World_GetCameraBottomBound()
for BlockX=ViewLeft to ViewRight
for BlockY=ViewTop to ViewBottom
World_CreateSprite(BlockX,BlockY)
next BlockY
World_SetSunLight(BlockX)
next BlockX
Global NumberTilesX
Global NumberTilesY
NumberTilesX=GetImageWidth(AtlasImageID)/32.0
NumberTilesY=GetImageHeight(AtlasImageID)/32.0
global AddLightFrontier as Int2Data[-1]
global RemoveLightFrontier as Int2Data[-1]
global TempFrontier as Int2Data
global BlockNeighbors as Int2Data[3]
BlockNeighbors[0].x=1
BlockNeighbors[0].y=0
BlockNeighbors[1].x=0
BlockNeighbors[1].y=1
BlockNeighbors[2].x=-1
BlockNeighbors[2].y=0
BlockNeighbors[3].x=0
BlockNeighbors[3].y=-1
global ViewZoom#
ViewZoom#=1.0
global ViewPosX#
global ViewPosY#
endfunction
function World_GetGroundHeight(BlockX)
for BlockY=1 to World.Block[0].length
if World.Block[BlockX,BlockY].TypID<>0 then exitfunction BlockY
next BlockY
endfunction 0
function World_GetBlockTypID(BlockX,BlockY)
endfunction World.Block[BlockX,BlockY].TypID
function World_GetCameraLeftBound()
ViewLeft=round(ScreenToWorldX(GetScreenBoundsLeft())/WorldTileSize)-1
ViewLeftClamp=Core_Clamp(ViewLeft,0,World.Block.length)
endfunction ViewLeftClamp
function World_GetCameraTopBound()
ViewTop=round(ScreenToWorldY(GetScreenBoundsTop())/WorldTileSize)-1
ViewTopClamp=Core_Clamp(ViewTop,0,World.Block[0].length)
endfunction ViewTopClamp
function World_GetCameraRightBound()
ViewRight=round(ScreenToWorldX(GetScreenBoundsRight())/WorldTileSize)+1
ViewRightClamp=Core_Clamp(ViewRight,0,World.Block.length)
endfunction ViewRightClamp
function World_GetCameraBottomBound()
ViewBottom=round(ScreenToWorldY(GetScreenBoundsBottom())/WorldTileSize)+1
ViewBottomClamp=Core_Clamp(ViewBottom,0,World.Block[0].length)
endfunction ViewBottomClamp