Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRodolfo D. Arce S <rodolfo.arce.s@gmail.com>2011-05-18 21:09:23 (GMT)
committer Rodolfo D. Arce S <rodolfo.arce.s@gmail.com>2011-05-18 21:09:23 (GMT)
commitdecfae19d747f765de74647dc07f82f65e8ab776 (patch)
tree3e1ae6a5a4c4778c16a941942c50077bd5eea93e
parentfffcd35aef9e2a499549d4fbda5cf397e5351a7d (diff)
Added separated class for tree object and a few lines regarding position and drawing
-rw-r--r--main.py17
-rw-r--r--tree.py119
2 files changed, 77 insertions, 59 deletions
diff --git a/main.py b/main.py
index da06551..c6699d8 100644
--- a/main.py
+++ b/main.py
@@ -1,13 +1,21 @@
import pygame
from pygame import K_ESCAPE
from random import randint
-
+from tree import Tree
+
window_h = 640
window_w = 480
+
screen = pygame.display.set_mode( (window_h, window_w) )
pygame.display.set_caption("Ranger")
-# Tree size
+tree = Tree(screen, window_h, window_w, (window_h/2, window_w/2), 15, 20, 20)
+
+# Tree
+global tree_color
+global bg_color
+tree_color = [51, 204, 0]
+bg_color = [204, 102, 0]
tree_height = tree_width = 40
tree_radius = 15
@@ -23,12 +31,11 @@ while True:
exit()
# Draw background
- bg_color = [204, 102, 0]
screen.fill(bg_color)
# Draw everything on top of that
- tree_color = [51, 204, 0]
- pygame.draw.circle(screen, tree_color, (window_h/2, window_w/2), tree_radius, 0)
+
+ #pygame.draw.circle(screen, tree_color, (window_h/2, window_w/2), tree_radius, 0)
#pygame.display.update()
diff --git a/tree.py b/tree.py
index 7360ac4..8136198 100644
--- a/tree.py
+++ b/tree.py
@@ -1,54 +1,65 @@
-pygame.draw.rect(screen, tree_color, \
- ( (window_h/2 - tree_height/2), \
- (window_w/2 - tree_width/2), \
- tree_height, \
- tree_width), \
- 0) \
-
-pygame.draw.circle(screen, tree_color, \
- ((window_h/2 + tree_height/2), \
- (window_w/2 + tree_width/2)), \
- tree_radius/randint(1,2), \
- 0)
-
-pygame.draw.circle(screen, tree_color, \
- ((window_h/2), \
- (window_w/2 + tree_width/2)), \
- tree_radius/randint(1,2), \
- 0)
-
-pygame.draw.circle(screen, tree_color, \
- ((window_h/2 + tree_height/2), \
- (window_w/2)), \
- tree_radius/randint(1,2), \
- 0)
-
-pygame.draw.circle(screen, tree_color, \
- ((window_h/2 - tree_height/2), \
- (window_w/2 - tree_width/2)), \
- tree_radius/randint(1,2), \
- 0)
-
-pygame.draw.circle(screen, tree_color, \
- ((window_h/2), \
- (window_w/2 - tree_width/2)), \
- tree_radius/randint(1,2), \
- 0)
-
-pygame.draw.circle(screen, tree_color, \
- ((window_h/2 - tree_height/2), \
- (window_w/2)), \
- tree_radius/randint(1,2), \
- 0)
-
-pygame.draw.circle(screen, tree_color, \
- ((window_h/2 + tree_height/2), \
- (window_w/2) - tree_width/2), \
- tree_radius/randint(1,2), \
- 0)
-
-pygame.draw.circle(screen, tree_color, \
- ((window_h/2 - tree_height/2), \
- (window_w/2) + tree_width/2), \
- tree_radius/randint(1,2), \
- 0)
+import pygame
+import random
+
+class Tree:
+ def __init__(self, surface, window_h, window_w, position, tree_size, height, width):
+ self.position = position
+ self.height = height
+ self.width = width
+ self.size = tree_size
+ self.surface = surface
+
+ pygame.draw.rect( self.surface, tree_color, \
+ ( (self.position[0] - self.height/2), \
+ (self.position[1] - self.width/2), \
+ self.size, \
+ self.size), \
+ 0)
+
+ pygame.draw.circle(self.surface, tree_color, \
+ ((self.position[0] + self.height/2), \
+ (self.position[1] + self.width/2)), \
+ self.size/randint(1,2), \
+ 0)
+
+ pygame.draw.circle(self.surface, tree_color, \
+ ((self.position[0]), \
+ (self.position[1] + self.width/2)), \
+ tree_size/randint(1,2), \
+ 0)
+
+ pygame.draw.circle(self.surface, tree_color, \
+ ((self.position[0] + selfheight/2), \
+ (self.position[1])), \
+ tree_size/randint(1,2), \
+ 0)
+
+ pygame.draw.circle(self.surface, tree_color, \
+ ((self.position[0] - self.height/2), \
+ (self.position[1] - self.width/2)), \
+ tree_size/randint(1,2), \
+ 0)
+
+ pygame.draw.circle(self.surface, tree_color, \
+ ((self.position[0]), \
+ (self.position[1] - tree_width/2)), \
+ tree_size/randint(1,2), \
+ 0)
+
+ pygame.draw.circle(self.surface, tree_color, \
+ ((self.position[0] - self.height/2), \
+ (self.position[1])), \
+ tree_size/randint(1,2), \
+ 0)
+
+ pygame.draw.circle(self.surface, tree_color, \
+ ((self.position[0] + self.height/2), \
+ (self.position[1]) - self.width/2), \
+ tree_size/randint(1,2), \
+ 0)
+
+ pygame.draw.circle(self.surface, tree_color, \
+ ((self.position[0] - self.height/2), \
+ (self.position[1]) + self.width/2), \
+ tree_size/randint(1,2), \
+ 0) \ No newline at end of file