Unbewohnte
4 years ago
commit
c169e36de3
17 changed files with 203 additions and 0 deletions
@ -0,0 +1,2 @@ |
|||||||
|
# Auto detect text files and perform LF normalization |
||||||
|
* text=auto |
@ -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. |
@ -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) |
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -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 |
@ -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 |
Binary file not shown.
After Width: | Height: | Size: 15 KiB |
After Width: | Height: | Size: 15 KiB |
After Width: | Height: | Size: 17 KiB |
After Width: | Height: | Size: 15 KiB |
After Width: | Height: | Size: 15 KiB |
After Width: | Height: | Size: 14 KiB |
@ -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() |
Loading…
Reference in new issue