Files
ScriptSorcerer f3a5647e5b 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
2026-07-04 23:50:07 +02:00

37 lines
983 B
Python

import pygame as pg
class Camera():
def __init__(self):
self.zoom = 2
self.offset = pg.math.Vector2(0, 0)
def world_to_screen(self, pos):
return (
int((pos[0] - self.offset.x) * self.zoom),
int((pos[1] - self.offset.y) * self.zoom)
)
def screen_to_world(self, pos):
return (
pos[0] / self.zoom + self.offset.x,
pos[1] / self.zoom + self.offset.y
)
def move(self, dx, dy):
self.offset.x += dx
self.offset.y += dy
def change_zoom(self, amount):
self.zoom += amount
self.zoom = max(0.5, min(self.zoom, 4.0))
def zoom_offset(self, screen_pos, zoom_factor):
world_before = self.screen_to_world(screen_pos)
self.change_zoom(zoom_factor)
world_after = self.screen_to_world(screen_pos)
self.offset.x += world_before[0] - world_after[0]
self.offset.y += world_before[1] - world_after[1]