-
Notifications
You must be signed in to change notification settings - Fork 0
Pygame Features
How To Use
The PygameVisibleVariable is used best with numbers maybe strings containing changing numbers to use it you need to do use a refresh_image attribute example.
import easycode as ec
import pygame as pg
import sys
pg.init()
W, H = 800, 600
screen = pg.display.set_mode((W, H))
pg.display.set_caption("Easycode-infinite PygameVisibleVariable Example")
clock = pg.time.Clock()
number = 0
variable = ec.PygameVisibleVariable("CourierNew", 50, (255, 255, 255), 0, 500, number, False)
draw_group = pg.sprite.GroupSingle(variable)
running = True
while running:
for event in pg.event.get():
if event.type == pg.QUIT:
running = False
screen.fill((0, 0, 0))
number += 1
variable.refresh_image(number)
draw_group.draw(screen)
pg.display.flip()
clock.tick(60)
pg.quit()
sys.exitIf you did it correctly you should get a variable that counts up really fast.
Explaining It
The PygameVisibleVariable has 7 required positional arguments and 1 optional argument that is required for a certain reason.
- font
The font can be any built-in font type or you can download custom ones and it will still work for example Consolas, CourierNew, monospace, Arial so like this.
# Import & setup code here
font = "Impact"
variable = ec.PygameVisibleVariable(font, 50, (255, 255, 255), 0, 500, 20, False)
# While Loop hereThis if done correctly should give you the Impact font
- fontsize
The fontsize can be any number a float or int then will be your fontsize such as 50, 25, 12.6, 8.3, or 22 it doesn't matter pick whatever you require so like this.
# Import & setup code here
fontsize = 20
variable = ec.PygameVisibleVariable("Arial", fontsize, (255, 255, 255), 0, 500, 20, False)
# While Loop hereThis if done correctly what you should get is Arial with a fontsize of 20.
- fontcolor
The fontcolor can be any RGB or 3 number tuple with each value having a max of 255 and a min of 0 this will change the color of the font so like this.
# Import & setup code here
fontcolor = (255, 169, 0)
variable = ec.PygameVisibleVariable("Arial", 20, fontcolor, 0, 500, 20, False)
# While Loop hereThis if done correctly what you should get is a orange color PygameVisibleVariable.
- x, y
x and y are the position of the PygameVisibleVariable so whatever these are is what will be your position of PygameVisibleVariable so like this.
# Import & setup code here
x, y = 400, 400
variable = ec.PygameVisibleVariable("Arial", 20, (255, 255, 255), x, y, 20, False)
# While Loop hereThis if done correctly should give you the PygameVisibleVariable 400 pixels right 400 pixels down from the topleft of your screen.
- string
While yes it says string its not actually a string its more of any variable booleans, bitflags, strings, floats, integerss, characters, lists, dicts, sets, tuples, and any others I did not mention so it will display it so like this.
# Import & setup code here
number = 0
string = f"You have {number} tacos"
variable = ec.PygameVisibleVariable("Arial", 20, (255, 255, 255), 400, 400, string, False)
# While Loop hereThis if done correctly should display the PygameVisibleVariable as You have 0 tacos.
- background_t_f, backgroundcolor
When you do this which probably is False when false it will just be a number and nothing else but if you say True on this boolean now you need a new positional argument backgroundcolor this can be any RGB tuple or 3 number tuple with each value having a max of 255 and a min of 0 backgroundcolor will become the background of your number so like this.
# Import & setup code here
background_t_f = True
backgroundcolor = ((225, 230, 255))
variable = ec.PygameVisibleVariable("Arial", 20, (128, 128, 128), 400, 400, 20, background_t_f, backgroundcolor)
# While Loop hereThis if done correctly should give you a PygameVisibleVariable with a azure background and gray text.
Attributes
PygameVisibleVariable has 1 Attribute called refresh_image what this does is it changes the number however it requires a screen.fill(color) to do so or else it become a blob.
This attribute requires 1 positional argument called new_val this is just whatever the new value of what you want PygameVisibleVariable to be so like this.
# setup, imports, upper part of while running loop
# DRAWING PART OF WHILE RUNNING LOOP
screen.fill((0, 0, 0))
number += 1
new_val = number
variable.refresh_image(new_val)
pg.display.flip()
# rest of while running loopLocal Variables
- self.font_name
- self.font_size
- self.font_color
- self.background_t_f
- self.background_color
- self.x
- self.y
- self.current_string
You can control these variables and adjust them anyway you want however this may lead to errors.
How To Use The PygameVisibleList is used best with numbers maybe strings containing changing numbers to use it you need to do use refresh_list and draw attributes example.
import easycode as ec
import pygame as pg
import sys
pg.init()
W, H = 800, 600
screen = pg.display.set_mode((W, H))
pg.display.set_caption("Easycode-infinite PygameVisibleList Example")
clock = pg.time.Clock()
counter = 0
counter_by_two = 0
counter_by_three = 0
counter_by_four = 0
variable_group = (counter, counter_by_two, counter_by_three, counter_by_four)
list = ec.PygameVisibleList("Monospace", 20, (255, 255, 255), 400, 100, variable_group, "vertical", False)
running = True
while running:
for event in pg.event.get():
if event.type == pg.QUIT:
running = False
screen.fill((0, 0, 0))
counter += 1
counter_by_two += 2
counter_by_three += 3
counter_by_four += 4
variable_group = [counter, counter_by_two, counter_by_three, counter_by_four]
list.refresh_list(variable_group)
list.draw(screen)
pg.display.flip()
clock.tick(60)
pg.quit()
sys.exitIf you did it correctly you should get 4 variables counting up one counts up by 1 another by 2 another by 3 another by 4.
Explaining It
The PygameVisibleList has 8 required positional arguments and 3 optional argument that is required for a certain reason.
The PygameVisibleList has 6 positonal arguments the same as the PygameVisibleVariable exactly the same because it is actually just a list of PygameVisibleVariable and a optional one is the same Ill explain what there names are and what they are equivalant to of the PygameVisibleVariable.
- positional argument 1 font = font
- positional argument 2 fontsize = fontsize
- positional argument 3 fontcolor = fontcolor
- positional argument 4 & 5 x, y = x, y
- positional argument 8 v_bg_tf = background_t_f
- positional argument 9 v_bg_color = backgroundcolor
every argument after this is its own but will also state its position - variablegroup positional argument 6
This is a list of all your variables so whatever your variables you want are so this can be either a tuple or list of variables the variables themselves don't matter it can be anything so like this.
# Import & setup code here
counter1 = 1
counter2 = 2
counter3 = 3
counter4 = 4
variablegroup = [counter1, counter2, counter3, counter4]
list = ec.PygameVisibleList("Arial", 20, (255, 255, 255), 400, 100, variablegroup, "vertical", False)
# While Loop hereThis if done correctly should give you a list of variables in the order 1 2 3 4.
- vh positional argument 7
This is a bitflag standing for vertical or horizontal it can have either 2 inputs "vertical" or "horizontal" if its vertical it displays them top to bottom if horizontal it displays them right to left so like this.
# Import & setup code here
vh = "horizontal"
list = ec.PygameVisibleList("Arial", 20, (255, 255, 255), 100, 400, [1, 2, 3, 4], vh, False)
# While Loop hereThis if done correctly should give you a list of 1 2 3 4 in that order but it goes left to right instead of top to bottom.
- optional arguments no examples not the optional argument from PygameVisibleVariable though
- positional argument 10 l_bg_tf
While v_bg_tf covers all the variables in a color this will cover the list in a color together instead of segregated also is True or False a boolean. - positional argument 11 l_bg_color While v_bg_color is the background color of the variables themselves l_bg_color is all of the color for the list so there not segregated ya you can do this if you want. Attributes
- refresh_list
refresh_list has 1 positional argument which is variable_group so ya it is pretty much the same as PygameVisibleVariable's refresh_image. - draw
draw just is how you draw the list if you try drawing it with a group it acts weird so you use a draw instead no blit either it requires one positional argument surface which ya its just the screen usually in less you name your screen something different.
Local Variables * self.font - self.fontsize
- self.fontcolor
- self.x
- self.y
- self.vh
- self.v_bg_t_f
- self.v_bg_color
- self.l_bg_t_f
- self.l_bg_color
You can control these variables and adjust them anyway you want however this may lead to errors.
Global Variables - curr_x
- curr_y
- spacing
- all_rects
- bg_rect
- combined_rect
You can control these variables and adjust them anyway you want however this may lead to errors.
How To Use The PygameHealthBar is great way to display your health its not based off your width you choose just the height but the width is width_per_hp * max_health + 4 which is how you control but if you dont want to do math just choose random numbers it is controlled in pos colors and you can either use update_hp or refresh_bar both are basically the same thing just one is if you prefer and upate method one is if you prefer the refresh method so like this.
import easycode as ec
import pygame as pg
import sys
pg.init()
W, H = 800, 600
screen = pg.display.set_mode((W, H))
pg.display.set_caption("Easycode-infinite PygameHealthBar Example")
clock = pg.time.Clock()
class Button(ec.PygameClickedCalculator): #! Hello I know that it is not defined yet but it is vey useful PygameClickedCalculator in short gives you 2 new attributes just know that this is why there is a yellow clicked attribute
def __init__(self, pos):
super().__init__()
self.image = pg.Surface((50, 50), pg.SRCALPHA)
pg.draw.circle(self.image, (255, 255, 255), (25, 25), 25)
self.rect = self.image.get_rect(center = pos)
regen_timer = 0
button = Button((400, 300))
current_health = 50
health = ec.PygameHealthBar(298, 30, 2, 100, current_health, 24, (128, 128, 128), (255, 0, 0))
draw_group = pg.sprite.Group(health, button)
running = True
while running:
for event in pg.event.get():
if event.type == pg.QUIT:
running = False
if button.clicked(event):
current_health -= 1
screen.fill((0, 0, 0))
regen_timer += 1
if regen_timer >= 30:
regen_timer = 0
current_health += 1
health.update_hp(current_health)
draw_group.draw(screen)
pg.display.flip()
clock.tick(60)
if current_health == 0:
running = False
print("you killed the button")
pg.quit()
sys.exitIf you did it correctly you should get a button with a healthbar if you did everytime you click it it goes down after half a second it goes up if it hits 0 then it closes the game and tells you you killed the button
Explaining It
The PygameHealthBar has 8 required positional arguments.
- x, y
x and y is the pos of you health bar if you put it at x is 30 and y is 20 it will be 30 pixels right from the topleft and 20 pixels down from the topleft so like this.
# Import & setup code here
x, y = 100, 40
health = ec.PygameHealthBar(x, y, 1, 50, 40, 30, (200, 200, 200), (200, 0, 0))
# While Loop hereThis if done correctly should display a healthbar at x 100 and y 40.
- width_per_1hp width_per_1hp is how wide in pixels a single health point so if its value is 5 then you take away 1 health point now it loses 5 pixels of health so like this.
# Import & setup code here
width_per_1hp = 3
health = ec.PygameHealthBar(200, 100, width_per_1hp, 50, 40, 30, (200, 200, 200), (200, 0, 0))
# While Loop hereThis if done correctly should mean now everytime the healthbar loses health it changes by 3 pixels.
- max_health
max_health tells the healthbar what the max_health is allowing it to limit your max health and tell the size of it so like this.
# Import & setup code here
max_health = 100
health = ec.PygameHealthBar(200, 100, 1, max_health, 40, 30, (200, 200, 200), (200, 0, 0))
# While Loop hereThis if done correctly should give you a healthbar with 100 hp.
- current_health
current_health tells the healthbar Im at this health right now so based off that information it displays that health so like this.
# Import & setup code here
current_health = 12
health = ec.PygameHealthBar(200, 100, 1, 60, current_health, 30, (200, 200, 200), (200, 0, 0))
# While Loop hereThis if done correctly should display the healthbar's current health as 12.
- bar_height
bar_height tells the healthbar how tall it should be I reccommend at least 5 but for example if you set it to 30 that means the bar will be 30 pixels tall.
# Import & setup code here
bar_height = 40
health = ec.PygameHealthBar(200, 100, 1, 60, 40, bar_height, (200, 200, 200), (200, 0, 0))
# While Loop hereThis when done correctly should display a healthbar that is 40 pixels tall.
- border_color, health_color These 2 arguments tell the color of the bar the bar has a border 2 pixels added every side but the border_color tells it what color the border should be and the health_color tells you what color the health should be like this.
# Import & setup code here
border_color, health_color = (255, 0, 255), (0, 255, 255)
health = ec.PygameHealthBar(200, 100, 1, 60, 40, 24, border_color, health_color)
# While Loop hereThis if done correctly should give you a health bar that has a purple border and cyan health.
Attributes
- refresh_bar, update_hp
these are both the exact same attributes with different names all it does is allows you to update the health.
Local Variables - self.x
- self.y
- self.w_p_1
- self.max_h
- self.height
- self.b_color
- self.h_color
- self.image
- self.rect
You can control these variables and adjust them anyway you want however this may lead to errors. Global Variables - draw_health
You can control this variable and adjust it anyway you want however this may lead to errors.
How To Use
The PygameDraggableSlider has 2 attributes handle_input and get_value it is meant to be able to be dragged to change a number in short so like this.
import easycode as ec
import pygame as pg
import sys
pg.init()
W, H = 800, 600
screen = pg.display.set_mode((W, H))
pg.display.set_caption("Easycode-infinite PygameDraggableSlider Example")
clock = pg.time.Clock()
number = 100
variable = ec.PygameVisibleVariable("Arial", 25, (255, 255, 255), 400, 400, number, False) # ignore this if you have not read visiblevariable yet just put that number and this thing in your code and ignore it
slider = ec.PygameDraggableSlider((255, 255, 255), 400, 100, 300, 500)
draw_group = pg.sprite.Group(slider, variable)
running = True
while running:
for event in pg.event.get():
if event.type == pg.QUIT:
running = False
slider.handle_input(event)
screen.fill((0, 0, 0))
number = int(slider.get_value() * 200)
variable.refresh_image(number)
draw_group.draw(screen)
pg.display.flip()
clock.tick(60)
pg.quit()
sys.exitThis will give you a number that ranges from 0 to 200 and should give you it based off where you put the draggable slider.