# class 사람 :
# def __init__(self,이름,연도) :
# self.연도=연도
# human=사람("유종훈",1986)
# print(human.연도)
# class 사람 :
# def __init__(self,이름) :
# self.성=이름[0]
# self.이름=이름[1:]
# human=사람("유종훈")
# print(human.성)
# print(human.이름)
# class 사람 :
# def __init__(self,친구0,친구1) :
# self.친구0=친구0
# self.친구1=친구1
# human=사람("유종훈","조현호")
# print(human.친구0)
# print(human.친구1)
# class 사람 :
# def __init__(self,친구0,친구1) :
# self.친구=[친구0,친구1]
# human=사람("유종훈","조현호")
# print(human.친구)
# class 사람 :
# def __init__(self) :
# self.친구들=[]
# def 친구추가(self,a):
# self.친구들.append(a)
# human=사람()
# human.친구추가("김하나")
# human.친구추가("김기리")
# print(human.친구들)
# class 사람 :
# def __init__(self,b,c) :
# self.친구들=c
# self.이름=b
# def 친구추가(self,a):
# self.친구들.append(a)
# human=사람("유종훈",["김철수","김영희"])
# human.친구추가("김범수")
# print(human.이름)
# print(human.친구들)
# class 사람 :
# def __init__(self,a,b):
# self.이름=a
# self.친구=b
# def 친구목록(self):
# print(self.이름,"친구목록")
# for i in range(len(self.친구)):
# print("-",self.친구[i])
# human=사람("유종훈",["김철수","김영희"])
# human.친구목록()
# class 사람 :
# def __init__(self,a,b):
# self.이름=a
# self.친구=b
# def 친구목록(self,c):
# for i in range(c):
# print(self.친구[i])
# human=사람("유종훈",["김철수","김영희","박영수","이미자"])
# human.친구목록(3)
# human.친구목록(1)
# class 차 :
# def __init__(self,a,b):
# self.바퀴=a
# self.가격=b
# car=차(2,1000)
# print(car.바퀴)
# print(car.가격)
# class 차 :
# def __init__(self, 바퀴, 가격)
# self.바퀴 = 바퀴
# self.가격 = 가격
# class 자전차(차):
# pass
# class 차 :
# pass
# class 자전차(차):
# def __init__(self,a,b):
# self.가격=b
# self.바퀴=a
# bicycle=자전차(2,100)
# print(bicycle.가격)
# class 차 :
# pass
# class 자전차(차):
# def __init__(self,a,b,c):
# self.가격=b
# self.바퀴=a
# self.구동계=c
# bicycle=자전차(2,100,"시마노")
# print(bicycle.구동계)
# class 차 :
# pass
# class 자동차(차):
# def __init__(self,a,b):
# self.바퀴 = a
# self.가격 = b
# def 정보(self):
# print("바퀴수",self.바퀴)
# print("가격",self.가격)
# car=자동차(4,1000)
# car.정보()
# class 차 :
# def __init__(self, 바퀴, 가격):
# self.바퀴 = 바퀴
# self.가격 = 가격
#
# def 정보(self):
# print("바퀴수",self.바퀴)
# print("가격",self.가격)
# class 자전차(차):
# def __init__(self,a,b):
# super().__init__(a,b)
# bicycle=자전차(2,100)
# bicycle.정보()
# class 차:
# def __init__(self, 바퀴, 가격):
# self.바퀴 = 바퀴
# self.가격 = 가격
# def info(self):
# print("바퀴수", self.바퀴)
# print("가격", self.가격)
# print("구동계",self.구동계)
# class 자전차(차):
# def __init__(self, 바퀴, 가격,구동계):
# super().__init__(바퀴, 가격)
# self.구동계=구동계
# class 자동차(차):
# def __init__(self, 바퀴, 가격):
# super().__init__(바퀴, 가격)
# bicycle=자전차(2,100,"시마노")
# bicycle.info()
# class 부모:
# def 호출(self):
# print("부모호출")
# class 자식:
# def 호출(self):
# print("자식호출")
# 자식()
# class 부모:
# def __init__(self):
# print("부모생성")
#
# class 자식:
# def __init__(self):
# print("자식생성")
#
# 자식()
# class 부모:
# def __init__(self):
# print("부모생성")
# class 자식:
# def __init__(self):
# print("자식생성")
# super().__init__()
import pygame # Pygame 라이브러리 부르기
import random # 난수를 생성하기 위 한 random 모듈 부르기
pygame.init()
# 화면 크기 설정 (가로, 세로)
WIDTH, HEIGHT = 1300, 770
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("JY Dino Game")
# 색상
WHITE = (255, 255, 255)
GREEN = (0, 255, 0)
RED = (255, 0, 0)
black = (0,0,0)
# 공룡 클래스
class Dino:
def __init__(self):
self.rect = pygame.Rect(50, 300, 40, 40) # 크기를 크게 설정
self.jumping = False
self.velocity_y = 0
def jump(self):
if not self.jumping:
self.jumping = True
self.velocity_y = -12 # 점프 높이 조절
def update(self):
self.rect.y += self.velocity_y
self.velocity_y += 0.5 # 중력
if self.rect.y > 300: # 바닥에 닿으면
self.rect.y = 300
self.jumping = False
self.velocity_y = 0 # 속도 초기화
# 장애물 클래스
class Obstacle:
def __init__(self):
self.rect = pygame.Rect(WIDTH, 300, 40, 40)
def update(self):
self.rect.x -= 5
class Score :
def __init__(self):
self.score=0
self.rank='-'
def rank_change(self):
if self.score==0 :
self.rank='Z'
elif 5>=self.score>0 :
self.rank='C'
elif 10>=self.score>5 :
self.rank='B'
elif 20>=self.score>10 :
self.rank='A'
elif 100>self.score>20 :
self.rank='S'
elif self.score>=100 :
self.rank='MASTER'
# 메인 루프
def main():
m = Score()
clock = pygame.time.Clock()
dino = Dino()
isrunning = True
obstacles = []
sum=0
speed = 60
while isrunning:
screen.fill(WHITE)
# 이벤트 처리
for event in pygame.event.get():
if event.type == pygame.QUIT:
isrunning = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
dino.jump()
# 장애물 생성
if random.randint(1, 100 ) <= 3:
if sum==3 :
obstacles.append(Obstacle())
sum=0
else :
sum=sum+1
# 장애물 업데이트
for obs in obstacles[:]:
obs.update()
if obs.rect.x < 0:
obstacles.remove(obs)
speed=speed+m.score
m.score=m.score+1
# 충돌 감지
if dino.rect.colliderect(obs):
isrunning = False
# 공룡 업데이트
dino.update()
# 그리기
pygame.draw.rect(screen, GREEN, dino.rect)
# 장애물 그리기
for obstacle in obstacles:
pygame.draw.rect(screen, RED, obstacle.rect)
myFont = pygame.font.SysFont(None, 40)
textSurface = myFont.render("score:"+str(m.score), True, (0, 0, 0))
screen.blit(textSurface, (800, 80))
myFont = pygame.font.SysFont(None, 40)
m.rank_change()
textSurface = myFont.render(m.rank, True, (0, 0, 0))
screen.blit(textSurface, (800, 110))
pygame.display.flip()
clock.tick(speed)
pygame.quit()
print("점수:",m.score)
print("등급:",m.rank)
# if __name__ == "__main__":
# main()
main()
아무거나 추가해보기top of page

실제 작동 상태를 확인하려면 라이브 사이트로 이동하세요.
20250920
20250920
댓글 0개
좋아요
댓글(0)
더 이상 게시물에 대한 댓글 기능이 지원되지 않습니다. 자세한 사항은 사이트 소유자에게 문의하세요.
bottom of page


