-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
133 lines (108 loc) · 3.73 KB
/
main.py
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import random
import pygame
from pygame import mixer
pygame.init()
mixer.init()
mixer.music.load('snd/audio2.ogg')
mixer.music.set_volume(100)
# mixer.music.play()
height = 600
width = 800
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption("Amogus")
background = pygame.image.load("img/Background/starBackground.png").convert()
ship = pygame.image.load("img/enemyShip.png").convert_alpha()
shipX = 0
shipY = 0
shipSpeed = 2
player = pygame.image.load("img/player.png").convert_alpha()
playerSpeed = 10
playerPositionX = 200
playerPositionY = height - 100
playerDeltaX = 0
playerDeltaY = 0
shoot = pygame.image.load("img/laserRed.png").convert_alpha()
shooting = False
shootX = 0
shootY = 0
score = 0
scoreFont = pygame.font.SysFont("Arial", 30)
running = True
clock = pygame.time.Clock()
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_w:
playerDeltaY = -playerSpeed
if event.key == pygame.K_s:
playerDeltaY = playerSpeed
if event.key == pygame.K_a:
playerDeltaX = -playerSpeed
if event.key == pygame.K_d:
playerDeltaX = playerSpeed
if event.key == pygame.K_h and not shooting:
shooting = True
shootX = playerPositionX
shootY = playerPositionY
if event.key == pygame.K_p:
background = pygame.image.load("img/body.png").convert()
shoot = pygame.image.load("img/amogus.png").convert_alpha()
if event.key == pygame.K_o:
background = pygame.image.load("img/Background/starBackground.png").convert()
shoot = pygame.image.load("img/laserRed.png").convert_alpha()
if event.type == pygame.KEYUP:
if event.key == pygame.K_w or event.key == pygame.K_s:
playerDeltaY = 0
if event.key == pygame.K_a or event.key == pygame.K_d:
playerDeltaX = 0
playerPositionX += playerDeltaX
# playerPositionY += playerDeltaY
if playerPositionX < 0:
playerPositionX = 0
if playerPositionY < 0:
playerPositionY = 0
if playerPositionX > width - 100:
playerPositionX = width - 100
if playerPositionY > height - 75:
playerPositionY = height - 75
screen.fill((255, 255, 255))
for i in range(10):
for j in range(10):
screen.blit(background, (i * 254, j * 256))
screen.blit(player, (playerPositionX, playerPositionY))
if shooting:
shootY -= 20
screen.blit(shoot, (shootX, shootY))
if shipX + 98 > shootX and shipX < shootX + 33:
if shipY + 50 > shootY and shipY < shootY + 9:
score += 1
print("Treffer:", score)
shooting = False
shipY = 0
shipX = random.randint(0, width - 50)
if shootY <= 0:
shooting = False
shipX += shipSpeed
if shipX + 98 > playerPositionX and shipX < playerPositionX + 99:
if shipY + 50 > playerPositionY and shipY < playerPositionY + 75:
shipX -= shipSpeed
print("SUS")
if shipY > height + 50:
shipY = -50
shipX = random.randint(0, 750)
if shipX < 0:
shipSpeed = -shipSpeed
shipX = 0
shipY += 50
elif shipX > width - 60:
shipSpeed = -shipSpeed
shipX: 800
shipY += 60
screen.blit(ship, (shipX, shipY))
scoreText = scoreFont.render("Score: " + str(score), True, (0, 0, 0))
screen.blit(scoreText, (10, 10))
pygame.display.update()
clock.tick(60)
pygame.quit()