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-06-11 19:43:49 (GMT)
committer Rodolfo D. Arce S <rodolfo.arce.s@gmail.com>2011-06-11 19:43:49 (GMT)
commit3c78463a6d155eb1d5780023513dc66ef0ffffee (patch)
tree62cc15e9996ee5b89568a76e72da78fdd6c424ee
parentb596b67f6f81eb61303106811af1c335c9abdaec (diff)
Non stop movement, speed control based on air
-rw-r--r--main.py22
-rw-r--r--ranger.py14
-rw-r--r--tree.py5
3 files changed, 29 insertions, 12 deletions
diff --git a/main.py b/main.py
index 3600a6e..426ca4d 100644
--- a/main.py
+++ b/main.py
@@ -2,6 +2,7 @@ import pygame
import time
import os
import sys
+import math
from pygame import K_ESCAPE
from pygame.locals import *
@@ -25,6 +26,9 @@ pygame.display.set_caption("Ranger")
window_h, window_w = screen.get_size ()
+if window_h > 1024:
+ screen = pygame.display.set_mode( (800,640) )
+window_h, window_w = screen.get_size ()
# Tree
trees = []
@@ -128,7 +132,7 @@ while True:
# Tree cutters kills trees
for arbol in trees:
for cortador in cutter:
- if cortador.collides_with(arbol):
+ if cortador.collides_with(arbol) and arbol.air == 1:
cortador.cut_tree = True
arbol.draw_alert(screen)
cortador.cut_time += 1
@@ -148,10 +152,10 @@ while True:
## SCORE IS DRAWN AFTER EVERYTHING ELSE
# Score is equal to amount of trees
for arbol in trees:
- air += 1
+ air = air + arbol.air
# HUD text
- hud_text = "Air: " + str(air) + " Score: " + str(score)
+ hud_text = "Air: " + str(air) + " Score: " + str(score) + " Speed: " + str(ranger.speed)
font = pygame.font.Font(None, 36)
text_hud = font.render( hud_text , 1, (0, 0, 0, 0))
screen.blit(text_hud, (0, 0))
@@ -168,7 +172,17 @@ while True:
cutter_difficulty = 100
elif score <= 150:
cutter_difficulty = 50
-
+
+ # Speed based on air
+ if air > 0:
+ if ranger.speed > 1.0 :
+ ranger.speed = math.fabs(air/10)
+ else:
+ ranger.speed = 1
+ else:
+ exit()
+
+
# Score updates after being shown
air = 0
diff --git a/ranger.py b/ranger.py
index 5d09147..88bfa67 100644
--- a/ranger.py
+++ b/ranger.py
@@ -34,13 +34,13 @@ class Ranger:
if event.key == pygame.K_DOWN:
self.direction_y = 1
self.direction_x = 0
- if event.type == pygame.KEYUP:
- if (event.key == pygame.K_LEFT and self.direction_x == -1 and self.direction_y == 0) or\
- (event.key == pygame.K_RIGHT and self.direction_x == 1 and self.direction_y == 0) or\
- (event.key == pygame.K_UP and self.direction_y == -1 and self.direction_x == 0) or\
- (event.key == pygame.K_DOWN and self.direction_y == 1 and self.direction_x == 0):
- self.direction_x = 0
- self.direction_y = 0
+ #if event.type == pygame.KEYUP:
+ # if (event.key == pygame.K_LEFT and self.direction_x == -1 and self.direction_y == 0) or\
+ # (event.key == pygame.K_RIGHT and self.direction_x == 1 and self.direction_y == 0) or\
+ # (event.key == pygame.K_UP and self.direction_y == -1 and self.direction_x == 0) or\
+ # (event.key == pygame.K_DOWN and self.direction_y == 1 and self.direction_x == 0):
+ # self.direction_x = 0
+ # self.direction_y = 0
# Handle Tree planting key
if event.type == pygame.KEYDOWN:
diff --git a/tree.py b/tree.py
index ef51e29..2520b22 100644
--- a/tree.py
+++ b/tree.py
@@ -7,8 +7,9 @@ cutting_time = 100
class Tree:
def __init__(self, position):
+ self.air = 0
self.cutting_time = cutting_time
- self.sprout_time = 200
+ self.sprout_time = 300
self.position = position
self.image = pygame.image.load(tree_images[randint(0, tree_images_number - 1)])
self.alert_image = pygame.image.load("images/atention.png")
@@ -23,6 +24,8 @@ class Tree:
def draw(self, on_surface):
if self.sprout_time <= 0:
on_surface.blit(self.image, self.position)
+ if self.air == 0:
+ self.air = 1
else:
sprout_text = str(self.sprout_time)
font = pygame.font.Font(None, 24)