예제 #1
0
 def regStage(self, window):
     background = Image(Point(600, 400), "ImagesAndSprites/StartScreen.gif")
     background.draw(window)
     self.platform1 = Image(Point(600, 675), "ImagesAndSprites/blue.gif")
     self.platform1.draw(window)
     self.pos1 = Point(400, 700)
     self.pos2 = Point(800, 700)
예제 #2
0
def town():

	prior = len(glbl.gw.items)


	gold_box = Gold_Box(glbl.player.gold)

	background = Image(Point(750, 250), glbl.MAPS / "sprites" / "village.png")
	background.draw(glbl.gw)

	#musicplays here
	#pygame.mixer.music.stop()
	
	if glbl.game_stats["town_tutorial"]:
		glbl.game_stats["town_tutorial"] = False
		town_tutorial()

	while True:
		pygame.mixer.music.stop()
		town_music = pygame.mixer.music.load("Town_Music.mp3")
		pygame.mixer.music.play(-1)
		if glbl.game_stats['orc_dead'] == "Dead":
			for i in glbl.gw.items[prior:]: i.undraw()
			return

		x = dialogue("Where would you like to go?", [
			"Inn", 
			"Wizard" if glbl.player.character_class == "Sorcerer" else "Blacksmith",
			"Shop",
			"Librarian",
			"Explore Forest"], right=True)

		if x == 0:
			pygame.mixer.music.stop()
			town_music = pygame.mixer.music.load("inn.mp3")
			pygame.mixer.music.play(-1)
			inn(gold_box)

		if x == 1:
			pygame.mixer.music.stop()
			shop_music = pygame.mixer.music.load("shop.mp3")
			pygame.mixer.music.play(-1)
			weapon_maker(gold_box)

		if x == 2:
			shop(gold_box)

		if x == 3:
			pygame.mixer.music.stop()
			librarian(gold_box)
		
		if x == 4:
			pygame.mixer.music.stop()
			town_music = pygame.mixer.music.load("Overworld_Music.mp3")
			pygame.mixer.music.play(-1)
			prep_exploration()
			if glbl.game_stats['reginald'] == 6:
				glbl.game_stats['reginald'] = 7
			if glbl.game_stats['reginald'] == 7:
				raise glbl.GameOver('Rat Invasion')
예제 #3
0
def main():
    fileInput = "C:\Programming\CS138\Week 8\canoe.gif"
    fileOutput = "C:\Programming\CS138\Week 8\grayCanoe.gif"

    image = Image(Point(400, 300), fileInput)  # Getting our image.
    width = image.getWidth()
    height = image.getHeight()
    win = GraphWin("Monochromatic Conversion", width,
                   height)  # Creating our window.
    image.draw(win)

    row = 0  # The starting pixel for our x-axis
    column = 0  # The starting pixel for our y-axis

    win.getMouse()

    for row in range(image.getWidth()):
        for column in range(image.getHeight()):
            r, g, b = image.getPixel(row, column)
            brightness = int(round(0.299 * r + 0.587 * g + 0.114 * b))
            image.setPixel(row, column,
                           color_rgb(brightness, brightness, brightness))
            win.update()

    image.save(fileOutput)
    win.getMouse()
    win.close()
 def draw(self, win, center):
     if not self.image:
         rank = str(self.specials.get(self.rank, self.rank))[0].upper()
         if self.rank == 10:
             rank = str(10)
         suite = self.suit.upper()
         self.image = Image(center, f"cards_pics/{rank + suite}.png")
     self.image.draw(win)
예제 #5
0
 def __init__(self, window):
     self.image = Image(Point(600, 400), "ImagesAndSprites/MenuScreen.gif")
     self.text = Text(Point(600, 600), "Press Any Key To Start")
     self.text.setFace("arial")
     self.text.setSize(36)
     self.text.setStyle("normal")
     self.text.setTextColor(color_rgb(0, 0, 0))
     self.image.draw(window)
     self.text.draw(window)
     self.run(window)
