main.py
import controller
def main():
main_window = controller.Controller()
main_window.mainLoop()
main()
controller.py
import sys
import pygame
import Thing
class Controller:
def __init__(self, width=640, height=480):
pygame.init()
self.width = width
self.height = height
self.screen = pygame.display.set_mode((self.width, self.height))
self.background = pygame.Surface(self.screen.get_size()).convert()
pygame.font.init()
self.tree = Thing.Thing(100, 100, "tree.png")
self.display_group = pygame.sprite.Group((self.tree,))
def mainLoop(self):
'''
start the game
'''
while True:
self.gameLoop()
def gameLoop(self):
'''
play the game
'''
pygame.key.set_repeat(1,50)
while True:
self.background.fill((50, 250, 250))
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
self.screen.blit(self.background, (0, 0))
self.display_group.draw(self.screen)
pygame.display.flip()
tree.py
import pygame
class Thing(pygame.sprite.Sprite):
def __init__(self, x, y, img_file):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load(img_file).convert_alpha()
self.rect = self.image.get_rect()
self.rect.x = x
self.rect.y = y
Learn More →
學完了怎麼開關編輯檔案,這裡介紹一個常見的資料格式,許多程式的資料庫或資料顯示方式都是 JSON
Sep 27, 2024(個人見解) 數學是一門學,一個 science,一套規則跟思考方法,不意外古希臘時數學是哲學的其中一個派別,也可以解釋為什麼絕大多數的理工科系是建立在數學之上的。
Sep 27, 2024體驗半隻腳踏入 cs 世界的日常 01 Intro https://hackmd.io/@lhsueh1/python101_intro :::spoiler 02 Accumulation Boolean and or
Mar 2, 2023簡單來說,class 就是自己寫的 type 之前稍微提到「物件導向」這個概念過,那時候我們說 in Python, everything is an object,而物件導向另一個主要的必要條件就是 we create objects,而這個 object 就是 class。(畢竟物件導向就叫 Object-oriented programming) 判斷一個程式語言是不是物件導向就可以用它有沒有 class 來粗略區分。 從之前遇過的各種 type 的經驗,可以總結出 class 常見的內容物有 value 跟 function。 Value 就像是之前用過的 turtle 有 color 或 shape 這些可微調事項,而 function 就像 turtle 可以 .up(), .down(), .goto() 的指令。 __init__ 下面是一個經典的 class
Feb 6, 2023or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up