December 23, 2024, 02:08:40 am

The Gang Garrison 2 Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

NOTICE: Wondering where all the forums have gone?

Join the community Discord server!

Pages: 1 ... 7 8 [9] 10 11 ... 77

Author Topic: Official PyGG2 Development thread  (Read 161083 times)

notajf

  • Guest
Re: Porting GG2 to another Language - New Thread
« Reply #120 on: September 04, 2011, 07:52:22 am »

Why so stagnant? :(
Logged

Orpheon

  • Moderator
  • *****
  • Karma: 15
  • Offline Offline
  • Posts: 6409
  • Developer
Re: Porting GG2 to another Language - New Thread
« Reply #121 on: September 04, 2011, 08:22:57 am »

Why so stagnant? :(
Because school and UDP gg2, for me.
Logged

Flaw

  • Junior Member
  • **
  • Karma: 0
  • Offline Offline
  • Posts: 109
Re: Porting GG2 to another Language - New Thread
« Reply #122 on: September 07, 2011, 11:58:08 am »

Why so stagnant? :(
Because school and ***** * ***** ** *****, for me.
Logged

notajf

  • Guest
Re: Porting GG2 to another Language - New Thread
« Reply #123 on: September 07, 2011, 02:23:57 pm »

Why so stagnant? :(
Because school and ***** * ***** ** *****, for me.
?
Logged

Maxaxle

  • Full Member
  • ***
  • Karma: -128
  • Offline Offline
  • Posts: 398
  • Resident Serious Business
    • My Site
Re: Porting GG2 to another Language - New Thread
« Reply #124 on: September 07, 2011, 09:06:20 pm »

Why so stagnant? :(
Because school and ***** * ***** ** *****, for me.
?
Either it's too private or it's TMI. Or it could be both. :barf:

EDIT: Who picked out the emoticons under [more]?
« Last Edit: September 07, 2011, 09:07:46 pm by Maxaxle »
Logged

notajf

  • Guest
Re: Porting GG2 to another Language - New Thread
« Reply #125 on: September 08, 2011, 01:44:06 am »

They are mostly the default ones for SMF
Logged

Orpheon

  • Moderator
  • *****
  • Karma: 15
  • Offline Offline
  • Posts: 6409
  • Developer
Re: Porting GG2 to another Language - New Thread
« Reply #126 on: September 10, 2011, 05:09:39 am »



Changed the collision detection the way MedO suggested it.

Now we need to work on the collision response again, as it's still not really working perfectly.

https://github.com/Orpheon/PyGG2
« Last Edit: September 10, 2011, 07:07:00 am by Orpheon »
Logged

Orpheon

  • Moderator
  • *****
  • Karma: 15
  • Offline Offline
  • Posts: 6409
  • Developer
Re: Porting GG2 to another Language - New Thread
« Reply #127 on: September 11, 2011, 08:46:47 am »

Against all odds, it works. We have a collision response code.
(even though it's a bit buggy at times)

Code: [Select]
def objectCheckCollision(character):

# Check if an object has hit the wallmask:

hasCollided = False

character.rect.centerx = character.x-character.xRectOffset
character.rect.centery = character.y-character.yRectOffset

clip = character.rect.clip(character.root.map.rect)

#find where clip's top-left point is in both rectangles
x1 = clip.left - character.root.map.rect.left
y1 = clip.top  - character.root.map.rect.top
 
#cycle through clip's area of the hitmasks
for x in range(clip.width):
for y in range(clip.height):
#returns True if neither pixel is blank
if character.root.map.mask.get_at((x1+x, y1+y)) == 1:
hasCollided = True

if hasCollided:
return True
else:
return False



def characterHitObstacle(character):


# THIS IS THE NEW VERSION; STILL WITH x/y


    newX = character.x
    newY = character.y

    hspeed = character.hspeed
    vspeed = character.vspeed

    length = lengthdir(hspeed, vspeed)

    if length == 0:# You haven't moved; if this happens something went wrong

        print "You haven't moved, yet managed to collide with something."
        return False


    # hs and vs is the normalized vector of hspeed and vspeed.
    hs = character.hspeed/length
    vs = character.vspeed/length

    while True:
        if not objectCheckCollision(character):
            break

        character.x -= hs
        character.y -= vs

# return True

    # This is the left-over velocity.
    hs = hspeed
    vs = vspeed

# The character got pushed out, but now we need to let him move in the directions he's allowed to move.


    character.x += sign(hs)

    if not objectCheckCollision(character) and abs(hs) > 0:

        # There's still room to move on the left/right

        i = 1
        while i <= abs(hs) and not objectCheckCollision(character):

            character.x += sign(hs)
            i += 1
    else:

        # Stop horizontal movement
        character.hspeed = 0
        character.hs = 0


    if objectCheckCollision(character):
        character.x -= sign(hs)

    character.y += sign(vs)

    if not objectCheckCollision(character) and abs(vs) > 0:

        # There's still room to move on the left/right


        i = 1
        while i <= abs(vs) and not objectCheckCollision(character):

            character.y += sign(vs)
            i += 1

    else:
        # Stop vertical movement
        character.vspeed = 0
        character.vs = 0

    if objectCheckCollision(character):
        character.y -= sign(vs)

    return True

PyGG2
Logged

notajf

  • Guest
Re: Porting GG2 to another Language - New Thread
« Reply #128 on: September 11, 2011, 08:48:19 am »

Against all odds, it works. We have a collision response code.
(even though it's a bit buggy at times)

Code: [Select]
def objectCheckCollision(character):

# Check if an object has hit the wallmask:

hasCollided = False

character.rect.centerx = character.x-character.xRectOffset
character.rect.centery = character.y-character.yRectOffset

clip = character.rect.clip(character.root.map.rect)

#find where clip's top-left point is in both rectangles
x1 = clip.left - character.root.map.rect.left
y1 = clip.top  - character.root.map.rect.top
 
#cycle through clip's area of the hitmasks
for x in range(clip.width):
for y in range(clip.height):
#returns True if neither pixel is blank
if character.root.map.mask.get_at((x1+x, y1+y)) == 1:
hasCollided = True

if hasCollided:
return True
else:
return False



def characterHitObstacle(character):


# THIS IS THE NEW VERSION; STILL WITH x/y


    newX = character.x
    newY = character.y

    hspeed = character.hspeed
    vspeed = character.vspeed

    length = lengthdir(hspeed, vspeed)

    if length == 0:# You haven't moved; if this happens something went wrong

        print "You haven't moved, yet managed to collide with something."
        return False


    # hs and vs is the normalized vector of hspeed and vspeed.
    hs = character.hspeed/length
    vs = character.vspeed/length

    while True:
        if not objectCheckCollision(character):
            break

        character.x -= hs
        character.y -= vs

# return True

    # This is the left-over velocity.
    hs = hspeed
    vs = vspeed

# The character got pushed out, but now we need to let him move in the directions he's allowed to move.


    character.x += sign(hs)

    if not objectCheckCollision(character) and abs(hs) > 0:

        # There's still room to move on the left/right

        i = 1
        while i <= abs(hs) and not objectCheckCollision(character):

            character.x += sign(hs)
            i += 1
    else:

        # Stop horizontal movement
        character.hspeed = 0
        character.hs = 0


    if objectCheckCollision(character):
        character.x -= sign(hs)

    character.y += sign(vs)

    if not objectCheckCollision(character) and abs(vs) > 0:

        # There's still room to move on the left/right


        i = 1
        while i <= abs(vs) and not objectCheckCollision(character):

            character.y += sign(vs)
            i += 1

    else:
        # Stop vertical movement
        character.vspeed = 0
        character.vs = 0

    if objectCheckCollision(character):
        character.y -= sign(vs)

    return True

PyGG2
Cool.

Now STOP USING TABS DAMNIT. Set your editor to replace tabs with 4 spaces :/
Logged

Orpheon

  • Moderator
  • *****
  • Karma: 15
  • Offline Offline
  • Posts: 6409
  • Developer
Re: Porting GG2 to another Language - New Thread
« Reply #129 on: September 11, 2011, 08:49:58 am »

Against all odds, it works. We have a collision response code.
(even though it's a bit buggy at times)

Code: [Select]
def objectCheckCollision(character):

# Check if an object has hit the wallmask:

hasCollided = False

character.rect.centerx = character.x-character.xRectOffset
character.rect.centery = character.y-character.yRectOffset

clip = character.rect.clip(character.root.map.rect)

#find where clip's top-left point is in both rectangles
x1 = clip.left - character.root.map.rect.left
y1 = clip.top  - character.root.map.rect.top
 
#cycle through clip's area of the hitmasks
for x in range(clip.width):
for y in range(clip.height):
#returns True if neither pixel is blank
if character.root.map.mask.get_at((x1+x, y1+y)) == 1:
hasCollided = True

if hasCollided:
return True
else:
return False



def characterHitObstacle(character):


# THIS IS THE NEW VERSION; STILL WITH x/y


    newX = character.x
    newY = character.y

    hspeed = character.hspeed
    vspeed = character.vspeed

    length = lengthdir(hspeed, vspeed)

    if length == 0:# You haven't moved; if this happens something went wrong

        print "You haven't moved, yet managed to collide with something."
        return False


    # hs and vs is the normalized vector of hspeed and vspeed.
    hs = character.hspeed/length
    vs = character.vspeed/length

    while True:
        if not objectCheckCollision(character):
            break

        character.x -= hs
        character.y -= vs

# return True

    # This is the left-over velocity.
    hs = hspeed
    vs = vspeed

# The character got pushed out, but now we need to let him move in the directions he's allowed to move.


    character.x += sign(hs)

    if not objectCheckCollision(character) and abs(hs) > 0:

        # There's still room to move on the left/right

        i = 1
        while i <= abs(hs) and not objectCheckCollision(character):

            character.x += sign(hs)
            i += 1
    else:

        # Stop horizontal movement
        character.hspeed = 0
        character.hs = 0


    if objectCheckCollision(character):
        character.x -= sign(hs)

    character.y += sign(vs)

    if not objectCheckCollision(character) and abs(vs) > 0:

        # There's still room to move on the left/right


        i = 1
        while i <= abs(vs) and not objectCheckCollision(character):

            character.y += sign(vs)
            i += 1

    else:
        # Stop vertical movement
        character.vspeed = 0
        character.vs = 0

    if objectCheckCollision(character):
        character.y -= sign(vs)

    return True

PyGG2
Cool.

Now STOP USING TABS DAMNIT. Set your editor to replace tabs with 4 spaces :/
Uhh...I did that.

Code: [Select]
Tab Width: 4
Insert spaces instead of the tabs: On
« Last Edit: September 11, 2011, 08:50:19 am by Orpheon »
Logged

Vindicator

  • Developer
  • ******
  • Karma: 84
  • Offline Offline
  • Posts: 2398
    • http://www.kylemoy.org/
Re: Porting GG2 to another Language - New Thread
« Reply #130 on: September 11, 2011, 10:12:57 pm »

Anyone want to point me towards something they want done? I'm learning python, but I'm not far enough into the mindset to just start doing things.
Logged

Orpheon

  • Moderator
  • *****
  • Karma: 15
  • Offline Offline
  • Posts: 6409
  • Developer
Re: Porting GG2 to another Language - New Thread
« Reply #131 on: September 12, 2011, 07:02:13 am »

Anyone want to point me towards something they want done? I'm learning python, but I'm not far enough into the mindset to just start doing things.
Umm, well...

-You can improve anything you see in the code which is buggy (collision code for example)
-You could try making other classes and a class-select screen
-You could try making weapons (Scattergun+Shot object)
-You could try making menus, atm it jumps right into the game
-You could try to make a map background separate from the foreground, and maybe do the wallmask loading from a string like it's in gg2.
-You could try making health and HUDs
-You could try to make a game mode, probably ctf first.
-You could go learn how Twisted works for later, because we'll probably be using that for the networking.

Only suggestions though.
Logged

notajf

  • Guest
Re: Porting GG2 to another Language - New Thread
« Reply #132 on: September 12, 2011, 10:19:34 am »

Against all odds, it works. We have a collision response code.
(even though it's a bit buggy at times)

Code: [Select]
def objectCheckCollision(character):

# Check if an object has hit the wallmask:

hasCollided = False

character.rect.centerx = character.x-character.xRectOffset
character.rect.centery = character.y-character.yRectOffset

clip = character.rect.clip(character.root.map.rect)

#find where clip's top-left point is in both rectangles
x1 = clip.left - character.root.map.rect.left
y1 = clip.top  - character.root.map.rect.top
 
#cycle through clip's area of the hitmasks
for x in range(clip.width):
for y in range(clip.height):
#returns True if neither pixel is blank
if character.root.map.mask.get_at((x1+x, y1+y)) == 1:
hasCollided = True

if hasCollided:
return True
else:
return False



def characterHitObstacle(character):


# THIS IS THE NEW VERSION; STILL WITH x/y


    newX = character.x
    newY = character.y

    hspeed = character.hspeed
    vspeed = character.vspeed

    length = lengthdir(hspeed, vspeed)

    if length == 0:# You haven't moved; if this happens something went wrong

        print "You haven't moved, yet managed to collide with something."
        return False


    # hs and vs is the normalized vector of hspeed and vspeed.
    hs = character.hspeed/length
    vs = character.vspeed/length

    while True:
        if not objectCheckCollision(character):
            break

        character.x -= hs
        character.y -= vs

# return True

    # This is the left-over velocity.
    hs = hspeed
    vs = vspeed

# The character got pushed out, but now we need to let him move in the directions he's allowed to move.


    character.x += sign(hs)

    if not objectCheckCollision(character) and abs(hs) > 0:

        # There's still room to move on the left/right

        i = 1
        while i <= abs(hs) and not objectCheckCollision(character):

            character.x += sign(hs)
            i += 1
    else:

        # Stop horizontal movement
        character.hspeed = 0
        character.hs = 0


    if objectCheckCollision(character):
        character.x -= sign(hs)

    character.y += sign(vs)

    if not objectCheckCollision(character) and abs(vs) > 0:

        # There's still room to move on the left/right


        i = 1
        while i <= abs(vs) and not objectCheckCollision(character):

            character.y += sign(vs)
            i += 1

    else:
        # Stop vertical movement
        character.vspeed = 0
        character.vs = 0

    if objectCheckCollision(character):
        character.y -= sign(vs)

    return True

PyGG2
Cool.

Now STOP USING TABS DAMNIT. Set your editor to replace tabs with 4 spaces :/
Uhh...I did that.

Code: [Select]
Tab Width: 4
Insert spaces instead of the tabs: On
No you didn't, the code you pasted there has tabs not spaces
Logged

Orpheon

  • Moderator
  • *****
  • Karma: 15
  • Offline Offline
  • Posts: 6409
  • Developer
Re: Porting GG2 to another Language - New Thread
« Reply #133 on: September 12, 2011, 10:24:55 am »

No you didn't, the code you pasted there has tabs not spaces
I still changed the options.
Logged

notajf

  • Guest
Re: Porting GG2 to another Language - New Thread
« Reply #134 on: September 12, 2011, 10:46:29 am »

No you didn't, the code you pasted there has tabs not spaces
I still changed the options.
well, fix your code. maybe you confused tab width and tabs to spaces
Logged
Pages: 1 ... 7 8 [9] 10 11 ... 77
 

Page created in 0.022 seconds with 36 queries.