Help With 2D sidescoller

Help With 2D sidescoller

Postby Tainin » Mon Jul 21, 2014 10:40 pm

is there a way that for every place it says Myblock.rect.(left/top) i can have it use every item in a list or every instance of the class instead of just the one instance Myblock?

Code: Select all
    if MyPlayer.rect.left + 45 > Myblock.rect.left and MyPlayer.rect.left < Myblock.rect.left + 45 and MyPlayer.rect.top +90 > Myblock.rect.top and MyPlayer.rect.top < Myblock.rect.top +45:
        OnBlock = 1
    else:
        OnBlock = 0
Tainin
 
Posts: 3
Joined: Mon Jul 21, 2014 10:33 pm

Re: Help With 2D sidescoller

Postby metulburr » Mon Jul 21, 2014 10:59 pm

you would just put your block sprites in a group and then check against spritecollideany. If it collides with anything in the group that sprite is returned, otherwise None.
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1420
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: Help With 2D sidescoller

Postby Tainin » Tue Jul 22, 2014 10:43 pm

metulburr wrote:you would just put your block sprites in a group and then check against spritecollideany. If it collides with anything in the group that sprite is returned, otherwise None.


I just figured that out a minuet ago but ran into one problem... when i try to add an another instance of the same class with the same name but different properties it just changes the properties of the existing instance... how can i add create multiple instances of the same class with the same name or somehow make the names unique...

PS: how can i make it so i can so the player can go through a block going up but not down or to the sides???
Tainin
 
Posts: 3
Joined: Mon Jul 21, 2014 10:33 pm

Re: Help With 2D sidescoller

Postby metulburr » Tue Jul 22, 2014 11:16 pm

I just figured that out a minuet ago but ran into one problem... when i try to add an another instance of the same class with the same name but different properties it just changes the properties of the existing instance... how can i add create multiple instances of the same class with the same name or somehow make the names unique...


Code: Select all
class Klass:
    pass
   
container = []

for _ in range(10):
    container.append(Klass())

print(container)


--output--
Code: Select all
[<__main__.Klass instance at 0x7f3dfb68d6c8>, <__main__.Klass instance at 0x7f3dfb68d680>, <__main__.Klass instance at 0x7f3dfb694908>, <__main__.Klass instance at 0x7f3dfb694950>, <__main__.Klass instance at 0x7f3dfb694998>, <__main__.Klass instance at 0x7f3dfb6949e0>, <__main__.Klass instance at 0x7f3dfb694a28>, <__main__.Klass instance at 0x7f3dfb694a70>, <__main__.Klass instance at 0x7f3dfb694ab8>, <__main__.Klass instance at 0x7f3dfb694b00>]


how can i make it so i can so the player can go through a block going up but not down or to the sides???

you can look through this platformer
https://github.com/metulburr/platformer ... ame.py#L93
the tlrb is top, left, right, botton embedded in the tilemaps xml file, which defines what side of the block the player can collide with.
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1420
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: Help With 2D sidescoller

Postby Tainin » Wed Jul 23, 2014 12:13 am

metulburr wrote:
I just figured that out a minuet ago but ran into one problem... when i try to add an another instance of the same class with the same name but different properties it just changes the properties of the existing instance... how can i add create multiple instances of the same class with the same name or somehow make the names unique...


Code: Select all
class Klass:
    pass
   
container = []

for _ in range(10):
    container.append(Klass())

print(container)


--output--
Code: Select all
[<__main__.Klass instance at 0x7f3dfb68d6c8>, <__main__.Klass instance at 0x7f3dfb68d680>, <__main__.Klass instance at 0x7f3dfb694908>, <__main__.Klass instance at 0x7f3dfb694950>, <__main__.Klass instance at 0x7f3dfb694998>, <__main__.Klass instance at 0x7f3dfb6949e0>, <__main__.Klass instance at 0x7f3dfb694a28>, <__main__.Klass instance at 0x7f3dfb694a70>, <__main__.Klass instance at 0x7f3dfb694ab8>, <__main__.Klass instance at 0x7f3dfb694b00>]


how can i make it so i can so the player can go through a block going up but not down or to the sides???

you can look through this platformer
https://github.com/metulburr/platformer ... ame.py#L93
the tlrb is top, left, right, botton embedded in the tilemaps xml file, which defines what side of the block the player can collide with.


Yeah... I don't understand pretty much anything you said/linked. I am a fairly nobody... Maybe this project is a bit over my head... I am going to work on it for a while longer and see if I can get any further...


Thanks so much for the help... Even if this is over my head and I admit defeat.
Tainin
 
Posts: 3
Joined: Mon Jul 21, 2014 10:33 pm


Return to Game Development

Who is online

Users browsing this forum: No registered users and 2 guests