Winkel, Tank, Debug
This commit is contained in:
parent
618348294c
commit
15b3fd2046
39
fahrzeug.py
39
fahrzeug.py
@ -1,6 +1,16 @@
|
|||||||
import pygame
|
import pygame
|
||||||
import math
|
import math
|
||||||
|
|
||||||
|
|
||||||
|
def get_angle(p1, p2):
|
||||||
|
dx = p2[0] - p1[0]
|
||||||
|
dy = p2[1] - p1[1]
|
||||||
|
rads = math.atan2(-dy,dx)
|
||||||
|
rads %= 2*math.pi
|
||||||
|
degs = math.degrees(rads)
|
||||||
|
return degs
|
||||||
|
|
||||||
|
|
||||||
class Fahrzeug(pygame.sprite.Sprite):
|
class Fahrzeug(pygame.sprite.Sprite):
|
||||||
def __init__(self, x, y):
|
def __init__(self, x, y):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
@ -8,7 +18,7 @@ class Fahrzeug(pygame.sprite.Sprite):
|
|||||||
self.rect = self.image.get_rect(center=(x, y))
|
self.rect = self.image.get_rect(center=(x, y))
|
||||||
self.rect.centerx = x
|
self.rect.centerx = x
|
||||||
self.rect.centery = y
|
self.rect.centery = y
|
||||||
self.speed = 2
|
self.speed = 1
|
||||||
self.dest_x = x
|
self.dest_x = x
|
||||||
self.dest_y = y
|
self.dest_y = y
|
||||||
self.direction = pygame.math.Vector2(0, -1)
|
self.direction = pygame.math.Vector2(0, -1)
|
||||||
@ -18,23 +28,28 @@ class Fahrzeug(pygame.sprite.Sprite):
|
|||||||
def draw(self, win):
|
def draw(self, win):
|
||||||
rotated_image = pygame.transform.rotate(self.image, self.angle)
|
rotated_image = pygame.transform.rotate(self.image, self.angle)
|
||||||
rotated_rect = rotated_image.get_rect(center=self.rect.center)
|
rotated_rect = rotated_image.get_rect(center=self.rect.center)
|
||||||
#debug nicht anrühren
|
|
||||||
|
#debug, nicht anrühren
|
||||||
#self.angle += 1
|
#self.angle += 1
|
||||||
#pygame.draw.rect(win, (255, 0, 0), rotated_rect)
|
#pygame.draw.rect(win, (255, 0, 0), rotated_rect)
|
||||||
|
|
||||||
win.blit(rotated_image, rotated_rect)
|
win.blit(rotated_image, rotated_rect)
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
if self.rect.centerx < self.dest_x:
|
if self.Tank > 0:
|
||||||
self.rect.centerx += self.speed
|
if self.rect.centerx < self.dest_x:
|
||||||
if self.rect.centerx > self.dest_x:
|
self.rect.centerx += self.speed
|
||||||
self.rect.centerx -= self.speed
|
if self.rect.centerx > self.dest_x:
|
||||||
if self.rect.centery < self.dest_y:
|
self.rect.centerx -= self.speed
|
||||||
self.rect.centery += self.speed
|
if self.rect.centery < self.dest_y:
|
||||||
if self.rect.centery > self.dest_y:
|
self.rect.centery += self.speed
|
||||||
self.rect.centery -= self.speed
|
if self.rect.centery > self.dest_y:
|
||||||
|
self.rect.centery -= self.speed
|
||||||
|
|
||||||
if self.rect.centerx != self.dest_x and self.rect.centery != self.dest_y:
|
if self.rect.centerx != self.dest_x or self.rect.centery != self.dest_y:
|
||||||
self.Tank -= 0.1
|
if self.Tank > 0:
|
||||||
|
self.Tank -= 0.1
|
||||||
|
self.angle = get_angle((self.rect.centerx, self.rect.centery), (self.dest_x, self.dest_y))-90
|
||||||
|
|
||||||
def dest(self, pos):
|
def dest(self, pos):
|
||||||
self.dest_x, self.dest_y = pos
|
self.dest_x, self.dest_y = pos
|
||||||
|
13
game.py
13
game.py
@ -43,8 +43,17 @@ def start():
|
|||||||
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))
|
||||||
|
|
||||||
font = pygame.font.SysFont(None, 24)
|
font = pygame.font.SysFont(None, 24)
|
||||||
img = font.render('Tank: '+str(round(player1.Tank,2)), True, white)
|
tank_label = font.render('Tank: '+str(round(player1.Tank,2)), True, white)
|
||||||
win.blit(img, (20, 20))
|
win.blit(tank_label, (20, 20))
|
||||||
|
|
||||||
|
#debug ausgabe
|
||||||
|
#---------------------------
|
||||||
|
#debug_selfrect = font.render('self centerx: ' + str(player1.rect.centerx) + ' self centery: ' + str(player1.rect.centery), True, white)
|
||||||
|
#win.blit(debug_selfrect, (20, 40))
|
||||||
|
|
||||||
|
#debug_selfrect = font.render('dest x: ' + str(player1.dest_x) + ' dest y: ' + str(player1.dest_y), True, white)
|
||||||
|
#win.blit(debug_selfrect, (20, 60))
|
||||||
|
#---------------------------
|
||||||
|
|
||||||
Erzmine.update()
|
Erzmine.update()
|
||||||
Erzmine.draw(win)
|
Erzmine.draw(win)
|
||||||
|
Loading…
Reference in New Issue
Block a user