April 25, 2024, 07:36:18 pm

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 2 [3] 4 5 ... 77

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

NAGN

  • Developer
  • ******
  • Karma: 146
  • Offline Offline
  • Posts: 16150
  • Yeah so now I have an idea
Re: Porting GG2 to another Language - New Thread
« Reply #30 on: August 27, 2011, 12:59:35 am »

that's fine for basic polygons but then it gets more complex with more complex terrain in which you need precise, per-pixel collisions so yes
Logged

NAGN

  • Developer
  • ******
  • Karma: 146
  • Offline Offline
  • Posts: 16150
  • Yeah so now I have an idea
Re: Porting GG2 to another Language - New Thread
« Reply #31 on: August 27, 2011, 01:03:43 am »

Going off on that idea, simplifying the per-pixel oriented nature of the wallmask may actually not be such a bad idea

stuff such as ramps can be rendered as jagged stairs, but actually handled as smooth lines that you move up upon, and in most maps you travel upon what is pretty much smooth terrain, although precision as small as one pixel will no longer be possible

box2d may not be the best engine then, as, doing some reasearch, the technique is very hard to achieve
Logged

Saniblues

  • Onion Knight
  • Administrator
  • *****
  • Karma: -1305
  • Offline Offline
  • Posts: 12206
Re: Porting GG2 to another Language - New Thread
« Reply #32 on: August 27, 2011, 01:03:59 am »

Of course, we could just re-create the maps using tilesets instead of scribbles in ms paint.
Logged
Quote from: mop
Quote from: MR MAGN3TIC
I don't like it.  :nah:
Oh, well, you might as well pack up and stop now, because he doesn't like it
I'm bored out of my skull, Lets play a different game!
Lets take a visit down below And cast the world in flames!

Orpheon

  • Moderator
  • *****
  • Karma: 15
  • Offline Offline
  • Posts: 6409
  • Developer
Re: Porting GG2 to another Language - New Thread
« Reply #33 on: August 27, 2011, 04:01:31 am »

Uhh, guys, I already looked at this problem for some time.

Assuming we're going with Python:

An idea about collisions:

Using masks to check would probably be too slow, so I thought we could do it like this.

Map Wallmasks would be passed at compile time in a special script that checks each pixels and creates a rect there if it is black/opaque/whatever.

This also allows us to scale the maps, which is not easy to do otherwise. Now we just have to scale the surface before drawing.

The string of rects would then be saved and embedded into the .png or even kept as separate file.

It can then be loaded without much problems and without much lag, and suddenly you have rects to collide with instead of masks.
(which, if you only check the rects in the area around the Character, is much faster)



My problem is this:
Code: [Select]
import os
import glob

import pygame
from load_image import load_image

from pygame.locals import *

surface = pygame.Surface()

path = 'Maps/'
for infile in glob.glob( os.path.join(path, '*_wm.png') ):

image, rect = load_image(infile)

# Loop through all the pixels and create a rect per black pixel

for a in range(0, ???)
There is no built-in function of pygame.Image to determine it's size, so I either have to guess a very large number or get creative.
Ideas?

All, and I mean all the objects we have have rectangular collision masks.
Collision detection is as simple as:

Code: [Select]
with CollisionRect
{
    if point_distance(x, y, other.x, other.y) > size_of_object+a_little_constant
    {
        continue;
    }
    else
    {
        if rect_collide(other, id)
        {
            reactToCollision()
            break;
        }
    }
}
Written in GMK syntax so that everyone can follow it, if programmed in a compiled language like C++ and packed into a dll, this could run fast as hell.
We don't need more, and this allows us to keep our pixel-based wallmasks.

PS: "CollisionRect" would be every zoomed pixel.
Logged

Flaw

  • Junior Member
  • **
  • Karma: 0
  • Offline Offline
  • Posts: 109
Re: Porting GG2 to another Language - New Thread
« Reply #34 on: August 27, 2011, 05:24:41 am »

Also, if Flaw every re-appears, I think he'll prefer Python too.
:c1:
Logged

Orpheon

  • Moderator
  • *****
  • Karma: 15
  • Offline Offline
  • Posts: 6409
  • Developer
Re: Porting GG2 to another Language - New Thread
« Reply #35 on: August 27, 2011, 05:30:47 am »

Also, if Flaw every re-appears, I think he'll prefer Python too.
:c1:
Welcome back!

Do you know Pygame (I mean well)?
Logged

Flaw

  • Junior Member
  • **
  • Karma: 0
  • Offline Offline
  • Posts: 109
Re: Porting GG2 to another Language - New Thread
« Reply #36 on: August 27, 2011, 05:36:17 am »

Also, if Flaw every re-appears, I think he'll prefer Python too.
:c1:
Welcome back!

Do you know Pygame (I mean well)?

