Re: [pygame] Capabilities of Pygame

2012-01-14 Thread R. Alan Monroe
 FORTRAN is still used in some circles because it's
 still very fast for number crunching.

A bit off topic, but I've seen this bit of folk wisdom repeated online
for a long time and have always been skeptical. How does a C command
that gets compiled to a CPU's MUL instruction differ in any way from a
Fortran command that also gets compiled to that same CPU's same MUL
instruction? Honest question.

Alan



Re: [pygame] man oh man Java is painful

2011-11-04 Thread R. Alan Monroe
 (though I understand Java is capable of as good or better
 performance than C/C++)

In  execution  speed,  yes.  In RAM usage and startup time, definitely
not.

Alan



Re: [pygame] trajectory

2011-07-22 Thread R. Alan Monroe


 i would like to know what are the common way to handle trajectory in a 2d
 game.

http://hyperphysics.phy-astr.gsu.edu/hbase/traj.html



Re: [pygame] Resolution for a 2d game

2011-05-16 Thread R. Alan Monroe

 Please don't force a fullscreen resolution. It doesn't restore properly on
 dual-head setups.

Agreed. Even on single screens it often repositions other running apps'
windows. A real nuisance.

Alan



Re: [pygame] Resolution for a 2d game

2011-05-16 Thread R. Alan Monroe

 For example, someone who play in 800*600 will move one side of the
 screen to another faster than someone who play in 1280*800... I
 really dont know how to handle several resolution especially for my
 online game.

Track all positions in floating point and multiply them by a
different scaling factor depending on resolution? OpenGL somewhat
automates this, and you get nice filtered scaling on your sprites,
too.

Alan



Re: [pygame] frame independant movement

2010-08-27 Thread R. Alan Monroe

 In other words, use a small enough time step that the difference
 is not big enough to be a problem. But if you're doing that, you
 might as well pick one sufficiently small time step and use a
 variable number of them per frame, so that the physics is
 always predictable whatever the frame rate.

While we're on the time topic, is there an easy way to do slo-mo, a la
Peggle Extreme Fever or a Burnout multi-car pileup?

Alan



Re: [pygame] frame independant movement

2010-02-03 Thread R. Alan Monroe
 The nice thing about limiting the framerate versus having calculations be
 done based on time passed is that it is much more consistent. With dt
 calculations you will often get huge jumps on slower computers and extra
 slow movement in cases on fast machines, just do to inaccuracies and error
 in the calculation.  On a slower machine, no matter which timing method you
 use it will be unpleasant.

What kind of innacuracies, specifically?



 One method for having a smooth variable framerate, without the issues of
 variable time calculations, is to have a fixed time step. Each frame, you
 may process more than one timestep, if you need to in order to keep up. The
 timestep has a fixed amount of time it is supposed to similate, say, .02,
 which would be 60 times per second. If the user is able to run at 60 fps,
 they get very smooth animation, as only one step is occuring on each frame.
 If the user can only run at 30 fps, they will get two steps each frame, so
 it will be jerkier, but still accurate. If they can only run at 10 fps, you
 would set a limit on it (maybe the max is two timesteps in a frame), so
 things would be slower for them but maybe still playable.

 [code snipped]

Is anyone aware of any websites that describe this time/frame business
pictorially? I have read about it repeatedly and browsed a lot of
pseudocod over the years, but without a proper diagram it's not really
sinking in for a visual thinker like myself.


Alan



Re: [pygame] Speed up image.tostring with OpenGL ?

2010-01-04 Thread R. Alan Monroe
 The only other way I know how to make OpenGL textures is with NumPy, using
 the GL_FLOAT token.  This may be better for your purposes--although the way
 I see it, converting a surface to a texture is going to involve a conversion
 no matter which way you do it.  Note that it's much faster to *update* a
 texture rather than create a new one.  If at all possible, this may be your
 best opinion to improve speed.

I'm very skeptical that PyOpenGL actually works correctly.

On my box (old 2.4 GHz laptop w/geforce 4), the classic nehe lesson 42
(drawing a maze to a texture) python port gives HORRIBLE framerates,
judging by eye to be about 5 fps, no matter whether I'm using Python
2.4, 2.5, 2.6, and I've tried repeated reinstalls and upgrades of
PyOpenGL. The maze drawing always stops prematurely too, but that may
be a logic bug in the ported version. Has anyone else duplicated this
problem? The original C version of lesson 42 works at full frame rate.

