Re: Create a game map?

2019-10-01 Thread AudioGames . net Forum — Developers room : frastlin via Audiogames-reflector


  


Re: Create a game map?

Hello,You don't iterate through tiles, you iterate through polygons. That way you can create a world that is endless and if you only have 1 object, then you're only looping through that one object.Look at:https://github.com/frastlin/PyAudioGame … ui/grid.pyThe Grid class is self-contained and is what you are looking for. It's extremely fast and can hold thousands of objects.

URL: https://forum.audiogames.net/post/465592/#p465592




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Create a game map?

2019-10-01 Thread AudioGames . net Forum — Developers room : chrisnorman7 via Audiogames-reflector


  


Re: Create a game map?

Hi,Probably an unpopular suggestion, but worth chucking out there:I know there's lots of boilerplate code in here, but I've taken the _Base class from my pyrts project.With the below code you can instantiate maps and tiles with relative ease. Of course there's no provision for storing objects, but that's only a matter of extending what I've written.I use this kind of setup a lot. If you want to see more sql in action, look at the pyrts source code, or check the running instance.from enum import Enum as PythonEnum
from inspect import isclass

from sqlalchemy import (
create_engine, Column, Integer, ForeignKey, Enum, inspect
)
from sqlalchemy.exc import DatabaseError
from sqlalchemy.orm import relationship, sessionmaker
from sqlalchemy.ext.declarative import declarative_base

engine = create_engine('sqlite:///:memory:')
Session = sessionmaker(bind=engine)
session = Session()


class TileTypes(PythonEnum):
"""The possible types for tiles."""

sand = 0
grass = 1
water = 2
wall = 3
lava = 4


class _Base:
"""Create a primary key and some useful methods."""
id = Column(Integer, primary_key=True)

def save(self):
"""Save this object."""
session.add(self)
try:
session.commit()
except DatabaseError:
session.rollback()
raise

def delete(self):
session.delete(self)
try:
session.commit()
except DatabaseError:
session.rollback()
raise

@classmethod
def query(cls, *args, **kwargs):
"""Return a query object with this class."""
return session.query(cls).filter(*args).filter_by(**kwargs)

@classmethod
def count(cls, *args, **kwargs):
"""Return the number of instances of this class in the database."""
return cls.query(*args, **kwargs).count()

@classmethod
def first(cls, *args, **kwargs):
"""Return the first instance of this class in the database."""
return cls.query(*args, **kwargs).first()

@classmethod
def get(cls, id):
"""Get an object with the given id."""
return cls.query().get(id)

@classmethod
def one(cls, *args, **kwargs):
return cls.query(*args, **kwargs).one()

@classmethod
def all(cls, *args, **kwargs):
"""Return all child objects."""
return cls.query(*args, **kwargs).all()

@classmethod
def classes(cls):
"""Return all table classes."""
for item in cls._decl_class_registry.values():
if isclass(item) and issubclass(item, cls):
yield item

@classmethod
def number_of_objects(cls):
"""Returns the number of objects in the database."""
count = 0
for base in cls.classes():
count += base.count()
return count

def __repr__(self):
name = type(self).__name__
string = '%s (' % name
attributes = []
i = inspect(type(self))
for column in i.c:
name = column.name
attributes.append('%s=%r' % (name, getattr(self, name)))
string += ', '.join(attributes)
return string + ')'

@classmethod
def get_class_from_table(cls, table):
"""Return the class whose __table__ attribute is the provided Table
instance."""
for value in cls._decl_class_registry.values():
if getattr(value, '__table__', None) is table:
return value


Base = declarative_base(bind=engine, cls=_Base)


class Tile(Base):
"""A tile on the map."""

__tablename__ = 'tiles'
x = Column(Integer, nullable=False)
y = Column(Integer, nullable=False)
type = Column(Enum(TileTypes), nullable=False)
map_id = Column(Integer, ForeignKey('maps.id'), nullable=False)
map = relationship(
'Map', backref='tiles', single_parent=True,
cascade='all, delete-orphan'
)


class Map(Base):
"""A map which can contain lots of tiles."""

__tablename__ = 'maps'
size_x = Column(Integer, nullable=False, default=100)
size_y = Column(Integer, nullable=False, default=100)
default_type = Column(
Enum(TileTypes), nullable=False, default=TileTypes.sand
)

