engine: Added tiled image
The tiled image function will return a surface the size of the screen with the given image tiled on it.
This commit is contained in:
parent
d7c8396a1d
commit
2e8ca139b2
|
@ -2,11 +2,31 @@
|
|||
|
||||
import pygame
|
||||
import os
|
||||
import screen
|
||||
|
||||
load_img = pygame.image.load
|
||||
join = os.path.join
|
||||
scr_size = screen.size
|
||||
draw = screen.draw
|
||||
|
||||
def load(game, image):
|
||||
path = join( join("images", game), image )
|
||||
img = load_img(path)
|
||||
return img.convert_alpha()
|
||||
|
||||
def render_tiled(image):
|
||||
(w, h) = image.get_size()
|
||||
(sw, sh) = scr_size()
|
||||
for i in xrange(sw / w):
|
||||
for j in xrange(sh / h):
|
||||
draw(image, w * i, h * j)
|
||||
|
||||
def tiled_image(game, image_file):
|
||||
image = load(game, image_file)
|
||||
(w, h) = image.get_size()
|
||||
(sw, sh) = scr_size()
|
||||
surf = pygame.Surface((sw, sh))
|
||||
for i in xrange( (sw / w) + 1 ):
|
||||
for j in xrange( (sh / h) + 1 ):
|
||||
surf.blit(image, (w * i, h * j))
|
||||
return surf.convert()
|
||||
|
|
|
@ -5,6 +5,8 @@ import games
|
|||
|
||||
import ship
|
||||
import enemy
|
||||
from engine.screen import draw
|
||||
from engine.image import tiled_image
|
||||
|
||||
RIGHT = pygame.K_RIGHT
|
||||
LEFT = pygame.K_LEFT
|
||||
|
@ -17,6 +19,7 @@ B = pygame.K_b
|
|||
class ArcadeState(games.GameState):
|
||||
def __init__(self, GAME):
|
||||
self.ship = ship.CSE1670(GAME, (10, 10), (0.7, 0.7))
|
||||
self.stars = tiled_image(GAME, "stars.png")
|
||||
self.fire_interval = 100
|
||||
self.beams = []
|
||||
self.enemies = [enemy.Trilord(GAME, (10, 10))]
|
||||
|
@ -27,6 +30,8 @@ class ArcadeState(games.GameState):
|
|||
self.k_space = False
|
||||
|
||||
def render(self):
|
||||
draw(self.stars, 0, 0)
|
||||
#render_tiled(self.stars)
|
||||
for beam in self.beams:
|
||||
beam.render()
|
||||
for enemy in self.enemies:
|
||||
|
@ -61,6 +66,7 @@ class ArcadeState(games.GameState):
|
|||
beam.move()
|
||||
if beam.is_offscreen():
|
||||
self.beams.remove(beam)
|
||||
|
||||
for enemy in self.enemies:
|
||||
collide = enemy.collide
|
||||
for beam in self.beams:
|
||||
|
|
Loading…
Reference in New Issue
Block a user