My self-written programs have really bad framerates too, but I barely
understand OpenGL so it's possible those are my own fault.

Alan



Re: [pygame] Make a sprite fall with realistic gravity?

2009-11-30 Thread R. Alan Monroe
 I've been trying to get a sprite (the ball) to fall from the top of
 the screen with realistic gravity. I did attempt it, however it's not
 so great so I won't post it here.

These might help:

http://hyperphysics.phy-astr.gsu.edu/hbase/traj.html

http://www.makingthemodernworld.org/learning_modules/maths/04.TU.02/?section=1

Alan



Re: [pygame] audio programming with pygame?

2009-05-23 Thread R. Alan Monroe

  i would like to learn how to program simple synthesizers and sound effects
 and it would be nice if i could experiment with this in python.

Along these lines, does anyone know of a way to:
1. write VSTs in Python (Steinberg Virtual Synthesizer format)
2. drive existing VSTs from Python

I don't have a current need for it, but I was curious in case the need
arose at some point.

Alan



Re: [pygame] Help Starting/doing The Main Code

2008-09-22 Thread R. Alan Monroe
 Well, I want to make an action platformer game like the metroid
 series, mega man series, castlevania series etc.I already have the
 sprites and the music, just need to know how to program the main
 code. I've looked at the code of many games, but each one of them
 was written differently... and no one of them had a weapon for the
 player to use. All of them were just platformers, jump and dodge.I
 have no idea of where to start...

This is pretty dated, but may help:
http://www.fastgraph.com/makegames/sidescroller/


Alan



Re: [pygame] Anybody think they can help me with my small problem?

2007-09-22 Thread R. Alan Monroe

 def check_mouse(self,mouse):
 m1 = mouse[0]
 m2 = mouse[1]

Can you just divide m1 and m2 by 100?

Alan



Re: [pygame] Anybody think they can help me with my small problem?

2007-09-22 Thread R. Alan Monroe
 Okay I took your idea Alan and I finally got the outcome that I wanted.
 Thanks.

Not sure you got what I meant :)

If you divide the mouse coordinate by 100, you'll automatically either
get a 0, 1, or 2 as the result. No need for any kind of in
range(0,50) comparison at all.

Alan



Re: [pygame] [Pygame] Generating a map

2007-08-10 Thread R. Alan Monroe

 talking a little recently about random terrain generation. One technique
 worth looking at is Perlins noise, one way of implementing which is to
 draw various surfaces full of random data, overlay them with different
 weights, and use the result to decide gameplay features such as the
 height of terrain.


After a LOT of trial and error, I managed to implement a proper Perlin
noise routine and draw a heightfield with it. Run main2D.py. I was
surprised at how slow it is.

Alan#http://freespace.virgin.net/hugo.elias/models/m_perlin.htm
#~ http://www.noisemachine.com/talk1/17.html

import random
import math

#===

p=[x for x in range(100)]
random.shuffle(p)
rg=[x/16.0 for x in range(100)]
random.shuffle(rg)
g=[ (math.cos(x), math.sin(x) ) for x in rg]



def noiser(x):
return g[x % 100]

def noiser2(x,y):
return g[ ( x + p[y%100] ) %100 ] 


#===
#===
#===



def interpolatednoiser(n):
intn = int(n)
fracn = n - intn
v1=noiser(intn) / 100.0
v2=noiser(intn + 1) / 100.0
ft = fracn * math.pi#cos interp
f = (1.0 - math.cos(ft)) * .5
return  v1*(1-f) + v2*f


def interpolatednoiser2(x, y):
intx = int(x)
fracx = x - intx
inty = int(y)
fracy = y - inty

gx, gy = noiser2(intx, inty)
v1 = (gx*fracx) + (gy*fracy)

gx, gy = noiser2(intx + 1, inty)
v2 = (gx*(fracx-1)) + (gy*fracy)

gx, gy = noiser2(intx, inty +1)
v3 = (gx*fracx) + (gy*(fracy-1))

gx, gy = noiser2(intx + 1, inty + 1)
v4 = (gx*(fracx-1)) + (gy*(fracy-1))

