Beispiel #1
0
    def __init__(self, parent):
        GameState.__init__(self, parent)

        self.app = ui.App(self.get_root().screen)

        text = """Insects:
_______________
Oh no, those pesky bugs, alright, so here is the low-down.
Ants are fast and regular, beetles are slow and strong.
Wasps fly (and thus can only be hit by towers)
Worms burrow underground and come up later
    (while underground they are immune to all damage)

Now go win!
Hit the "Menu" button to go back to the menu!"""

        ui.Label(self.app, text, text_color=(255,255,255), pos=(5,70), anchor="topleft", small_text=True)

        ui.Button(self.app, "Menu", text_color=(0,0,0), pos=(5,5),
                  callback=lambda: self.parent.use_child("menu"))

        self.bg = data.image("data/background1.png").copy()
        for i in xrange(35):
            self.bg.blit(data.image("data/worker-1.png"), (random.randint(150,800), 5))
            self.bg.blit(data.image("data/tower-base.png"), (random.randint(150,800), 5))

        n = self.bg.copy()
        n.fill((255,228,196,65))
        self.bg.blit(n, (0,0))
Beispiel #2
0
    def __init__(self, parent):
        GameState.__init__(self, parent)

        self.app = ui.App(self.get_root().screen)
        ui.Label(self.app, "Bug Me Not!", text_color=(255,255,255), pos=(100,25), anchor="topleft")

        ui.Button(self.app, "Play - easy", text_color=(0,0,0), pos=(150,100),
                  callback=lambda: self.parent.use_child("game-easy"))
        ui.Button(self.app, "Play - medium", text_color=(0,0,0), pos=(325,100),
                  callback=lambda: self.parent.use_child("game-medium"))
        ui.Button(self.app, "Play - hard", text_color=(0,0,0), pos=(525,100),
                  callback=lambda: self.parent.use_child("game-hard"))

        ui.Button(self.app, "Quit", text_color=(0,0,0), pos=(100,150),
                  callback=self._kill)
        ui.Button(self.app, "Tutorial", text_color=(0,255,255), pos=(200,150),
                  callback=lambda: self.parent.use_child("tut"))
        ui.Button(self.app, "Story", text_color=(0,255,255), pos=(375,150),
                  callback=lambda: self.parent.use_child("story"))

        self.bg = data.image("data/background1.png").copy()
        for i in xrange(100):
            self.bg.blit(data.image("data/worker-1.png"), (random.randint(0,800), random.randint(200,300)))
            self.bg.blit(data.image("data/tower-base.png"), (random.randint(0,800), random.randint(200,300)))

        n = self.bg.copy()
        n.fill((255,228,196,65))
        self.bg.blit(n, (0,0))

        for i in xrange(300):
            i = random.choice(("ant-1.png", "beetle-1.png", "worm-1.png", "wasp-1.png"))
            self.bg.blit(data.image("data/"+i), (random.randint(0,800), random.randint(350,600)))

        self.killed = False
Beispiel #3
0
    def __init__(self, parent):
        GameState.__init__(self, parent)

        self.app = ui.App(self.get_root().screen)

        text = """Specials:
_______________
Yeah, you have some life-lines if you get too fed up with losing:
Bug-killer - spray bug killer at the insects
  Mom+broom - call your mom, who naturally freaks out and whacks the
      bugs and your bots
  Get the Mower - go grab the lawn mower and mow over everything,
      clearing the board"""

        ui.Label(self.app, text, text_color=(255,255,255), pos=(5,70), anchor="topleft", small_text=True)

        ui.Button(self.app, "Menu", text_color=(0,0,0), pos=(5,5),
                  callback=lambda: self.parent.use_child("menu"))
        ui.Button(self.app, "Next", text_color=(0,0,0), pos=(80,5),
                  callback=lambda: self.parent.use_child("tut6"))

        self.bg = data.image("data/background1.png").copy()
        for i in xrange(35):
            self.bg.blit(data.image("data/worker-1.png"), (random.randint(150,800), 5))
            self.bg.blit(data.image("data/tower-base.png"), (random.randint(150,800), 5))

        n = self.bg.copy()
        n.fill((255,228,196,65))
        self.bg.blit(n, (0,0))
