Re: [pygame] Fill a Rect object with color?

2009-11-08 Thread Yanom Mobis
UMM actually -- BoomTower has 2 rect objects: rect (the tower itself) and 
rangerect (a specific area around the tower). It's rangerect i have to fill.

--- On Sun, 11/8/09, stabbingfinger stabbingfin...@gmail.com wrote:

From: stabbingfinger stabbingfin...@gmail.com
Subject: Re: [pygame] Fill a Rect object with color?
To: pygame-users@seul.org
Date: Sunday, November 8, 2009, 1:39 AM

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.




  

[pygame] Fill a Rect object with color?

2009-11-07 Thread Yanom Mobis
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?

2009-11-07 Thread Ian Mallett
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?

2009-11-07 Thread Russell Cumins
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?

2009-11-07 Thread Henrique Nakashima
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?

2009-11-07 Thread DR0ID

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?

2009-11-07 Thread B W
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()


Re: [pygame] Fill a Rect object with color?

2009-11-07 Thread Yanom Mobis
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?

2009-11-07 Thread Russell Cumins
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?

2009-11-07 Thread stabbingfinger
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.