mirror of
https://github.com/Apologieze/Monkeycrash.git
synced 2026-01-18 16:27:32 +01:00
Update adding balance
This commit is contained in:
119
crash.py
119
crash.py
@@ -18,6 +18,8 @@ screen = pg.display.set_mode(res, pg.FULLSCREEN) if FULLSCREEN else pg.display.s
|
||||
pg.display.set_caption('Monke Crash')
|
||||
clock = pg.time.Clock()
|
||||
bet_balance = 0.0
|
||||
initial_bet = 0.0
|
||||
live_bet = 0.0
|
||||
# pg.mouse.set_visible(False)
|
||||
|
||||
"""Fonction pour passer la fenêtre en thème sombre"""
|
||||
@@ -33,20 +35,23 @@ def dark_bar():
|
||||
pg.display.set_mode(res)
|
||||
|
||||
class Game_state():
|
||||
def __init__(self,balance=50.0):
|
||||
self.balance = balance
|
||||
|
||||
def generate_multiplicateur(self):
|
||||
choice = randint(0, 99)
|
||||
print("choice", choice)
|
||||
if choice < 10:
|
||||
return 1 + (randint(0, 5) / 100)
|
||||
elif choice < 30:
|
||||
return 1 + (randint(1, 50) / 100)
|
||||
elif choice < 60:
|
||||
return 1 + (randint(50, 100) / 100)
|
||||
elif choice < 85:
|
||||
return randint(200, 300) / 100
|
||||
elif choice < 90:
|
||||
return randint(300, 500) / 100
|
||||
elif choice < 40:
|
||||
return 1 + (randint(1, 30) / 100)
|
||||
elif choice < 70:
|
||||
return 1 + (randint(15, 100) / 100)
|
||||
elif choice < 88:
|
||||
return randint(180, 300) / 100
|
||||
elif choice < 95:
|
||||
return randint(300, 500) / 100
|
||||
elif choice < 97:
|
||||
return randint(500, 999) / 100
|
||||
elif choice < 99:
|
||||
return randint(1000, 5000) / 100
|
||||
@@ -68,6 +73,7 @@ class Rocket(pg.sprite.Sprite):
|
||||
self.move_y = -1
|
||||
self.left = False
|
||||
self.fall = False
|
||||
self.fall_index = 0
|
||||
|
||||
self.image = self.rocket_anim[1]
|
||||
self.rect = self.image.get_rect(bottomleft=(-20,res[1]-150))
|
||||
@@ -91,10 +97,14 @@ class Rocket(pg.sprite.Sprite):
|
||||
self.move_y = 0
|
||||
|
||||
def descendre(self):
|
||||
if self.rect.bottom+130 < res[1]:
|
||||
if self.fall_index < 50:
|
||||
new_round()
|
||||
self.fall_index += 1
|
||||
elif self.rect.bottom+110 < res[1]:
|
||||
self.rect.bottom += 10
|
||||
else:
|
||||
self.fall = False
|
||||
self.fall_index = 0
|
||||
self.reset()
|
||||
|
||||
def apply_position(self):
|
||||
@@ -117,6 +127,8 @@ class Rocket(pg.sprite.Sprite):
|
||||
self.text_multi = big_font.render(str(self.live_multi)[0:4]+'x', True, 'white')
|
||||
if self.left:
|
||||
self.text_multi_rect = self.text_multi.get_rect(midright=(self.rect.left, self.rect.centery))
|
||||
if self.live_multi > 9:
|
||||
self.multi_add = 0.05
|
||||
else:
|
||||
self.text_multi_rect = self.text_multi.get_rect(midleft=(self.rect.right-30,self.rect.centery))
|
||||
if self.text_multi_rect.right+20 >= res[0]:
|
||||
@@ -125,6 +137,12 @@ class Rocket(pg.sprite.Sprite):
|
||||
self.change_animation(1)
|
||||
screen.blit(self.text_multi, self.text_multi_rect)
|
||||
|
||||
def update_live_bet(self):
|
||||
global live_bet
|
||||
if not gui.cashout:
|
||||
arrondi = 1 if live_bet > 99 else 2
|
||||
live_bet = round(initial_bet * self.live_multi,arrondi)
|
||||
|
||||
def reset(self):
|
||||
global running
|
||||
self.rect = self.image.get_rect(bottomleft=(-20, res[1] - 150))
|
||||
@@ -144,6 +162,7 @@ class Rocket(pg.sprite.Sprite):
|
||||
self.change_animation(0)
|
||||
self.apply_position()
|
||||
self.multi_update()
|
||||
self.update_live_bet()
|
||||
#self.animation_state()
|
||||
|
||||
class Courbe():
|
||||
@@ -160,36 +179,66 @@ class Courbe():
|
||||
pg.draw.arc(screen, self.color, self.rect, 4.71, self.angle, 5)
|
||||
|
||||
class Gui():
|
||||
def __init__(self):
|
||||
def __init__(self,game):
|
||||
self.game = game
|
||||
self.cashout = False
|
||||
self.point_y = res[1]-148
|
||||
self.background_rect = pg.Rect(0, self.point_y, res[0], 150)
|
||||
self.screen_rect = pg.Rect(res[0]-555, res[1]-70, 330,60)
|
||||
self.text_screen = big_font.render(str(bet_balance)+'¥', True, 'white')
|
||||
self.text_screen_rect = self.text_screen.get_rect(center = self.screen_rect.center)
|
||||
self.static_text = big_font.render("Balance:", True, '#fab3fe')
|
||||
self.static_text_rect = self.static_text.get_rect(bottomleft=(10, res[1]-70))
|
||||
self.balance_text = big_font.render(str(self.game.balance) + '¥', True, '#fab3fe')
|
||||
self.balance_text_rect = self.balance_text.get_rect(bottomleft= (20,res[1]-20))
|
||||
|
||||
self.bet_button = Button(res[0] - 200, res[1] - 110, 168, 66, 1, "Placer", big_font,-1,self)
|
||||
|
||||
self.back_bet_button = Button(res[0] - 820, res[1] - 120, 168, 66, 2, "Retirer", big_font,-3,self)
|
||||
|
||||
self.hundred_button = Button(res[0] - 280, res[1] - 110, 60, 30, 0, '+100', small_font,0,self)
|
||||
self.ten_button = Button(res[0] - 350, res[1] - 110, 60, 30, 0, '+10', small_font,1,self)
|
||||
self.one_button = Button(res[0] - 420, res[1] - 110, 60, 30, 0, '+1', small_font,2,self)
|
||||
self.cents_button = Button(res[0] - 490, res[1] - 110, 60, 30, 0, '+0.1', small_font,3,self)
|
||||
self.x_button = Button(res[0] - 560, res[1] - 110, 60, 30, 3, 'X', small_font,-2,self)
|
||||
self.reset_live_bet()
|
||||
|
||||
def reset_text(self):
|
||||
self.text_screen = big_font.render(str(bet_balance)+'¥', True, 'white')
|
||||
self.text_screen_rect = self.text_screen.get_rect(center = self.screen_rect.center)
|
||||
|
||||
def reset_balance_text(self):
|
||||
aff_balance = str(int(self.game.balance))+str(self.game.balance%1)[1:4]
|
||||
self.balance_text = big_font.render(aff_balance + '¥', True, '#fab3fe')
|
||||
self.balance_text_rect = self.balance_text.get_rect(bottomleft=(20, res[1] - 20))
|
||||
|
||||
def reset_live_bet(self):
|
||||
self.text_live_bet = mid_font.render("Mise en cour: "+str(live_bet)+'¥', True, 'white')
|
||||
self.text_live_bet_rect = self.text_live_bet.get_rect(midleft = (self.screen_rect.left-310, self.screen_rect.centery+15))
|
||||
|
||||
def update(self):
|
||||
pg.draw.rect(screen, "#262626", self.background_rect)
|
||||
pg.draw.rect(screen, (20,20,20), self.screen_rect, border_radius=6)
|
||||
pg.draw.line(screen, "#853370", (0, self.point_y), (res[0], self.point_y), 7)
|
||||
self.bet_button.update()
|
||||
self.hundred_button.update()
|
||||
self.ten_button.update()
|
||||
self.one_button.update()
|
||||
self.cents_button.update()
|
||||
self.x_button.update()
|
||||
if not running:
|
||||
self.bet_button.update()
|
||||
self.hundred_button.update()
|
||||
self.ten_button.update()
|
||||
self.one_button.update()
|
||||
self.cents_button.update()
|
||||
self.x_button.update()
|
||||
self.cashout = False
|
||||
else:
|
||||
self.reset_live_bet()
|
||||
if live_bet != 0:
|
||||
self.back_bet_button.update()
|
||||
|
||||
if live_bet >0:
|
||||
screen.blit(self.text_live_bet, self.text_live_bet_rect)
|
||||
|
||||
screen.blit(self.text_screen, self.text_screen_rect)
|
||||
screen.blit(self.static_text, self.static_text_rect)
|
||||
screen.blit(self.balance_text, self.balance_text_rect)
|
||||
|
||||
class Button():
|
||||
def __init__(self,left,top,width,height,color,text,font,n_id,receiver=None):
|
||||
@@ -200,18 +249,34 @@ class Button():
|
||||
self.color_passive, self.color_active = ('#6441A4', "#392E5C") if color == 1 else ('#0E9DD9', '#12769e')
|
||||
if color == 3:
|
||||
self.color_passive, self.color_active = '#D23636', '#881f1e'
|
||||
elif color == 2:
|
||||
self.color_passive, self.color_active = '#fb7e18', '#d66e1a'
|
||||
self.text = font.render(text, True, 'white')
|
||||
self.text_rect = self.text.get_rect(center=self.rect.center)
|
||||
|
||||
def adding(self):
|
||||
global bet_balance
|
||||
global bet_balance, live_bet, initial_bet
|
||||
change = [100,10,1,0.1]
|
||||
if self.n_id >= 0:
|
||||
bet_balance = round(bet_balance+change[self.n_id],1)
|
||||
elif self.n_id == -2:
|
||||
bet_balance = 0.0
|
||||
elif self.n_id == -1:
|
||||
if bet_balance <= game_state.balance:
|
||||
initial_bet = bet_balance
|
||||
live_bet = bet_balance
|
||||
self.receiver.reset_live_bet()
|
||||
elif self.n_id == -3:
|
||||
self.retirer()
|
||||
|
||||
self.receiver.reset_text()
|
||||
|
||||
def retirer(self):
|
||||
global live_bet
|
||||
game_state.balance += live_bet
|
||||
gui.reset_balance_text()
|
||||
live_bet = 0.0
|
||||
gui.cashout = True
|
||||
|
||||
def update(self):
|
||||
#color = self.color_active if self.rect.collidepoint(pos) and not mou[0] else self.color_passive
|
||||
@@ -252,6 +317,9 @@ class Timer():
|
||||
self.text_rect = self.text.get_rect(center=self.rect.center)
|
||||
|
||||
def reset(self):
|
||||
game_state.balance -= initial_bet
|
||||
gui.reset_balance_text()
|
||||
|
||||
self.angle = 90
|
||||
|
||||
def update(self):
|
||||
@@ -265,22 +333,27 @@ class Timer():
|
||||
running = True
|
||||
self.reset()
|
||||
|
||||
|
||||
def new_round():
|
||||
global live_bet, initial_bet
|
||||
live_bet, initial_bet = 0.0, 0.0
|
||||
gui.reset_live_bet()
|
||||
|
||||
if not FULLSCREEN:
|
||||
dark_bar()
|
||||
|
||||
"""Création de toutes les instances"""
|
||||
number_font = pg.font.Font("Image\Poppins2.ttf", 90)
|
||||
big_font = pg.font.Font("Image\Poppins2.ttf", 40)
|
||||
small_font = pg.font.Font("Image\Poppins2.ttf", 20)
|
||||
number_font = pg.font.Font("Image/Poppins2.ttf", 90)
|
||||
big_font = pg.font.Font("Image/Poppins2.ttf", 40)
|
||||
mid_font = pg.font.Font("Image/Poppins2.ttf", 30)
|
||||
small_font = pg.font.Font("Image/Poppins2.ttf", 20)
|
||||
|
||||
game_state = Game_state(100.0)
|
||||
rocket = pg.sprite.GroupSingle()
|
||||
rocket.add(Rocket(Game_state()))
|
||||
rocket.add(Rocket(game_state))
|
||||
|
||||
courbe = Courbe()
|
||||
|
||||
gui = Gui()
|
||||
gui = Gui(game_state)
|
||||
|
||||
timer = Timer()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user