Beispiel #4
0
    def __init__(self, parent):
        GameState.__init__(self, parent)

        self.app = ui.App(self.get_root().screen)

        text = """Towers and Workers:
_________________________
You can build towers to defend.
To build a tower, click the tower icon in the "Basic" group of buttons,
on the ui bar. The ui bar is along the bottom of the screen.
Once you have clicked the tower, place it anywhere that isn't
"red" - or not allowed. You can only build towers if you have enough
money and scraps. Once you have a tower, you need some workers to build it.
Workers build towers, upgrade towers (only if different type), and collect scraps.
Once your tower is built, you can upgrade it by clicking on it,
and then selecting either one of the new tower types there, or upgrading along the same type,
clicking the tower that has the "up arrow" and looks the same
Upgrades the tower. Clicking one of the other Towers to upgrade to (if avaiable)
the tower is destroyed and a new build point is placed. Your workers have to build this new tower again now."""

        ui.Label(self.app, text, text_color=(255,255,255), pos=(5,70), anchor="topleft", small_text=True)

        ui.Button(self.app, "Menu", text_color=(0,0,0), pos=(5,5),
                  callback=lambda: self.parent.use_child("menu"))
        ui.Button(self.app, "Next", text_color=(0,0,0), pos=(80,5),
                  callback=lambda: self.parent.use_child("tut3"))

        self.bg = data.image("data/background1.png").copy()
        for i in xrange(35):
            self.bg.blit(data.image("data/worker-1.png"), (random.randint(150,800), 5))
            self.bg.blit(data.image("data/tower-base.png"), (random.randint(150,800), 5))

        n = self.bg.copy()
        n.fill((255,228,196,65))
        self.bg.blit(n, (0,0))
Beispiel #5
0
    def __init__(self, parent):
        GameState.__init__(self, parent)

        self.app = ui.App(self.get_root().screen)

        text = """Warriors:
_____________________
Building warriors is the only way to win the game.
There are three kinds of warriors
  Warriors: regular, the fight bugs and try to make their way to the enemy hive to assult it
  Trapper: faster, weaker bot that throws nets around enemies
  Guards: these guys follow your workers around and protect them
Warriors cannot attack Flying or immune insects, but trappers can trap flying ones."""

        ui.Label(self.app, text, text_color=(255,255,255), pos=(5,70), anchor="topleft", small_text=True)

        ui.Button(self.app, "Menu", text_color=(0,0,0), pos=(5,5),
                  callback=lambda: self.parent.use_child("menu"))
        ui.Button(self.app, "Next", text_color=(0,0,0), pos=(80,5),
                  callback=lambda: self.parent.use_child("tut4"))

        self.bg = data.image("data/background1.png").copy()
        for i in xrange(35):
            self.bg.blit(data.image("data/worker-1.png"), (random.randint(150,800), 5))
            self.bg.blit(data.image("data/tower-base.png"), (random.randint(150,800), 5))

        n = self.bg.copy()
        n.fill((255,228,196,65))
        self.bg.blit(n, (0,0))
Beispiel #6
0
    def __init__(self, parent):
        GameState.__init__(self, parent)

        self.app = ui.App(self.get_root().screen)

        text = """
It is a normal day, and you are up in your room tinkering and creating your latest invention.
All of a sudden this perfect day is shattered when your mom calls out
"Hey, get those insects off the lawn and away from the lawn, NOW!"

"Sigh, once again..." you mutter as you trudge down stares.
Then, all of a sudden, you realize, she didn't say HOW I get rid of them.
So, why not test my latest inventions while clearing the lawn? Yes, genius!

You march out the front door, down the porch and stand firmly on the patio.
"Hey bugs, Get off my Lawn!", you shout, as you start laying out your plan of action.
___________________________
Can your assortment of defenses and bots stop the insect hoard?
"""

        ui.Label(self.app, text, text_color=(255,255,255), pos=(5,70), anchor="topleft", small_text=True)

        ui.Button(self.app, "Menu", text_color=(0,0,0), pos=(5,5),
                  callback=lambda: self.parent.use_child("menu"))

        self.bg = data.image("data/background1.png").copy()
        for i in xrange(35):
            self.bg.blit(data.image("data/worker-1.png"), (random.randint(150,800), 5))
            self.bg.blit(data.image("data/tower-base.png"), (random.randint(150,800), 5))

        n = self.bg.copy()
        n.fill((255,228,196,65))
        self.bg.blit(n, (0,0))
Beispiel #7
0
    def __init__(self, territory, owner, type="frigate", oldship=None, test=False):
        type = type.replace(" ", "").lower()
        self._alive = True
        self.owner = owner
        self.type = type

        td = ship_types[type]
        self.hull_max = td["hull"]
        self.crew_max = td["crew"]
        self.speed_max = td["speed"]

        if oldship:
            self.hull = oldship.hull
            self.crew = oldship.crew
            self.speed = oldship.speed
        else:
            self.hull = self.hull_max
            self.crew = self.crew_max
            self.speed = self.speed_max

        self.damage_multiplier = td["damage_multiplier"]

        # Keep compatibility with battle_test, all new variables need to go
        # below here.
        if test:
            return

        self.territory = territory
        self.image = data.image(self.type + ".png")
        self.shadow = data.image(self.type + "_shadow.png")
        self.anchor = data.image("anchor.png")

        self.pos = self._get_spawn_pos()
        self.rect = self.image.get_rect()
        self.rect.center = self.pos
        self.aoff = self.rect.width - self.anchor.get_width(), self.rect.height - self.anchor.get_height()

        # Total resources can only equal hold capacity
        self.hold_capacity = td["hold_capacity"]

        if oldship:
            self.resources = oldship.resources
        else:
            self.resources = Resources(0, 0, 0)  # Start empty

        self.string = 0
        self.distance_from_capitol = 0
        self.am_gathering = False
        self.gather_target = "gold"
        self.gather_island = None
        self.gather_moveto = None

        self.can_move = True
        self.can_attack = True
        self.goto = None
        self.camera = self.owner.state.world.camera
        self.vertical_offset = 0
        self.hopping = False
        self.anchored_to = territory.capitol
