To much gap between last commit

Im now working next on shoorting for turret

Added new sand map and new cannon tower images aswell as function to play animations, showing range, placing turrets on allowed tiles for towers

Buy and cancel button to buy towers
This commit is contained in:
2026-07-04 23:50:07 +02:00
parent 0171a5c845
commit f3a5647e5b
40 changed files with 248 additions and 24 deletions
+16 -5
View File
@@ -1,17 +1,18 @@
from game.util import *
import pygame as pg
import math
class Enemy(pg.sprite.Group):
def __init__(self, game, speed, health):
super().__init__()
self.game = game
self.waypoints = self.game.tilemap.waypoints
print(self.waypoints)
self.speed = speed
self.angle = 0
self.health = health
self.image = self.game.assets['enemy']
self.image = pg.transform.rotate(self.game.assets['enemy'].copy(), self.angle)
self.rect = self.image.get_rect()
self.pos = pg.Vector2(
@@ -23,12 +24,16 @@ class Enemy(pg.sprite.Group):
self.rect.center = self.pos
def update(self):
self.move()
self.rotate()
def move(self):
if self.target_index >= len(self.waypoints):
return
tile_size = self.game.tilemap.tile_size
target = pg.Vector2(
self.target = pg.Vector2(
tile_to_pixel(
self.waypoints[self.target_index],
tile_size,
@@ -36,16 +41,22 @@ class Enemy(pg.sprite.Group):
)
)
direction = target - self.pos
direction = self.target - self.pos
distance = direction.length()
if distance <= self.speed:
self.pos = target
self.pos = self.target
self.target_index += 1
else:
direction = direction.normalize()
self.pos += direction * self.speed
def rotate(self):
dist = self.target - self.pos
self.angle = math.degrees(math.atan2(-dist[1], dist[0]))
self.image = pg.transform.rotate(self.game.assets['enemy'].copy(), self.angle)
self.rect = self.image.get_rect()
self.rect.center = self.pos
def render(self, surf, camera):