ftx = fracx * math.pi#cos interp
fx = (1.0 - math.cos(ftx)) * .5
midx1=  v1*(1-fx) + v2*fx  
midx2 = v3*(1-fx) + v4*fx 
fty = fracy * math.pi#cos interp
fy = (1.0 - math.cos(fty)) * .5
return  (midx1*(1.0-fy)) + (midx2 * fy)



#===
#===
#===

def perlin1(x,oct=6,per=0.7):
total=0
j=0
for i in range(oct):
freq = 2**i
amp = per**(i*2)
j = interpolatednoiser( x * freq) * amp
total += j
return total

def perlin2(x, y, oct=6,per=0.9):
total=0
for i in range(oct):
freq = 2**i
amp = per**i  #(i*2)
total += interpolatednoiser2( x * freq, y*freq) * amp
return total

#===
#===
#===

def testperlin1():
for x in range(25):
y=perlin1(x, 4)
z=int(y*50)
print y

def testperlin2():
for y in range(10):
row = []
for x in range(10):
z = perlin2(x/4.0,y/4.0, 4)
row.append(z)
print %3.3f %(z,),
print


if __name__ == __main__:
#print p
#print g
#testperlin1()
testperlin2()


import pygame
import math
from pygame.locals import *

import perlin


def main():
pygame.init()
screen = pygame.display.set_mode((1024,768) )

stretch=50.0
zoom=6
octaves=4
persist=0.7
minc=255
maxc=0
screen.fill( (0,0,0) )
for y in range(400):
for x in range (400):
p=perlin.perlin2(x/stretch, y/stretch, octaves, persist ) 
#*(y/400.0) )
z = p*170 +128 #- 30 #classic
c=int(z)
if cmaxc:
maxc=c
if cminc:
minc=c
if c255:
c=255
if c=0:
c=0
pygame.draw.line(screen, (c,c,c), (x+y/3, y + 20), (x+y/3, y + 
(20-(z/4))) ) #grayscale
screen.set_at( (x+512,y), (c,c,c) )

pygame.display.update()
event = pygame.event.poll()
if event.type == QUIT or (event.type == KEYDOWN and event.key == 
K_ESCAPE):
break

print minc:, minc,  maxc:,maxc

while 1:
event = pygame.event.wait()
if event.type == QUIT or (event.type == KEYDOWN and event.key == 
K_ESCAPE):
break
if (event.type == KEYDOWN and event.key == K_o):
octaves += 1



main()


Re: [pygame] Path finding demo, now with more fugu

2007-04-21 Thread R. Alan Monroe
 Just put a path finding demo on my website, that you may find interesting.

 http://www.willmcgugan.com/2007/04/20/swim-fugu-swim/

Works great, although it pegs the cpu at 100% :)

Alan



Re: [pygame] Scripting language

2006-12-18 Thread R. Alan Monroe
 I've been reading up on perspective broker since you emailed it and I  
 think a solution of that sort is the most likely that I will end up  
 with.

Also check out a competing but lesser known technology: Ice from
http://www.zeroc.com/

Alan



Re: [pygame] PyOpenGL

2006-08-08 Thread R. Alan Monroe
 The whole Numeric / numarray / numpy / scipy thing is getting a bit confusing.

I agree. Bloody nightmare.

Alan



Re: [pygame] movie

2006-08-01 Thread R. Alan Monroe
 hello,
   I am new to pygame and I want to make a very short movie(25secs tops)
   it requires a snake to twist and turn, and change direction. how can I do 
 this?
   Brian

One way is to do it like Windows Mystify screensaver. You know the
one I'm talking about? Use a list to hold the current position of the
head, body, body, body, body, tail pieces.

Alan



Re: [pygame] Sky Algorithm

2006-07-15 Thread R. Alan Monroe
 Let's say I have a simple flat bitmap, and I wish to tile it across a 3d
 plane and suspend it in the air, so it looks like cloud cover. I could 
 'drag' those tiling perspective corrected bitmaps about to simulate it 
 pretty well, I believe, but I don't want to use OpenGL to do it.

Without OpenGL I'm thinking you're stuck with software rendering. This
was one of the top hits on google using search terms raycaster
texture mapped floor plane. Plenty of pictures and explanations.
http://student.kuleuven.be/~m0216922/CG/raycasting2.html

Alan