AI generálta ütközés
This commit is contained in:
@@ -18,5 +18,8 @@ Teljesen AI-generált szakaszokat egy `# !!! CHATGPT !!!` komment jelzi
|
|||||||
### gamestates/battle.py
|
### gamestates/battle.py
|
||||||
* menük
|
* menük
|
||||||
|
|
||||||
|
### gamestates/overworld.py és objects.py
|
||||||
|
* ütközés
|
||||||
|
|
||||||
## Dokumentáció
|
## Dokumentáció
|
||||||
Ezen a fájlon kívül minden dokumentáció AI generálta.
|
Ezen a fájlon kívül minden dokumentáció AI generálta.
|
||||||
@@ -27,6 +27,7 @@ def start_battle(battle_id):
|
|||||||
def switch(game):
|
def switch(game):
|
||||||
in_battle_transition = False
|
in_battle_transition = False
|
||||||
|
|
||||||
|
# !!! CHATGPT !!!
|
||||||
def update(game, dt):
|
def update(game, dt):
|
||||||
global btrans_active, btrans_timer
|
global btrans_active, btrans_timer
|
||||||
if btrans_active:
|
if btrans_active:
|
||||||
@@ -36,7 +37,7 @@ def update(game, dt):
|
|||||||
game.mos_enabled = False
|
game.mos_enabled = False
|
||||||
btrans_active = False
|
btrans_active = False
|
||||||
btrans_sound.stop()
|
btrans_sound.stop()
|
||||||
gamestate.switch_gamestate(game,"battle")
|
gamestate.switch_gamestate(game, "battle")
|
||||||
|
|
||||||
game.mos_enabled = True
|
game.mos_enabled = True
|
||||||
cycle_progress = (btrans_timer % BTRANS_PULSE_DUR) / BTRANS_PULSE_DUR
|
cycle_progress = (btrans_timer % BTRANS_PULSE_DUR) / BTRANS_PULSE_DUR
|
||||||
@@ -57,24 +58,51 @@ def update(game, dt):
|
|||||||
elif controls.is_control_pressed(3): # Jobb
|
elif controls.is_control_pressed(3): # Jobb
|
||||||
balthasar.set_direction(DIR_RIGHT)
|
balthasar.set_direction(DIR_RIGHT)
|
||||||
|
|
||||||
|
# Calculate movement delta based on input
|
||||||
|
dx = 0
|
||||||
|
dy = 0
|
||||||
walking = False
|
walking = False
|
||||||
|
|
||||||
if controls.is_control_held(0): # Fel
|
if controls.is_control_held(0): # Fel (Up)
|
||||||
overworld.scroll_y -= WALK_SPEED * dt
|
dy += WALK_SPEED * dt
|
||||||
walking = True
|
walking = True
|
||||||
elif controls.is_control_held(1): # Le
|
elif controls.is_control_held(1): # Le (Down)
|
||||||
overworld.scroll_y += WALK_SPEED * dt
|
dy -= WALK_SPEED * dt
|
||||||
walking = True
|
walking = True
|
||||||
|
|
||||||
if controls.is_control_held(2): # Bal
|
if controls.is_control_held(2): # Bal (Left)
|
||||||
overworld.scroll_x += WALK_SPEED * dt
|
dx -= WALK_SPEED * dt
|
||||||
walking = True
|
walking = True
|
||||||
elif controls.is_control_held(3): # Jobb
|
elif controls.is_control_held(3): # Jobb (Right)
|
||||||
overworld.scroll_x -= WALK_SPEED * dt
|
dx += WALK_SPEED * dt
|
||||||
walking = True
|
walking = True
|
||||||
|
|
||||||
balthasar.set_walking(walking)
|
balthasar.set_walking(walking)
|
||||||
|
|
||||||
|
if walking:
|
||||||
|
# Get current world position
|
||||||
|
cur_x, cur_y = overworld.get_player_world_pos(game)
|
||||||
|
|
||||||
|
# Define collision box dimensions for Balthasar (e.g., 12 width, 10 height at feet)
|
||||||
|
box_w = 12
|
||||||
|
box_h = 10
|
||||||
|
|
||||||
|
# Test and apply X movement independently (Slide on walls)
|
||||||
|
if dx != 0:
|
||||||
|
next_x = cur_x + dx
|
||||||
|
if overworld.is_box_walkable(next_x, cur_y, box_w, box_h):
|
||||||
|
overworld.scroll_x -= dx # Note: scroll moves inverse to world pos change
|
||||||
|
|
||||||
|
# Re-fetch current world pos after potential X movement update
|
||||||
|
cur_x, cur_y = overworld.get_player_world_pos(game)
|
||||||
|
|
||||||
|
# Test and apply Y movement independently
|
||||||
|
if dy != 0:
|
||||||
|
next_y = cur_y + dy
|
||||||
|
if overworld.is_box_walkable(cur_x, next_y, box_w, box_h):
|
||||||
|
overworld.scroll_y -= dy # Note: scroll moves inverse to world pos change
|
||||||
|
# !!! CHATGPT VÉGE !!!
|
||||||
|
|
||||||
def draw(game):
|
def draw(game):
|
||||||
overworld.render(game)
|
overworld.render(game)
|
||||||
balthasar.render(game)
|
balthasar.render(game)
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ class OverworldMap:
|
|||||||
x = 0
|
x = 0
|
||||||
y = len(OVERWORLD_MAP)
|
y = len(OVERWORLD_MAP)
|
||||||
for row in OVERWORLD_MAP:
|
for row in OVERWORLD_MAP:
|
||||||
|
y -= 1
|
||||||
for tile in row:
|
for tile in row:
|
||||||
self.sprites.append([
|
self.sprites.append([
|
||||||
assets.sprites["overworld"].get_texture(
|
assets.sprites["overworld"].get_texture(
|
||||||
@@ -82,9 +83,59 @@ class OverworldMap:
|
|||||||
)
|
)
|
||||||
])
|
])
|
||||||
x += 1
|
x += 1
|
||||||
y -= 1
|
|
||||||
x = 0
|
x = 0
|
||||||
|
# !!! CHATGPT !!!
|
||||||
|
def get_player_world_pos(self, game):
|
||||||
|
"""Calculates the player's world pixel position based on scroll."""
|
||||||
|
base_offset_x = (game.screen_width / 2) - ((OVERWORLD_WIDTH * OVERWORLD_TILE_WIDTH) / 2)
|
||||||
|
base_offset_y = (game.screen_height / 2) - ((OVERWORLD_HEIGHT * OVERWORLD_TILE_HEIGHT) / 2)
|
||||||
|
|
||||||
|
# Player pixel position in the world coordinate space
|
||||||
|
player_world_x = (game.screen_width / 2) - base_offset_x - self.scroll_x
|
||||||
|
player_world_y = (game.screen_height / 2) - base_offset_y - self.scroll_y
|
||||||
|
|
||||||
|
return player_world_x, player_world_y
|
||||||
|
|
||||||
|
def get_tile_at(self, world_x, world_y):
|
||||||
|
"""Returns the map tile ID at a given world pixel position."""
|
||||||
|
tile_x = int(world_x // OVERWORLD_TILE_WIDTH)
|
||||||
|
tile_y = int(world_y // OVERWORLD_TILE_HEIGHT)
|
||||||
|
|
||||||
|
# Check bounds
|
||||||
|
if 0 <= tile_x < OVERWORLD_WIDTH and 0 <= tile_y < OVERWORLD_HEIGHT:
|
||||||
|
return OVERWORLD_MAP[OVERWORLD_HEIGHT - 1 - tile_y][tile_x]
|
||||||
|
return None # Out of bounds / wall
|
||||||
|
|
||||||
|
def is_box_walkable(self, world_x, world_y, width, height):
|
||||||
|
"""Checks if a bounding box (e.g., player's feet) is entirely on walkable tiles."""
|
||||||
|
feet_offset_y = (B_SPRITE_HEIGHT - height) / 2
|
||||||
|
box_center_y = world_y - feet_offset_y
|
||||||
|
|
||||||
|
left = world_x - (width / 2)
|
||||||
|
right = world_x + (width / 2) - 1
|
||||||
|
bottom = box_center_y - (height / 2)
|
||||||
|
top = box_center_y + (height / 2) - 1
|
||||||
|
|
||||||
|
# Check the four corners of the bounding box
|
||||||
|
corners = [
|
||||||
|
(left, bottom),
|
||||||
|
(right, bottom),
|
||||||
|
(left, top),
|
||||||
|
(right, top)
|
||||||
|
]
|
||||||
|
|
||||||
|
for cx, cy in corners:
|
||||||
|
tile_x = int(cx // OVERWORLD_TILE_WIDTH)
|
||||||
|
tile_y = int(cy // OVERWORLD_TILE_HEIGHT)
|
||||||
|
|
||||||
|
# Check map bounds
|
||||||
|
if not (0 <= tile_x < OVERWORLD_WIDTH and 0 <= tile_y < OVERWORLD_HEIGHT):
|
||||||
|
return False # Out of bounds is a wall
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
# !!! CHATGPT VÉGE !!!
|
||||||
|
|
||||||
def render(self, game):
|
def render(self, game):
|
||||||
for s in self.sprites:
|
for s in self.sprites:
|
||||||
|
|||||||
Reference in New Issue
Block a user