-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
94 lines (74 loc) · 3.83 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# 30.10.24
import os
import sys
import time
# External libraries
from pyboy import PyBoy
from rich.console import Console
from rich.panel import Panel
from rich.table import Table
from rich import box
# Internal utilities
from Src.Engine.engine import MarioLandMonitor
def main():
pyboy = PyBoy(os.path.join('rom', 'mario.gb'))
monitor = MarioLandMonitor(pyboy)
console = Console()
try:
while True:
pyboy.tick()
# Fetch the game state
localPlayer, landGame, entityList = monitor.get_game_state()
# Use a rich panel to display the game state title and description
console.print(Panel(f"[bold blue]Game State[/bold blue] - World {landGame.current_world}, Stage {landGame.current_stage}", style="bold green"))
# Create a table to display local player details
player_table = Table(title="Local Player Info", box=box.ROUNDED)
player_table.add_column("Attribute", justify="center", style="cyan", no_wrap=True)
player_table.add_column("Value", justify="center", style="magenta")
# Add rows with player data
player_table.add_row("Position (X, Y)", f"({localPlayer.position.x}, {localPlayer.position.y})")
player_table.add_row("Pose", str(localPlayer.pose))
player_table.add_row("Direction", localPlayer.direction)
player_table.add_row("Jump State", localPlayer.jump_state)
player_table.add_row("Speed Y", str(localPlayer.speed_y))
player_table.add_row("Grounded", str(localPlayer.grounded))
player_table.add_row("Starman Timer", str(localPlayer.starman_timer))
player_table.add_row("Powerup Status", str(localPlayer.powerup_status))
player_table.add_row("Hard Mode", str(localPlayer.hard_mode))
player_table.add_row("Powerup Status Timer", str(localPlayer.powerup_status_timer))
player_table.add_row("Has Superball", str(localPlayer.has_superball))
console.print(player_table)
# Display Land Game Info in a rich panel
land_game_info = f"Score: {landGame.score} | Lives: {landGame.lives} | Coins: {landGame.coins} | Timer: {landGame.timer.minutes}:{landGame.timer.seconds:02d}"
console.print(Panel(land_game_info, title="Land Game Info", style="bold yellow"))
# Display entity list
if entityList:
console.print(Panel("[bold green]Entities in Game[/bold green]"))
entity_table = Table(title="Active Enemies", box=box.ROUNDED)
entity_table.add_column("Enemy Type", justify="center", style="cyan", no_wrap=True)
entity_table.add_column("HP", justify="center", style="magenta")
entity_table.add_column("Pos X", justify="center", style="cyan")
entity_table.add_column("Pos Y", justify="center", style="magenta")
entity_table.add_column("Pose", justify="center", style="green")
entity_table.add_column("Timer", justify="center", style="yellow")
for enemy in entityList:
entity_table.add_row(
enemy['type'],
str(enemy['hp']),
str(enemy['pos_x']),
str(enemy['pos_y']),
str(enemy['pose']),
str(enemy['timer'])
)
console.print(entity_table)
else:
console.print("[bold red]No enemies detected[/bold red]", style="bold red")
time.sleep(0.01)
os.system('cls')
except KeyboardInterrupt:
console.print("\n[bold red]Stopped ...[/bold red]", style="bold red")
sys.exit(0)
finally:
pyboy.stop()
if __name__ == "__main__":
main()