Browse Source

Enemy direction

master
Unbewohnte 4 years ago
parent
commit
78acb64336
  1. 4
      Main.py
  2. 17
      beings.py

4
Main.py

@ -52,7 +52,9 @@ def play():
enemy.enemy_shoot(window,start_color,enemy_bul_img) enemy.enemy_shoot(window,start_color,enemy_bul_img)
enemy.draw(window,start_color,enemy_image) enemy.draw(window,start_color,enemy_image)
enemy.update() enemy.move('right')
if enemy.enemy_x == windowX:
enemy.enemy_x = 1
enemy.collision() enemy.collision()
if player.out_of_area(): if player.out_of_area():

17
beings.py

@ -6,10 +6,12 @@ from bullets import Bullet
import time import time
import sys import sys
############
windowX = 832 windowX = 832
windowY = 832 windowY = 832
bullets_on_screen = [] bullets_on_screen = []
enemy_bul_on_screen = [] enemy_bul_on_screen = []
############
class Player: class Player:
def __init__(self): def __init__(self):
@ -105,14 +107,19 @@ class Enemy:
self.enemy_y = 100 self.enemy_y = 100
self.en_width = 32 self.en_width = 32
self.en_height = 64 self.en_height = 64
self.vel = 3
def draw(self,window,en_color,en_image): 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)) 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)) window.blit(en_image,(self.enemy_x, self.enemy_y))
def update(self): def move(self,side):
self.enemy_x += 3 if str(side) == "right":
if self.enemy_x >= 600: self.enemy_x += self.vel
self.enemy_x = 1 elif str(side) == "left":
self.enemy_x -= self.vel
elif str(side) == "up":
self.enemy_y -= self.vel
elif str(side) == "down":
self.enemy_y += self.vel
def enemy_shoot(self,window,start_color,bul_image): #Have NO IDEA how it`ll work def enemy_shoot(self,window,start_color,bul_image): #Have NO IDEA how it`ll work
new_bullet = Bullet(self.enemy_x + self.en_width/2, self.enemy_y + 10) new_bullet = Bullet(self.enemy_x + self.en_width/2, self.enemy_y + 10)
enemy_bul_on_screen.append(new_bullet) enemy_bul_on_screen.append(new_bullet)

Loading…
Cancel
Save