commit c169e36de3543917cb1dbd93d4888c5f79ec1fb3 Author: Unbewohnte Date: Thu Aug 6 18:29:00 2020 +0300 Initial commit diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..dfe0770 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..4f47a9c --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 Unbewohnte + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Main.py b/Main.py new file mode 100644 index 0000000..49242f3 --- /dev/null +++ b/Main.py @@ -0,0 +1,73 @@ +import pygame +import pygame_menu +import sys +import random +import time +from bullets import * +from player import * +from enemy import * + +pygame.init() +pygame.display.set_caption('Healthless') +windowX = 600 +windowY = 600 +window = pygame.display.set_mode((windowX,windowY)) +icon = pygame.image.load('pics/logo.png') +pygame.display.set_icon(icon) + +######## Images +bullet_image = pygame.image.load('pics/second_bullet.png') +enemy_image = pygame.image.load('pics/enemy.png') +player_image = pygame.image.load('pics/player.png') +arrow_img = pygame.image.load('pics/arrow.png') +####### +#rand_color = (int(random.randint(0,254)),int(random.randint(0,254)) ,int(random.randint(0,254))) + +#################################################### Variables +FPS = 70 +clock = pygame.time.Clock() +start_color = (0,0,0) +pygame.mouse.set_visible(False) +enemy = Enemy(100,100,30,60,30,30) +player = Player(300,300,10,64,32,100) +####################################################### +################################################################ MAINLOOP START +def play(): + gamerun = True + while gamerun == True: + for event in pygame.event.get(): + if event.type == pygame.QUIT: + gamerun = False + pygame.quit(),sys.exit() + break + + window.fill((0,70,80)) + + player.debug() + player.shoot(window,start_color,bullet_image) + player.draw(window,start_color,player_image) + player.update(window,start_color,bullet_image) + + enemy.draw(window,start_color,enemy_image) + enemy.update() + + clock.tick(FPS) + pygame.display.update() #Update a display + pass +################################################################## MAINLOOP END +def quit(): + pygame_menu.events.EXIT + sys.exit() + +menu_bool = True +while menu_bool == True: + for event in pygame.event.get(): + if event.type == pygame.QUIT: + menu_bool = False + pygame.quit(),sys.exit() + break + + menu = pygame_menu.Menu(windowX,windowY,'Healthless',theme = pygame_menu.themes.THEME_BLUE) + menu.add_button('Play', play) + menu.add_button('Quit', quit) + menu.mainloop(window) diff --git a/__pycache__/bullets.cpython-38.pyc b/__pycache__/bullets.cpython-38.pyc new file mode 100644 index 0000000..8bd8c6d Binary files /dev/null and b/__pycache__/bullets.cpython-38.pyc differ diff --git a/__pycache__/enemy.cpython-38.pyc b/__pycache__/enemy.cpython-38.pyc new file mode 100644 index 0000000..f38be93 Binary files /dev/null and b/__pycache__/enemy.cpython-38.pyc differ diff --git a/__pycache__/player.cpython-38.pyc b/__pycache__/player.cpython-38.pyc new file mode 100644 index 0000000..e996501 Binary files /dev/null and b/__pycache__/player.cpython-38.pyc differ diff --git a/bullets.py b/bullets.py new file mode 100644 index 0000000..f28b089 --- /dev/null +++ b/bullets.py @@ -0,0 +1,15 @@ +import pygame +import random + +class Bullet: + def __init__(self, bullet_x,bullet_y): + self.bullet_x = bullet_x + random.randint(-8,8) # -8 -- 8 + self.bullet_y = bullet_y + self.bullet_width = 4 + self.bullet_height = 12 + self.bullet_vel = random.randint(12,22) #12 -- 22 + def draw(self,window,start_color,bullet_image): + self.rect = pygame.draw.rect(window,start_color,(self.bullet_x,self.bullet_y,self.bullet_width,self.bullet_height)) + window.blit(bullet_image,(self.bullet_x, self.bullet_y)) + def move(self): + self.bullet_y -= self.bullet_vel diff --git a/enemy.py b/enemy.py new file mode 100644 index 0000000..21b0541 --- /dev/null +++ b/enemy.py @@ -0,0 +1,23 @@ +import pygame +from player import * +from bullets import * + + + +class Enemy: + def __init__(self,enemy_x,enemy_y,en_width,en_height,en_damage,en_health): + self.enemy_x = enemy_x + self.enemy_y = enemy_y + self.en_width = en_width + self.en_height = en_height + self.en_damage = en_damage + self.en_health = en_health + def draw(self,window,en_color,en_image): + pygame.draw.rect(window,en_color,(self.enemy_x, self.enemy_y, self.en_width, self.en_height)) + window.blit(en_image,(self.enemy_x, self.enemy_y)) + def update(self): + self.enemy_x += 3 #self.vel here #3 + if self.enemy_x >= 600: + self.enemy_x = 1 + def enemy_shoot(self): + pass diff --git a/pics/Desktop temp — ярлык.lnk b/pics/Desktop temp — ярлык.lnk new file mode 100644 index 0000000..61e8454 Binary files /dev/null and b/pics/Desktop temp — ярлык.lnk differ diff --git a/pics/arrow.png b/pics/arrow.png new file mode 100644 index 0000000..0511cd5 Binary files /dev/null and b/pics/arrow.png differ diff --git a/pics/bullet.png b/pics/bullet.png new file mode 100644 index 0000000..9338dd0 Binary files /dev/null and b/pics/bullet.png differ diff --git a/pics/enemy.png b/pics/enemy.png new file mode 100644 index 0000000..b73cf78 Binary files /dev/null and b/pics/enemy.png differ diff --git a/pics/logo.png b/pics/logo.png new file mode 100644 index 0000000..b86aac6 Binary files /dev/null and b/pics/logo.png differ diff --git a/pics/player.png b/pics/player.png new file mode 100644 index 0000000..a06e232 Binary files /dev/null and b/pics/player.png differ diff --git a/pics/second_bullet.png b/pics/second_bullet.png new file mode 100644 index 0000000..095e1bb Binary files /dev/null and b/pics/second_bullet.png differ diff --git a/player.py b/player.py new file mode 100644 index 0000000..304ec12 --- /dev/null +++ b/player.py @@ -0,0 +1,59 @@ +import pygame +import bullets +from bullets import Bullet +import time +import sys + +windowX = 600 +windowY = 600 + +bullets_on_screen = [] + +class Player: + def __init__(self,x,y,vel,height,width,health): + self.x = x + self.y = y + self.vel = vel + self.height = height + self.width = width + self.health = health + + def update(self,window,start_color,bul_image): + keys = pygame.key.get_pressed() + if keys[pygame.K_LEFT] and self.x > 5 : + self.x -= self.vel + + if keys[pygame.K_RIGHT] and self.x < windowX- self.width - 5 : + self.x += self.vel + + if keys[pygame.K_UP] and self.y + self.height > self.height + 5 : + self.y -= self.vel + + if keys[pygame.K_DOWN] and self.y + self.height < windowY-15 : + self.y += self.vel + + def draw(self,window,color,player_image): + self.rect = pygame.draw.rect(window,color,(self.x,self.y,self.width,self.height)) + window.blit(player_image,(self.x, self.y)) + def shoot(self,window,start_color,bul_image): + keys = pygame.key.get_pressed() + if keys[pygame.K_z]: + new_bullet = Bullet(self.x + self.width/2, self.y + 10) + bullets_on_screen.append(new_bullet) + if int(len(bullets_on_screen)) > 0: + for bullet in bullets_on_screen: + bullet.draw(window,start_color,bul_image) + bullet.move() + if bullet.bullet_y <= -20: + bullets_on_screen.remove(bullet) + print('Bullets: ' + str(len(bullets_on_screen))) + + def debug(self): + keys = pygame.key.get_pressed() + if keys[pygame.K_d]: + self.x = 300 + self.y = 300 + + # def check__health(self): ################################# Work with that + # if self.health <= 0: + # mainmenu.deathscreen() diff --git a/surfaces.py b/surfaces.py new file mode 100644 index 0000000..72ccc1a --- /dev/null +++ b/surfaces.py @@ -0,0 +1,10 @@ +import pygame + +class surface: + def __init__(self,name): + self.surf_name = name + if self.surf_name == 'kill': + killsurf() + + def killsurf(self): + pass