Esempio n. 1
0
	def update(self):
		dx = 0
		dy = 0
		keys = self._context._system_state.inputs[self.id]
		if keys[INDEX_RIGHT]:
			dx += 1
		if keys[INDEX_LEFT]:
			dx -= 1
		if keys[INDEX_UP]:
			dy += 1
		if keys[INDEX_DOWN]:
			dy -= 1
		self.x += dx*PLAYER_SPEED
		self.y += dy*PLAYER_SPEED
		self.frame += 1
	
		if self._context.collision:
			for i in range(self._context.array_fill - 1, -1, -1):
				if (int(self._context.bullet_array[ARRAY_COLLIDE_MASK,i]) & (1 << self.id)):
					self._context.delete_bullet(i)
					self.vanish()
		
		if self._context.collisionML:
			for i in range(self._context.array_ml_fill - 1, -1, -1):
				if (int(self._context.bullet_array_ml[ARRAY_ML_COLLIDE_MASK,i]) & (1 << self.id)):
					self._context.bullet_list[i].vanish()
					self.vanish()
		
		
		if keys[INDEX_SHOT]:
			
			foe_aimed_list = []
			for foe in self._context.foe_list:
				if foe.y > self.y and abs(foe.x - self.x) < SHOT_WIDTH / 2:
					foe_aimed_list.append(foe)

			if foe_aimed_list:
				foe_choosen = random.randint(0,len(foe_aimed_list) - 1)
				shot = Shot(self._context)
				shot.x = self.x
				shot.y = self.y
				shot.aimed_foe = foe_aimed_list[foe_choosen]


		return self
Esempio n. 2
0
    def update(self):
        dx = 0
        dy = 0
        keys = self._context._system_state.inputs[self.id]
        if keys[INDEX_RIGHT]:
            dx += 1
        if keys[INDEX_LEFT]:
            dx -= 1
        if keys[INDEX_UP]:
            dy += 1
        if keys[INDEX_DOWN]:
            dy -= 1
        self.x += dx * PLAYER_SPEED
        self.y += dy * PLAYER_SPEED
        self.frame += 1

        if self._context.collision:
            for i in range(self._context.array_fill - 1, -1, -1):
                if (int(self._context.bullet_array[ARRAY_COLLIDE_MASK, i]) &
                    (1 << self.id)):
                    self._context.delete_bullet(i)
                    self.vanish()

        if self._context.collisionML:
            for i in range(self._context.array_ml_fill - 1, -1, -1):
                if (int(self._context.bullet_array_ml[ARRAY_ML_COLLIDE_MASK,
                                                      i]) & (1 << self.id)):
                    self._context.bullet_list[i].vanish()
                    self.vanish()

        if keys[INDEX_SHOT]:

            foe_aimed_list = []
            for foe in self._context.foe_list:
                if foe.y > self.y and abs(foe.x - self.x) < SHOT_WIDTH / 2:
                    foe_aimed_list.append(foe)

            if foe_aimed_list:
                foe_choosen = random.randint(0, len(foe_aimed_list) - 1)
                shot = Shot(self._context)
                shot.x = self.x
                shot.y = self.y
                shot.aimed_foe = foe_aimed_list[foe_choosen]

        return self