예제 #6
0
    def __init__(self, window, player1, player2):
        self.window = window
        self.p1 = Player(player1, None)
        self.p2 = Player(player2, None)
        background = Image(Point(600, 400), "ImagesAndSprites/StartScreen.gif")
        background.draw(window)
        self.createHealthBars(window)
        self.startGame(window)
        self.countDown = Text(
            Point(window.getWidth() / 2,
                  window.getHeight() / 2), '')
        self.countdown(window)
        self.plyJumpRender = Image(Point(300, 50),
                                   "ImagesAndSprites/Apple.gif")
        self.plyJumpRender.draw(window)

        self.plyJumpRender2 = Image(Point(900, 50),
                                    "ImagesAndSprites/Apple.gif")
        self.plyJumpRender2.draw(window)
        # plyJumpRender2.move(150, 0)

        self.worldRenderer = Image(Point(800, 3), "ImagesAndSprites/blue.gif")
        self.worldRenderer.draw(window)
        self.worldRenderer.move(-200, 400)

        # Hitbox defines as
        # Obj, width, height, weight, pos, ignored
        self.plyJump = hitbox(self.plyJumpRender, 1)
        self.plyJump2 = hitbox(self.plyJumpRender2, 1)
        self.platform = hitbox(self.worldRenderer, 0)
        self.time1 = 0
        self.time2 = 0
        while True:
            self.update(window)
            if (self.getWinner() == 1):
                p1wins(window)
                time.sleep(2)
                break
            if (self.getWinner() == 2):
                p2wins(window)
                time.sleep(2)
                break
예제 #7
0
def move_card_down():

    border = 190

    back_of_card = Image(Point(WIN.getWidth() / 2,
                               WIN.getHeight() / 4), "images/deck.png")
    back_of_card.draw(WIN)

    # Moves card down
    while back_of_card.getAnchor().getY() < WIN.getHeight() - border:
        back_of_card.move(0, MOVEMENT_SPEED)
        update()

    return back_of_card
예제 #8
0
def show_total(amount):
    totalWin = GraphWin("Transaction", 250,250)
    totalWin.setBackground("Yellow")

    amountText = Text(Point(125,50), amount)
    amountText.setStyle("bold")
    amountText.draw(totalWin)
    amountLabel = Text(Point(50,50), "Total:")
    amountLabel.draw(totalWin)

    tenderedBox = Entry(Point(125,100), 5)
    tenderedBox.setText("0")
    tenderedBox.setFill("white")
    tenderedBox.draw(totalWin)
    label = Text(Point(50,100), "Given: ")
    label.draw(totalWin)

    button = Image(Point(125, 200), "icons/button.png")
    button.draw(totalWin)
    buttonRect = Rectangle(Point(50,184), Point(203,218))

    calcFlag = False
    while True:
        errorFlag = False
        try:
            click = totalWin.getMouse()
        except:
            totalWin.close()
            break
        if(isPtInRect(buttonRect, click)):
            if(calcFlag):
                    change.undraw()
            try:
                tendered = tenderedBox.getText()
            except:
                errorFlag = True
                tenderedBox.setText("0")
            if(float(tendered) < amount):
                errorFlag = True
                tenderedBox.setText(str(amount))
            if(not errorFlag):
                change = Text(Point(125, 150), "Change:    "
                              + str(float(tendered) - amount))
                change.setStyle("bold")
                change.draw(totalWin)
                calcFlag = True
    return
예제 #9
0
def reveal_card(card_images, back_of_card):

    # Card images is a list of the relative directorys on all 52 cards.
    rand_card_dir = random.choice(card_images)

    # Deletes the card once revealed, this simulates a real deck much better.
    card_images.remove(rand_card_dir)

    rand_card = Image(back_of_card.getAnchor(), rand_card_dir)

    # Replaces back of deck image with the random card picked
    back_of_card.undraw()
    rand_card.draw(WIN)

    # Reads the string on the card name to obtain the value
    val = get_card_val(rand_card_dir)

    return rand_card, val
예제 #10
0
def confirmation():
    window0 = GraphWin("Success!", 200,100)
    window0.setBackground("white")
    text = Text(Point(100,20), "Success!")
    text.setFace("courier")
    text.draw(window0)

    exitImage = Image(Point(100,65), "icons/exit.png")
    exitImage.draw(window0)
    exitButton = Rectangle(Point(60,48), Point(140,80))
    while True:
        try:
            click = window0.getMouse()
        except:
            window0.close()
            break
        if(isPtInRect(exitButton, click)):
            window0.close()
            break
    return
예제 #11
0
 def __init__(self, window):
     self.image = Image(Point(600, 400), "ImagesAndSprites/MenuScreen.gif")
     self.text = Text(Point(600, 600), "Player 1 Wins!")
     self.text.setSize(36)
     self.image.draw(window)
     self.text.draw(window)
예제 #12
0
from PIL import Image as PILImage
# Timer
start = time.time()

# sqrt(256^3) = 4096, so square of 4096
colours_per_row = 4096

# if we have 5 colours we need to go to x == 5 - 1
r = 0
g = 0
b = 0

x = 0
y = 0

rgb_ppm = Image(Point(colours_per_row / 2, colours_per_row / 2),
                colours_per_row, colours_per_row)

num_colours_set = 0

