[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[pygame] Yeah looks like i'm doing quite well so far, completed my goal for today.
- To: pygame-users@xxxxxxxx
- Subject: [pygame] Yeah looks like i'm doing quite well so far, completed my goal for today.
- From: "Lamonte Harris" <pyth0nc0d3r@xxxxxxxxx>
- Date: Mon, 10 Sep 2007 20:05:51 -0500
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: pygame-users-outgoing@xxxxxxxx
- Delivered-to: pygame-users@xxxxxxxx
- Delivery-date: Mon, 10 Sep 2007 21:06:01 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:mime-version:content-type; bh=UwCOLkju59sS/sP/HSTTqK6N+aYFVsQ2PU+VD6Kuq5U=; b=YaWEpsug3oXTRU5X5ALBnu+ELvlpQO0vPL1poTDHSmH1MS471vYDcphL/10L4zdlJdoYYfk+2vLaeSRrOKfH2y1lf/+diDr6JUAHLN8GgT8+C7MrYQTwLFGy9G8JtSoBDnj62W4Vn2d9hCXC7NVxuZs4HXAZbuDWKe1g8ljXJNA=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:mime-version:content-type; b=bhCYSw9eo35w8BW9/k4XoLQTVYstOBQR3GtiMAGCLBnblKiCazfz35fR+3oNuZrYwQMQ/IBaSh3njDseLf5HQCb+3N2geLU1hwmoUfHaKXibS7xJEVUxLFSztlDfYCtFdnuE0MWsR7WAxG8WJjNYLEC8O+5ef4qsqYhGU0rOGz4=
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
Yeah took some time of thinking and fixing and rethinking. Pygame is like a strategy puzzle. I've just mapping script, where in the text file are numbers. I read the numbers from 1,2 and switch then into rects that I created. Them I displayed them on the screen. Its quite nice to make something so cool without asking for help :P. Check it out and tell me what you think[attachements]
My only flaw is, the rects render upside down. What could I do to fix that?
Attachment:
map1.map
Description: Binary data
import pygame,sys,string
from pygame.locals import *
class map_:
def __init__(self,wndow=(300,300)):
self.size = wndow
self.map = [[],[],[]]
self.surfaces = [[],[]]
self.window = pygame.display.set_mode(self.size)
pygame.init()
def create_box(self,size,color,rect):
box = pygame.Surface((size))
pygame.draw.rect(box,color,box.get_rect())
self.surfaces[0].append(box)
self.surfaces[1].append(rect)
def load_text_map(self,map):
file = open(map,"r")
links = file.readlines()
file.close()
x = 0
for i in links:
i = string.replace(i,"\n","")
i = i.split(",")
for e in i:
self.map[x].append(e)
x += 1
def draw_box(self):
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT: sys.exit()
e = 0
while e < len(self.surfaces[0]):
self.window.blit(self.surfaces[0][e],self.surfaces[1][e])
e += 1
pygame.display.update()
def render_map(self,aray,dict):
x=0
for e in aray:
z = 0
for y in e:
aray[x][z] = dict[int(y)]
z += 1
x += 1
return aray
def hex_converter(self,hexcolorcode):
hexcolorcode = hexcolorcode[1:]
red = hexcolorcode[0:2]
red = int(red,16)
blue = hexcolorcode[2:4]
blue = int(blue,16)
green = hexcolorcode[4:6]
green = int(green,16)
return (red,green,blue)
def main(self):
z = 0
x = 0
y = 0
m = 0
while z < len(self.map):
q = 0
while q < len(self.map[z]):
self.create_box(self.map[z][q][0],self.map[z][q][1],(x,y))
y += 100
q += 1
y = 0
x += 100
z += 1
self.draw_box()
Map = map_()
tiles = {1 : [(100,100),Map.hex_converter("#E0ECFF")], 2 : [(100,100),Map.hex_converter("#B5EDBC")] }
Map.load_text_map("map1.map")
Map.render_map(Map.map,tiles)
Map.main()