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
61119cda
Kaydet (Commit)
61119cda
authored
Nis 22, 2019
tarafından
Batuhan Taşkaya
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
more spriting
üst
7a8705ae
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
62 additions
and
32 deletions
+62
-32
controller.py
lordlarkamarasi/controller.py
+28
-28
players.py
lordlarkamarasi/players.py
+8
-1
sprites.py
lordlarkamarasi/sprites.py
+26
-0
textures.py
lordlarkamarasi/textures.py
+0
-3
No files found.
lordlarkamarasi/controller.py
Dosyayı görüntüle @
61119cda
...
...
@@ -10,10 +10,9 @@ from typing import Tuple
import
pygame
from
pygame.locals
import
*
from
lordlarkamarasi.textures
import
AVAILABLE_BLOCKS
,
BASE_PATH
,
TILE_SIZE
,
Blocks
,
Entities
from
lordlarkamarasi.textures
import
AVAILABLE_BLOCKS
,
BASE_PATH
,
TILE_SIZE
,
Blocks
from
lordlarkamarasi.players
import
PlayerRegistery
MOVE_KEYS
=
{
K_RIGHT
,
K_LEFT
,
K_UP
,
K_DOWN
}
from
lordlarkamarasi.sprites
import
Player
class
Map
(
UserList
):
def
__init__
(
self
,
width
,
height
,
surface
):
...
...
@@ -54,43 +53,44 @@ class Map(UserList):
class
Game
:
def
__init__
(
self
,
window
:
Tuple
[
int
,
int
]
=
(
800
,
800
)
):
def
__init__
(
self
):
pygame
.
init
()
pygame
.
display
.
set_caption
(
"Lordlar Kamarası"
)
self
.
surface
=
pygame
.
display
.
set_mode
(
window
)
self
.
surface
=
pygame
.
display
.
set_mode
((
800
,
800
),
DOUBLEBUF
)
self
.
surface
.
set_alpha
()
self
.
map
=
Map
.
from_file
(
'maps/base_map.ini'
)
self
.
playerreg
=
PlayerRegistery
()
self
.
sprites
=
pygame
.
sprite
.
Group
()
self
.
playerreg
=
PlayerRegistery
(
sprite_hook
=
self
.
sprites
)
self
.
player
=
self
.
playerreg
.
join
(
"BTaskaya"
)
self
.
logger
=
logging
.
getLogger
(
'Game'
)
self
.
frame_count
,
self
.
frame_rate
=
0
,
0
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
()
pygame
.
display
.
update
()
self
.
sprites
.
update
()
def
event_handler
(
self
):
event
=
pygame
.
event
.
wait
()
while
event
.
type
is
not
QUIT
:
while
event
.
type
!=
QUIT
:
t0
=
time
.
clock
()
self
.
logger
.
info
(
f
"Event handled: {event}"
)
self
.
process_event
(
event
)
event
=
pygame
.
event
.
wait
()
self
.
draw_players
()
pygame
.
display
.
update
()
t1
=
time
.
clock
()
self
.
logger
.
info
(
f
"Event processed in {t1 - t0} seconds"
)
event
=
pygame
.
event
.
poll
()
else
:
pygame
.
quit
()
def
start
(
self
):
self
.
draw_map
()
self
.
event_handler
()
def
draw_map
(
self
):
...
...
@@ -101,12 +101,12 @@ class Game:
self
.
surface
.
blit
(
block
.
value
.
texture
,
(
cpos
*
TILE_SIZE
,
rpos
*
TILE_SIZE
)
)
def
draw_players
(
self
):
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
))
self
.
sprites
.
draw
(
self
.
surface
)
if
__name__
==
"__main__"
:
logging
.
basicConfig
(
level
=
logging
.
DEBUG
)
logging
.
basicConfig
(
level
=
logging
.
INFO
)
game
=
Game
()
game
.
start
()
lordlarkamarasi/players.py
Dosyayı görüntüle @
61119cda
from
dataclasses
import
dataclass
,
field
from
collections
import
UserDict
from
lordlarkamarasi.sprites
import
Player
@dataclass
class
Coordinates
:
...
...
@@ -12,11 +13,17 @@ class Coordinates:
class
Player
:
username
:
str
coord
:
Coordinates
=
field
(
default_factory
=
Coordinates
,
repr
=
False
)
player
:
Player
=
field
(
default_factory
=
Player
,
repr
=
False
)
class
PlayerRegistery
(
UserDict
):
def
__init__
(
self
,
sprite_hook
,
*
args
,
**
kwargs
):
super
()
.
__init__
(
*
args
,
**
kwargs
)
self
.
sprite_hook
=
sprite_hook
def
join
(
self
,
username
):
self
.
data
[
username
]
=
Player
(
username
)
self
.
sprite_hook
.
add
(
self
.
data
[
username
]
.
player
)
return
self
.
data
[
username
]
def
quit
(
self
,
username
):
self
.
sprite_hook
.
remove
(
self
.
data
[
username
]
.
player
)
del
self
.
data
[
username
]
lordlarkamarasi/sprites.py
0 → 100644
Dosyayı görüntüle @
61119cda
import
pygame
from
lordlarkamarasi.textures
import
relative_load
class
Player
(
pygame
.
sprite
.
Sprite
):
def
__init__
(
self
):
super
()
.
__init__
()
self
.
image
=
relative_load
(
'textures/entities/player.png'
)
self
.
rect
=
self
.
image
.
get_rect
()
self
.
rect
.
centerx
=
800
/
2
self
.
rect
.
bottom
=
800
-
10
self
.
speedx
=
0
def
update
(
self
):
self
.
speedx
=
0
keystate
=
pygame
.
key
.
get_pressed
()
if
keystate
[
pygame
.
K_LEFT
]:
self
.
speedx
=
-
1
if
keystate
[
pygame
.
K_RIGHT
]:
self
.
speedx
=
1
self
.
rect
.
x
+=
self
.
speedx
if
self
.
rect
.
right
>
800
:
self
.
rect
.
right
=
800
if
self
.
rect
.
left
<
0
:
self
.
rect
.
left
=
0
lordlarkamarasi/textures.py
Dosyayı görüntüle @
61119cda
...
...
@@ -29,9 +29,6 @@ class Blocks(Enum):
block
,
=
filter
(
lambda
member
:
member
.
value
.
id
==
id
,
cls
.
__members__
.
values
())
return
cls
(
block
)
class
Entities
(
Enum
):
PLAYER
=
Texture
(
0xF0
,
relative_load
(
"textures/entities/player.png"
))
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
...
...
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