Beispiel #8
0
    def __init__(self, pos):
        self.pos = pos
        self.image = random.choice([data.image("island.png"), data.image("island2.png"), data.image("island3.png")])
        self.rect = self.image.get_rect()
        self.rect.center = self.pos
        self.capitol = False
        self.capitol_image = data.image("island_capitol-test.png")
        self.cap_rect = self.capitol_image.get_rect()
        self.cap_rect.midbottom = self.rect.center

        self.resources = []  # can be gold, crew and string
        self.font = data.font(None, 20)
Beispiel #9
0
    def __init__(self, parent):
        GameState.__init__(self, parent)

        self.app = ui.App(self.get_root().screen)
        ui.Label(self.app, 'You lost...\noh well, like they say:\n    Try, try again :)', text_color=(255,0,0), pos=(0,0), anchor="topleft")

        ui.Button(self.app, "Menu", text_color=(0,0,0), pos=(50,150),
                  callback=lambda: self.parent.use_child("menu"))

        self.bg = data.image("data/background1.png").copy()
        for i in xrange(500):
            i = random.choice(("ant-1.png", "beetle-1.png", "worm-1.png", "wasp-1.png"))
            self.bg.blit(data.image("data/"+i), (random.randint(0,800), random.randint(350,600)))
        n = self.bg.copy()
        n.fill((0,0,0,75))
        self.bg.blit(n, (0,0))
Beispiel #10
0
def main():
    """Check for dimensionality miss-matches for the data sets in data.py"""
    N = 1000
    noise = 0.08

    X, T = friedman_2(N, noise)
    if len(X) != len(T):
        raise Exception(
            "Lengths of X and T in Friedman 2 dataset do not match")

    X, T = friedman_3(N, noise)
    if len(X) != len(T):
        raise Exception(
            "Lengths of X and T in Friedman 3 dataset do not match")

    X, T = boston_housing(N)
    if len(X) != len(T):
        raise Exception(
            "Lengths of X and T in Boston Housing dataset do not match")

    X, T = airfoil(None)
    if len(X) != len(T):
        raise Exception("Lengths of X and T in Airfoil dataset do not match")

    X, T = slump(None)
    if len(X) != len(T):
        raise Exception("Lengths of X and T in Slump dataset do not match")

    X, T = banana(None)
    if len(X) != len(T):
        raise Exception("Lengths of X and T in Banana dataset do not match")

    X, T = titanic(None)
    if len(X) != len(T):
        raise Exception("Lengths of X and T in Titanic dataset do not match")

    X, T = waveform(None)
    if len(X) != len(T):
        raise Exception("Lengths of X and T in Waveform dataset do not match")

    X, T = german(None)
    if len(X) != len(T):
        raise Exception("Lengths of X and T in German dataset do not match")

    X, T = image(None)
    if len(X) != len(T):
        raise Exception("Lengths of X and T in Image dataset do not match")

    X, T = breast_cancer(None)
    if len(X) != len(T):
        raise Exception(
            "Lengths of X and T in breast cancer dataset do not match")

    X, T = splice(None)
    if len(X) != len(T):
        raise Exception("Lengths of X and T in splice dataset do not match")

    X, T = thyroid(None)
    if len(X) != len(T):
        raise Exception("Lengths of X and T in thyroid dataset do not match")
Beispiel #11
0
    def __init__(self, parent):
        GameState.__init__(self, parent)

        self.app = ui.App(self.get_root().screen)
        ui.Label(self.app, "You won, congratulations!", text_color=(75,75,255), pos=(0,0), anchor="topleft")

        ui.Button(self.app, "Menu", text_color=(0,0,0), pos=(50,150),
                  callback=lambda: self.parent.use_child("menu"))

        self.bg = data.image("data/background1.png").copy()
        for i in xrange(100):
            self.bg.blit(data.image("data/worker-1.png"), (random.randint(0,800), random.randint(200,600)))
            self.bg.blit(data.image("data/tower-base.png"), (random.randint(0,800), random.randint(200,600)))

        n = self.bg.copy()
        n.fill((0,0,0,75))
        self.bg.blit(n, (0,0))
Beispiel #12
0
    def __init__(self, screen_size=(640, 480),
                 world_size = (5000, 5000),
                 screen_rect=(640, 480),
                 screen=None):
        self.ssize = screen_size
        self.wsize = world_size

        self.mo = MapObject(self.wsize, self)
        self.tile_image = data.image("water.png")
        self.rock = data.image("rock.png")
        self.cur_timer = 0
        self.cur_cycle = 0

        self.camera = Camera(self.ssize, self.wsize, screen_rect)

        self.islands = []

        self.make_islands()

        self.font = data.font(None, 30)
        self.font2 = data.font("Pieces-of-Eight.ttf", 25)
        
        self.screen = screen
Beispiel #13
0
    def __init__(self, parent):
        GameState.__init__(self, parent)

        self.app = ui.App(self.get_root().screen)

        text = """Traps:
_______________________
Traps are used to either slow or do damage to bugs in a quick fashion.
Basically, if you have the money, just place them anywhere that isn't red, and they are built instantly.
The kinds are:
  Spike: insects get hurt as they run over these, depletes over time
  Bomb: when an insect gets close enough to this trap,
      it detonates, hitting all bugs in a wide area with a strong attack
  Cage: this just stops insects for a while, until it depletes
________________________
Techs:
________________________
Techs are used to upgrade your workers, warriors and traps.
Just click the upgrade buttons under the tech label in the ui.
Each button is the image of the thing it upgrades,
with an up arrow (regular warrior for warriors, spike trap for traps.)"""

        ui.Label(self.app, text, text_color=(255,255,255), pos=(5,70), anchor="topleft", small_text=True)

        ui.Button(self.app, "Menu", text_color=(0,0,0), pos=(5,5),
                  callback=lambda: self.parent.use_child("menu"))
        ui.Button(self.app, "Next", text_color=(0,0,0), pos=(80,5),
                  callback=lambda: self.parent.use_child("tut5"))

        self.bg = data.image("data/background1.png").copy()
        for i in xrange(35):
            self.bg.blit(data.image("data/worker-1.png"), (random.randint(150,800), 5))
            self.bg.blit(data.image("data/tower-base.png"), (random.randint(150,800), 5))

        n = self.bg.copy()
        n.fill((255,228,196,65))
        self.bg.blit(n, (0,0))
Beispiel #14
0
    def __init__(self, parent):
        GameState.__init__(self, parent)

        self.app = ui.App(self.get_root().screen)

        text = """Welcome to Bug Me Not!
The Strategy game where you try and remove the invading insects
from your lawn!
___________________________________
The game mechanics themselves are fairly simple.
You are trying to destroy the insect hive before too many insects get
through your defenses and into the house. The hive is at the top left
corner of the screen, and the way into the house is at the bottom right,
where our hero is sitting.
________________________________

You must build towers to defend, workers to build towers and gather resources,
and, finally, warriors to assault the insect hive.
__________________________________
Click Next to continue with the tutorial..."""

        ui.Label(self.app, text, text_color=(255,255,255), pos=(5,70), anchor="topleft", small_text=True)

        ui.Button(self.app, "Menu", text_color=(0,0,0), pos=(5,5),
                  callback=lambda: self.parent.use_child("menu"))
        ui.Button(self.app, "Next", text_color=(0,0,0), pos=(80,5),
                  callback=lambda: self.parent.use_child("tut2"))

        self.bg = data.image("data/background1.png").copy()
        for i in xrange(35):
            self.bg.blit(data.image("data/worker-1.png"), (random.randint(150,800), 5))
            self.bg.blit(data.image("data/tower-base.png"), (random.randint(150,800), 5))

        n = self.bg.copy()
        n.fill((255,228,196,65))
        self.bg.blit(n, (0,0))
Beispiel #15
0
 def __init__(self, owner, pos):
     self.owner = owner
     self.owner.priority_to_be_rendered_objects.append(self)
     self.pos = list(pos)
     self.images = [
         data.image("exp1.png"),
         data.image("exp2.png"),
         data.image("exp3.png"),
         data.image("exp4.png"),
         data.image("exp5.png"),
         data.image("exp6.png"),
         data.image("exp7.png"),
         data.image("exp8.png"),
     ]
     self.r = self.images[0].get_rect()
     self.r.center = self.pos
     self.counter = 0
     self.cur = 0
     self.dead = False
Beispiel #16
0
	def process_data(self):
		self.emit(SIGNAL("send_update(QString)"), "Constructing Image...")
		
		self.x_pos = self.cur_data.x_pos
		self.y_pos = self.cur_data.y_pos

		#proximity_levels = [150.0, 130.0, 90.0, 45.0, 30.0, 25, 20, 15, 10, 5, 1]
		#proximity_depths = [25.0, 30.0, 40.0, 50.0, 80.0, 100.0, 150.0, 175.0, 200.0, 225.0, 255.0]

		proximity_depths = [80.0, 100.0, 120.0, 160.0, 180.0, 200.0, 220.0, 255.0]
		proximity_levels = [8, 7, 6, 5, 4, 3, 2, 1]



		smallest_x 	= 1000
		largest_x 	= 0
		smallest_y 	= 1000
		largest_y 	= 0

		for x,y in list(zip(self.x_pos, self.y_pos)):
			if x > largest_x:
				largest_x = x
			if x < smallest_x:
				smallest_x = x
			if y > largest_y:
				largest_y = y
			if y < smallest_y:
				smallest_y = y

		translated_x = []
		translated_y = []

		for x,y in list(zip(self.x_pos, self.y_pos)):
			translated_x.append(x-smallest_x)
			translated_y.append(y-smallest_y)

		x_size = largest_x - smallest_x
		y_size = largest_y - smallest_y

		x_scale = int(ceil(float(x_size/20)))
		y_scale = int(ceil(float(y_size/20)))

		new_image = data.image()



		for x in range(28):
			x_upscaled = (x-4)*x_scale
			
			if x < 5 or x > 25:
				x_skip = True
			else:
				x_skip = False
			


			for y in range(28):
				
				if x_skip:
					new_image.add_pixel_XY(0.0, x, y)
					continue

				if y < 5 or y > 25:
					new_image.add_pixel_XY(0.0, x, y)
					continue
				

				
				y_upscaled = (y-4)*y_scale

				level = get_hit_proximity(x_upscaled, y_upscaled, translated_x, translated_y)
				value = 0.0

				for levels, depths in list(zip(proximity_levels, proximity_depths)):

					if level <= levels:
						value = depths

				new_image.add_pixel_XY(value, x, y)

		new_image.output_terminal()
		new_image.label = 0

		image,_ = data.convert_image_data([new_image])

		image = np.array(image)

		proba = self.cur_model.predict_proba(image)

		highest_prob = 0.0
		cur_index = 0
		highest_prob_index = 0
		for probability in proba[0]:
			if probability > highest_prob:
				highest_prob = probability
				highest_prob_index = cur_index
			cur_index += 1

		self.emit(SIGNAL("send_update(QString)"), "Digit is a "+str(highest_prob_index)+" with probability of "+str(highest_prob))
		return
Beispiel #17
0
 def render_bg(self, screen):
     screen.blit(data.image("hud_bg_bottom.png"), (0,380))
     map = self.minimap.update()
     screen.blit(map, self.minimap.rect)
Beispiel #18
0
 def render_bg(self, screen):
     screen.blit(data.image("hud_bg_top.png"), (0,0))
