Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
isometric
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Teckids
Projekt Hack-n-Fun
Material und Vorlagen
Thema Spieleprogrammierung
isometric
Commits
aa72b94d
Commit
aa72b94d
authored
5 years ago
by
Philipp Stahl
Browse files
Options
Downloads
Patches
Plain Diff
Added map loading
parent
e9974997
Branches
master
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
main.py
+51
-12
51 additions, 12 deletions
main.py
with
51 additions
and
12 deletions
main.py
+
51
−
12
View file @
aa72b94d
"""
Author: Kirill Schmidt,
Lukas Weichelt
, Robert Seimetz
Author: Kirill Schmidt,
Philipp Stahl
, Robert Seimetz
A game with an isometric (2.5D) view.
"""
# Import modules
import
sys
import
pygame
import
pygame
,
pytmx
from
pygame.locals
import
*
# Set constants
...
...
@@ -15,19 +14,48 @@ SCREEN_WIDTH = 720
TILE_HEIGHT
=
46
TILE_WIDTH
=
46
# Spritegroups
all_sprites
=
pygame
.
sprite
.
RenderClear
()
passable
=
pygame
.
sprite
.
RenderClear
()
building
=
pygame
.
sprite
.
RenderClear
()
screen
=
pygame
.
display
.
set_mode
((
SCREEN_HEIGHT
,
SCREEN_WIDTH
))
class
Way
(
pygame
.
sprite
.
Sprite
):
def
__init__
(
self
,
x
,
y
):
pygame
.
sprite
.
Sprite
.
__init__
(
self
)
self
.
image
=
"
sprites/grass.png
"
self
.
rect
=
self
.
images
.
get_rect
()
self
.
rect
.
topleft
=
twoDtoIso
(
x
,
y
)
class
Map
():
def
__init__
(
self
,
surface
):
self
.
Map
=
pytmx
.
load_pygame
(
surface
,
pixelalpha
=
True
)
self
.
width
=
self
.
Map
.
width
*
self
.
Map
.
tilewidth
self
.
height
=
self
.
Map
.
height
*
self
.
Map
.
tileheight
self
.
data
=
self
.
Map
def
render
(
self
,
surface
):
tile_image
=
self
.
data
.
get_tile_image_by_gid
for
layer
in
self
.
data
.
visible_layers
:
if
isinstance
(
layer
,
pytmx
.
TiledTileLayer
):
for
x
,
y
,
gid
,
in
layer
:
tile
=
tile_image
(
gid
)
if
tile
:
surface
.
blit
(
tile
,
(
x
*
self
.
Map
.
tilewidth
,
y
*
self
.
Map
.
tileheight
))
def
draw
():
screen
.
fill
((
0
,
0
,
0
))
all_sprites
.
draw
(
screen
)
pygame
.
display
.
flip
()
def
main
():
# Initialise screen
pygame
.
init
()
screen
=
pygame
.
display
.
set_mode
((
SCREEN_HEIGHT
,
SCREEN_WIDTH
))
pygame
.
display
.
set_caption
(
SCREEN_NAME
)
# Fill background
background
=
pygame
.
Surface
(
screen
.
get_size
())
background
=
background
.
convert
()
background
.
fill
((
0
,
0
,
0
))
# Blit everything to the screen
screen
.
blit
(
background
,
(
0
,
0
))
screen
.
fill
((
0
,
0
,
0
))
pygame
.
display
.
update
()
# Initialise map
...
...
@@ -40,6 +68,17 @@ def main():
[
1
,
1
,
1
,
1
,
1
]
]
'''
map1 = Map(
"
foo.tmx
"
)
for obejects in map1.data.objects:
if objects.name ==
"
way
"
:
sprite = Way(obejcts.x, objects.y)
if objects.type ==
"
passable
"
:
passable.add(sprite)
all_sprites.add(sprite)
'''
# Load images
wall
=
pygame
.
image
.
load
(
'
sprites/wall.png
'
).
convert
()
grass
=
pygame
.
image
.
load
(
'
sprites/grass.png
'
).
convert
()
...
...
@@ -68,10 +107,10 @@ def main():
# Event loop
while
1
:
#draw()
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
QUIT
:
pygame
.
quit
()
sys
.
exit
()
exit
(
0
)
# Function to convert cartesian coordinates to isometric
def
twoDtoIso
(
cartX
,
cartY
):
isoX
=
cartX
-
cartY
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment