Skip to content

Commit aaf5e40

Browse files
committed
Few fixed to the pygameui library, docs havent been updated
1 parent 042a1cb commit aaf5e40

File tree

8 files changed

+802
-215
lines changed

8 files changed

+802
-215
lines changed
7.06 KB
Binary file not shown.

docs/getting-started.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ import pygameui
2020

2121
# Initialize
2222
pygame.init()
23-
screen = pygame.display.set_mode((width, height))
23+
screen = pygame.display.set_mode((800, 600)) # Set your own width and height
2424

2525
# Create UI elements
26-
ui_element = pygameui.Element(position=(x, y))
26+
ui_element = pygameui.Element(position=(250, 250), width=200, height=50)
2727

2828
# Main loop
2929
running = True
@@ -35,7 +35,7 @@ while running:
3535
running = False
3636

3737
# Reset screen
38-
screen.fill(background_color)
38+
screen.fill((0,0,0))
3939

4040
# Update element, moves, checks actions etc
4141
ui_element.update()
@@ -50,7 +50,9 @@ while running:
5050
To add more UI elements, simply create more instances of the `Element` class or its subclasses (like `Button`, `Text`, etc.) and follow the same pattern.
5151

5252
## Example create text
53+
5354
First create a text object:
55+
5456
```python
5557
my_text = pygameui.Text(
5658
text="Hello World",
@@ -61,6 +63,7 @@ my_text = pygameui.Text(
6163
```
6264

6365
And then in the main loop, you would call:
66+
6467
```python
6568
my_text.update()
6669
my_text.draw(screen)

examples/dashboard.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282

8383
if logout_btn.was_clicked():
8484
status.change_text("Logging out...")
85-
status.change_text_color(ERROR_COLOR)
85+
status.set_text_color(ERROR_COLOR)
8686

8787
if clear_notif_btn.was_clicked():
8888
notif1.change_text("No new notifications")

examples/game_ui.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ def perform_attack():
9292
global health, mana, gold, experience
9393

9494
# Update combat log
95-
log_entry3.change_text(log_entry2.content)
96-
log_entry2.change_text(log_entry1.content)
95+
log_entry3.change_text(log_entry2._content)
96+
log_entry2.change_text(log_entry1._content)
9797
log_entry1.change_text("You attack! Damage dealt!")
9898

9999
# Simulate battle effects
@@ -111,14 +111,14 @@ def cast_spell():
111111
global health, mana, gold, experience
112112

113113
if mana < 15:
114-
log_entry3.change_text(log_entry2.content)
115-
log_entry2.change_text(log_entry1.content)
114+
log_entry3.change_text(log_entry2._content)
115+
log_entry2.change_text(log_entry1._content)
116116
log_entry1.change_text("Not enough mana!")
117117
return
118118

119119
# Update combat log
120-
log_entry3.change_text(log_entry2.content)
121-
log_entry2.change_text(log_entry1.content)
120+
log_entry3.change_text(log_entry2._content)
121+
log_entry2.change_text(log_entry1._content)
122122
log_entry1.change_text("You cast a spell! Critical hit!")
123123

124124
# Simulate battle effects
@@ -136,14 +136,14 @@ def use_item():
136136
global health, mana, gold
137137

138138
if gold < 50:
139-
log_entry3.change_text(log_entry2.content)
140-
log_entry2.change_text(log_entry1.content)
139+
log_entry3.change_text(log_entry2._content)
140+
log_entry2.change_text(log_entry1._content)
141141
log_entry1.change_text("Not enough gold!")
142142
return
143143

144144
# Update combat log
145-
log_entry3.change_text(log_entry2.content)
146-
log_entry2.change_text(log_entry1.content)
145+
log_entry3.change_text(log_entry2._content)
146+
log_entry2.change_text(log_entry1._content)
147147
log_entry1.change_text("You used a health potion!")
148148

149149
# Simulate item use
@@ -156,8 +156,8 @@ def use_item():
156156

157157
def attempt_run():
158158
# Update combat log
159-
log_entry3.change_text(log_entry2.content)
160-
log_entry2.change_text(log_entry1.content)
159+
log_entry3.change_text(log_entry2._content)
160+
log_entry2.change_text(log_entry1._content)
161161

162162
if random.random() > 0.5:
163163
log_entry1.change_text("You escaped successfully!")
@@ -177,14 +177,14 @@ def update_stats():
177177
gold_text.change_text(f"Gold: {gold}")
178178

179179
# Update bar elements - adjust width and position
180-
health_bar.rect.width = (health/max_health) * 200
181-
health_bar.rect.centerx = 200 - (200-(health/max_health*200))/2
180+
health_bar._rect.width = (health/max_health) * 200
181+
health_bar._rect.centerx = 200 - (200-(health/max_health*200))/2
182182

183-
mana_bar.rect.width = (mana/max_mana) * 200
184-
mana_bar.rect.centerx = 480 - (200-(mana/max_mana*200))/2
183+
mana_bar._rect.width = (mana/max_mana) * 200
184+
mana_bar._rect.centerx = 480 - (200-(mana/max_mana*200))/2
185185

186-
xp_bar.rect.width = (experience/max_experience) * 600
187-
xp_bar.rect.centerx = 400 - (600-(experience/max_experience*600))/2
186+
xp_bar._rect.width = (experience/max_experience) * 600
187+
xp_bar._rect.centerx = 400 - (600-(experience/max_experience*600))/2
188188

189189
# Main game loop
190190
running = True

examples/login_screen.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ def attempt_login():
7272

7373
if username == "admin" and password == "password":
7474
status_msg.change_text("Login successful!")
75-
status_msg.change_text_color(SUCCESS_COLOR)
75+
status_msg.set_text_color(SUCCESS_COLOR)
7676
else:
7777
status_msg.change_text("Invalid username or password")
78-
status_msg.change_text_color(ERROR_COLOR)
78+
status_msg.set_text_color(ERROR_COLOR)
7979

8080
# Main game loop
8181
running = True

examples/settings_menu.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,23 +75,23 @@ def handle_button_click(button):
7575

7676
if button == fullscreen_btn:
7777
fullscreen_enabled = not fullscreen_enabled
78-
fullscreen_btn.text = "Enabled" if fullscreen_enabled else "Disabled"
78+
fullscreen_btn._text = "Enabled" if fullscreen_enabled else "Disabled"
7979

8080
elif button == vsync_btn:
8181
vsync_enabled = not vsync_enabled
82-
vsync_btn.text = "Enabled" if vsync_enabled else "Disabled"
82+
vsync_btn._text = "Enabled" if vsync_enabled else "Disabled"
8383

8484
elif button == resolution_btn:
8585
resolution_index = (resolution_index + 1) % len(resolution_options)
86-
resolution_btn.text = resolution_options[resolution_index]
86+
resolution_btn._text = resolution_options[resolution_index]
8787

8888
elif button == save_btn:
8989
status_msg.change_text("Settings saved successfully!")
90-
status_msg.change_text_color((86, 235, 120))
90+
status_msg.set_text_color((86, 235, 120))
9191

9292
elif button == cancel_btn:
9393
status_msg.change_text("Changes discarded")
94-
status_msg.change_text_color((235, 86, 86))
94+
status_msg.set_text_color((235, 86, 86))
9595

9696
# Main game loop
9797
running = True

0 commit comments

Comments
 (0)