Erz,Tank,Ziel #1
45
background.py
Normal file
45
background.py
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
import pygame
|
||||||
|
|
||||||
|
|
||||||
|
class Erz(pygame.sprite.Sprite):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
self.image = pygame.image.load("Erzmine.jpg").convert_alpha()
|
||||||
|
self.rect = self.image.get_rect()
|
||||||
|
self.rect = 330, 20
|
||||||
|
|
||||||
|
|
||||||
|
def draw(self, win):
|
||||||
|
groesse = pygame.transform.scale(self.image, (100, 100))
|
||||||
|
win.blit(groesse, self.rect)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Tank(pygame.sprite.Sprite):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
self.image = pygame.image.load("Tank.png").convert_alpha()
|
||||||
|
self.rect = self.image.get_rect()
|
||||||
|
self.rect = 30, 220
|
||||||
|
|
||||||
|
|
||||||
|
def draw(self, win):
|
||||||
|
groesse = pygame.transform.scale(self.image, (100, 100))
|
||||||
|
win.blit(groesse, self.rect)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Ziel(pygame.sprite.Sprite):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
self.image = pygame.image.load("Ziel.jpg").convert_alpha()
|
||||||
|
self.rect = self.image.get_rect()
|
||||||
|
self.rect = 330, 520
|
||||||
|
|
||||||
|
|
||||||
|
def draw(self, win):
|
||||||
|
groesse = pygame.transform.scale(self.image, (100, 100))
|
||||||
|
win.blit(groesse, self.rect)
|
||||||
|
|
14
game.py
14
game.py
@ -1,4 +1,6 @@
|
|||||||
import pygame
|
import pygame
|
||||||
|
|
||||||
Yadciel marked this conversation as resolved
Outdated
|
|||||||
|
import background
|
||||||
import player
|
import player
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
@ -6,6 +8,9 @@ def start():
|
|||||||
pygame.init()
|
pygame.init()
|
||||||
win = pygame.display.set_mode((800, 800))
|
win = pygame.display.set_mode((800, 800))
|
||||||
player1 = player.Player(0, 0)
|
player1 = player.Player(0, 0)
|
||||||
|
Erzmine = background.Erz()
|
||||||
|
Tanken = background.Tank()
|
||||||
|
Ziele = background.Ziel()
|
||||||
Faxor marked this conversation as resolved
Outdated
Yadciel
commented
Ziele? mehrere? Ziele? mehrere?
|
|||||||
|
|
||||||
# Farben
|
# Farben
|
||||||
white = (255, 255, 255)
|
white = (255, 255, 255)
|
||||||
@ -38,6 +43,15 @@ def start():
|
|||||||
if tilemap[x][y] == 1:
|
if tilemap[x][y] == 1:
|
||||||
pygame.draw.rect(win, blue, (x * tile_size, y * tile_size, tile_size, tile_size))
|
pygame.draw.rect(win, blue, (x * tile_size, y * tile_size, tile_size, tile_size))
|
||||||
|
|
||||||
|
Erzmine.update()
|
||||||
|
Erzmine.draw(win)
|
||||||
|
|
||||||
|
Tanken.update()
|
||||||
|
Tanken.draw(win)
|
||||||
|
|
||||||
|
Ziele.update()
|
||||||
|
Ziele.draw(win)
|
||||||
|
|
||||||
player1.update()
|
player1.update()
|
||||||
player1.draw(win)
|
player1.draw(win)
|
||||||
|
|
||||||
|
3
main.py
3
main.py
@ -5,6 +5,8 @@ import game
|
|||||||
pygame.init()
|
pygame.init()
|
||||||
win = pygame.display.set_mode((500, 500))
|
win = pygame.display.set_mode((500, 500))
|
||||||
|
|
||||||
|
clock = pygame.time.Clock()
|
||||||
|
|
||||||
# Farben
|
# Farben
|
||||||
white = (255, 255, 255)
|
white = (255, 255, 255)
|
||||||
black = (0, 0, 0)
|
black = (0, 0, 0)
|
||||||
@ -48,4 +50,5 @@ while True:
|
|||||||
pygame.draw.rect(win, gray, quit_button)
|
pygame.draw.rect(win, gray, quit_button)
|
||||||
win.blit(quit_text, (quit_button.x + 10, quit_button.y + 10))
|
win.blit(quit_text, (quit_button.x + 10, quit_button.y + 10))
|
||||||
|
|
||||||
|
clock.tick(60)
|
||||||
pygame.display.update()
|
pygame.display.update()
|
@ -27,8 +27,8 @@ class Player(pygame.sprite.Sprite):
|
|||||||
self.rect.y -= self.speed
|
self.rect.y -= self.speed
|
||||||
|
|
||||||
direction = pygame.math.Vector2(self.dest_x - self.rect.centerx, self.dest_y - self.rect.centery)
|
direction = pygame.math.Vector2(self.dest_x - self.rect.centerx, self.dest_y - self.rect.centery)
|
||||||
angle = -math.degrees(math.atan2(direction.y, direction.x))
|
#angle = -math.degrees(math.atan2(direction.y, direction.x))
|
||||||
Faxor marked this conversation as resolved
Outdated
Yadciel
commented
kommentar? kommentar?
|
|||||||
self.image = pygame.transform.rotate(self.image, angle)
|
#self.image = pygame.transform.rotate(self.image, angle)
|
||||||
self.rect = self.image.get_rect(center=self.rect.center)
|
self.rect = self.image.get_rect(center=self.rect.center)
|
||||||
self.direction = direction.normalize()
|
self.direction = direction.normalize()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user
raus