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
8c0fdd0e
Kaydet (Commit)
8c0fdd0e
authored
Nis 21, 2019
tarafından
Batuhan Taşkaya
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
a try to player movement
üst
e1cde7ff
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
13 deletions
+36
-13
controller.py
lordlarkamarasi/controller.py
+31
-11
players.py
lordlarkamarasi/players.py
+5
-2
No files found.
lordlarkamarasi/controller.py
Dosyayı görüntüle @
8c0fdd0e
import
itertools
import
random
import
time
import
logging
from
collections
import
UserList
from
contextlib
import
suppress
from
configparser
import
ConfigParser
from
typing
import
Tuple
import
pygame
from
pygame.locals
import
QUIT
from
pygame.locals
import
*
from
lordlarkamarasi.textures
import
AVAILABLE_BLOCKS
,
BASE_PATH
,
TILE_SIZE
,
Blocks
,
Entities
from
lordlarkamarasi.players
import
PlayerRegistery
MOVE_KEYS
=
{
K_RIGHT
,
K_LEFT
,
K_UP
,
K_DOWN
}
class
Map
(
UserList
):
def
__init__
(
self
,
width
,
height
,
surface
):
self
.
width
=
width
...
...
@@ -59,34 +62,51 @@ class Game:
self
.
map
=
Map
.
from_file
(
'maps/base_map.ini'
)
self
.
playerreg
=
PlayerRegistery
()
self
.
player
=
self
.
playerreg
.
join
(
"BTaskaya"
)
self
.
logger
=
logging
.
getLogger
(
'Game'
)
def
process_event
(
self
,
event
:
pygame
.
event
.
EventType
):
if
event
.
type
is
MOUSEMOTION
:
x
,
y
=
event
.
rel
if
x
>
0
and
self
.
player
.
coord
.
x
<=
self
.
map
.
width
:
self
.
player
.
coord
.
x
+=
1
elif
x
<
0
and
self
.
player
.
coord
.
x
>
self
.
map
.
width
:
self
.
player
.
coord
.
x
-=
1
if
y
>
0
and
self
.
player
.
coord
.
y
<=
self
.
map
.
height
:
self
.
player
.
coord
.
y
+=
1
elif
y
<
0
and
self
.
player
.
coord
.
y
>
self
.
map
.
height
:
self
.
player
.
coord
.
y
-=
1
self
.
draw_map
()
def
event_handler
(
self
,
interval
:
int
=
0.005
):
pygame
.
display
.
update
()
def
event_handler
(
self
):
event
=
pygame
.
event
.
wait
()
while
event
.
type
is
not
QUIT
:
self
.
process_event
(
event
)
pygame
.
display
.
update
()
time
.
sleep
(
interval
)
event
=
pygame
.
event
.
wait
()
print
(
event
)
else
:
pygame
.
quit
()
def
start
(
self
):
self
.
playerreg
.
join
(
"BTaskaya"
)
self
.
event_handler
()
def
draw_map
(
self
):
self
.
logger
.
info
(
f
"Drawing surface to {self.map.width * self.map.height} tiles"
)
for
rpos
,
row
in
enumerate
(
self
.
map
):
for
cpos
,
block
in
enumerate
(
row
):
self
.
surface
.
blit
(
block
.
value
.
texture
,
(
cpos
*
TILE_SIZE
,
rpos
*
TILE_SIZE
)
)
self
.
logger
.
info
(
f
"Drawing {len(self.playerreg)} players"
)
for
player
in
self
.
playerreg
.
values
():
self
.
surface
.
blit
(
Entities
.
PLAYER
.
value
.
texture
,
(
player
.
coord
.
x
*
TILE_SIZE
,
player
.
coord
.
y
*
TILE_SIZE
))
if
__name__
==
"__main__"
:
logging
.
basicConfig
(
level
=
logging
.
DEBUG
)
game
=
Game
()
game
.
start
()
lordlarkamarasi/players.py
Dosyayı görüntüle @
8c0fdd0e
...
...
@@ -6,14 +6,17 @@ class Coordinates:
x
:
int
=
0
y
:
int
=
0
def
__repr__
(
self
):
return
f
"{self.y}:{self.x}"
@dataclass
class
Player
:
username
:
str
coord
:
Coordinates
=
field
(
default_factory
=
Coordinates
)
coord
:
Coordinates
=
field
(
default_factory
=
Coordinates
,
repr
=
False
)
class
PlayerRegistery
(
UserDict
):
def
join
(
self
,
username
):
self
.
data
[
username
]
=
Player
(
username
)
return
self
.
data
[
username
]
def
quit
(
self
,
username
):
del
self
.
data
[
username
]
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