Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
L
LordlarKamarasi
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
LordlarKamarasi
Commits
7ad67d8e
Kaydet (Commit)
7ad67d8e
authored
Nis 21, 2019
tarafından
Batuhan Taşkaya
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Config system for map
üst
4eb5bbd9
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
19 deletions
+37
-19
controller.py
lordlarkamarasi/controller.py
+20
-8
base_map.ini
lordlarkamarasi/maps/base_map.ini
+6
-0
textures.py
lordlarkamarasi/textures.py
+11
-11
No files found.
lordlarkamarasi/controller.py
Dosyayı görüntüle @
7ad67d8e
...
...
@@ -3,23 +3,35 @@ import random
import
time
from
collections
import
UserList
from
contextlib
import
suppress
from
configparser
import
ConfigParser
from
typing
import
Tuple
import
pygame
from
pygame.locals
import
QUIT
from
lordlarkamarasi.textures
import
AVAILABLE_BLOCKS
,
TILE_SIZE
,
Blocks
from
lordlarkamarasi.textures
import
AVAILABLE_BLOCKS
,
BASE_PATH
,
TILE_SIZE
,
Blocks
class
Map
(
UserList
):
def
__init__
(
self
,
width
,
height
):
def
__init__
(
self
,
width
,
height
,
surface
):
self
.
width
=
width
self
.
height
=
height
self
.
data
=
list
(
list
(
itertools
.
repeat
(
Blocks
.
GRASS
,
width
))
for
_
in
range
(
height
)
)
self
.
_shake_map
()
self
.
data
=
surface
@classmethod
def
from_file
(
cls
,
file
):
cfg
=
ConfigParser
()
cfg
.
read
(
BASE_PATH
/
file
)
meta
=
cfg
[
'meta'
]
width
,
height
=
meta
.
getint
(
'width'
),
meta
.
getint
(
'height'
)
ground
=
cfg
[
'ground'
]
default
=
Blocks
.
get_by_id
(
ground
.
getint
(
'default'
))
surface
=
[
list
(
itertools
.
repeat
(
default
,
width
))
for
_
in
range
(
height
)]
return
cls
(
width
,
height
,
surface
)
def
_shake_map
(
self
):
for
_
in
range
((
self
.
width
*
self
.
height
)
//
32
):
print
(
random
.
choice
(
AVAILABLE_BLOCKS
))
...
...
@@ -44,7 +56,7 @@ class Game:
pygame
.
display
.
set_caption
(
"Lordlar Kamarası"
)
self
.
surface
=
pygame
.
display
.
set_mode
(
window
)
self
.
map
=
Map
(
*
(
meter
//
25
for
meter
in
window
)
)
self
.
map
=
Map
.
from_file
(
'maps/base_map.ini'
)
def
process_event
(
self
,
event
:
pygame
.
event
.
EventType
):
self
.
draw_map
()
...
...
lordlarkamarasi/maps/base_map.ini
0 → 100644
Dosyayı görüntüle @
7ad67d8e
[meta]
width
=
32
height
=
32
[ground]
default
=
0
lordlarkamarasi/textures.py
Dosyayı görüntüle @
7ad67d8e
...
...
@@ -10,8 +10,7 @@ BASE_PATH = Path(__file__).parent
def
relative_load
(
path
:
str
)
->
pygame
.
Surface
:
return
pygame
.
image
.
load
(
os
.
fspath
(
BASE_PATH
/
path
))
return
pygame
.
image
.
load
(
os
.
fspath
(
BASE_PATH
/
path
))
@dataclass
class
Block
:
...
...
@@ -21,16 +20,17 @@ class Block:
class
Blocks
(
Enum
):
STONE
=
Block
(
0
,
relative_load
(
"textures/land/stone
.png"
))
GRASS
=
Block
(
1
,
relative_load
(
"textures/land/grass
.png"
))
GRASS
=
Block
(
0
,
relative_load
(
"textures/land/grass
.png"
))
STONE
=
Block
(
1
,
relative_load
(
"textures/land/stone
.png"
))
WATER
=
Block
(
2
,
relative_load
(
"textures/land/water.png"
))
SAND
=
Block
(
3
,
relative_load
(
"textures/land/sand.png"
))
AVAILABLE_BLOCKS
=
list
(
filter
(
lambda
block
:
not
block
.
value
.
must_connect
,
Blocks
.
__members__
.
values
())
)
MUST_CONNECT_BLOCKS
=
list
(
filter
(
lambda
block
:
block
.
value
.
must_connect
,
Blocks
.
__members__
.
values
())
)
# use set substractions
@classmethod
def
get_by_id
(
cls
,
id
):
block
,
=
filter
(
lambda
member
:
member
.
value
.
id
==
id
,
cls
.
__members__
.
values
())
return
cls
(
block
)
ALL_BLOCKS
=
set
(
Blocks
.
__members__
.
values
())
AVAILABLE_BLOCKS
=
set
(
filter
(
lambda
block
:
not
block
.
value
.
must_connect
,
ALL_BLOCKS
))
MUST_CONNECT_BLOCKS
=
ALL_BLOCKS
-
AVAILABLE_BLOCKS
TILE_SIZE
=
25
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment