[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] very easy snippets to start: where from i can get?



well, more ugly code: this is about arrays and how can i get several
sprites from just one picture:

randomize
xed=320:yed=240:sprn=32:maxspd=4:spram=16
dim xdr[sprn],ydr[sprn],xpo[sprn],ypo[sprn],sprid[sprn]
for i=0 to sprn:sprid[i]=3:next
wdwd=1
setdisplay(xed,yed,32,wdwd)
for i=0 to sprn:xdr[i]=rnd(4):ydr[i]=rnd(4):xpo[i]=1:ypo[i]=1:next
screenopen(1,xed,yed,0,0,0,0,0)
loadimage("ubuntumarks2.png",1):pasteicon(0,0,1):screen(1)
for y=0 to 1:for x=0 To 9:k=x+(y*10):grab(1+k,x*32,y*32,32,32):next:next
screen(0)
for xt=0 to xed step 32:for yt=0 to yed step 32
  pasteicon(xt,yt,1):next:next
while (0=0)
  for i=0 to sprn-1
    bob(1+i,xpo[i],ypo[i],sprid[i])
    xpo[i]=xpo[i]+xdr[i]:ypo[i]=ypo[i]+ydr[i]
    if xpo[i]>(xed-32) then:xpo[i]=0:end if
    if xpo[i]<0 then:xpo[i]=(xed-32):end if
    if ypo[i]>(yed-32) then:ypo[i]=0:end if
    if ypo[i]<0 then:ypo[i]=(yed-32):end if
    next
  i=rnd(sprn):xdr[i]=(rnd(8)-4):ydr[i]=(rnd(8)-4):sprid[i]=1+(rnd(spram))
  waitvbl
  if key(27) then:end:end if  '- esc key
  wend
waitkey


the picture i were using with the sprites were this one:
http://img355.imageshack.us/img355/1572/ubuntumarks2jj3.png

thanks again! :-)


------------

On Fri, Jul 25, 2008 at 5:34 PM, Paulo Silva <nitrofurano@xxxxxxxxx> wrote:
> thanks! is exactly like that were what i'm looking for! :-)
>
> --------------------------
>
>
>
> On Fri, Jul 25, 2008 at 4:51 PM, Brad Montgomery
> <brad@xxxxxxxxxxxxxxxxxx> wrote:
>> Ahhhh!  My eyes!!!!   :)
>>
>> On Fri, Jul 25, 2008 at 10:47 AM, Peter Shinners <pete@xxxxxxxxxxxx> wrote:
>>> Paulo Silva wrote:
>>>>
>>>> for example, this code, how do it would look like with Python-Pygame?
>>>>
>>>> http://pastebin.com/f5642fd17
>>>> (runs on sdlBasic)
>>>>
>>>
>>> I have created the ugliest pygame code in the world to match you example. I
>>> hope it provides an interest for you to actually learn a bit of Python's
>>> elegence (little of which is on display here)
>>>
>>> -----------------------------------
>>> import pygame, random
>>> from random import randint as rnd
>>>
>>> def waitkey():
>>>   while 1:
>>>       e = pygame.event.wait()
>>>       if e.type in (pygame.QUIT, pygame.KEYDOWN):
>>>           return
>>>
>>>
>>> finp="ring5.png";fout=finp+".bmp"
>>> xed=320;yed=240
>>> window=pygame.display.set_mode((xed, yed),0,32)
>>> img=pygame.image.load(finp);window.blit(img,(0,0))
>>> for i in range(100):
>>>   color=rnd(0,255),rnd(0,255),rnd(0,255)
>>>   box=rnd(0,xed),rnd(0,yed),rnd(0,xed),rnd(0,yed)
>>>   window.fill(color,box)
>>> pygame.display.flip()
>>> pygame.image.save(window,fout)
>>> waitkey()
>>> -----------------------------------
>>>
>>>
>>
>>
>>
>> --
>> brad [bradmontgomery.net]
>>
>