|
|
|
@ -7,7 +7,7 @@ import pygame
|
|
|
|
|
from time import time
|
|
|
|
|
import numpy as np
|
|
|
|
|
from numpy import sqrt
|
|
|
|
|
from math import atan, degrees
|
|
|
|
|
from math import atan, degrees,radians, cos, sin
|
|
|
|
|
|
|
|
|
|
decision_matrix = np.array([[0,1,2],[3,4,5],[6,7,8]])
|
|
|
|
|
suffix_matrix = ['_up_left.png',
|
|
|
|
@ -48,6 +48,7 @@ class Perso():
|
|
|
|
|
pygame.image.load(img_path+texture+'_down_right.png').convert_alpha(),]
|
|
|
|
|
self.img = self.imgs[0]
|
|
|
|
|
self.canon = pygame.image.load(img_path+texture_canon).convert_alpha()
|
|
|
|
|
self.degres = 0
|
|
|
|
|
self.texture_proj = texture_proj
|
|
|
|
|
|
|
|
|
|
self.size = self.img.get_size()
|
|
|
|
@ -129,13 +130,13 @@ class Perso():
|
|
|
|
|
x_mouse, y_mouse = pygame.mouse.get_pos()
|
|
|
|
|
if x_mouse==self.posx:
|
|
|
|
|
x_mouse+=0.1
|
|
|
|
|
degres = degrees(abs(atan((y_mouse-self.posy)/(x_mouse-self.posx))))
|
|
|
|
|
self.degres = degrees(abs(atan((y_mouse-self.posy)/(x_mouse-self.posx))))
|
|
|
|
|
if y_mouse > self.posy:
|
|
|
|
|
degres = -degres
|
|
|
|
|
self.degres = -self.degres
|
|
|
|
|
if x_mouse < self.posx:
|
|
|
|
|
degres = 180-degres
|
|
|
|
|
self.degres = 180-self.degres
|
|
|
|
|
|
|
|
|
|
canon = pygame.transform.rotate(self.canon,degres)
|
|
|
|
|
canon = pygame.transform.rotate(self.canon,self.degres)
|
|
|
|
|
|
|
|
|
|
# Get rects
|
|
|
|
|
perso_rect = self.img.get_rect()
|
|
|
|
@ -146,7 +147,7 @@ class Perso():
|
|
|
|
|
|
|
|
|
|
def fire(self,name,texture):
|
|
|
|
|
if (time()-self.last_fire> 0.2):
|
|
|
|
|
new_proj = Projectile(name,self.texture_proj,3,(self.posx+int(self.img.get_height()/2),self.posy+int(self.img.get_width()/2)),[self.direction[0],self.direction[1]])
|
|
|
|
|
new_proj = Projectile(name,self.texture_proj,10,(self.posx+int(self.img.get_height()/2),self.posy+int(self.img.get_width()/2)),self.degres)
|
|
|
|
|
self.projectiles.append(new_proj)
|
|
|
|
|
self.last_fire = time()
|
|
|
|
|
|
|
|
|
@ -154,17 +155,15 @@ class Perso():
|
|
|
|
|
|
|
|
|
|
class Projectile():
|
|
|
|
|
|
|
|
|
|
def __init__(self,name,texture,speed,position,direction):
|
|
|
|
|
def __init__(self,name,texture,speed,position,angle):
|
|
|
|
|
self.name = name
|
|
|
|
|
self.speed = speed
|
|
|
|
|
self.position = position
|
|
|
|
|
self.direction = direction
|
|
|
|
|
|
|
|
|
|
index = decision_matrix[self.direction[1]+1,self.direction[0]+1]
|
|
|
|
|
self.img = pygame.image.load(img_path+texture+suffix_matrix[index]).convert_alpha()
|
|
|
|
|
self.direction = direction = [cos(radians(angle)),-sin(radians(angle))]
|
|
|
|
|
self.img = pygame.transform.rotate(pygame.image.load(img_path+texture).convert_alpha(),angle)
|
|
|
|
|
|
|
|
|
|
def move(self):
|
|
|
|
|
self.position = (self.position[0]+self.speed*self.direction[0],self.position[1]+self.speed*self.direction[1])
|
|
|
|
|
self.position = (int(self.position[0]+self.speed*self.direction[0]),int(self.position[1]+self.speed*self.direction[1]))
|
|
|
|
|
|
|
|
|
|
def draw(self,surface):
|
|
|
|
|
surface.blit(self.img,self.position)
|
|
|
|
|