Well, I have made some working stuff using it, so yes, I guess, kind of.
Logged

Orpheon

  • Moderator
  • *****
  • Karma: 15
  • Offline Offline
  • Posts: 6409
  • Developer
Re: Porting GG2 to another Language - New Thread
« Reply #37 on: August 27, 2011, 05:40:53 am »

Also, if Flaw every re-appears, I think he'll prefer Python too.
:c1:
Welcome back!

Do you know Pygame (I mean well)?
Well, I have made some working stuff using it, so yes, I guess, kind of.
Do you know:

a) How to scale sprites?
b) How to know the size of a sprite?
Logged

Jowly

  • Veteran Beta Tester
  • *****
  • Karma: 2
  • Offline Offline
  • Posts: 3040
Re: Porting GG2 to another Language - New Thread
« Reply #38 on: August 27, 2011, 11:26:23 am »

Quote from: Orpheon
We don't need more, and this allows us to keep our pixel-based wallmasks.
Brilliant
Logged

NAGN

  • Developer
  • ******
  • Karma: 146
  • Offline Offline
  • Posts: 16150
  • Yeah so now I have an idea
Re: Porting GG2 to another Language - New Thread
« Reply #39 on: August 27, 2011, 12:21:41 pm »

Orpheon are you suggesting that to calculate collisions we'd need to make a rect for every single pixel in the wallmask?
Logged

Orpheon

  • Moderator
  • *****
  • Karma: 15
  • Offline Offline
  • Posts: 6409
  • Developer
Re: Porting GG2 to another Language - New Thread
« Reply #40 on: August 27, 2011, 12:35:05 pm »

Orpheon are you suggesting that to calculate collisions we'd need to make a rect for every single pixel in the wallmask?
Yes.

But...

1) Those pixels correspond to 6 or 36 (not sure which) pixels ingame
2) You only need to check those near enough to the character.

The second point is important. It means per character maybe 8 rects, and of course as soon as a hit is detected you can stop checking.
If programmed in Fortran or C or some other really fast language and put into a dll, the computer could do this at an absurd speed.

It's also probably pretty much what Box2d does, only we don't even have to check for masks or stuff. Just rects.
« Last Edit: August 27, 2011, 12:35:37 pm by Orpheon »
Logged

NAGN

  • Developer
  • ******
  • Karma: 146
  • Offline Offline
  • Posts: 16150
  • Yeah so now I have an idea
Re: Porting GG2 to another Language - New Thread
« Reply #41 on: August 27, 2011, 01:09:31 pm »

I suppose in reality there's no reason to calculate the rects for every pixel on the map, just the surfaces where you can stand, and we could do some light optimization to make all the wallmasks hallow shells
Logged

Orpheon

  • Moderator
  • *****
  • Karma: 15
  • Offline Offline
  • Posts: 6409
  • Developer
Re: Porting GG2 to another Language - New Thread
« Reply #42 on: August 27, 2011, 01:48:50 pm »

I suppose in reality there's no reason to calculate the rects for every pixel on the map, just the surfaces where you can stand, and we could do some light optimization to make all the wallmasks hallow shells
Well, you have to be careful you don't mess with the collision reaction code, but yeah.

Also, the algorithm for hollow wallmask is easy.

Just check if there are rects all around you, if yes self-destruct.
Logged

Vindicator

  • Developer
  • ******
  • Karma: 84
  • Offline Offline
  • Posts: 2398
    • http://www.kylemoy.org/
Re: Porting GG2 to another Language - New Thread
« Reply #43 on: August 27, 2011, 07:31:29 pm »

I suppose in reality there's no reason to calculate the rects for every pixel on the map, just the surfaces where you can stand, and we could do some light optimization to make all the wallmasks hallow shells
Well, you have to be careful you don't mess with the collision reaction code, but yeah.

Also, the algorithm for hollow wallmask is easy.

Just check if there are rects all around you, if yes self-destruct.

Well, that or we can simply go through all the squares and merge them and make a few large rectangles.
Logged

Orpheon

  • Moderator
  • *****
  • Karma: 15
  • Offline Offline
  • Posts: 6409
  • Developer
Re: Porting GG2 to another Language - New Thread
« Reply #44 on: August 28, 2011, 04:37:19 am »

I suppose in reality there's no reason to calculate the rects for every pixel on the map, just the surfaces where you can stand, and we could do some light optimization to make all the wallmasks hallow shells
Well, you have to be careful you don't mess with the collision reaction code, but yeah.

Also, the algorithm for hollow wallmask is easy.

Just check if there are rects all around you, if yes self-destruct.

Well, that or we can simply go through all the squares and merge them and make a few large rectangles.
We can do that later.

Though that algorithm would probably be slightly more complicated.
Logged
Pages: 1 2 [3] 4 5 ... 77
 

Page created in 0.048 seconds with 50 queries.