-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain_Game
More file actions
76 lines (57 loc) · 1.87 KB
/
Main_Game
File metadata and controls
76 lines (57 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import pygame
import random
import sys
from PIL import Image
backGround = Image.open("gameMap.jpg")
(x,y) = backGround.size
def safeArr(im):
safeArr = list([])
for x in range(im.size[0]):
for y in range(im.size[1]):
g = im.getpixel((x,y))[1]
if g == 255:
safeArr.append((x,y))
return safeArr
newSafeArr = safeArr(backGround)
pygame.init()
screen = pygame.display.set_mode((x,y))
backgroundIm = pygame.image.load("gameMap.jpg").convert()
hero = pygame.image.load("hero.jpg").convert()
goal = pygame.image.load("goal.jpg").convert()
screen.blit(backgroundIm, [0,0])
pos1 = random.choice(newSafeArr)
screen.blit(goal, [pos1[0], pos1[1]])
#hero_rect = hero.get_rect()
vel = 5
pos = random.choice(newSafeArr)
heroX = pos[0]
heroY = pos[1]
Xchange = heroX
Ychange = heroY
#main loop
while True:
for event in pygame.event.get():
print(screen.get_at((heroX, heroY)))
if screen.get_at((heroX, heroY)) == (0, 0, 0, 255):
pygame.quit()
screen.blit(hero, [heroX, heroY])
screen.fill((0,255,0), ((Xchange, Ychange), (5, 5)))
Xchange = heroX
Ychange = heroY
pygame.display.flip()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_UP:
heroY -= vel
Ychange = heroY + 5
if event.key == pygame.K_DOWN:
heroY += vel
Ychange = heroY - 5
if event.key == pygame.K_LEFT:
heroX -= vel
Xchange = heroX + 5
if event.key == pygame.K_RIGHT:
heroX += vel
Xchange = heroX - 5
if screen.get_at((heroX, heroY)) == (0, 0, 254, 255):
print("THANK YOU FOR PLAYING")
pygame.quit()