Допустим, у вас есть класс игрока, который выглядит примерно так, мне нравится использовать pygame.sprite.collide_rect (), в этом случае у нас также будет класс стены.
class Player(pygame.sprite.Sprite):
def __init__(self,x,y):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.Surface((32,32))
self.rect = Rect(x, y, 32, 32)
def move(self, px, py):
if px != 0:
self.move_on_axis(px, 0)
if py != 0:
self.move_on_axis(0, py)
def move_on_axis(self, px, py):
self.rect.x += px
self.rect.y += py
Здесь мы щекочаем за столкновения с чем-либо в группе стен, которые мы добавляем, когда когда-либо создаем новую стену.
for wall in walls:
if pygame.sprite.collide_rect(self, wall):
if px > 0:
self.rect.right = wall.rect.left
if px < 0:
self.rect.left = wall.rect.right
if py > 0:
self.rect.bottom = wall.rect.top
if py < 0:
self.rect.top = wall.rect.bottom
class Wall(pygame.sprite.Sprite):
def __init__(self, wx):
super().__init__()
all_Sprite_List.add(self)
walls.add(self)
self.image = pygame.Surface((32,32))
self.rect = Rect(wx[0], wx[1], 32, 32)
Я не уверен, что это решение вашей проблемы, но это позволит вам добавить [KnownType(typeof(entity.Name))]
в ваш Model.tt
. Не точно имя объекта, а имена объектов каждого свойства навигации коллекции.
Это строка 1-70 моего измененного файла Model.tt
. Я только изменил строки между комментариями //START MODIFICATION
и //END MODIFICATION
.
<#@ template language="C#" debug="false" hostspecific="true"#>
<#@ include file="EF6.Utility.CS.ttinclude"#><#@
output extension=".cs"#><#
const string inputFile = @"Model.edmx";
var textTransform = DynamicTextTransformation.Create(this);
var code = new CodeGenerationTools(this);
var ef = new MetadataTools(this);
var typeMapper = new TypeMapper(code, ef, textTransform.Errors);
var fileManager = EntityFrameworkTemplateFileManager.Create(this);
var itemCollection = new EdmMetadataLoader(textTransform.Host, textTransform.Errors).CreateEdmItemCollection(inputFile);
var codeStringGenerator = new CodeStringGenerator(code, typeMapper, ef);
if (!typeMapper.VerifyCaseInsensitiveTypeUniqueness(typeMapper.GetAllGlobalItems(itemCollection), inputFile))
{
return string.Empty;
}
WriteHeader(codeStringGenerator, fileManager);
foreach (var entity in typeMapper.GetItemsToGenerate<EntityType>(itemCollection))
{
fileManager.StartNewFile(entity.Name + ".cs");
BeginNamespace(code);
#>
//START MODIFICATION
using System.Runtime.Serialization;
<#=codeStringGenerator.UsingDirectives(inHeader: false)#>
<#
var propertiesWithDefaultValues = typeMapper.GetPropertiesWithDefaultValues(entity);
var collectionNavigationProperties = typeMapper.GetCollectionNavigationProperties(entity);
var complexProperties = typeMapper.GetComplexProperties(entity);
foreach (var navigationProperty in collectionNavigationProperties)
{
#>
[KnownType(typeof(<#=typeMapper.GetTypeName(navigationProperty.ToEndMember.GetEntityType())#>))]
<#
}
#>
<#=codeStringGenerator.EntityClassOpening(entity)#>
{
<#
if (propertiesWithDefaultValues.Any() || collectionNavigationProperties.Any() || complexProperties.Any())
{
#>
public <#=code.Escape(entity)#>()
{
//END MODIFICATION
<#
foreach (var edmProperty in propertiesWithDefaultValues)
{
#>
this.<#=code.Escape(edmProperty)#> = <#=typeMapper.CreateLiteral(edmProperty.DefaultValue)#>;
<#
}
foreach (var navigationProperty in collectionNavigationProperties)
{
#>
this.<#=code.Escape(navigationProperty)#> = new HashSet<<#=typeMapper.GetTypeName(navigationProperty.ToEndMember.GetEntityType())#>>();
<#
}
foreach (var complexProperty in complexProperties)
{
#>
this.<#=code.Escape(complexProperty)#> = new <#=typeMapper.GetTypeName(complexProperty.TypeUsage)#>();
<#
}
#>
}