- Joined
- Jun 29, 2021
- Messages
- 2
- Reaction score
- 0
Working one the movement for a tactical turnbased pygame.
I'm stumped as to how to get a selected object to move one tile at a time up to it's max movement to the mouse's pos.
Right now this is what I have. I'm not sure how to proceed. Any help will be great.
I'm stumped as to how to get a selected object to move one tile at a time up to it's max movement to the mouse's pos.
Right now this is what I have. I'm not sure how to proceed. Any help will be great.
Python:
# This is the Sprites.py
import pygame as pg
from settings import *
# define some colors (R, G, B)
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
DARKGREY = (40, 40, 40)
LIGHTGREY = (100, 100, 100)
GREEN = (0, 255, 0)
RED = (255, 0, 0)
YELLOW = (255, 255, 0)
CYAN = (0, 255, 255)
# game settings
WIDTH = 1024 # 16 * 64 or 32 * 32 or 64 * 16
HEIGHT = 768 # 16 * 48 or 32 * 24 or 64 * 12
FPS = 60
TITLE = "Tilemap Testing"
BGCOLOR = DARKGREY
TILESIZE = 32
GRIDWIDTH = WIDTH / TILESIZE
GRIDHEIGHT = HEIGHT / TILESIZE
class Player(pg.sprite.Sprite):
def __init__(self, game, x, y):
self.groups = game.all_sprites
pg.sprite.Sprite.__init__(self, self.groups)
self.game = game
self.image = pg.Surface((TILESIZE, TILESIZE))
self.image.fill(CYAN)
self.rect = self.image.get_rect()
self.x = x
self.y = y
self.rect.x = self.x * TILESIZE
self.rect.y = self.y * TILESIZE
def move(self, vect):
x = vect[0] - self.rect.x
y = vect[1] - self.rect.y
self.rect.move_ip(x, y)
def collide_with_walls(self, dx=0, dy=0):
for wall in self.game.walls:
if wall.x >= self.x + dx and wall.y >= self.y + dy:
return True
return False