@property
def size(self):
return self.size_x, self.size_y

@size.setter
def size(self, value):
self.size_x, self.size_y = value

def tile_at(self, x, y):
"""Return the type of tile at the given coordinates."""
tile = Tile.first(map=self, x=x, y=

Re: Create a game map?

2019-09-28 Thread AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector


  


Re: Create a game map?

I'm bringing this up because I do want to try an array and compare it to my system.I figured out how to create a numpy 3d array, use the zero's function with x, y, and z dimentions. Here's the problem:import numpy as np
lst = np.zeros((5000, 5000, 5000))
ValueError: array is too big; `arr.size * arr.dtype.itemsize` is larger than the maximum possible size.This is, without a doubt, a huge array. It is also something that I may not need. However, an array of 1000 of each entry is also something that numpy hates, and I could definately see myself reaching 1k tile size.However, my solution, to loop through tiles, is also really slow (5000 * 5000 * 5000 or 1000 * 1000 * 1000) entries to loop through? No thanks. Ideas/tips?Edit:Even 200 * 200 * 200 lags like a bitch when I loop through tiles. Yeah no, I will try and switch away from my systemas soon as possible.

URL: https://forum.audiogames.net/post/464917/#p464917




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Create a game map?

2019-09-28 Thread AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector


  


Re: Create a game map?

I'm bringing this up because I do want to try an array and compare it to my system.I figured out how to create a numpy 3d array, use the zero's function with x, y, and z dimentions. Here's the problem:import numpy as np
lst = np.zeros((5000, 5000, 5000))
ValueError: array is too big; `arr.size * arr.dtype.itemsize` is larger than the maximum possible size.This is, without a doubt, a huge array. It is also something that I may not need. However, an array of 1000 of each entry is also something that numpy hates, and I could definately see myself reaching 1k tile size.However, my solution, to loop through tiles, is also really slow (5000 * 5000 * 5000 or 1000 * 1000 * 1000) entries to loop through? No thanks. Ideas/tips?

URL: https://forum.audiogames.net/post/464917/#p464917




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Create a game map?

2019-09-27 Thread AudioGames . net Forum — Developers room : frastlin via Audiogames-reflector


  


Re: Create a game map?

Look for a point in polygon algorithm in your language of choice, and just use polygons.Python:https://pypi.org/project/collision/_javascript_:https://www.npmjs.com/package/flatten-jsFor 3D objects, you'll want something like Panda3D or BabylonJS.

URL: https://forum.audiogames.net/post/464848/#p464848




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Create a game map?

2019-09-27 Thread AudioGames . net Forum — Developers room : nuno69 via Audiogames-reflector


  


Re: Create a game map?

@2, it's good! I would use enum for type, but can you please send me the class?

URL: https://forum.audiogames.net/post/464698/#p464698




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Create a game map?

2019-09-11 Thread AudioGames . net Forum — Developers room : kianoosh via Audiogames-reflector


  


Re: Create a game map?

For instance, you may asign 1 through 100 to tile types, 101 through 200 to door types, 201 to 300 to walls. And I'm organizing it like that because you don't know how many tiles/walls you're going to have, And you might gradually increase the amount of them so you reserve 100 for each catigory. However, i meant putting tiles as string in an array and parsing each element to get each tile's left and right boundaries. Or an array of classes

URL: https://forum.audiogames.net/post/461248/#p461248




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Create a game map?

2019-09-11 Thread AudioGames . net Forum — Developers room : kianoosh via Audiogames-reflector


  


Re: Create a game map?

For instance, you may asign 1 through 100 to tile types, 101 through 200 to door types, 201 to 300 to walls. And I'm organizing it like that because you don't know how many tiles/walls you're going to have, And you might gradually increase the amount of them so you reserve 100 for each catigory

URL: https://forum.audiogames.net/post/461248/#p461248




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Create a game map?

2019-09-11 Thread AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector


  


Re: Create a game map?

@6, I would modify the index operator to allow me to pass in a tuple, which reads a bit smoother, then define a class as an enum to hold all my tile types:from aenum import Enum
class Tile(Enum, start=0):
Wall
Empty
#...

if map[(player.x, player.y)].type == Tile.Wall.value: #Tile is a wall
elif ...: # ...Things like that.

URL: https://forum.audiogames.net/post/461236/#p461236




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Create a game map?

2019-09-11 Thread AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector


  


Re: Create a game map?

@4/5, really? Could you explain a bit as to why post 2's approach wouldn't be that good? I am asking because I can't picture having multiple tile sets in a 2d array, not unless I want to do something like this:if map[player.x][player.y] == -1: #wall logic should go hereNow, how do I determine what wall sound to play?Or something like thisif map[player.x][player.y] == 0: #Wood tile play soundif map[player.x][player.y] == 1: #Ash tile play sound.With post 2's approach I would be able to tell what sound to play by checking the tile type, how would you two go about implementing multiple tiles in a 2D array, though?

URL: https://forum.audiogames.net/post/461185/#p461185




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Create a game map?

2019-09-11 Thread AudioGames . net Forum — Developers room : kianoosh via Audiogames-reflector


  


Re: Create a game map?

Nuno You eventually need to check every square the player walks on, and perhaps the surrounding squares so the array is your best bet. It's fast and performant

URL: https://forum.audiogames.net/post/461134/#p461134




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Create a game map?

2019-09-10 Thread AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector


  


Re: Create a game map?

a 2D array is the best your going to get. Just check each square as the player navigates, and use NumPy (don't use lists of lists, vectors of vectors, etc.) or the equivalent for your language of choice. Since you're accessing them directly by index your most likely going to get O(1) performance, or extremely close to it.I'm telling you not to use lists of lists/vectors of vectors/... because those will create massive levels of indirection and tons of cache misses, and they're not built for that. Use a dedicated library that is able to represent a 2D vector properly without all the problems. You could make your own 2D vector class, too, though you then need to figure out if you want row-major order or column-major order. C, for example, uses row-major order. If you want to use row-major order, then create the list and resize it to map width * map height, then access it as map width * row + column in the index operator function.

URL: https://forum.audiogames.net/post/461073/#p461073




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Create a game map?

2019-09-10 Thread AudioGames . net Forum — Developers room : alisson via Audiogames-reflector


  


Re: Create a game map?

I use a dictionaries, and im implementing a real staircase on my 3d map. Its a bit buggy for now, but im managing to make the map work slowly, and is greath how things are getting betther and betther. If you want you can check my github where I have my map sistem.https://github.com/CartridgeSoft/game-engine-test

URL: https://forum.audiogames.net/post/461051/#p461051




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Create a game map?

2019-09-10 Thread AudioGames . net Forum — Developers room : pauliyobo via Audiogames-reflector


  


Re: Create a game map?

you could create a class which is the map interface and then create classes that can represent your tiles, zones, and stuff. I'd do something like the followingclass MapObj{    // a map object    // this is the base class from where all the other objects such as tiles and zones can inherit    // sorry if the code doesn't follow c#'s code convention, feel free to adjust it.    public int minX;    public int maxX;    public int minY;    public int maxY;    // if you wanted a 3d map you could add minxZ and maxZ too.    public MapObj(int minx, int maxx, int miny, int maxy)    {        this.minX = minx;        this.maxX = maxx;        this.minY = minY;        this.maxY = maxY;    }    public bool covers(int x, int y)    {        // here you could define a function that would return true if the set of coordinates are covered from the tile    }}Then you could create a tile like thispublic class tile : MapObj{    public string type;    public tile(int minx, int maxx, int miny, int maxy, string type)    : base(minx, maxx, miny, maxy)    {        this.type = type;    }}you could implement then a function get_tile_type() which would return the type of the tile. if the type is wall, then boom you have it.If you want I could send you the map class that I've made so that you can fully use it.

URL: https://forum.audiogames.net/post/460831/#p460831




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Create a game map?

2019-09-10 Thread AudioGames . net Forum — Developers room : nuno69 via Audiogames-reflector


  


Create a game map?

Hi! How should I go for creating a game map? I tried 2D array but then implementing stuff like walls is tedious as I need to check each and every square. ANy other advice?

URL: https://forum.audiogames.net/post/460812/#p460812




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector