(Nov-14-2017, 09:23 PM)metulburr Wrote: if you remove the elif, to have all if, you can do two angles at the same time making it more "natural" feeling
(Nov-14-2017, 08:40 PM)Windspar Wrote: here a pygame example
import pygame pygame.init() SCREEN = 600, 400 class Bullet: def __init__(self, x, y, color, movement): self.position = [x - movement[0], y - movement[1]] self.color = color self.movement = movement def blit(self, surface): self.position[0] += self.movement[0] self.position[1] += self.movement[1] position = int(self.position[0]), int(self.position[1]) pygame.draw.circle(surface, self.color, position, 3) class Ship: def __init__(self, x, y, color, pointlist): self.position = [x, y] self.pointlist = pointlist self.color = color def move(self, x, y): self.position[0] += x self.position[1] += y def blit(self, surface): points = [] for point in self.pointlist: points.append((self.position[0] + point[0], self.position[1] + point[1])) pygame.draw.polygon(surface, self.color, points) class Pauser: def __init__(self, length): self.length = length self.last_tick = 0 def elaspe(self, ticks): if ticks > self.last_tick + self.length: self.last_tick = ticks return True return False class App: def __init__(self): pygame.display.set_caption("Invaders") # create are screen. Your main surface self.screen = pygame.display.set_mode(SCREEN) # create a clock for framerate control self.clock = pygame.time.Clock() self.bullets = [] self.bullets_pauser = Pauser(300) self.ship = Ship(300, 370, (0,0,200), ((0,0), (-20,30), (20,30))) def loop(self): running = True self.ticks = 0 while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False elif event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: running = False last_ticks = self.ticks self.ticks = pygame.time.get_ticks() speed = (self.ticks - last_ticks) * 0.05 # grab all keys return True if pressed key_press = pygame.key.get_pressed() # creaate bullets if key_press[pygame.K_SPACE]: # shoot bullets in intervals if self.bullets_pauser.elaspe(self.ticks): x, y = self.ship.position self.bullets.append(Bullet(x, y, (0,0,200), (0,-10))) # ship movement ship_speed = speed * 3 if key_press[pygame.K_LEFT]: self.ship.move(-ship_speed, 0) if key_press[pygame.K_RIGHT]: self.ship.move(ship_speed, 0) if key_press[pygame.K_UP]: self.ship.move(0, -ship_speed) if key_press[pygame.K_DOWN]: self.ship.move(0, ship_speed) # clear screen self.screen.fill((0,0,0)) # blits bullets remove_list = [] for enum, bullet in enumerate(self.bullets): if bullet.position[1] < 0: remove_list.append(enum) else: bullet.blit(self.screen) for enum, index in enumerate(remove_list): self.bullets.pop(index - enum) self.ship.blit(self.screen) pygame.display.flip() # frame per seconds self.clock.tick(30) def main(): app = App() app.loop() pygame.quit() if __name__ == '__main__': main()
Thank very much metulburr
But I'm looking for a code with the less libraries
Thanks for your concern