-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
90 lines (72 loc) · 2.73 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
import sys
import pygame as pg
import os
from pygame.locals import * # import all constants (not good practice)
from graphics.sprites.card import Card
from graphics.sprites.deck import Deck
from graphics.sprites.character import Character
from graphics.constants import (SCREEN_SIZE, BACKGROUND, ORIGIN, LEFT_MOUSE)
from graphics.sprites.card_overview import CardOverview
from graphics.lib.spritestripanim import SpriteStripAnim
__CURDIR__ = os.path.dirname(os.path.realpath(__file__)) + '/'
__GRAPHICSDIR__ = __CURDIR__ + 'graphics/'
shooting_spritesheet = __GRAPHICSDIR__ + 'img/shooting_spritesheet.png'
FPS = 120
frames = FPS / 12
def initialize():
global window
pg.init()
window = pg.display.set_mode(SCREEN_SIZE)
def get_background():
bg_img = pg.image.load(__GRAPHICSDIR__ + BACKGROUND).convert()
bg_img = pg.transform.smoothscale(bg_img, SCREEN_SIZE)
return bg_img
def set_background():
window.blit(bg_img, ORIGIN)
clock = pg.time.Clock()
if __name__ == '__main__':
initialize()
strips = [
SpriteStripAnim(shooting_spritesheet, (0, 0, 400, 620), 6, -1, True, frames)
]
n = 0
strips[n].iter()
shooting_image = strips[n].next()
bg_img = get_background()
my_deck = Deck()
card1 = Card(__GRAPHICSDIR__ + 'img/bang.png')
card2 = Card(__GRAPHICSDIR__ + 'img/beer.png')
card3 = Card(__GRAPHICSDIR__ + 'img/gatling.png')
card4 = Card(__GRAPHICSDIR__ + 'img/missed.png')
card5 = Card(__GRAPHICSDIR__ + 'img/Trang.png')
overview_card = CardOverview(__GRAPHICSDIR__ + 'img/back-playing.png')
my_deck.get_card(card1)
my_deck.get_card(card2)
my_deck.get_card(card3)
my_deck.get_card(card4)
my_deck.get_card(card5)
char1 = Character(__GRAPHICSDIR__ + 'img/molly_stark.png', 4)
while True:
set_background()
char1.display_all(window)
my_deck.display_all_cards(window)
overview_card.reset_img(window)
for event in pg.event.get():
if event.type == QUIT:
pg.quit()
sys.exit()
elif event.type == MOUSEBUTTONUP and event.button == LEFT_MOUSE:
my_deck.on_click(event.pos)
elif event.type == MOUSEMOTION:
target_card = my_deck.on_hover(event.pos)
if target_card is not None:
overview_card.update_img(
target_card.get_image_path(), window)
else:
if char1.is_hover(event.pos):
overview_card.update_img(
__GRAPHICSDIR__ + 'img/molly_stark.png', window)
window.blit(shooting_image, (250, 0))
pg.display.flip()
shooting_image = strips[n].next()
clock.tick(FPS)