for r in range(0, 256):

    for g in range(0, 256):

        for b in range(0, 256):
            # First pixel is x,y = 0,0 and rgb = 0,0,0
            rgb_ppm.setPixel(x, y, color_rgb(r, g, b))
            num_colours_set += 1
            # Increment x until x = the number of colours needed
            x = x + 1
            if x == colours_per_row:
                x = 0
예제 #13
0
def draw_deck():
    # This is the back of the deck
    deck = Image(Point(WIN.getWidth() / 2,
                       WIN.getHeight() * 5 / 19), "images/deck.png")
    deck.draw(WIN)
    return deck
예제 #14
0
 def getImage(self, path):
     return Image(Point(0, 0), path)
예제 #15
0
def pause_menu(right):

	start = 500 if right else 0
	prior = len(gw.items)

	pause_overlay = Image(Point(500, 250), MAP / "pause_overlay.png")
	pause_overlay.draw(gw)


	# Everything for the Character Information
	info_box = Rectangle(Point(551 - start, 100), Point(959 - start, 400))
	info_box.setFill(color_rgb(50, 50, 50))
	info_box.setWidth(3)
	info_box.draw(gw)

	# The Character Icon
	info_icon = Image(Point(613 - start, 163), MAPS / "characters" / f"{player.character_class}_portrait.png")
	info_icon.draw(gw)

	# Shows the Header that includes the player's name and level.
	info_header = Text(Point(572 - start, 179))
	info_header.setAnchor("w")
	info_header.setSize(22)
	info_header.setText(f"      {player.name + f'LV: {player.lvl}'.rjust(16)[len(player.name):]}\n      HP:\n      EXP:\nItems:")
	info_header.draw(gw)

	# Draw the HP bar.
	hp_bar = Bar(player.current_HP, player.base_HP, "red", Point(750 - start, 149), Point(948 - start, 173))
	hp_bar.show()


	# Draws the EXP bar
	exp_bar = Bar(player.current_EXP, player.next_EXP, "green", Point(750 - start, 179), Point(948 - start, 203))
	exp_bar.show()

	# Lists off the player's current inventory.
	info_header_underline = Line(Point(573 - start, 240), Point(937 - start, 240))
	info_header_underline.setWidth(1)
	info_header_underline.setOutline("white")
	info_header_underline.draw(gw)
	info_footer = Text(Point(573 - start, 246))
	info_footer.setAnchor("nw")
	info_footer.setSize(14)
	info_footer.setText(inventory())
	info_footer.draw(gw)

	
	# Lists off the pause menu options.
	choice_box = Rectangle(Point(start + 125, 165), Point(start + 370, 335))
	choice_box.setFill(color_rgb(50, 50, 50))
	choice_box.setWidth(3)
	choice_box.draw(gw)

	choice_text = Text(Point(start + 260, 250))
	choice_text.setAnchor("c")
	choice_text.setSize(20)
	choice_text.setText("Resume\nDrink Potion\nEat Apple\nSave Game\nQuit Game")
	choice_text.draw(gw)
	

	selector = Polygon(Point(start + 137, 183), Point(start + 137, 195), Point(start + 154, 189))
	selector.setFill("red")
	selector.draw(gw)

	selection = 0
	saved = False

	while True:
		
		while True:
			key = gw.checkKey().lower()

			if key != "":
				if key in ["space", "return"]:
					break

				elif key in ["escape"]:
					while selection > 0:
						selector.move(0, -30)
						selection -= 1


				if key in ["up", "w", "left", "a"]:
					selection = (selection - 1) % 5
					if selection != 4:
						selector.move(0, -30)
					else:
						selector.move(0, 120)


				elif key in ["down", "s", "right", "d"]:
					selection = (selection + 1) % 5
					if selection != 0:
						selector.move(0, 30)
					else:
						selector.move(0, -120)

		# Resume Game
		if selection == 0:
			for i in gw.items[prior:]: i.undraw()
			return

		# Drink Potion
		if selection == 1:
			if player.items["Potions"] == 0:
				dialogue("You have no more potions to drink.", right=right)
			elif player.current_HP == player.base_HP:
				dialogue("You are already at max HP", right=right)
			else:
				player.items["Potions"] -= 1
				player.current_HP += round(randint(4, 10) * 4.2)
				if player.current_HP > player.base_HP:
					player.current_HP = player.base_HP
				hp_bar.update(player.current_HP, player.base_HP)

		# Eat Apple
		if selection == 2:
			if player.items["Apples"] == 0:
				dialogue("You have no more apples to eat.", right=right)
			elif player.current_HP == player.base_HP:
				dialogue("You are already at max HP", right=right)
			else:
				player.items["Apples"] -= 1
				player.current_HP += randint(1, 4)
				if player.current_HP > player.base_HP:
					player.current_HP = player.base_HP
				hp_bar.update(player.current_HP, player.base_HP)

		# Save Game
		if selection == 3:
			saved = True
			save_state = open("save_state.txt", "w")  
			
			stats_to_save = [player.character_class, player.name, player.lvl, player.attack, player.defense, 
				player.current_HP, player.base_HP, player.current_SP, player.base_SP, player.current_EXP, player.next_EXP,
				player.gold, player.items, game_stats
			]

			line_to_save = ''
			for i in stats_to_save:
				line_to_save = line_to_save + str(i) + "\n"

			save_state.write(b64encode(line_to_save.encode("UTF-8")).decode("UTF-8"))
			save_state.close()

			dialogue("Game saved.", right=right)

		# Quit Game
		if selection == 4:

			if not saved:
				dialogue(f"You have not saved recently.")

			if dialogue("Are you sure you want to quit?", ["Yes", "No"], right=right) == 0:
				raise GameOver('Town Quit')

		info_footer.setText(inventory())
