Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- The point of this incarnation of the game is that there will be 3 areas for the player to explore, all connected by a center field.
- Tasks:
- Setup D-pad so that the image rotates with each direction
- Get Monsters moving
- Make Volume Control function do Pause instead???
- #Come up with Loop or List system for Text Parsing
- #Implement Pause function
- Setup Cities 2 & 3 - Top Right & Bottom Left
- #Have Spacebar be some kind of quick move thing - moves 10 instead of 5, etc.
- This will require direction detection
- Have Function so Player doesn't go off screen
- Inventory Screen
- Villagers
- Text Bubble When Talking to Villagers
- Player Eventually Surpasses Screen over Very Long Distance
- Add Water
- Change Rects to Blitted Objects
- How would I create a Mini-Map??
- Take everything that's blitting/being drawn & draw it again at 1/8 size & position it in the lower right corner
- What's a non-guess based way to math out the map
- """
- """
- Controls List:
- quick controls list:
- k - kills game
- p - pauses game
- i - brings up inventory screen
- arrow keys - move
- m - mute/unmute music
- spacebar - quick move
- """
- import pygame, sys
- from pygame.locals import *
- class Wall(pygame.sprite.Sprite):
- def __init__(self, pos, color, xoffset, yoffset):
- pygame.sprite.Sprite.__init__(self)
- self.image = pygame.image.load('archer_2.png')
- self.rect = self.image.get_rect()
- self.pos = pos
- wallsList.add(self)
- self.xoffset = xoffset
- self.yoffset = yoffset
- self.color = color
- def draw(self):
- pygame.draw.rect(gameDisplay, self.color, (self.pos[0], self.pos[1], 50, 50))
- class Player(pygame.sprite.Sprite):
- def __init__(self, xoffset, yoffset):
- pygame.sprite.Sprite.__init__(self)
- self.image = pygame.image.load('worker_0.png')
- self.rect = self.image.get_rect()
- self.pos = [200, 425]
- playersList.add(self)
- self.xoffset = xoffset
- self.yoffset = yoffset
- def draw(self):
- playBlit = gameDisplay.blit(self.image, (self.pos[0], self.pos[1]), (0, 0, 50, 50))
- #Collision Dection Here - USE SPRITES IN THIS INCARNATION
- class Monster(pygame.sprite.Sprite):
- def __init__(self, pos, xoffset, yoffset):
- pygame.sprite.Sprite.__init__(self)
- self.image = pygame.image.load('archon0.png')
- self.rect = self.image.get_rect()
- self.pos = pos
- monstersList.add(self)
- self.xoffset = xoffset
- self.yoffset = yoffset
- # self.startPosX = pos[0]
- # self.startPosY = pos[1]
- # self.monsterMoveX = 0
- def draw(self):
- gameDisplay.blit(self.image, self.pos)
- def wander(self):
- self.monsterMoveX = 5
- #Movement Code here ... there is some better way to do this
- def drawBackground(display, bg_img, bg_rect):
- nrows = int(winWidth / 20) + 1
- ncols = int(winHeight / 20) + 1
- for row in range(nrows):
- for col in range(ncols):
- bg_rect.topleft = (row * 20, col * 20)
- gameDisplay.blit(bg_img, bg_rect, (40, 41, 20, 20))
- def volumeControl(): #Maybe I should make this pause instead??
- curVol = pygame.mixer.music.get_volume()
- if curVol > 0.0:
- pygame.mixer.music.set_volume(0.0)
- elif curVol == 0.0:
- pygame.mixer.music.set_volume(1.0)
- # def drawIt():
- # for wall in wallsList:
- # wall.pos[0] += xoffset
- # wall.pos[1] += yoffset
- # wall.draw()
- # for player in playersList:
- # player.pos[0] += xchange
- # player.pos[1] += ychange
- # player.draw()
- # for monster in monstersList:
- # monster.pos[0] += xchange
- # monster.pos[1] += ychange
- # monster.draw()
- def intro():
- messages = []
- run = True
- while run:
- for event in pygame.event.get():
- if event.type == KEYDOWN:
- if event.key == K_k:
- pygame.quit()
- sys.exit()
- if event.key == K_p:
- gameLoop()
- if event.key == K_m:
- volumeControl()
- #Efficient way to do this?
- #for loop with messages?
- messages.append(("Luna's Game", 100))
- messages.append(("Press p to Play", 350))
- for message in messages:
- font = pygame.font.Font(None, 100)
- text = font.render(message[0], 1, green)
- textpos = text.get_rect()
- textpos.centerx = gameDisplay.get_rect().centerx
- textpos.y = message[1]
- gameDisplay.blit(text, textpos)
- # text2 = font.render("Press p to play", 1, green)
- # textpos2 = text2.get_rect()
- # textpos2.centerx = gameDisplay.get_rect().centerx
- # textpos2.y = 350
- # gameDisplay.blit(text2, textpos2)
- # intro_img = pygame.image.load('archer_2.png')
- # intro_rect = intro_img.get_rect()
- # gameDisplay.blit(intro_img, intro_rect.topleft)
- pygame.display.update()
- pygame.mixer.init()
- pygame.mixer.music.load('gate.mp3')
- pygame.mixer.music.play(-1)
- playersList = pygame.sprite.Group()
- wallsList = pygame.sprite.Group()
- monstersList = pygame.sprite.Group()
- bg_img = pygame.image.load('grasclif.bmp')
- bg_rect = bg_img.get_rect()
- healthbar_img = pygame.image.load('blood_red_bar.png')
- healthbar_rect = healthbar_img.get_rect()
- black = (0, 0, 0)
- red = (255, 0, 0)
- green = (0, 255, 0)
- white = (125, 125, 125)
- grey = (25, 25, 25)
- brown = (139, 69, 19)
- dark_brown = (100, 50, 19)
- dark_green = (0, 50, 0)
- dark_red = (150, 0, 0)
- winWidth = 800
- winHeight = 600
- pygame.init()
- gameDisplay = pygame.display.set_mode((winWidth, winHeight))
- pygame.display.set_caption('Exploring Game')
- offset = 0
- xchange = 0
- ychange = 0
- playerx = winWidth / 2
- playery = winHeight - 50
- xoffset = 0
- yoffset = 0
- playChar = Player(xoffset, yoffset)
- clock = pygame.time.Clock()
- city1 = ["W" * (winWidth/50), #16 Tiles Across
- "W W",
- "W H R H W",
- "W R W",
- "W R W",
- "W R W",
- "W H R H W",
- "W H R W",
- "W R H W",
- "WRRRRRRRRRRRRRRRRRRRRRRRR",
- "W R W",
- "W R W",
- "W H R H W",
- "W R W",
- "W R W",
- "W R W",
- "W R W",
- "W R W",
- "WWWWWWWRWWWWWWWW"
- ]
- field = ["W" * (winWidth/50), #16 Tiles Across
- " R ",
- " M R ",
- " R ",
- " M R ",
- " R ",
- " R ",
- " R ",
- " R ",
- "RRRRRRRRRRRRRRRR",
- " M ",
- " M ",
- " ",
- " M ",
- " ",
- ]
- fieldUp = [" R ",
- " R ",
- " R ",
- " RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
- " R ",
- " R ",
- " R ",
- " R ",
- " R ",
- " R ",
- " R ",
- " R ",
- " R ",
- " R ",
- " R ",
- ]
- city2 = ["W W", #This still needs to go up and to the right
- "W H R H W",
- "W R W",
- "RRRRRRRRRRRRRRRW",
- "W R W",
- "W H R H W",
- "W H R W",
- "W R H W",
- "WRRRRRRRRRRRRRRRRRRRRRRRR",
- "W R W",
- "W R W",
- "W H R H W",
- "W R W",
- "W R W",
- "W R W",
- "W R W",
- "W R W",
- "W R W",
- "W R W",
- "W R W",
- "W R W",
- "W R W",
- "WWWWWWWRWWWWWWWW",
- " R ",
- " R ",
- " R ",
- " R ",
- " R ",
- " R ",
- " R ",
- " R ",
- " R ",
- " R ",
- " R ",
- ]
- #This can probably be more efficiently done using a separate file, a function, or some serious nested loops/enumerate
- x = y = 0
- for row in city1:
- for col in row:
- pos = [x, y]
- if col == "W":
- Wall(pos, grey, xoffset, yoffset)
- # if col == "P":
- # Player(pos, xoffset, yoffset)
- if col == "M":
- Monster(pos, xoffset, yoffset)
- if col == "R": #Road
- Wall(pos, brown, xoffset, yoffset)
- if col == "H": #House
- Wall(pos, dark_red, xoffset, yoffset)
- x+= 50
- y+= 50
- x = 0
- a = b = 0 #It would probably be ok to reuse x & y, but I'd rather not
- fieldPos = 1200
- for row in field:
- for col in row:
- pos = [a + fieldPos, b]
- if col == "M":
- Monster(pos, xoffset, yoffset)
- if col == "R": #Road
- Wall(pos, brown, xoffset, yoffset)
- a+=50
- b+=50
- a=0
- i = j = 0 #This is not displaying properly ... no idea why
- city2PosX = 1400
- city2PosY = -1500
- for row in city2:
- for col in row:
- pos = [i + city2PosX, j + city2PosY]
- if col == "W":
- Wall(pos, grey, xoffset, yoffset)
- if col == "R":
- Wall(pos, brown, xoffset, yoffset)
- if col =="H":
- Wall(pos, red, xoffset, yoffset)
- i+=50
- j+=50
- i=0
- # def keyHandle(): # I think this is slower though??
- # for event in pygame.event.get():
- # if event.type == KEYDOWN:
- # if event.key == K_k:
- # pygame.quit()
- # sys.exit()
- # if event.key == K_m:
- # volumeControl()
- def pause():
- gamePause = True
- while gamePause:
- for event in pygame.event.get():
- if event.type == KEYDOWN:
- if event.key == K_k:
- pygame.quit()
- sys.exit()
- if event.key == K_p:
- gamePause = False
- gameDisplay.fill(black)
- font = pygame.font.Font(None, 100)
- text = font.render("The Game Is Paused", 1, green)
- textpos = text.get_rect()
- textpos.centerx = gameDisplay.get_rect().centerx
- textpos.centery = gameDisplay.get_rect().centery
- gameDisplay.blit(text, textpos)
- pygame.display.update()
- def inventory():
- messages = []
- inventory_active = True
- while inventory_active:
- for event in pygame.event.get():
- if event.type == KEYDOWN:
- if event.key == K_k:
- pygame.quit()
- sys.exit()
- if event.key == K_i:
- inventory_active = False
- gameDisplay.fill(black)
- pygame.draw.rect(gameDisplay, dark_brown, (75, 50, 650, 500)) #Do this in non-naive way
- pygame.draw.rect(gameDisplay, dark_green, (125, 100, 550, 400))
- messages.append(("Inventory", winWidth / 2.75, 100))
- messages.append(("Sword", 150, 200))
- messages.append(("Shield", 150, 300))
- for message in messages:
- font = pygame.font.Font(None, 60)
- text = font.render(message[0], 1, white)
- textpos = text.get_rect()
- #textpos.centerx = gameDisplay.get_rect().centerx
- textpos.x = message[1]
- textpos.y = message[2]
- gameDisplay.blit(text, textpos)
- pygame.display.update()
- def gameLoop():
- global xoffset, yoffset, xchange, ychange
- run = True
- while run:
- gameDisplay.fill(black)
- drawBackground(gameDisplay, bg_img, bg_rect)
- # keyHandle()
- for event in pygame.event.get():
- if event.type == KEYDOWN:
- if event.key == K_k:
- pygame.quit()
- sys.exit()
- if event.key == K_m:
- volumeControl()
- if event.key == K_LEFT: #Setup so that each of these rotates the image
- xoffset = 5
- xchange = -2
- if event.key == K_RIGHT:
- xoffset = -5
- xchange = 2
- if event.key == K_UP:
- yoffset = 5
- ychange = -2
- if event.key == K_DOWN:
- yoffset = -5
- ychange = 2
- if event.key == K_SPACE:
- if xchange == 0:
- xchange += 0
- if xchange > 0:
- xchange += 10
- xoffset -= 8
- if xchange < 0:
- xchange -= 10
- xoffset += 4
- if ychange == 0:
- ychange += 0
- if ychange < 0:
- ychange -= 10
- yoffset += 4
- if ychange > 0:
- ychange += 10
- yoffset -= 4
- if event.key == K_p:
- pause()
- if event.key == K_i:
- inventory()
- if event.type == KEYUP:
- if event.key == K_LEFT:
- xoffset = 0
- xchange = 0
- elif event.key == K_RIGHT:
- xoffset = 0
- xchange = 0
- elif event.key == K_UP:
- yoffset = 0
- ychange = 0
- elif event.key == K_DOWN:
- yoffset = 0
- ychange = 0
- if event.key == K_SPACE:
- if xchange == 0: #technically unnecessary
- xchange = 0
- if xchange > 0:
- xchange -= 10
- xoffset += 8
- if xchange < 0:
- xchange += 10
- xoffset -= 4
- if ychange == 0:
- ychange += 0
- if ychange < 0:
- ychange += 10
- yoffset -= 4
- if ychange > 0:
- ychange -= 10
- yoffset += 4
- # playersList.update()
- # wallsList.update()
- # monstersList.update()
- #Why don't these work?!?!
- # playersList.draw(gameDisplay)
- # wallsList.draw(gameDisplay)
- # monstersList.draw(gameDisplay)
- for wall in wallsList:
- wall.pos[0] += xoffset
- wall.pos[1] += yoffset
- wall.draw()
- for player in playersList:
- player.pos[0] += xchange
- player.pos[1] += ychange
- player.draw()
- for monster in monstersList:
- monster.pos[0] += xoffset
- monster.pos[1] += yoffset
- monster.draw()
- gameDisplay.blit(healthbar_img, (30, 20))
- # playerx += xchange
- # playery += ychange
- clock.tick(30)
- pygame.display.update()
- if __name__ == "__main__":
- intro()
- # gameLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement