Skip to main content

Ralsina.Me — Roberto Alsina's website

Posts about python (old posts, page 27)

New library: ChipScene

This is the re­al out­come of my Py­Week fail­ure: a neat li­brary.

Take Chip­munk and Qt mash them up, and what do you get?

A OpenGL-ac­cel­er­at­ed, mul­ti­plat­for­m, easy-­to-use play­ground!

But watch the sil­ly video that shows no in­ter­est­ing fea­tures in­stead:

You can't see it but there are 29 bal­loon­s, num­bered, that bounce around hap­pi­ly.

Per­for­mance in the video sucks be­cause I had to dis­able OpenGL in or­der to cap­ture it cor­rect­ly (and video record­ing kills my note­book,any­way). That de­mo nor­mal­ly runs in 3 sec­ond­s, not 57.

Here's the non-boil­er­plate code for that de­mo:

def fillWorld(scene):
  items=[]
  for x in range(1, 29):
      b=cs.CPBodyItem(bpos=[0+13*random.randint(0,25), -50-30*random.randint(0,10)],m=10)
      s=cs.CPCircleShapeItem(10, b, e=.5, offset=[0, 0])
      t=QtGui.QGraphicsSimpleTextItem(str(x), s)
      t.setPos(-5, -5)
      items.append(b)
  items.append(cs.CPSegmentShapeItem([0, 50], [500, 450], 1, None, e=.7))
  items.append(cs.CPSegmentShapeItem([0, 450], [500, 50], 1, None, e=.7))

  for i in items:
      scene.addItem(i)

Neat, is­n't it?

You can get it at the Chip­Scene google code project in­clud­ing, of course, the source.

What I learned at PyWeek

  1. I don't have the time for this kind of dead­­­lines any­­more. Not even one al­l-nighter? I did noth­ing on Sat­ur­­day ex­­cept re­al work and fam­i­­ly re­u­nion?

  2. It's re­al­­ly easy to write games with Python. It's most­­ly just a mat­ter of hav­ing a good game con­­cep­t. The cod­ing is the easy part.

  3. Chip­­munk is cool. Qt's graph­ic scene stuff is cool. My Chip­­munkScene is coolest ;-) I should re­­think the API but the con­­cept is killer stuff. With a lit­­tle work this thing is like LEGO!

  4. I will try again in Py­Week6.

A little further on TLB

A bit of pro­gress, al­though not much time to work on it any­more so I will prob­a­bly not make it.

Ob­jects now can do things when they are hit by oth­er kinds of things.

Ex­am­ple: If a ball hits the bot­tom of the cat­a­pult cup, the cat­a­pult shoot­s. If some­thing hits the tar­get ob­jec­t, you win the lev­el.

First pic of TLB

Not a game yet, but the en­gine is start­ing to look good.

tlb1

The ball drop­s, fol­lows both ramp­s, bounces down the stairs, hits the domi­noes, the last one falls on the piv­ot­ing ram­p, slides down and to the left, falls stand­ing and leans left, then hits the rest of the domi­noes.

PyWeek progress: the 4 hour mark

Sud­den­ly I was hav­ing a calm day at work, and Rosario is tak­ing care of the baby, so I spent a few hours on the Py­Week projec­t.

I have in­te­grat­ed Chip­munk with QGraph­ic­sS­cene.

What does it mean? That I can now...

  • Cre­ate a scene

  • Cre­ate a view on­­to that scene

  • Cre­ate bal­l­s, walls and poly­­gons as scene items

  • Watch said bal­l­s/wal­l­s/poly­­gons bounce around hap­pi­­ly un­der Chip­­munk di­rec­­tion.

For ex­am­ple, here's enough code to cre­ate a few balls a box and a stair­case:

self.scene=ChipScene()
self.ui.view.setScene(self.scene)

for x in range (0, 10):
    self.scene.addBall(x*50.0+10, 50.0, 10.)
    self.scene.addBall(x*50.0+20, 20.0, 10.)
self.scene.addWall(0., 0., 0., 500.)
self.scene.addWall(0., 500., 500., 500.)
self.scene.addWall(500., 500., 500., 0.)
self.scene.addWall(500., 0., 0., 0.)
for i in range (0, 20):
    self.scene.addWall(i*20, 200+i*20, i*20+20, 200+i*20)
    self.scene.addWall(i*20+20, 200+i*20, i*20+20, 200+i*20+20)

self.scene.addPoly([[0, 50], [0, 100], [100, 100], [100, 50], [0, 50]])

I de­clare that nifty.