Python Pacman program


#1

I am having a program problem. If it were a normal problem I would just paste in the syntax, and figure out myself, but there is no syntax. Syntax wise, there is nothing wrong. But I am trying to put in walls on my background, but they do not appear.

This is what the wall is supposed to look like, but as I said, it does not show up.

from tkinter import *
import random
import time



class Game:
    def __init__(self):
        self.tk = Tk()
        self.tk.title("Pacman")
        self.tk.resizable(0, 0)
        self.tk.wm_attributes("-topmost", 1)
        self.canvas = Canvas(self.tk, width = 500, height = 500, highlightthickness = 0)
        self.canvas.pack()
        self.tk.update()
        self.canvas_height = 500
        self.canvas_width = 500
        self.bg = PhotoImage(file='C:\Back_Ground.gif')
        w = self.bg.width()
        h = self.bg.width()
        for x in range(0, 5):
            for y in range(0, 5):
                self.canvas.create_image(x * w, y * h, image = self.bg, anchor = 'nw')
        self.sprites = []
        self.running = True

    def mainloop(self):
        while 1:
            if self.running == True:
                for sprite in self.sprites:
                    sprite.move()
            self.tk.update_idletasks()
            self.tk.update()
            time.sleep(0.01)



class Coords:
    def __init__(self, x1=0, y1=0, x2=0, y2=0):
        self.x1 = x1
        self.y1 = y1
        self.x2 = x2
        self.y2 = y2


def within_x(co1, co2):
    if co1.x1 > co2.x1 and co1.x1 < co2.x2:
        return True
    elif co1.x2 > co2.x1 and co1.x2 < co2.x2:
        return True
    elif co2.x1 > co1.x1 and co2.x1 < co1.x2:
        return True
    elif co2.x2 > co1.x1 and co2.x2 < co1.x2:
        return True
    else:
        return False

def within_y(co1, co2):
    if (co1.y1 > co2.y1 and co1.y1 < co2.y2) \
           or (co1.y2 > co2.y1 and co1.y2 < co2.y2) \
           or (co2.y1 > co1.y1 and co2.y1 < co1.y2) \
           or (co2.y2 > co1.y1 and co2.y2 < co1.y2):
        return True
    else:
        return False

def collided_left(co1, co2):
    if within_y(co1, co2):
        if co1.x1 <= co2.x2 and co1.x1 >= co2.x1:
            return True
    return False

def collided_right(co1, co2):
    if within_y(co1, co2):
        if co1.x2 >= co2.x1 and co1.x2 <= co2.x2:
            return True
    return False


def collided_bottom(y, co1, co2):
    if within_x(co1, co2):
        y_calc = co1.y2 + y
        if y_calc >= co2.y1 and y_calc <= co2.y2:
            return True
    return False

class Sprite:
    def __init__(self, game):
        self.game = game
        self.endgame = False
        self.coordinates = None
    def move(self):
        pass
    def coords(self):
        return self.coordinates

class PlatformSprite(Sprite):
    def __init__(self, game, photo_image, x, y, width, height):
        Sprite.__init__(self, game)
        self.photo_image = photo_image
        self.image = game.canvas.create_image(x, y, image = self.photo_image, anchor = 'nw')
        self.coordinates = Coords(x, y, x + width, y + height)



g = Game()
wall1 = PlatformSprite(g, PhotoImage(file="C:\\Users\coolDawg1234\Documents\Python35-32\Wall_Short.gif"), 0, 480, 100, 10)
g.sprites.append(wall1)
g.mainloop()

Please show me, or tell me what the problem is.
Tanks in advance!


#2

do you have the gif and background image for me? So i can actually run the program?


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.