Answer the question
In order to leave comments, you need to log in
In list (python3) the objects seem to affect each other, where could I go wrong?
Link to the project: https://github.com/LAGx/abstract_game.git
error in game_objects/player/player.py (initialization in __init__)
and game_objects/bullet/regular.py (responsible for creating player bullets)
actually this is what question:
in order to be able to shoot many independent bullets at once, I decided to create a list of bullet objects. It works, but each next bullet affects the direction of all the previous ones:
this is all updated 60 times per second (
if self.mousepress[0]: #эта штука создает новые объекты и помещает в лист (кстати, мне кажется что здесь и ошибка, мб оно на самом деле и не создает новый объект, а переопределяет старый)
self.allBullets.append(game_objects.bullet.regular.RegularBullet([ self.pos[0], self.pos[1] ], list(self.mouse)))
for n in range(len(self.allBullets)):#эта фигня для отрисовки
self.allBullets[n].blit(canvas)
)
import phisic.vector
import pygame
from serving.cord import *
class RegularBullet:
posi = [0, 0]
vector = phisic.vector.Vector()
color = [167,34,46]
speed = 2#30
isInit = False
def __init__(self, start = [0,0], end = [0,0]):
self.posi = start
self.vector.changeXEx(end[0] - start[0])
self.vector.changeYEx(end[1] + start[1])
lenth = self.vector.getLenth()
self.vector.changeXEx((self.vector.posX)/lenth)
self.vector.changeYEx((-self.vector.posY)/lenth)
self.isInit = True
def blit(self, canvas):
pygame.draw.line(canvas,self.color, [self.posi[0], -self.posi[1]], [self.posi[0]+self.vector.posX*self.speed*10, -self.posi[1]-self.vector.posY*self.speed*10], 4)
self.posi[0] += self.vector.posX * self.speed
self.posi[1] += self.vector.posY * self.speed
import numpy
import pygame
class Vector:
posX = float(0)
posY = float(0)
def getLenth(self):
return numpy.sqrt((self.posX * self.posX) + (self.posY * self.posY))
#Ex - заменить
#Plus - добавить
def changeXEx(self,X):
self.posX = X
def changeXPlus(self,X):
self.posX = self.posX + X
def changeYEx(self,Y):
self.posY = -Y
def changeYPlus(self,Y):
self.posY = self.posY + Y
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question