Skip to content

Instantly share code, notes, and snippets.

@Drvanon
Created May 25, 2012 20:34
Show Gist options
  • Save Drvanon/2790423 to your computer and use it in GitHub Desktop.
Save Drvanon/2790423 to your computer and use it in GitHub Desktop.
from time import time
import pygame
from pygame.locals import *
from sys import exit
pygame.init()
class Upgrade(object):
def __init__(self, ID, Type, player):
self.health = 100
self.Type = Type
self.timer = 0
self.started = False
self.start = 0
self.out = True
self.ID = ID
self.pressed = False
self.AddedStatus = False
self.status = 'out'
self.source = player.energy
if self.Type == 'Drain':
self.ValueM = 2
self.ValueE = 1
self.kind = 'basic'
if self.Type == 'Plant':
self.ValueM = -1
self.ValueE = -2
self.speed = 2
self.kind = 'basic'
def update(self, player, hk, source):
if self.out == True:
self.status = 'out'
else:
self.status = 'on'
if self.started == True:
if self.AddedStatus == False:
hk[self.ID] = str(self.ID + 1) + ' basic ' + self.Type + str(self.health) + ' on'
self.AddedStatus = True
if self.out == True:
self.start = time()
self.timer = 0
self.out = False
if time() - self.start > self.timer:
player.product = player.product + self.ValueM
source = source - self.ValueE
self.timer = self.timer + self.speed
if source <= 0:
source = 0
self.started = False
self.timer = 0
self.out = True
if self.pressed == True:
if self.out == True:
self.started = True
elif self.out == False:
self.out = True
self.started = False
self.pressed = False
self.AddedStatus = False
pass
if self.started == False:
if self.AddedStatus == False:
hk[self.ID] = str(self.ID + 1) +' basic ' + self.Type + ' out'
self.AddedStatus = True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment