def depart_view(): # set view for player to travel from one planet to another bacon.draw_image(redrocket, 561, 485) if myplayer.destination: bacon.draw_image(depart, 561, 485) bacon.push_color() bacon.set_color(1,1,1,1) # white bacon.draw_string(planet, "destination set: %s" % myplayer.destination, 400, 470) bacon.pop_color bacon.push_color() # place pin bacon.set_color(.74, .07, .07, 1) # red bacon.draw_image(target, myplayer.destination_x - 7, myplayer.destination_y - 20) bacon.pop_color() bacon.push_color() # set fuel usage in red on gauge gauge_level = (179 * (myplayer.fuel_used/100.0)) if gauge_level == 0: gauge_level = 14 bacon.set_color(.74, .07, .07, 1) # red bacon.fill_rect(14, 496, (gauge_level), 530) bacon.pop_color() bacon.push_color() bacon.set_color(0, 0, 0, 1) if myplayer.fuel_used > myship.fuel: bacon.draw_string(planet, "need more fuel", 16, 522) else: bacon.draw_string(planet, "fuel used: %r " % myplayer.fuel_used, 16, 522) bacon.pop_color()
def cargo_view(): bacon.push_color() bacon.set_color(1, 1, 1, 0) # white bacon.draw_image(triangle, 268, 450) #point triangle at icon bacon.fill_rect(150, 40, 425, 450) # create white background box bacon.pop_color() bacon.push_color() # draw cargo robot bacon.draw_image(robot, 175, 65) bacon.pop_color() bacon.push_color() bacon.set_color(0, 0, 0, 1) #black bacon.draw_string(robot_speak, "Here is the ", (175 + robot.width + 5), 82) bacon.draw_string(robot_speak, "cargo manifest ", (175 + robot.width + 5), 97) bacon.draw_string(robot_speak, "you requested,", (175 + robot.width + 5), 112) bacon.draw_string(robot_speak, "Captian.", (175 + robot.width + 5), 127) bacon.draw_string(planet, "Name", 175, 175) bacon.draw_string(planet, "Cost", 295, 175) bacon.draw_string(planet, "Quantity", 350, 175) bacon.draw_string(planet, "(%d)" % myship.cargo_load_calculator(), 360, 150) n = 0 for item in myship.current_cargo: n += 1 bacon.draw_string(planet, "%s" % item[0], 175, (180 + (line_height * n))) bacon.draw_string(planet, "%d" % item[1], 295, (180 + (line_height * n))) bacon.draw_string(planet, "%d" % item[2], 350, (180 + (line_height * n))) bacon.pop_color()
def depart_view(): # set view for player to travel from one planet to another bacon.draw_image(redrocket, 561, 485) if myplayer.destination: bacon.draw_image(depart, 561, 485) bacon.push_color() bacon.set_color(1, 1, 1, 1) # white bacon.draw_string(planet, "destination set: %s" % myplayer.destination, 400, 470) bacon.pop_color bacon.push_color() # place pin bacon.set_color(.74, .07, .07, 1) # red bacon.draw_image(target, myplayer.destination_x - 7, myplayer.destination_y - 20) bacon.pop_color() bacon.push_color() # set fuel usage in red on gauge gauge_level = (179 * (myplayer.fuel_used / 100.0)) if gauge_level == 0: gauge_level = 14 bacon.set_color(.74, .07, .07, 1) # red bacon.fill_rect(14, 496, (gauge_level), 530) bacon.pop_color() bacon.push_color() bacon.set_color(0, 0, 0, 1) if myplayer.fuel_used > myship.fuel: bacon.draw_string(planet, "need more fuel", 16, 522) else: bacon.draw_string(planet, "fuel used: %r " % myplayer.fuel_used, 16, 522) bacon.pop_color()
def banking(): x, y = bacon.mouse.x, bacon.mouse.y bacon.draw_image(money, 458, 485) bacon.draw_image(triangle, 463, 450) #point triangle at icon bacon.fill_rect(350, 375, 620, 450) # create white background box bacon.push_color bacon.set_color(0, 0, 0, 1) bacon.draw_rect(515, 378, 617, 406) # for deposit bacon.draw_string(planet, "Cash: %d" % myplayer.money_in_pocket, 355, 400) bacon.draw_rect(515, 412, 617, 442) # for withdrawal bacon.draw_string(planet, "Bank: %d" % myplayer.money_in_bank, 355, 435) bacon.pop_color() bacon.push_color() bacon.set_color(.20, .58, .03, 1) # green if x in range(515, 617) and y in range(412, 442): # withdrawal bacon.fill_rect(516, 413, 616, 441) elif x in range(515, 617) and y in range(378, 406): # deposit bacon.fill_rect(516, 379, 616, 405) bacon.pop_color() bacon.draw_string(planet, "Deposit", 518, 400) bacon.draw_string(planet, "Withdrawal", 518, 435)
def refuel(): x, y = bacon.mouse.x, bacon.mouse.y main_view() bacon.draw_image(battery, 189, 485) bacon.draw_image(triangle, 173, 450) #point triangle at icon bacon.fill_rect(95, 375, 268, 450) # create white dialogue box bacon.push_color() bacon.set_color(0, 0, 0, 1) bacon.draw_string( planet, "Refuel cost: %d " % abs((100 - myship.fuel) * fuel_cost), 105, 402) bacon.draw_rect(102, 408, 140, 444) #yes rectangle if x in range(102, 140) and y in range(408, 444): #yes box hover color bacon.push_color() bacon.set_color(.2, .58, .03, 1) #green bacon.fill_rect(103, 409, 139, 443) bacon.pop_color() bacon.draw_rect(230, 408, 260, 444) #no box if x in range(230, 260) and y in range(408, 444): #no box hover color bacon.push_color() bacon.set_color(.74, .07, .07, 1) # red bacon.fill_rect(231, 409, 259, 443) bacon.pop_color() bacon.draw_string(planet, "Yes No", 106, 438) bacon.pop_color() core_action()
def refuel(): x, y = bacon.mouse.x, bacon.mouse.y main_view() bacon.draw_image(battery, 189, 485) bacon.draw_image(triangle, 173, 450) #point triangle at icon bacon.fill_rect(95, 375, 268, 450) # create white dialogue box bacon.push_color() bacon.set_color(0, 0, 0, 1) bacon.draw_string(planet, "Refuel cost: %d " % abs((100 - myship.fuel) * fuel_cost), 105, 402) bacon.draw_rect(102, 408, 140, 444) #yes rectangle if x in range(102, 140) and y in range(408, 444): #yes box hover color bacon.push_color() bacon.set_color(.2, .58, .03, 1) #green bacon.fill_rect(103, 409, 139, 443) bacon.pop_color() bacon.draw_rect(230, 408, 260, 444) #no box if x in range(230, 260) and y in range(408, 444): #no box hover color bacon.push_color() bacon.set_color(.74, .07, .07, 1) # red bacon.fill_rect(231, 409, 259, 443) bacon.pop_color() bacon.draw_string(planet, "Yes No", 106, 438) bacon.pop_color() core_action()
def main_view(): # call from on_tick to draw main game elements bacon.draw_image(background, 0, 0) # place backdrop for item in planet_list: # place planet names bacon.draw_string(planet, item[0], item[1] + 13, item[2] + 8) bacon.push_color() # set fuel gauge bacon.set_color(.2, .58, .03, 1) #green bacon.fill_rect(14, 496, (179 * (myship.fuel/100.0)), 530) bacon.pop_color() bacon.push_color() # place star for current location bacon.draw_image(star, myplayer.location_x - 8, myplayer.location_y - 6) bacon.pop_color() bacon.push_color() bacon.set_color(0,0,0,.2) bacon.fill_rect(0, 0, 640, 40) #HUD top bar bacon.set_color(1,1,1,1) bacon.draw_string(planet, "%s cash: %d bank: %d turn: %d" % ( myplayer.name, myplayer.money_in_pocket, myplayer.money_in_bank, myplayer.turn), 20, 30) bacon.pop_color()
def main_view(): # call from on_tick to draw main game elements bacon.draw_image(background, 0, 0) # place backdrop for item in planet_list: # place planet names bacon.draw_string(planet, item[0], item[1] + 13, item[2] + 8) bacon.push_color() # set fuel gauge bacon.set_color(.2, .58, .03, 1) #green bacon.fill_rect(14, 496, (179 * (myship.fuel / 100.0)), 530) bacon.pop_color() bacon.push_color() # place star for current location bacon.draw_image(star, myplayer.location_x - 8, myplayer.location_y - 6) bacon.pop_color() bacon.push_color() bacon.set_color(0, 0, 0, .2) bacon.fill_rect(0, 0, 640, 40) #HUD top bar bacon.set_color(1, 1, 1, 1) bacon.draw_string( planet, "%s cash: %d bank: %d turn: %d" % (myplayer.name, myplayer.money_in_pocket, myplayer.money_in_bank, myplayer.turn), 20, 30) bacon.pop_color()
def on_tick(self): #global banking_window x, y = bacon.mouse.x, bacon.mouse.y main_view() # build the main page elements core_action() # build the hover colors for screen icons # if window is active, run function to display it if window.bank: banking() if window.cargo: cargo_view() if window.merchant: merchant_view() if window.destination: depart_view() if window.refuel: refuel() if window.bank == True or window.cargo == True or window.merchant == True: pass else: for item in planet_list: # on mouse hover over planet usage if x in range(item[1], item[1] + 12) and y in range( item[2], item[2] + 12): distance_and_fuel(myplayer.location_x, myplayer.location_y, item[1], item[2]) bacon.push_color() # place pin bacon.set_color(.74, .07, .07, 1) # red bacon.draw_image(target, item[1] - 7, item[2] - 20) bacon.pop_color() bacon.push_color() # set fuel usage in red on gauge gauge_level = (179 * (myplayer.fuel_used / 100.0)) if gauge_level == 0: gauge_level = 14 bacon.set_color(.74, .07, .07, 1) # red bacon.fill_rect(14, 496, (gauge_level), 530) bacon.pop_color() bacon.push_color() bacon.set_color(0, 0, 0, 1) gauge_level = (179 * (myplayer.fuel_used / 100.0)) if gauge_level == 0: gauge_level = 14 if myplayer.fuel_used > myship.fuel: bacon.draw_string(planet, "need more fuel", 16, 522) else: bacon.draw_string( planet, "fuel used: %r " % myplayer.fuel_used, 16, 522) bacon.pop_color() if bacon.Keys.space in bacon.keys or bacon.mouse.left: if window.merchant: for i, item in enumerate(myship.current_cargo, 1): # process selling element if x in range(220, 265) and y in range( (160 + (line_height * i)), (160 + line_height + line_height * i)): if item[2] == 0: self.current_cargo.remove(item) pass elif myship.remove_cargo(item[0]): myplayer.money_in_pocket += transfer_element_to_market( item[0]) for i, item in enumerate(element_pricelist, 1): # process buying element if x in range(300, 345) and y in range( (160 + (line_height * i)), (160 + line_height + line_height * i)): if item[2] == 0: pass elif myship.add_cargo(item[0], item[1]): myplayer.remove_money_from_pocket(item[1]) item[2] -= 1 if myplayer.money_in_pocket < 0: myplayer.money_in_bank += myplayer.money_in_pocket myplayer.money_in_pocket = 0 if window.bank: if x in range(515, 617) and y in range( 412, 442) and myplayer.money_in_bank > 1000: myplayer.money_in_bank -= 1000 myplayer.money_in_pocket += 1000 elif x in range(515, 617) and y in range( 378, 406) and myplayer.money_in_pocket > 1000: myplayer.money_in_bank += 1000 myplayer.money_in_pocket -= 1000
def on_tick(self): x, y = bacon.mouse.x, bacon.mouse.y oberon = [5000, 75, 40, 5] # set ship attributes intrepid = [6000, 225, 80, 2] excelsior = [4000, 100, 60, 2] firefly = [7000, 125, 80, 3] bacon.draw_image(title, 0, 0) bacon.draw_string(planet, "Select your starship", 240, 450) if x in range( (bacon.window.width * 0/4 + 20), (bacon.window.width * 0/4 + 20 + ship1.width)) and y in range( 300, (300 + ship1.height)): bacon.draw_image(triangle, (bacon.window.width * 0/4 + 42), 265) bacon.fill_rect(0, 125, 200, 265) bacon.push_color() bacon.set_color(0,0,0,1) #black bacon.draw_string(planet, "Class: Oberon", 10, 153) bacon.draw_string(planet, "Price: %d credits" % oberon[0], 10, 153 + line_height * 4) bacon.draw_string(planet, "Cargo Space: %d" % oberon[1], 10, 153 + line_height) bacon.draw_string(planet, "Weight: %d tons" % oberon[2], 10, 153 + line_height * 2) bacon.draw_string(planet, "Max Velocity: %d" % oberon[3], 10, 153 + line_height * 3) bacon.pop_color() if bacon.mouse.left: myplayer.ship = "Oberon" myplayer.money_in_pocket -= oberon[0] myship.cost_to_buy = oberon[0] myship.hauling_capacity = oberon[1] myship.weight = oberon[2] myship.velocity = oberon[3] bacon.run(Game()) bacon.draw_image(ship1, (bacon.window.width * 0/4 + 40), 300) if x in range( (bacon.window.width * 1/4 + 20), (bacon.window.width * 1/4 + 20 + ship1.width)) and y in range( 300, (300 + ship1.height)): bacon.draw_image(triangle, (bacon.window.width * 1/4 + 45), 265) bacon.fill_rect(135, 125, 335, 265) bacon.push_color() bacon.set_color(0,0,0,1) #black bacon.draw_string(planet, "Class: Intrepid", 145, 153) bacon.draw_string(planet, "Price: %d credits" % intrepid[0], 145, 153 + line_height * 4) bacon.draw_string(planet, "Cargo Space: %d" % intrepid[1], 145, 153 + line_height) bacon.draw_string(planet, "Weight: %d tons" % intrepid[2], 145, 153 + line_height * 2) bacon.draw_string(planet, "Max Velocity: %d" % intrepid[3], 145, 153 + line_height * 3) bacon.pop_color() if bacon.mouse.left: myplayer.ship = "Intrepid" myplayer.money_in_pocket -= intrepid[0] myship.cost_to_buy = intrepid[0] myship.hauling_capacity = intrepid[1] myship.weight = intrepid[2] myship.velocity = intrepid[3] bacon.run(Game()) bacon.draw_image(ship2, (bacon.window.width * 1/4 + 40), 300) if x in range( (bacon.window.width * 2/4 + 20), (bacon.window.width * 2/4 + 20 + ship1.width)) and y in range( 300, (300 + ship1.height)): bacon.draw_image(triangle, (bacon.window.width * 2/4 + 29), 265) bacon.fill_rect(290, 125, 490, 265) bacon.push_color() bacon.set_color(0,0,0,1) #black bacon.draw_string(planet, "Class: Excelsior", 300, 153) bacon.draw_string(planet, "Price: %d credits" % excelsior[0], 300, 153 + line_height * 4) bacon.draw_string(planet, "Cargo Space: %d" % excelsior[1], 300, 153 + line_height) bacon.draw_string(planet, "Weight: %d tons" % excelsior[2], 300, 153 + line_height * 2) bacon.draw_string(planet, "Max Velocity: %d" % excelsior[3], 300, 153 + line_height * 3) bacon.pop_color() if bacon.mouse.left: myplayer.ship = "Excelsior" myplayer.money_in_pocket -= excelsior[0] myship.cost_to_buy = excelsior[0] myship.hauling_capacity = excelsior[1] myship.weight = excelsior[2] myship.velocity = excelsior[3] bacon.run(Game()) bacon.draw_image(ship3, (bacon.window.width * 2/4 + 30), 300) if x in range( (bacon.window.width * 3/4 + 20), (bacon.window.width * 3/4 + 20 + ship1.width)) and y in range( 300, (300 + ship1.height)): bacon.draw_image(triangle, (bacon.window.width * 3/4 + 22), 265) bacon.fill_rect(440, 125, 640, 265) bacon.push_color() bacon.set_color(0,0,0,1) #black bacon.draw_string(planet, "Class: Firefly", 450, 153) bacon.draw_string(planet, "Price: %d credits" % firefly[0], 450, 153 + line_height * 4) bacon.draw_string(planet, "Cargo Space: %d" % firefly[1], 450, 153 + line_height) bacon.draw_string(planet, "Weight: %d tons" % firefly[2], 450, 153 + line_height * 2) bacon.draw_string(planet, "Max Velocity: %d" % firefly[3], 450, 153 + line_height * 3) bacon.pop_color() if bacon.mouse.left: myplayer.ship = "Firefly" myplayer.money_in_pocket -= firefly[0] myship.cost_to_buy = firefly[0] myship.hauling_capacity = firefly[1] myship.weight = firefly[2] myship.velocity = firefly[3] bacon.run(Game()) bacon.draw_image(ship4, (bacon.window.width * 3/4 + 20), 300)
def merchant_view(): x, y = bacon.mouse.x, bacon.mouse.y bacon.push_color() bacon.set_color(1, 1, 1, 0) # white bacon.draw_image(triangle, 367, 450) #point triangle at icon bacon.fill_rect(0, 40, 640, 450) # create white background box bacon.pop_color() bacon.push_color() bacon.draw_image(robot, 20, 65) # draw cargo robot n = planet_locator.index((myplayer.location_x, myplayer.location_y)) bacon.draw_image(planet_master[n].merchant_photo, 350, 65) #draw planet merchant bacon.pop_color() bacon.push_color() bacon.set_color(0, 0, 0, 1) #black bacon.draw_string(robot_speak, "Here is the ", (20 + robot.width + 5), 82) # cargo robot speech bacon.draw_string(robot_speak, "cargo manifest ", (20 + robot.width + 5), 97) bacon.draw_string(robot_speak, "you requested,", (20 + robot.width + 5), 112) bacon.draw_string(robot_speak, "Captian.", (20 + robot.width + 5), 127) bacon.draw_string(robot_speak, "Buy something,", (350 + merch1.width + 5), 82) # planet merchent speach bacon.draw_string(robot_speak, "will ya!?", (350 + merch1.width + 5), 97) bacon.draw_string(planet, "Name", 20, 175) # current cargo labels bacon.draw_string(planet, "Cost", 140, 175) bacon.draw_string(planet, "Quantity", 195, 175) bacon.draw_string(planet, "(%d)" % myship.cargo_load_calculator(), 205, 150) n = 0 for item in myship.current_cargo: # draw current cargo n += 1 bacon.draw_string(planet, "%s" % item[0], 20, (180 + (line_height * n))) bacon.draw_string(planet, "%d" % item[1], 140, (180 + (line_height * n))) bacon.draw_string(planet, "%d" % item[2], 195, (180 + (line_height * n))) bacon.draw_string(planet, "Name", 350, 175) # merchant labels bacon.draw_string(planet, "Cost", 490, 175) bacon.draw_string(planet, "Quantity", 545, 175) n = 0 for item in element_pricelist: # draw merchant quantities on hand n += 1 bacon.draw_string(planet, "%s" % item[0], 350, (180 + (line_height * n))) bacon.draw_string(planet, "%d" % item[1], 490, (180 + (line_height * n))) bacon.draw_string(planet, "%d" % item[2], 545, (180 + (line_height * n))) bacon.push_color() # draw rectange for i, item in enumerate(myship.current_cargo, 1): # draw sell buttons for cargo bacon.draw_rect( 220, (160 + (line_height * i)), 265, (160 + line_height + line_height * i)) # draw rectange if x in range(220, 265) and y in range((160 + (line_height * i)), (160 + line_height + line_height * i)): bacon.push_color # fill rectangle on hover bacon.set_color(.20, .58, .03, 1) # green bacon.fill_rect( 221, (161 + (line_height * i)), 264, (159 + line_height + line_height * i)) bacon.pop_color() bacon.draw_string(planet, "sell", 226, (180 + (line_height * i)))# sell text for rectangle for i, item in enumerate(element_pricelist, 1): # draw buy buttons for merchant bacon.draw_rect( 300, (160 + (line_height * i)), 345, (160 + line_height + line_height * i)) # draw rectange if x in range(300, 345) and y in range((160 + (line_height * i)), (160 + line_height + line_height * i)): bacon.push_color # fill rectangle on hover bacon.set_color(.20, .58, .03, 1) # red bacon.fill_rect( 301, (161 + (line_height * i)), 344, (159 + line_height + line_height * i)) bacon.pop_color() bacon.draw_string(planet, "buy", 308, (180 + (line_height * i)))# buy text for rectangle bacon.pop_color()
def fill(self): bacon.fill_rect(self.x1, self.y1, self.x2, self.y2)
def merchant_view(): x, y = bacon.mouse.x, bacon.mouse.y bacon.push_color() bacon.set_color(1, 1, 1, 0) # white bacon.draw_image(triangle, 367, 450) #point triangle at icon bacon.fill_rect(0, 40, 640, 450) # create white background box bacon.pop_color() bacon.push_color() bacon.draw_image(robot, 20, 65) # draw cargo robot n = planet_locator.index((myplayer.location_x, myplayer.location_y)) bacon.draw_image(planet_master[n].merchant_photo, 350, 65) #draw planet merchant bacon.pop_color() bacon.push_color() bacon.set_color(0, 0, 0, 1) #black bacon.draw_string(robot_speak, "Here is the ", (20 + robot.width + 5), 82) # cargo robot speech bacon.draw_string(robot_speak, "cargo manifest ", (20 + robot.width + 5), 97) bacon.draw_string(robot_speak, "you requested,", (20 + robot.width + 5), 112) bacon.draw_string(robot_speak, "Captian.", (20 + robot.width + 5), 127) bacon.draw_string(robot_speak, "Buy something,", (350 + merch1.width + 5), 82) # planet merchent speach bacon.draw_string(robot_speak, "will ya!?", (350 + merch1.width + 5), 97) bacon.draw_string(planet, "Name", 20, 175) # current cargo labels bacon.draw_string(planet, "Cost", 140, 175) bacon.draw_string(planet, "Quantity", 195, 175) bacon.draw_string(planet, "(%d)" % myship.cargo_load_calculator(), 205, 150) n = 0 for item in myship.current_cargo: # draw current cargo n += 1 bacon.draw_string(planet, "%s" % item[0], 20, (180 + (line_height * n))) bacon.draw_string(planet, "%d" % item[1], 140, (180 + (line_height * n))) bacon.draw_string(planet, "%d" % item[2], 195, (180 + (line_height * n))) bacon.draw_string(planet, "Name", 350, 175) # merchant labels bacon.draw_string(planet, "Cost", 490, 175) bacon.draw_string(planet, "Quantity", 545, 175) n = 0 for item in element_pricelist: # draw merchant quantities on hand n += 1 bacon.draw_string(planet, "%s" % item[0], 350, (180 + (line_height * n))) bacon.draw_string(planet, "%d" % item[1], 490, (180 + (line_height * n))) bacon.draw_string(planet, "%d" % item[2], 545, (180 + (line_height * n))) bacon.push_color() # draw rectange for i, item in enumerate(myship.current_cargo, 1): # draw sell buttons for cargo bacon.draw_rect(220, (160 + (line_height * i)), 265, (160 + line_height + line_height * i)) # draw rectange if x in range(220, 265) and y in range( (160 + (line_height * i)), (160 + line_height + line_height * i)): bacon.push_color # fill rectangle on hover bacon.set_color(.20, .58, .03, 1) # green bacon.fill_rect(221, (161 + (line_height * i)), 264, (159 + line_height + line_height * i)) bacon.pop_color() bacon.draw_string(planet, "sell", 226, (180 + (line_height * i))) # sell text for rectangle for i, item in enumerate(element_pricelist, 1): # draw buy buttons for merchant bacon.draw_rect(300, (160 + (line_height * i)), 345, (160 + line_height + line_height * i)) # draw rectange if x in range(300, 345) and y in range( (160 + (line_height * i)), (160 + line_height + line_height * i)): bacon.push_color # fill rectangle on hover bacon.set_color(.20, .58, .03, 1) # red bacon.fill_rect(301, (161 + (line_height * i)), 344, (159 + line_height + line_height * i)) bacon.pop_color() bacon.draw_string(planet, "buy", 308, (180 + (line_height * i))) # buy text for rectangle bacon.pop_color()
def draw_object(self): bacon.fill_rect(-self.width/2, -self.height/2, self.width/2, self.height/2)
def on_tick(self): bacon.clear(0, 0, 0, 1) bacon.set_color(1, 0, 0, 1) bacon.fill_rect(50, 50, 150, 150) bacon.set_color(0, 1, 0, 1) bacon.draw_rect(50, 50, 150, 150)
def on_tick(self): #global banking_window x, y = bacon.mouse.x, bacon.mouse.y main_view() # build the main page elements core_action() # build the hover colors for screen icons # if window is active, run function to display it if window.bank: banking() if window.cargo: cargo_view() if window.merchant: merchant_view() if window.destination: depart_view() if window.refuel: refuel() if window.bank == True or window.cargo == True or window.merchant ==True: pass else: for item in planet_list: # on mouse hover over planet usage if x in range(item[1], item[1] + 12) and y in range(item[2], item[2] + 12): distance_and_fuel(myplayer.location_x, myplayer.location_y, item[1], item[2]) bacon.push_color() # place pin bacon.set_color(.74, .07, .07, 1) # red bacon.draw_image(target, item[1] - 7, item[2] - 20) bacon.pop_color() bacon.push_color() # set fuel usage in red on gauge gauge_level = (179 * (myplayer.fuel_used/100.0)) if gauge_level == 0: gauge_level = 14 bacon.set_color(.74, .07, .07, 1) # red bacon.fill_rect(14, 496, (gauge_level), 530) bacon.pop_color() bacon.push_color() bacon.set_color(0, 0, 0, 1) gauge_level = (179 * (myplayer.fuel_used/100.0)) if gauge_level == 0: gauge_level = 14 if myplayer.fuel_used > myship.fuel: bacon.draw_string(planet, "need more fuel", 16, 522) else: bacon.draw_string(planet, "fuel used: %r " % myplayer.fuel_used, 16, 522) bacon.pop_color() if bacon.Keys.space in bacon.keys or bacon.mouse.left: if window.merchant: for i, item in enumerate(myship.current_cargo, 1): # process selling element if x in range(220, 265) and y in range( (160 + (line_height * i)), (160 + line_height + line_height * i)): if item[2] == 0: self.current_cargo.remove(item) pass elif myship.remove_cargo(item[0]): myplayer.money_in_pocket += transfer_element_to_market(item[0]) for i, item in enumerate(element_pricelist, 1): # process buying element if x in range(300, 345) and y in range( (160 + (line_height * i)), (160 + line_height + line_height * i)): if item[2] == 0: pass elif myship.add_cargo(item[0], item[1]): myplayer.remove_money_from_pocket(item[1]) item[2] -= 1 if myplayer.money_in_pocket < 0: myplayer.money_in_bank += myplayer.money_in_pocket myplayer.money_in_pocket = 0 if window.bank: if x in range(515, 617) and y in range(412, 442) and myplayer.money_in_bank > 1000: myplayer.money_in_bank -= 1000 myplayer.money_in_pocket += 1000 elif x in range(515, 617) and y in range(378, 406) and myplayer.money_in_pocket > 1000: myplayer.money_in_bank += 1000 myplayer.money_in_pocket -= 1000
def on_tick(self): x, y = bacon.mouse.x, bacon.mouse.y oberon = [5000, 75, 40, 5] # set ship attributes intrepid = [6000, 225, 80, 2] excelsior = [4000, 100, 60, 2] firefly = [7000, 125, 80, 3] bacon.draw_image(title, 0, 0) bacon.draw_string(planet, "Select your starship", 240, 450) if x in range( (bacon.window.width * 0 / 4 + 20), (bacon.window.width * 0 / 4 + 20 + ship1.width)) and y in range( 300, (300 + ship1.height)): bacon.draw_image(triangle, (bacon.window.width * 0 / 4 + 42), 265) bacon.fill_rect(0, 125, 200, 265) bacon.push_color() bacon.set_color(0, 0, 0, 1) #black bacon.draw_string(planet, "Class: Oberon", 10, 153) bacon.draw_string(planet, "Price: %d credits" % oberon[0], 10, 153 + line_height * 4) bacon.draw_string(planet, "Cargo Space: %d" % oberon[1], 10, 153 + line_height) bacon.draw_string(planet, "Weight: %d tons" % oberon[2], 10, 153 + line_height * 2) bacon.draw_string(planet, "Max Velocity: %d" % oberon[3], 10, 153 + line_height * 3) bacon.pop_color() if bacon.mouse.left: myplayer.ship = "Oberon" myplayer.money_in_pocket -= oberon[0] myship.cost_to_buy = oberon[0] myship.hauling_capacity = oberon[1] myship.weight = oberon[2] myship.velocity = oberon[3] bacon.run(Game()) bacon.draw_image(ship1, (bacon.window.width * 0 / 4 + 40), 300) if x in range( (bacon.window.width * 1 / 4 + 20), (bacon.window.width * 1 / 4 + 20 + ship1.width)) and y in range( 300, (300 + ship1.height)): bacon.draw_image(triangle, (bacon.window.width * 1 / 4 + 45), 265) bacon.fill_rect(135, 125, 335, 265) bacon.push_color() bacon.set_color(0, 0, 0, 1) #black bacon.draw_string(planet, "Class: Intrepid", 145, 153) bacon.draw_string(planet, "Price: %d credits" % intrepid[0], 145, 153 + line_height * 4) bacon.draw_string(planet, "Cargo Space: %d" % intrepid[1], 145, 153 + line_height) bacon.draw_string(planet, "Weight: %d tons" % intrepid[2], 145, 153 + line_height * 2) bacon.draw_string(planet, "Max Velocity: %d" % intrepid[3], 145, 153 + line_height * 3) bacon.pop_color() if bacon.mouse.left: myplayer.ship = "Intrepid" myplayer.money_in_pocket -= intrepid[0] myship.cost_to_buy = intrepid[0] myship.hauling_capacity = intrepid[1] myship.weight = intrepid[2] myship.velocity = intrepid[3] bacon.run(Game()) bacon.draw_image(ship2, (bacon.window.width * 1 / 4 + 40), 300) if x in range( (bacon.window.width * 2 / 4 + 20), (bacon.window.width * 2 / 4 + 20 + ship1.width)) and y in range( 300, (300 + ship1.height)): bacon.draw_image(triangle, (bacon.window.width * 2 / 4 + 29), 265) bacon.fill_rect(290, 125, 490, 265) bacon.push_color() bacon.set_color(0, 0, 0, 1) #black bacon.draw_string(planet, "Class: Excelsior", 300, 153) bacon.draw_string(planet, "Price: %d credits" % excelsior[0], 300, 153 + line_height * 4) bacon.draw_string(planet, "Cargo Space: %d" % excelsior[1], 300, 153 + line_height) bacon.draw_string(planet, "Weight: %d tons" % excelsior[2], 300, 153 + line_height * 2) bacon.draw_string(planet, "Max Velocity: %d" % excelsior[3], 300, 153 + line_height * 3) bacon.pop_color() if bacon.mouse.left: myplayer.ship = "Excelsior" myplayer.money_in_pocket -= excelsior[0] myship.cost_to_buy = excelsior[0] myship.hauling_capacity = excelsior[1] myship.weight = excelsior[2] myship.velocity = excelsior[3] bacon.run(Game()) bacon.draw_image(ship3, (bacon.window.width * 2 / 4 + 30), 300) if x in range( (bacon.window.width * 3 / 4 + 20), (bacon.window.width * 3 / 4 + 20 + ship1.width)) and y in range( 300, (300 + ship1.height)): bacon.draw_image(triangle, (bacon.window.width * 3 / 4 + 22), 265) bacon.fill_rect(440, 125, 640, 265) bacon.push_color() bacon.set_color(0, 0, 0, 1) #black bacon.draw_string(planet, "Class: Firefly", 450, 153) bacon.draw_string(planet, "Price: %d credits" % firefly[0], 450, 153 + line_height * 4) bacon.draw_string(planet, "Cargo Space: %d" % firefly[1], 450, 153 + line_height) bacon.draw_string(planet, "Weight: %d tons" % firefly[2], 450, 153 + line_height * 2) bacon.draw_string(planet, "Max Velocity: %d" % firefly[3], 450, 153 + line_height * 3) bacon.pop_color() if bacon.mouse.left: myplayer.ship = "Firefly" myplayer.money_in_pocket -= firefly[0] myship.cost_to_buy = firefly[0] myship.hauling_capacity = firefly[1] myship.weight = firefly[2] myship.velocity = firefly[3] bacon.run(Game()) bacon.draw_image(ship4, (bacon.window.width * 3 / 4 + 20), 300)
def on_mouse_button(self, button, pressed): x, y = bacon.mouse.x, bacon.mouse.y if window.bank: #money goest into/out of bank in 1000 increments for speed/simplicity if x in range(515, 617) and y in range(412, 442) and myplayer.money_in_bank > 1000: myplayer.money_in_bank -= 1000 myplayer.money_in_pocket += 1000 elif x in range(515, 617) and y in range(378, 406) and myplayer.money_in_pocket > 1000: myplayer.money_in_bank += 1000 myplayer.money_in_pocket -= 1000 if window.destination: for item in planet_list: # on mouse hover over planet if x in range(item[1], item[1] + 12) and y in range(item[2], item[2] + 12): distance_and_fuel(myplayer.location_x, myplayer.location_y, item[1], item[2]) bacon.push_color() # place pin bacon.set_color(.74, .07, .07, 1) # red bacon.draw_image(target, item[1] - 7, item[2] - 20) bacon.pop_color() bacon.push_color() # set fuel usage in red on gauge gauge_level = (179 * (myplayer.fuel_used/100.0)) if gauge_level == 0: gauge_level = 14 bacon.set_color(.74, .07, .07, 1) # red bacon.fill_rect(14, 496, (gauge_level), 530) bacon.pop_color() bacon.push_color() bacon.set_color(0, 0, 0, 1) if myplayer.fuel_used > myship.fuel: bacon.draw_string(planet, "need more fuel", 16, 522) else: bacon.draw_string(planet, "fuel used: %r " % myplayer.fuel_used, 16, 522) bacon.pop_color() myplayer.destination = copy.copy(item[0]) myplayer.destination_x = copy.copy(item[1]) myplayer.destination_y = copy.copy(item[2]) bacon.draw_image(depart, 561, 485) if myplayer.destination: # set up next turn properties if myplayer.destination_x == myplayer.location_x and myplayer.destination_y == myplayer.location_y: return False elif x in range( depart_range['x1'], depart_range['x2']) and y in range( depart_range['y1'], depart_range['y2']): myplayer.location_x = copy.copy(myplayer.destination_x) # move player to destination myplayer.location_y = copy.copy(myplayer.destination_y) myplayer.turn += 1 # advance turn myship.fuel -= myplayer.fuel_used # remove fuel from flight myplayer.destination_x = None # return destination variables to none myplayer.destination_y = None myplayer.destination = None if myplayer.money_in_bank < 0: myplayer.money_in_bank += (myplayer.money_in_bank * .15) # calc bank loan interest else: myplayer.money_in_bank += (myplayer.money_in_bank * .05) # calc bank interest price_refresh()# recalculate price index and quantities if myplayer.turn > 10: bacon.run(Game_Over()) if window.refuel: if x in range(230, 260) and y in range(408, 444): # no refill window.refuel = False if x in range(102, 140) and y in range(408, 444): # yes refill refill_tank() window.refuel = False
def on_mouse_button(self, button, pressed): x, y = bacon.mouse.x, bacon.mouse.y if window.bank: #money goest into/out of bank in 1000 increments for speed/simplicity if x in range(515, 617) and y in range( 412, 442) and myplayer.money_in_bank > 1000: myplayer.money_in_bank -= 1000 myplayer.money_in_pocket += 1000 elif x in range(515, 617) and y in range( 378, 406) and myplayer.money_in_pocket > 1000: myplayer.money_in_bank += 1000 myplayer.money_in_pocket -= 1000 if window.destination: for item in planet_list: # on mouse hover over planet if x in range(item[1], item[1] + 12) and y in range( item[2], item[2] + 12): distance_and_fuel(myplayer.location_x, myplayer.location_y, item[1], item[2]) bacon.push_color() # place pin bacon.set_color(.74, .07, .07, 1) # red bacon.draw_image(target, item[1] - 7, item[2] - 20) bacon.pop_color() bacon.push_color() # set fuel usage in red on gauge gauge_level = (179 * (myplayer.fuel_used / 100.0)) if gauge_level == 0: gauge_level = 14 bacon.set_color(.74, .07, .07, 1) # red bacon.fill_rect(14, 496, (gauge_level), 530) bacon.pop_color() bacon.push_color() bacon.set_color(0, 0, 0, 1) if myplayer.fuel_used > myship.fuel: bacon.draw_string(planet, "need more fuel", 16, 522) else: bacon.draw_string( planet, "fuel used: %r " % myplayer.fuel_used, 16, 522) bacon.pop_color() myplayer.destination = copy.copy(item[0]) myplayer.destination_x = copy.copy(item[1]) myplayer.destination_y = copy.copy(item[2]) bacon.draw_image(depart, 561, 485) if myplayer.destination: # set up next turn properties if myplayer.destination_x == myplayer.location_x and myplayer.destination_y == myplayer.location_y: return False elif x in range(depart_range['x1'], depart_range['x2']) and y in range( depart_range['y1'], depart_range['y2']): myplayer.location_x = copy.copy( myplayer.destination_x) # move player to destination myplayer.location_y = copy.copy(myplayer.destination_y) myplayer.turn += 1 # advance turn myship.fuel -= myplayer.fuel_used # remove fuel from flight myplayer.destination_x = None # return destination variables to none myplayer.destination_y = None myplayer.destination = None if myplayer.money_in_bank < 0: myplayer.money_in_bank += (myplayer.money_in_bank * .15 ) # calc bank loan interest else: myplayer.money_in_bank += (myplayer.money_in_bank * .05 ) # calc bank interest price_refresh() # recalculate price index and quantities if myplayer.turn > 10: bacon.run(Game_Over()) if window.refuel: if x in range(230, 260) and y in range(408, 444): # no refill window.refuel = False if x in range(102, 140) and y in range(408, 444): # yes refill refill_tank() window.refuel = False