Beispiel #19
0
    def update(self):

        for event in pygame.event.get():
            if self.app.update(event):
                continue
            if event.type == QUIT:
                self.get_root().shutdown()
                return

            if event.type == MOUSEBUTTONDOWN:
                if self.selected_ui:
                    self.selected_ui.kill()
                    self.selected_ui = None
                if event.button == 1:
                    if self.selected_object:
                        self.selected_object.selected = False
                    if event.pos[1] <= 500: #this is for us!
                        grid = self.map_grid.screen_to_grid(event.pos)
                        if self.build_active:
                            if self.building == objects.TowerBase:
                                if self.map_grid.empty_around(grid):
                                    self.build_active = False
                                    objects.BuildTower(self, self.map_grid.grid_to_screen(grid))
                                    for i in self.bot_group.objects:
                                        i.reset_target()
                            elif self.building: #must be a trap of some sort!
                                if self.map_grid.is_open(grid):
                                    self.build_active = False
                                    self.building(self, self.map_grid.grid_to_screen(grid))
                        self.build_active = False
                        for i in self.tower_group.objects:
                            if i.rect.collidepoint(event.pos):
                                i.selected = True
                                self.selected_object = i
                                self.selected_ui = ui.TowerInfo(self.app, i)
                    else:
                        self.build_active = False
                        self.building = None
                if event.button == 3: #right
                    self.build_active = False
                    self.building = None

            if event.type == KEYDOWN:
                if event.key == K_s:
                    pygame.image.save(self.screen, "test.png")

        used = False
        for i in self.app.widgets:
            x = i.get_status()
            if x:
                self.status_message.set(x)
                used = True
                break
        if not used:
            self.status_message.set(None)

        self.hero_group.update()
        self.hive_group.update()
        self.build_tower_group.update()
        self.bot_group.update()
        self.insect_group.update()
        self.scraps_group.update()
        self.tower_group.update()
        self.bullet_group.update()
        self.damage_notes_group.update()
        self.trap_group.update()
        self.special_group.update()
        self.main_group.sort()
        self.flying_group.sort()

        self.screen.blit(self.background, (0,0))

        if self.build_active:
            self.screen.blit(self.build_overlay, (0,0))

        pygame.draw.rect(self.screen, (255,0,255), (self.map_grid.screen_to_screen(pygame.mouse.get_pos()), (20,20)), 2)

        self.main_group.render()
        self.flying_group.render()
        self.damage_notes_group.render()

        #mouse stuffs!
        if self.build_active:
            x, y = self.map_grid.screen_to_screen(pygame.mouse.get_pos())
            grid = self.map_grid.screen_to_grid((x,y))
            if self.building == objects.TowerBase:
                if self.map_grid.empty_around(grid):
                    i = data.image(self.building.ui_icon)
                    r = i.get_rect()
                    r.midbottom = x+10, y+20
                    self.screen.blit(i, r)
            else:
                if self.map_grid.is_open(grid):
                    i = data.image(self.building.ui_icon)
                    r = i.get_rect()
                    r.midbottom = x+10, y+20
                    self.screen.blit(i, r)
            


        self.screen.blit(self.ui_background, (0,500))
        
        self.app.render()
        self.screen.blit(self.money_ui, self.money_ui_pos)
        self.screen.blit(self.scraps_ui, self.scraps_ui_pos)
        self.screen.blit(self.kills_ui, self.kills_ui_pos)
        self.screen.blit(self.font.render("units: %s/20"%len(self.bot_group.objects), 1, (255,255,255)), (90,570))

        if self.hero.was_killed:
            self.parent.use_child("lose")
        if self.hive.was_killed:
            self.parent.use_child("win")

        text = self.font.render("Insect level: %s"%self.hive.level, 1, (255,255,255))
        new = pygame.Surface((text.get_width()+8, text.get_height()+8)).convert_alpha()
        new.fill((75,75,255,50))
        pygame.draw.rect(new, (0,0,0), ((0,0),new.get_size()), 2)
        new.blit(text, (4, 4))
        self.screen.blit(new, (85,3))

        pygame.display.flip()