예제 #16
0
	'inn_stays': -1,
	"librarian": 0,
	"level_tutorial": True,
	'reginald': -1,
	'rat_name': 'Fief',
	"floor_key": [False, False, False, False, False, False, False, False, 
				  False, False, False, False, False, False, False, False],
	"portals": [],
	'orc_dead': False
	}

found_items = {
	"Potions": 0, "Apples": 0, "Herbs": 0, "magic_item": 0, 
	"Fire Scroll": 0, "Thunder Scroll": 0, "Ice Scroll": 0}

load_overlay = Image(Point(500, 250), MAP / "load_overlay.png")
map_background = Image(Point(750, 250), MAP / "map_background.png")
# load_overlay = Image(Point(500, 250), MAP / "null_icon.png")

not_walkable = ['T', 'W', 'R', 'x']

teleport_chars = ["`", "~", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "-", "_", "=", "+"]

alphabet = ["A", "B", "C", "D", "E", "F", "G", "H", "I", 'J', 'K', 'L', 'M', 
			'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
			'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
			'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

punctuation = ['space', '.', ',', "'", '"', '!', '?']

gw = GraphWin("Console Quest.py", 1000, 500)
예제 #17
0
def drawBoard(board, win):
    tileWidth = WIDTH/board.boardWidth
    tileHeight = HEIGHT/board.boardWidth

    for i in range(board.boardWidth*board.boardWidth):
        # Calc rank/file using top left as 0, 0
        i_file = i % board.boardWidth
        i_rank = int(i/board.boardWidth)

        rect = Rectangle(Point(i_file*tileWidth, i_rank*tileHeight), Point((i_file+1)*tileWidth, (i_rank+1)*tileHeight))
        if i_rank%2 == 0:
            rect.setFill(color_rgb(241, 217, 181)) if i%2 == 0 else rect.setFill(color_rgb(181, 136, 99))
        else:
            rect.setFill(color_rgb(181, 136, 99)) if i%2 == 0 else rect.setFill(color_rgb(241, 217, 181))
        rect.draw(win)

        piece = board.getTile(i)
        if piece != 0:
            piece_sprite = None
            if piece == 'p':
                piece_sprite = Image(tileToCoord(board, i), 'chess/img/bp.png')
            elif piece == 'P':
                piece_sprite = Image(tileToCoord(board, i), 'chess/img/wp.png')
            elif piece == 'r':
                piece_sprite = Image(tileToCoord(board, i), 'chess/img/br.png')
            elif piece == 'R':
                piece_sprite = Image(tileToCoord(board, i), 'chess/img/wr.png')
            elif piece == 'n':
                piece_sprite = Image(tileToCoord(board, i), 'chess/img/bn.png')
            elif piece == 'N':
                piece_sprite = Image(tileToCoord(board, i), 'chess/img/wn.png')
            elif piece == 'b':
                piece_sprite = Image(tileToCoord(board, i), 'chess/img/bb.png')
            elif piece == 'B':
                piece_sprite = Image(tileToCoord(board, i), 'chess/img/wb.png')
            elif piece == 'k':
                piece_sprite = Image(tileToCoord(board, i), 'chess/img/bk.png')
            elif piece == 'K':
                piece_sprite = Image(tileToCoord(board, i), 'chess/img/wk.png')
            elif piece == 'q':
                piece_sprite = Image(tileToCoord(board, i), 'chess/img/bq.png')
            elif piece == 'Q':
                piece_sprite = Image(tileToCoord(board, i), 'chess/img/wq.png')
            else:
                message = Text(tileToCoord(board, i), piece)
                message.draw(win)
            piece_sprite.draw(win)
예제 #18
0
 def createImage(self, center):
     return Image(center, "cardset/%02d%s.gif" % (self.rank, self.suit))