Skip to content

Commit 615f075

Browse files
committed
New game mechanics
1 parent 4dbcff5 commit 615f075

166 files changed

Lines changed: 707 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
794 KB
Binary file not shown.
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Bomb Jack
2+
import pgzrun
3+
WIDTH = 600
4+
HEIGHT = 650
5+
jack = Actor('jackf',(300,300))
6+
ground = Actor('ground',(300,640))
7+
roof = Actor('roof',(300,61))
8+
platform1 = Actor('platform1',(400,180))
9+
platform2 = Actor('platform2',(420,580))
10+
platform3 = Actor('platform3',(320,440))
11+
platform4 = Actor('platform4',(180,250))
12+
platform5 = Actor('platform5',(120,510))
13+
platformList = [roof,ground,platform1,platform2,platform3,platform4,platform5]
14+
jack.thrust = gameState = count = frame = score = 0
15+
jack.dir = "l"
16+
bombs = []
17+
bombXY = [(110,95),(170,95),(230,95),(430,95),(490,95),(550,95),(40,290),(40,350),(40,410),(40,470),(560,290),(560,350),(560,410),(560,470),(110,605),(170,605),(230,605),(360,545),(420,545),(480,545)]
18+
for b in bombXY:
19+
bombs.append(Actor('bomb1', center=(b[0], b[1])))
20+
bombs[len(bombs)-1].state = 1
21+
22+
def draw():
23+
screen.blit("background",(0,0))
24+
for p in platformList: p.draw()
25+
for b in bombs :
26+
if b.state > 0 :
27+
b.image = "bomb"+str(int(b.state))
28+
b.draw()
29+
jack.draw()
30+
screen.draw.text("SCORE:"+str(score), center= (300, 28), owidth=0.5, ocolor=(255,255,255), color=(255,0,0) , fontsize=40)
31+
if gameState == 1: screen.draw.text("LEVEL CLEARED", center = (300, 300), owidth=0.5, ocolor=(255,255,255), color=(0,255,255) , fontsize=50)
32+
33+
def update():
34+
global count, frame
35+
if gameState == 0:
36+
jack.dir = "f"
37+
ytest = jack.y
38+
if keyboard.up:
39+
jack.dir = "u"
40+
if checkCollisions(platformList,(jack.x,jack.y+(jack.height/2))) == False : jack.y += 4
41+
if checkCollisions(platformList,(jack.x,jack.y-32)) == False : jack.y -= jack.thrust
42+
jack.thrust = limit(jack.thrust-0.4,0,20)
43+
if jack.y > ytest+1: jack.dir = "d"
44+
if jack.y < ytest-1: jack.dir = "u"
45+
if keyboard.left and jack.x > 40:
46+
if jack.y != ytest:
47+
jack.dir = "lf"
48+
jack.y -= 2
49+
else:
50+
jack.dir = "l" + str(frame%2+1)
51+
jack.x -= 2
52+
if keyboard.right and jack.x < 560:
53+
if jack.y != ytest:
54+
jack.dir = "rf"
55+
jack.y -= 2
56+
else:
57+
jack.dir = "r" + str(frame%2+1)
58+
jack.x += 2
59+
jack.image = "jack" + jack.dir
60+
checkBombs()
61+
count += 1
62+
if(count%5 == 0) : frame += 1
63+
64+
def on_key_down(key):
65+
global gameState
66+
if gameState == 0:
67+
if key.name == "UP" and jack.dir == "f":
68+
jack.thrust = 20
69+
jack.dir = "u"
70+
71+
def limit(n, minn, maxn):
72+
return max(min(maxn, n), minn)
73+
74+
def checkCollisions(cList, point):
75+
for i in range(0, len(cList)):
76+
if cList[i].collidepoint(point):
77+
return True
78+
return False
79+
80+
def checkBombs():
81+
global gameState, score
82+
bombsCollected = 0
83+
for b in bombs:
84+
if b.state > 1: b.state += 0.4
85+
if b.state == 0 : bombsCollected += 1
86+
if b.collidepoint((jack.x,jack.y)) and b.state == 1:
87+
b.state = 1.4
88+
if int(b.state) > 4 :
89+
b.state = 0
90+
score += 100
91+
if bombsCollected == len(bombs): gameState = 1
92+
93+
pgzrun.go()
236 KB
2.77 KB
2.9 KB
2.84 KB
2.88 KB
2.88 KB
5.32 KB
2.98 KB

0 commit comments

Comments
 (0)