Beispiel #20
0
    def __init__(self, parent, mode="easy"):
        GameState.__init__(self, parent)

        self.screen = self.get_root().screen

        self.audio = sound.SoundManager('data')
        pygame.mixer.music.load("data/ants_on_my_lawn.ogg")
        pygame.mixer.music.set_volume(0.6)
        pygame.mixer.music.play(-1)
        #self.audio.sounds['ants_on_my_lawn.ogg'].set_volume(0.6)
        #self.audio.sounds['ants_on_my_lawn.ogg'].play(loops=-1)

        self.background = data.image("data/background1.png")
        self.ui_background = data.image("data/porch_ui.png")

        self.main_group = objects.GameGroup()
        self.flying_group = objects.GameGroup()
        self.hero_group = objects.GameGroup()
        self.hive_group = objects.GameGroup()
        self.build_tower_group = objects.GameGroup()
        self.bot_group = objects.GameGroup()
        self.tower_group = objects.GameGroup()
        self.insect_group = objects.GameGroup()
        self.scraps_group = objects.GameGroup()
        self.blocking_group = objects.GameGroup()
        self.bullet_group = objects.GameGroup()
        self.trap_group = objects.GameGroup()
        self.special_group = objects.GameGroup()

        self.damage_notes_group = objects.GameGroup()

        if mode == "easy":
            level = 1
            scraps = 10
            self.money = 500
            self.scraps = 500
        elif mode=="medium":
            level = 4
            scraps = 6
            self.money = 425
            self.scraps = 425
        else:
            level = 7
            scraps = 3
            self.money = 350
            self.scraps = 350
        self.hive = objects.Hive(self)
        self.hive.level = level
        self.hive.max_hp += level
        self.hive.hp += level



        self.kills = 0

        self.font = data.font("data/font.ttf", 24)

        self.money_ui = self.font.render("money: %s"%self.money, 1, (255,255,255))
        self.money_ui_pos = (0, 530)
        self.scraps_ui = self.font.render("scraps: %s"%self.scraps, 1, (255,255,255))
        self.scraps_ui_pos = (0, 550)
        self.kills_ui = self.font.render("kills: %s"%self.kills, 1, (255,255,255))
        self.kills_ui_pos = (0, 570)

        self.map_grid = map_grid.MapGrid(self)

        self.hero = objects.Hero(self)

        self.map_grid.make_random(random.randint(40, 60), scraps)

        self.build_active = None
        self.building = None
        self.build_overlay = None

        self.selected_object = None
        self.selected_ui = None

        #UI here, so it has access to all the data above!
        self.app = ui.App(self.screen)
        ui.Button(self.app, "Quit Game", pos=(0,500), callback=self.goback,
                  status_message="Quit game...?")

        #Make build objects gui
        #TODO: implement multiple kinds of warriors/traps!!!

        l = ui.Label(self.app, "Basic", pos=(180, 500))
        ui.LinesGroup(self.app, l)
        b = ui.Button(self.app, image=objects.TowerBase.ui_icon, pos=l.rect.inflate(0,2).bottomleft,
                  callback=self.build_tower,
                      status_message=("Build a Tower\ncost:\n  money: %s\n  scraps: %s"+\
                                      "\n----------\nattack: %s\nrange: %s\nspeed: %s")%(objects.TowerBase.money_cost,
                                                                                         objects.TowerBase.scrap_cost,
                                                                                         objects.TowerBase.base_attack,
                                                                                         objects.TowerBase.base_range,
                                                                                         objects.TowerBase.base_shoot_speed),
                      anchor="topleft")
        
        b = ui.Button(self.app, image=objects.Worker.ui_icon, pos=b.rect.inflate(8,0).topright,
                  callback=self.build_worker,
                      status_message=("Build a Worker\ncost:\n  money: %s\n  scraps: %s"+\
                                      "\n----------\nattack: %s\nhp: %s\nspeed: %s")%(objects.Worker.money_cost,
                                                                                      objects.Worker.scrap_cost,
                                                                                      objects.Worker.base_damage,
                                                                                      objects.Worker.base_hp,
                                                                                      objects.Worker.base_speed),
                      anchor="topleft")
        self.build_worker_button = b

        l = ui.Label(self.app, "Warriors ", pos=(250, 500))
        ui.LinesGroup(self.app, l)
        b = ui.Button(self.app, image=objects.BattleBot.ui_icon, pos=l.rect.inflate(0,2).bottomleft,
                  callback=self.build_warrior,
                      status_message=("Build a Warrior\ncost:\n  money: %s\n  scraps: %s"+\
                                      "\n----------\nattack: %s\nhp: %s\nspeed: %s\nspecial: %s")%(objects.BattleBot.money_cost,
                                                                                      objects.BattleBot.scrap_cost,
                                                                                      objects.BattleBot.base_damage,
                                                                                      objects.BattleBot.base_hp,
                                                                                      objects.BattleBot.base_speed,
                                                                                                   objects.BattleBot.special),
                      anchor="topleft")
        self.build_warrior_button = b

        b = ui.Button(self.app, image=objects.TrapperBot.ui_icon, pos=b.rect.inflate(8,0).topright,
                  callback=self.build_trapper,
                      status_message=("Build a Trapper\ncost:\n  money: %s\n  scraps: %s"+\
                                      "\n----------\nattack: %s\nhp: %s\nspeed: %s\nspecial: %s")%(objects.TrapperBot.money_cost,
                                                                                      objects.TrapperBot.scrap_cost,
                                                                                      objects.TrapperBot.base_damage,
                                                                                      objects.TrapperBot.base_hp,
                                                                                      objects.TrapperBot.base_speed,
                                                                                                   objects.TrapperBot.special),
                      anchor="topleft")
        self.build_trapper_button = b

        b = ui.Button(self.app, image=objects.GuardBot.ui_icon, pos=b.rect.inflate(8,0).topright,
                  callback=self.build_guard,
                      status_message=("Build a Guard\ncost:\n  money: %s\n  scraps: %s"+\
                                      "\n----------\nattack: %s\nhp: %s\nspeed: %s\nspecial: %s")%(objects.GuardBot.money_cost,
                                                                                      objects.GuardBot.scrap_cost,
                                                                                      objects.GuardBot.base_damage,
                                                                                      objects.GuardBot.base_hp,
                                                                                      objects.GuardBot.base_speed,
                                                                                                   objects.GuardBot.special),
                      anchor="topleft")
        self.build_guard_button = b
        

        l = ui.Label(self.app, " Traps ", pos=(370, 500))
        ui.LinesGroup(self.app, l)
        b = ui.Button(self.app, image=objects.SpikeTrap.ui_icon, pos=l.rect.inflate(0,2).bottomleft,
                  callback=self.build_spike_trap,
                      status_message=("Build a Spike Trap\ncost:\n  money: %s\n  scraps: %s"+\
                                      "\n----------\nattack: %s\nuses: %s\nspecial: %s")%(objects.SpikeTrap.money_cost,
                                                                                      objects.SpikeTrap.scrap_cost,
                                                                                      objects.SpikeTrap.base_damage,
                                                                                      objects.SpikeTrap.base_usage_count,
                                                                                      objects.SpikeTrap.special),
                      anchor="topleft")
        self.build_spike_trap_button = b

        b = ui.Button(self.app, image=objects.CageTrap.ui_icon, pos=b.rect.inflate(8,0).topright,
                  callback=self.build_cage_trap,
                      status_message=("Build a Cage Trap\ncost:\n  money: %s\n  scraps: %s"+\
                                      "\n----------\nattack: %s\nuses: %s\nspecial: %s")%(objects.CageTrap.money_cost,
                                                                                      objects.CageTrap.scrap_cost,
                                                                                      objects.CageTrap.base_damage,
                                                                                      objects.CageTrap.base_usage_count,
                                                                                      objects.CageTrap.special),
                      anchor="topleft")
        self.build_cage_trap_button = b

        b = ui.Button(self.app, image=objects.BombTrap.ui_icon, pos=b.rect.inflate(8,0).topright,
                  callback=self.build_bomb_trap,
                      status_message=("Build a Bomb Trap\ncost:\n  money: %s\n  scraps: %s"+\
                                      "\n----------\nattack: %s\nuses: %s\nspecial: %s")%(objects.BombTrap.money_cost,
                                                                                      objects.BombTrap.scrap_cost,
                                                                                      objects.BombTrap.base_damage,
                                                                                      objects.BombTrap.base_usage_count,
                                                                                      objects.BombTrap.special),
                      anchor="topleft")
        self.build_bomb_trap_button = b


        #Ooh, techs, gotta love them!
        l = ui.Label(self.app, "  Techs   ", pos=(470, 500))
        ui.LinesGroup(self.app, l)
        i = pygame.Surface((30,30)).convert_alpha()
        i.fill((0,0,0,0))
        i.blit(data.image("data/worker-1.png"), (10,10))
        i.blit(data.image("data/arrow.png"), (0,0))
        self.upg_worker = ui.Button(self.app, image=i, pos=l.rect.inflate(0,2).bottomleft,
                      callback=self.upgrade_worker,
                      status_message="Upgrade Workers\ncurrent level: %s\ncost:\n  money: %s"%(self.hero.worker_level,
                                                                                     self.hero.tech_worker_upgrade_cost),
                      anchor="topleft")

        i = pygame.Surface((40,40)).convert_alpha()
        i.fill((0,0,0,0))
        i.blit(data.image("data/warrior-1.png"), (10,10))
        i.blit(data.image("data/arrow.png"), (0,0))
        self.upg_warrior = ui.Button(self.app, image=i, pos=self.upg_worker.rect.inflate(8,0).topright,
                      callback=self.upgrade_warrior,
                      status_message="Upgrade Warriors\ncurrent level: %s\ncost:\n  money: %s"%(self.hero.warrior_level,
                                                                                      self.hero.tech_warrior_upgrade_cost),
                      anchor="topleft")

        i = pygame.Surface((30,30)).convert_alpha()
        i.fill((0,0,0,0))
        i.blit(data.image("data/spikes.png"), (10,10))
        i.blit(data.image("data/arrow.png"), (0,0))
        self.upg_traps = ui.Button(self.app, image=i, pos=self.upg_warrior.rect.inflate(8,0).topright,
                      callback=self.upgrade_traps,
                      status_message="Upgrade Traps\ncurrent level: %s\ncost:\n  money: %s"%(self.hero.trap_level,
                                                                                   self.hero.tech_trap_upgrade_cost),
                      anchor="topleft")

        l = ui.Label(self.app, "Specials    ", pos=(610, 500))
        ui.LinesGroup(self.app, l)
        i = pygame.transform.scale(data.image("data/spray_can.png"), (35, 60))
        self.special_spray = ui.Button(self.app, image=i, pos=l.rect.inflate(0,2).bottomleft,
                      callback=self.use_spray_special,
                      status_message="Insects whooping on you?\nUse your spray can - kills all baddies!",
                      anchor="topleft")
        i = pygame.transform.scale(data.image("data/broom.png"), (35, 60))
        self.special_broom = ui.Button(self.app, image=i, pos=self.special_spray.rect.inflate(8,0).topright,
                      callback=self.use_broom_special,
                      status_message="Wah! They are too strong!\nCall down some major beatdown\nfrom your mom's broom!",
                      anchor="topleft")
        i = pygame.transform.scale(data.image("data/mower.png"), (50, 50))
        self.special_mower = ui.Button(self.app, image=i, pos=self.special_broom.rect.inflate(8,0).topright,
                      callback=self.use_mower_special,
                      status_message="Get off my lawn already!!\nFine. I can do some major damage to you, ya punks!\nVrrrrm!",
                      anchor="topleft")

        self.status_message = ui.PopupManager(self.app)
        self.status_message.set("Testing, 1,2,3")

        if mode == "easy":
            self.money += self.hero.tech_worker_upgrade_cost
            self.upgrade_worker()