[pygame] Fill a Rect object with color?
This is kind of embarrasing but I forgot how to fill a rect object with a certain color.
Re: [pygame] Fill a Rect object with color?
I don't think rect objects were meant for that. You could go: rect = a rect object pygame.draw.rect(surface,color,rect,0) Ian
Re: [pygame] Fill a Rect object with color?
Or you can create a surface the size of the rect and use the Surface's fill() method. E.g. position = x,y = 0,0 size = w,h = 32,32 colour = 0,255,0 rect = Rect(position, size) image = Surface(size) image.fill(colour) 2009/11/7 Ian Mallett geometr...@gmail.com I don't think rect objects were meant for that. You could go: rect = a rect object pygame.draw.rect(surface,color,rect,0) Ian
Re: [pygame] Fill a Rect object with color?
Yes, rects are only objects that delimit a rectangular area. Areas that can be drawn onto are Surfaces, and you could draw rectangles to those surfaces the ways Ian and RusselI mentioned. On Sat, Nov 7, 2009 at 16:34, Yanom Mobis ya...@rocketmail.com wrote: This is kind of embarrasing but I forgot how to fill a rect object with a certain color.
Re: [pygame] Fill a Rect object with color?
Hi even simpler: image.fill(color, rect) ~DR0ID Russell Cumins schrieb: Or you can create a surface the size of the rect and use the Surface's fill() method. E.g. position = x,y = 0,0 size = w,h = 32,32 colour = 0,255,0 rect = Rect(position, size) image = Surface(size) image.fill(colour) 2009/11/7 Ian Mallett geometr...@gmail.com mailto:geometr...@gmail.com I don't think rect objects were meant for that. You could go: rect = a rect object pygame.draw.rect(surface,color,rect,0) Ian
Re: [pygame] Fill a Rect object with color?
On Sat, Nov 7, 2009 at 10:34 AM, Yanom Mobis ya...@rocketmail.com wrote: This is kind of embarrasing but I forgot how to fill a rect object with a certain color. Here's everything so you can see the full context. import pygame from pygame.locals import * pygame.init() pygame.display.set_mode((800,600)) s = pygame.display.get_surface() r = pygame.Rect(100,100,100,100) s.fill(Color(red), r) pygame.display.flip() while 1: pygame.event.get()
[pygame] Anyone got this game? Nerd N' Roll Rancing 3000
Nerd N' Roll Rancing 3000 http://www.pygame.org/project-Nerd+N%27+Roll+Rancing+3000-1037-.html If you have the source or the exe of this game, let me know since I am a begger who are interested of building similar game - multiplayer 2d car race. I have experience with vb6/c# and ruby and created a small python console apps before. Any tips/links/tutorials to help me in the process? I was thinking of starting with this book - http://www.apress.com/book/view/9781590598726 (Beginning Game Development with Python and Pygame: From Novice to Professional) Thanks!
Re: [pygame] Fill a Rect object with color?
i tried that the problem is that class BoomTower has rect object rangerect, and in class BoomTower( yattayatta ) def __init__(yatta, yatta): (rangerect defined) def shoot( yatta, yatta): (this code here needs to do the filling) so ya the last line of function BoomTower.shoot needs to fill that BoomTower object's rangerect with a certain color does that make any sense? Not to be rude but am i confusing you? --- On Sat, 11/7/09, Ian Mallett geometr...@gmail.com wrote: From: Ian Mallett geometr...@gmail.com Subject: Re: [pygame] Fill a Rect object with color? To: pygame-users@seul.org Date: Saturday, November 7, 2009, 12:45 PM I don't think rect objects were meant for that. You could go: rect = a rect object pygame.draw.rect(surface,color,rect,0) Ian
Re: [pygame] Fill a Rect object with color?
I'm not 100% sure what you are wanting to change the colour so forgive me if I'm going off on a tangent here. From what you have said thus far I am assuming you want to change the colour of the BoomTower object when it if firing. What I would do is this... class BoomTower: def __init__(self,position,size,colour,fireColour): self.colour = colour self.fireColour = fireColour self.rect = Rect(position,size) self.image = Surface(size) self.image.fill(colour) ## Set the colour to the default def shoot(self,...): ...## Your other code here self.image.fill(self.fireColour) You probably need to add some more code elsewhere to change the colour back for when the BoomTower object is not firing. 2009/11/8 Yanom Mobis ya...@rocketmail.com i tried that the problem is that class BoomTower has rect object rangerect, and in class BoomTower( yattayatta ) def __init__(yatta, yatta): (rangerect defined) def shoot( yatta, yatta): (this code here needs to do the filling) so ya the last line of function BoomTower.shoot needs to fill that BoomTower object's rangerect with a certain color does that make any sense? Not to be rude but am i confusing you? --- On *Sat, 11/7/09, Ian Mallett geometr...@gmail.com* wrote: From: Ian Mallett geometr...@gmail.com Subject: Re: [pygame] Fill a Rect object with color? To: pygame-users@seul.org Date: Saturday, November 7, 2009, 12:45 PM I don't think rect objects were meant for that. You could go: rect = a rect object pygame.draw.rect(surface,color,rect,0) Ian
Re: [pygame] Fill a Rect object with color?
Lemme borrow Russell's method to show what I think is your missing piece: some way of getting a boom tower's rectangle onto the game's playfield (the main PyGame surface). Run it, and left-click the mouse to change the state of the boom tower. import pygame from pygame.locals import * class BoomTower: def __init__(self, bounds, normal_color, fire_color): self.normal_image = pygame.Surface((bounds.w,bounds.h)) self.normal_image = self.normal_image.convert() self.normal_image.fill(normal_color) ## Set the colour to the default self.fire_image = pygame.Surface((bounds.w,bounds.h)) self.fire_image = self.fire_image.convert() self.fire_image.fill(fire_color) self.current_image = self.normal_image def get_current_image(self): return self.current_image def shoot(self): ## Your other code here if self.current_image is self.normal_image: self.current_image = self.fire_image else: self.current_image = self.normal_image def draw(self, surface, pos): rect = self.current_image.get_rect() rect.center = pos surface.blit(self.current_image, rect) pygame.init() pygame.display.set_mode((800,600)) s = pygame.display.get_surface() r = pygame.Rect(50,50,100,100) boom_tower = BoomTower(r, Color(white), Color(red)) while 1: for event in pygame.event.get(): if event.type == MOUSEBUTTONDOWN: boom_tower.shoot() boom_tower.draw(s, r.center) pygame.display.flip() Gumm Russell Cumins wrote: I'm not 100% sure what you are wanting to change the colour so forgive me if I'm going off on a tangent here. From what you have said thus far I am assuming you want to change the colour of the BoomTower object when it if firing. What I would do is this... class BoomTower: def __init__(self,position,size,colour,fireColour): self.colour = colour self.fireColour = fireColour self.rect = Rect(position,size) self.image = Surface(size) self.image.fill(colour) ## Set the colour to the default def shoot(self,...): ...## Your other code here self.image.fill(self.fireColour) You probably need to add some more code elsewhere to change the colour back for when the BoomTower object is not firing.