forked from MuhammadDaffaRafifWibowo/Galactic-endless
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
88 lines (74 loc) · 3.21 KB
/
Copy pathmain.py
File metadata and controls
88 lines (74 loc) · 3.21 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
77
78
79
80
81
82
83
84
85
86
87
88
import pygame
import math
import random
pygame.init()
screen_width = 1200
screen_height = 800
background = pygame.image.load('mappp/7.png')
alien_img = pygame.image.load('ufo (1)/6.png')
ufo_img = pygame.image.load('ufo (1)/8.png')
player_img = pygame.image.load('DurrrSpaceShip.png')
bintang_img = pygame.image.load('star.png')
ally_img = pygame.image.load('fighter.png')
pygame.display.set_caption('Galactic Endless')
window = pygame.display.set_mode((screen_width, screen_height ))
clock = pygame.time.Clock()
Gameover = False
nyawa = 3
score = 0
machineGun = False
class player(object):
def __init__(self):
self.img = player_img
self.width = self.img.get_width()
self.height = self.img.get_height()
self.x = screen_width//2
self.y = screen_height//2
#sudut dimana pemain sedang menghadap
self.sudut = 0
#untuk merotasi pesawat player dan memberikan nilai baru dari gambar ketika sedang berotasi
self.rotasiSurf = pygame.transform.rotate(self.img, self.sudut)
self.rotasiRect = self.rotasiSurf.get_rect()
#Membenarkan posisi pesawat agar berada di tengah window
self.rotasiRect.center = (self.x, self.y)
self.cosin = math.cos(math.radians(self.sudut + 90))
self.sin = math.sin(math.radians(self.sudut + 90))
#Memberi tahu dimana posisi depan kita
self.head = (self.x + self.cosin * self.width//2, self.y - self.sin * self.height//2)
def draw(self, window):
#window.blit(self.img,[self.x, self.y, self.width, self.height])
window.blit(self.rotasiSurf, self.rotasiRect)
def putarKiri(self):
self.sudut += 5
self.rotasiSurf = pygame.transform.rotate(self.img, self.sudut)
self.rotasiRect = self.rotasiSurf.get_rect()
self.rotasiRect.center = (self.x, self.y)
self.cosin = math.cos(math.radians(self.sudut + 90))
self.sin = math.sin(math.radians(self.sudut + 90))
self.head = (self.x + self.cosin * self.width//2, self.y - self.sin * self.height//2)
def putarKanan(self):
self.sudut -= 5
self.rotasiSurf = pygame.transform.rotate(self.img, self.sudut)
self.rotasiRect = self.rotasiSurf.get_rect()
self.rotasiRect.center = (self.x, self.y)
self.cosin = math.cos(math.radians(self.sudut + 90))
self.sin = math.sin(math.radians(self.sudut + 90))
self.head = (self.x + self.cosin * self.width//2, self.y - self.sin * self.height//2)
def maju(self):
self.x += self.cosin * 6
self.y -= self.sin * 6
self.rotasiSurf = pygame.transform.rotate(self.img, self.sudut)
self.rotasiRect = self.rotasiSurf.get_rect()
self.rotasiRect.center = (self.x, self.y)
self.cosin = math.cos(math.radians(self.sudut + 90))
self.sin = math.sin(math.radians(self.sudut + 90))
self.head = (self.x + self.cosin * self.width//2, self.y - self.sin * self.height//2)
def batasRenderPlayer(self):
if self.x > screen_width + 50 :
self.x = 0
elif self.x < 0 - self.width :
self.x = screen_width
elif self.y < -50 :
self.y = screen_height
elif self.y > screen_height + 50:
self.y = 0