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

Re: [pygame] Mode 7 Demo



Do you have a link to landscape.bmp and sky.png?

Traceback (most recent call last):
  File "mode7.py", line 9, in ?
    ground = pygame.image.load("landscape.bmp") ## 1000x1000 works
pygame.error: Couldn't open landscape.bmp

Traceback (most recent call last):
  File "mode7.py", line 10, in ?
    sky = pygame.image.load("sky.png") ## At least 800x300
pygame.error: Couldn't open sky.png

I converted  the landscape.jpg to landscape.bmp to get the second Traceback.

This looks nice!
Arigato!
-- 
b h a a l u u at g m a i l dot c o m
"You assist an evil system most effectively by obeying its
orders and decrees. An evil system never deserves such
allegiance.  Allegiance to it means partaking of the evil.
A good person will resist an evil system with his or her
whole soul." [Mahatma Gandhi]



On Jan 26, 2008 11:49 AM, Kris Schnee <kschnee@xxxxxxxxxx> wrote:
> I put together a quick-and-dirty demo of a "Mode 7" pseudo-3D effect. I
> have no specific plans for it, but it looks neat. The framerate is bad.
> Thoughts?
>
> Screenshot at <http://kschnee.xepher.net/pics/080126_mode7.jpg>.
> Example of the effect in "Secret of Mana":
> <http://mmxz.zophar.net/rpg/mana2/images/flammie.gif>
>
> Kris
>
> """
> Quick demo of a "Mode 7" pseudo-3D effect,
> as seen in some 16-bit-era video games.
> """
>
> import pygame
> screen = pygame.display.set_mode((800,600))
>
> ground = pygame.image.load("landscape.bmp") ## 1000x1000 works
> sky = pygame.image.load("sky.png") ## At least 800x300
>
> ## Fog @ horizon.
> fog = pygame.surface.Surface((800,20)).convert_alpha()
> for y in range(20):
>     a = 200 - (10*y)
>     pygame.draw.rect(fog,(255,255,255,a),(0,y,800,5))
>
> class Mode7:
>     def __init__(self,**options):
>         self.sky = options.get("sky")
>         self.ground = options.get("ground")
>         self.fog = options.get("fog")
>         ## "Location" of the top-left part we'll draw.
>         self.ground_x, self.ground_y = options.get("coords",(0,0))
>         self.movement = options.get("movement",(3,3))
>
>     def Draw(self):
>         stretch_factor = 200.0 ## Try eg. 75.0 also
>         for y in range(300,600):
>             ## Take a line from the original & stretch it.
>             img_y = (y+self.ground_y-300) * 2
>             line = pygame.surface.Surface((800,1))
>             line.blit(self.ground,(0,0),(self.ground_x,img_y,800,1))
>             w = 800 * (1.0 + ((y-300)/stretch_factor) )
>             x = -(w-800)/2 ## Draw wide line left of screen's edge
>             line = pygame.transform.scale(line,(w,1))
>             screen.blit(line,(x,y))
>         screen.blit(self.sky,(0,0),(200,0,800,300))
>         screen.blit(self.fog,(0,300))
>
>     def Go(self):
>         for n in range(40):
> ##            screen.fill((0,0,0)) ## Not needed; screen is filled
>             self.Draw()
>             pygame.display.update()
>             self.ground_x += self.movement[0]
>             self.ground_y += self.movement[1]
>
>
> m7 = Mode7(sky=sky,ground=ground,fog=fog)
> m7.Go()
>
>