Unbewohnte 4 years ago
parent
commit
80c058b15c
  1. 17
      Main.py
  2. 2
      bullets.py
  3. 16
      enemy.py
  4. 15
      player.py

17
Main.py

@ -3,10 +3,11 @@ import pygame_menu
import sys import sys
import random import random
import time import time
from bullets import * from bullets import Bullet
from player import * from player import Player
from enemy import * from enemy import Enemy
from surfaces import Surface from surfaces import Surface
######## Set up things that will not change ######## Set up things that will not change
pygame.init() pygame.init()
pygame.display.set_caption('Healthless') pygame.display.set_caption('Healthless')
@ -41,7 +42,7 @@ def play():
window.fill((41, 64, 59)) # (41,64,59) window.fill((41, 64, 59)) # (41,64,59)
test_surface.place(window,352,352) test_surface.place(window,100,100)
player.teleportation() player.teleportation()
player.shoot(window,start_color,bullet_image) player.shoot(window,start_color,bullet_image)
@ -50,8 +51,14 @@ def play():
enemy.draw(window,start_color,enemy_image) enemy.draw(window,start_color,enemy_image)
enemy.update() enemy.update()
enemy.collision(enemy)
if player.out_of_area():
print(player.x, player.y)
break
if player.y <= 0: #Just to try a "death" if enemy.out_of_area():
print('Random is on our side')
break break
clock.tick(FPS) clock.tick(FPS)

2
bullets.py

@ -7,7 +7,7 @@ class Bullet:
self.bullet_y = bullet_y self.bullet_y = bullet_y
self.bullet_width = 4 self.bullet_width = 4
self.bullet_height = 12 self.bullet_height = 12
self.bullet_vel = random.randint(12,22) #12 -- 22 self.bullet_vel = random.randint(16,28) #12 -- 22
def draw(self,window,start_color,bullet_image): 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)) 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)) window.blit(bullet_image,(self.bullet_x, self.bullet_y))

16
enemy.py

@ -1,8 +1,10 @@
import pygame import pygame
from player import * from player import *
from bullets import Bullet from bullets import Bullet
from random import randint
windowX = 640
windowY = 640
class Enemy: class Enemy:
def __init__(self): def __init__(self):
@ -20,3 +22,15 @@ class Enemy:
self.enemy_x = 1 self.enemy_x = 1
def enemy_shoot(self): #Have NO IDEA how it`ll work def enemy_shoot(self): #Have NO IDEA how it`ll work
pass pass
def out_of_area(self):
if self.enemy_x > windowX or self.enemy_x < 0 or self.enemy_y > windowY or self.enemy_y < 0:
return True
else:
return False
def collision(self,enemy):
for bullet in bullets_on_screen:
if bullet.bullet_x + bullet.bullet_width/2 >= enemy.enemy_x and bullet.bullet_x + bullet.bullet_width/2 <= enemy.enemy_x + enemy.en_width and bullet.bullet_y <= enemy.enemy_y:
enemy.enemy_x += randint(-50,50)
enemy.enemy_y += randint(-50,50)

15
player.py

@ -64,7 +64,7 @@ class Player:
print('teleportation cooldown : '+ str(self.tp_cooldown)) print('teleportation cooldown : '+ str(self.tp_cooldown))
keys = pygame.key.get_pressed() keys = pygame.key.get_pressed()
if keys[pygame.K_d] and keys[pygame.K_UP] and self.tp_cooldown == 0: #front-dash if keys[pygame.K_d] and keys[pygame.K_UP] and self.tp_cooldown == 0: #forward-dash
self.y -= self.height*2 self.y -= self.height*2
self.tp_cooldown = 100 self.tp_cooldown = 100
@ -76,6 +76,17 @@ class Player:
self.x += self.height*2 self.x += self.height*2
self.tp_cooldown = 100 self.tp_cooldown = 100
if keys[pygame.K_d] and keys[pygame.K_DOWN] and self.tp_cooldown == 0: #back-dash if keys[pygame.K_d] and keys[pygame.K_DOWN] and self.tp_cooldown == 0: #backward-dash
self.y += self.height*2 self.y += self.height*2
self.tp_cooldown = 100 self.tp_cooldown = 100
# if keys[pygame.K_d] and keys[pygame.K_DOWN] and keys[pygame.K_RIGHT] and self.tp_cooldown == 0: #back-right-dash
# self.y += self.height*2
# self.x += self.height*2
# self.tp_cooldown = 100
def out_of_area(self):
if self.x > windowX or self.x < 0 or self.y > windowY or self.y < 0:
return True
else:
return False

Loading…
Cancel
Save