diff --git a/__pycache__/pygame.cpython-39.pyc b/__pycache__/pygame.cpython-39.pyc new file mode 100644 index 00000000..065764f2 Binary files /dev/null and b/__pycache__/pygame.cpython-39.pyc differ diff --git a/main.py b/main.py index 9421809f..390ee75d 100644 --- a/main.py +++ b/main.py @@ -3,4 +3,7 @@ if __name__=='__main__': main() - pg.quit() \ No newline at end of file + pg.quit() + +#커밋 테스트 +#커밋 테스트 by jonghyun diff --git a/resources/graphics/Screen/Adventure_0.png b/resources/graphics/Screen/Adventure_0.png index 78c12fc1..a69cc236 100644 Binary files a/resources/graphics/Screen/Adventure_0.png and b/resources/graphics/Screen/Adventure_0.png differ diff --git a/resources/graphics/Screen/Adventure_1.png b/resources/graphics/Screen/Adventure_1.png index f2825cb2..add0ad84 100644 Binary files a/resources/graphics/Screen/Adventure_1.png and b/resources/graphics/Screen/Adventure_1.png differ diff --git a/resources/graphics/Screen/ClickedEasy.png b/resources/graphics/Screen/ClickedEasy.png new file mode 100644 index 00000000..73c38faf Binary files /dev/null and b/resources/graphics/Screen/ClickedEasy.png differ diff --git a/resources/graphics/Screen/ClickedHard.png b/resources/graphics/Screen/ClickedHard.png new file mode 100644 index 00000000..f241f327 Binary files /dev/null and b/resources/graphics/Screen/ClickedHard.png differ diff --git a/resources/graphics/Screen/ClickedMuteSound.png b/resources/graphics/Screen/ClickedMuteSound.png new file mode 100644 index 00000000..24e2f5f7 Binary files /dev/null and b/resources/graphics/Screen/ClickedMuteSound.png differ diff --git a/resources/graphics/Screen/ClickedNormal.png b/resources/graphics/Screen/ClickedNormal.png new file mode 100644 index 00000000..460660b4 Binary files /dev/null and b/resources/graphics/Screen/ClickedNormal.png differ diff --git a/resources/graphics/Screen/ClickedSound.png b/resources/graphics/Screen/ClickedSound.png new file mode 100644 index 00000000..7e4429e7 Binary files /dev/null and b/resources/graphics/Screen/ClickedSound.png differ diff --git a/resources/graphics/Screen/EasyMode.png b/resources/graphics/Screen/EasyMode.png new file mode 100644 index 00000000..c2f8082a Binary files /dev/null and b/resources/graphics/Screen/EasyMode.png differ diff --git a/resources/graphics/Screen/GameOff.png b/resources/graphics/Screen/GameOff.png new file mode 100644 index 00000000..18348f40 Binary files /dev/null and b/resources/graphics/Screen/GameOff.png differ diff --git a/resources/graphics/Screen/HardMode.png b/resources/graphics/Screen/HardMode.png new file mode 100644 index 00000000..6697f6ec Binary files /dev/null and b/resources/graphics/Screen/HardMode.png differ diff --git a/resources/graphics/Screen/Item1_1.png b/resources/graphics/Screen/Item1_1.png new file mode 100644 index 00000000..ce92e003 Binary files /dev/null and b/resources/graphics/Screen/Item1_1.png differ diff --git a/resources/graphics/Screen/Item1_2.png b/resources/graphics/Screen/Item1_2.png new file mode 100644 index 00000000..ed75b40c Binary files /dev/null and b/resources/graphics/Screen/Item1_2.png differ diff --git a/resources/graphics/Screen/Item2_1.png b/resources/graphics/Screen/Item2_1.png new file mode 100644 index 00000000..aabe6f64 Binary files /dev/null and b/resources/graphics/Screen/Item2_1.png differ diff --git a/resources/graphics/Screen/Item2_2.png b/resources/graphics/Screen/Item2_2.png new file mode 100644 index 00000000..cfaeb775 Binary files /dev/null and b/resources/graphics/Screen/Item2_2.png differ diff --git a/resources/graphics/Screen/MainMenuBtn.png b/resources/graphics/Screen/MainMenuBtn.png new file mode 100644 index 00000000..f3b3b87b Binary files /dev/null and b/resources/graphics/Screen/MainMenuBtn.png differ diff --git a/resources/graphics/Screen/NextStageBtn.png b/resources/graphics/Screen/NextStageBtn.png new file mode 100644 index 00000000..973a6bcc Binary files /dev/null and b/resources/graphics/Screen/NextStageBtn.png differ diff --git a/resources/graphics/Screen/NormalMode.png b/resources/graphics/Screen/NormalMode.png new file mode 100644 index 00000000..e88cab0f Binary files /dev/null and b/resources/graphics/Screen/NormalMode.png differ diff --git a/resources/graphics/Screen/Shovel.png b/resources/graphics/Screen/Shovel.png new file mode 100644 index 00000000..25634980 Binary files /dev/null and b/resources/graphics/Screen/Shovel.png differ diff --git a/resources/graphics/Screen/Sound.png b/resources/graphics/Screen/Sound.png new file mode 100644 index 00000000..af6a8fdb Binary files /dev/null and b/resources/graphics/Screen/Sound.png differ diff --git a/resources/graphics/Screen/SunFlower_1.png b/resources/graphics/Screen/SunFlower_1.png new file mode 100644 index 00000000..bbeddaba Binary files /dev/null and b/resources/graphics/Screen/SunFlower_1.png differ diff --git a/resources/graphics/Screen/muteSound.png b/resources/graphics/Screen/muteSound.png new file mode 100644 index 00000000..3b555a68 Binary files /dev/null and b/resources/graphics/Screen/muteSound.png differ diff --git a/resources/graphics/Screen/sound_off.png b/resources/graphics/Screen/sound_off.png new file mode 100644 index 00000000..7ca1da7b Binary files /dev/null and b/resources/graphics/Screen/sound_off.png differ diff --git a/resources/graphics/Screen/sound_on.png b/resources/graphics/Screen/sound_on.png new file mode 100644 index 00000000..59b6251e Binary files /dev/null and b/resources/graphics/Screen/sound_on.png differ diff --git a/resources/graphics/Screen/speedup1.png b/resources/graphics/Screen/speedup1.png new file mode 100644 index 00000000..04ee6db9 Binary files /dev/null and b/resources/graphics/Screen/speedup1.png differ diff --git a/resources/graphics/Screen/speedup2.png b/resources/graphics/Screen/speedup2.png new file mode 100644 index 00000000..bb469c99 Binary files /dev/null and b/resources/graphics/Screen/speedup2.png differ diff --git a/resources/graphics/Screen/speedup3.png b/resources/graphics/Screen/speedup3.png new file mode 100644 index 00000000..f465917f Binary files /dev/null and b/resources/graphics/Screen/speedup3.png differ diff --git a/resources/graphics/Screen/test.png b/resources/graphics/Screen/test.png new file mode 100644 index 00000000..c376653f Binary files /dev/null and b/resources/graphics/Screen/test.png differ diff --git a/source/__pycache__/__init__.cpython-37.pyc b/source/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 00000000..34bdbacf Binary files /dev/null and b/source/__pycache__/__init__.cpython-37.pyc differ diff --git a/source/__pycache__/__init__.cpython-39.pyc b/source/__pycache__/__init__.cpython-39.pyc new file mode 100644 index 00000000..b00c77a2 Binary files /dev/null and b/source/__pycache__/__init__.cpython-39.pyc differ diff --git a/source/__pycache__/constants.cpython-37.pyc b/source/__pycache__/constants.cpython-37.pyc new file mode 100644 index 00000000..44dddfed Binary files /dev/null and b/source/__pycache__/constants.cpython-37.pyc differ diff --git a/source/__pycache__/constants.cpython-39.pyc b/source/__pycache__/constants.cpython-39.pyc new file mode 100644 index 00000000..9120a3ac Binary files /dev/null and b/source/__pycache__/constants.cpython-39.pyc differ diff --git a/source/__pycache__/main.cpython-37.pyc b/source/__pycache__/main.cpython-37.pyc new file mode 100644 index 00000000..5e209fd3 Binary files /dev/null and b/source/__pycache__/main.cpython-37.pyc differ diff --git a/source/__pycache__/main.cpython-39.pyc b/source/__pycache__/main.cpython-39.pyc new file mode 100644 index 00000000..75b49142 Binary files /dev/null and b/source/__pycache__/main.cpython-39.pyc differ diff --git a/source/__pycache__/tool.cpython-37.pyc b/source/__pycache__/tool.cpython-37.pyc new file mode 100644 index 00000000..9449bf17 Binary files /dev/null and b/source/__pycache__/tool.cpython-37.pyc differ diff --git a/source/__pycache__/tool.cpython-39.pyc b/source/__pycache__/tool.cpython-39.pyc new file mode 100644 index 00000000..4e10a047 Binary files /dev/null and b/source/__pycache__/tool.cpython-39.pyc differ diff --git a/source/component/__pycache__/__init__.cpython-37.pyc b/source/component/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 00000000..b47b2860 Binary files /dev/null and b/source/component/__pycache__/__init__.cpython-37.pyc differ diff --git a/source/component/__pycache__/__init__.cpython-39.pyc b/source/component/__pycache__/__init__.cpython-39.pyc new file mode 100644 index 00000000..60886b85 Binary files /dev/null and b/source/component/__pycache__/__init__.cpython-39.pyc differ diff --git a/source/component/__pycache__/map.cpython-37.pyc b/source/component/__pycache__/map.cpython-37.pyc new file mode 100644 index 00000000..2b747844 Binary files /dev/null and b/source/component/__pycache__/map.cpython-37.pyc differ diff --git a/source/component/__pycache__/map.cpython-39.pyc b/source/component/__pycache__/map.cpython-39.pyc new file mode 100644 index 00000000..df9df2ff Binary files /dev/null and b/source/component/__pycache__/map.cpython-39.pyc differ diff --git a/source/component/__pycache__/menubar.cpython-37.pyc b/source/component/__pycache__/menubar.cpython-37.pyc new file mode 100644 index 00000000..717f6d6e Binary files /dev/null and b/source/component/__pycache__/menubar.cpython-37.pyc differ diff --git a/source/component/__pycache__/menubar.cpython-39.pyc b/source/component/__pycache__/menubar.cpython-39.pyc new file mode 100644 index 00000000..3c27cd67 Binary files /dev/null and b/source/component/__pycache__/menubar.cpython-39.pyc differ diff --git a/source/component/__pycache__/plant.cpython-37.pyc b/source/component/__pycache__/plant.cpython-37.pyc new file mode 100644 index 00000000..ea41954c Binary files /dev/null and b/source/component/__pycache__/plant.cpython-37.pyc differ diff --git a/source/component/__pycache__/plant.cpython-39.pyc b/source/component/__pycache__/plant.cpython-39.pyc new file mode 100644 index 00000000..6c105547 Binary files /dev/null and b/source/component/__pycache__/plant.cpython-39.pyc differ diff --git a/source/component/__pycache__/zombie.cpython-37.pyc b/source/component/__pycache__/zombie.cpython-37.pyc new file mode 100644 index 00000000..5ea3a047 Binary files /dev/null and b/source/component/__pycache__/zombie.cpython-37.pyc differ diff --git a/source/component/__pycache__/zombie.cpython-39.pyc b/source/component/__pycache__/zombie.cpython-39.pyc new file mode 100644 index 00000000..7947c8e9 Binary files /dev/null and b/source/component/__pycache__/zombie.cpython-39.pyc differ diff --git a/source/component/menubar.py b/source/component/menubar.py index 56054a52..f13b1dc9 100644 --- a/source/component/menubar.py +++ b/source/component/menubar.py @@ -1,9 +1,11 @@ __author__ = 'marble_xu' +import os import random import pygame as pg from .. import tool from .. import constants as c +from ..state import mainmenu as main PANEL_Y_START = 87 PANEL_X_START = 22 @@ -65,6 +67,10 @@ def __init__(self, x, y, name_index, scale=0.78): self.refresh_timer = 0 self.select = True + self.sound_dir = os.path.join('source','sound') #경로 추가 + self.start_sound = pg.mixer.Sound(os.path.join(self.sound_dir, '게임시작버튼.mp3')) #버튼을 누르는 소리 + self.start_sound.set_volume(2) #소리크기 설정 + def loadFrame(self, name, scale): frame = tool.GFX[name] rect = frame.get_rect() @@ -77,6 +83,8 @@ def checkMouseClick(self, mouse_pos): x, y = mouse_pos if(x >= self.rect.x and x <= self.rect.right and y >= self.rect.y and y <= self.rect.bottom): + if(main.Menu().isClickedSound()) : + self.start_sound.play() #소리를 재생합니다 return True return False @@ -251,6 +259,10 @@ def loadImages(self, sun_value): self.button_rect.x = 155 self.button_rect.y = 547 + self.sound_dir = os.path.join('source','sound') #경로 추가 + self.start_sound = pg.mixer.Sound(os.path.join(self.sound_dir, '게임시작버튼.mp3')) #시작버튼을 누르는 소리 + self.start_sound.set_volume(2) #소리크기 설정 + def setupCards(self, card_list): self.card_list = [] x = PANEL_X_START - PANEL_X_INTERNAL @@ -301,6 +313,8 @@ def checkStartButtonClick(self, mouse_pos): x, y = mouse_pos if (x >= self.button_rect.x and x <= self.button_rect.right and y >= self.button_rect.y and y <= self.button_rect.bottom): + if(main.Menu().isClickedSound()) : + self.start_sound.play() #소리를 재생합니다 return True return False diff --git a/source/component/plant.py b/source/component/plant.py index 684065b1..a48e06a3 100644 --- a/source/component/plant.py +++ b/source/component/plant.py @@ -2,8 +2,13 @@ import random import pygame as pg +from pygame.color import Color from .. import tool from .. import constants as c +import os +from ..state import mainmenu as main + + class Car(pg.sprite.Sprite): def __init__(self, x, y, map_y): @@ -19,18 +24,24 @@ def __init__(self, x, y, map_y): self.state = c.IDLE self.dead = False + self.sound_dir = os.path.join('source','sound') #경로 추가 + self.drive_sound = pg.mixer.Sound(os.path.join(self.sound_dir, '잔디깎이돌진.mp3')) #잔디깎이가 돌진하는 소리 + self.drive_sound.set_volume(0.1) + def update(self, game_info): self.current_time = game_info[c.CURRENT_TIME] if self.state == c.IDLE: pass elif self.state == c.WALK: - self.rect.x += 4 + self.rect.x += 4 * c.DELTA_TIME if self.rect.x > c.SCREEN_WIDTH: self.dead = True def setWalk(self): if self.state == c.IDLE: self.state = c.WALK + if(main.Menu().isClickedSound()) : + self.drive_sound.play() def draw(self, surface): surface.blit(self.image, self.rect) @@ -55,6 +66,12 @@ def __init__(self, x, start_y, dest_y, name, damage, ice): self.state = c.FLY self.current_time = 0 + self.sound_dir = os.path.join('source','sound') #경로 추가 + self.attack_sound = pg.mixer.Sound(os.path.join(self.sound_dir, '식물이공격하는소리.mp3')) #식물이 공격하는 소리 + self.attack_sound.set_volume(0.2) + if(main.Menu().isClickedSound()) : + self.attack_sound.play() + def loadFrames(self, frames, name): frame_list = tool.GFX[name] if name in tool.PLANT_RECT: @@ -87,10 +104,10 @@ def update(self, game_info): self.current_time = game_info[c.CURRENT_TIME] if self.state == c.FLY: if self.rect.y != self.dest_y: - self.rect.y += self.y_vel + self.rect.y += self.y_vel * c.DELTA_TIME if self.y_vel * (self.dest_y - self.rect.y) < 0: self.rect.y = self.dest_y - self.rect.x += self.x_vel + self.rect.x += self.x_vel * c.DELTA_TIME if self.rect.x > c.SCREEN_WIDTH: self.kill() elif self.state == c.EXPLODE: @@ -128,6 +145,15 @@ def __init__(self, x, y, name, health, bullet_group, scale=1): self.animate_interval = 100 self.hit_timer = 0 + + self.sound_dir = os.path.join('source','sound') #경로 추가 + self.attack_sound = pg.mixer.Sound(os.path.join(self.sound_dir, '식물이공격하는소리.mp3')) #식물이 공격하는 소리 + self.attack_sound.set_volume(0.2) + + self.atkUpTimer = 0 + self.isShooter = False + + def loadFrames(self, frames, name, scale, color=c.BLACK): frame_list = tool.GFX[name] if name in tool.PLANT_RECT: @@ -192,6 +218,14 @@ def animation(self): else: self.image.set_alpha(192) + if(c.ATK_TIME_UP == 2 and self.isShooter): + if(self.current_time - self.atkUpTimer) >= 300: + self.image.set_alpha(255) + self.atkUpTimer = self.current_time + else: + self.image.set_alpha(192) + + def canAttack(self, zombie): if (self.state != c.SLEEP and zombie.state != c.DIE and self.rect.x <= zombie.rect.right): @@ -227,16 +261,20 @@ def __init__(self, x, y, dest_x, dest_y, is_big=True): scale = 0.6 self.sun_value = 12 Plant.__init__(self, x, y, c.SUN, 0, None, scale) - self.move_speed = 1 + self.move_speed = 1 self.dest_x = dest_x self.dest_y = dest_y self.die_timer = 0 + self.sound_dir = os.path.join('source','sound') #경로 추가 + self.getSun_sound = pg.mixer.Sound(os.path.join(self.sound_dir, '빛에너지.mp3')) #빛에너지를 먹는 소리 + + def handleState(self): if self.rect.centerx != self.dest_x: - self.rect.centerx += self.move_speed if self.rect.centerx < self.dest_x else -self.move_speed + self.rect.centerx += self.move_speed * c.DELTA_TIME if self.rect.centerx < self.dest_x else -self.move_speed * c.DELTA_TIME if self.rect.bottom != self.dest_y: - self.rect.bottom += self.move_speed if self.rect.bottom < self.dest_y else -self.move_speed + self.rect.bottom += self.move_speed * c.DELTA_TIME if self.rect.bottom < self.dest_y else -self.move_speed * c.DELTA_TIME if self.rect.centerx == self.dest_x and self.rect.bottom == self.dest_y: if self.die_timer == 0: @@ -250,6 +288,8 @@ def checkCollision(self, x, y): return False if(x >= self.rect.x and x <= self.rect.right and y >= self.rect.y and y <= self.rect.bottom): + if(main.Menu().isClickedSound()) : + self.getSun_sound.play() self.state = c.DIE self.kill() return True @@ -272,9 +312,11 @@ class PeaShooter(Plant): def __init__(self, x, y, bullet_group): Plant.__init__(self, x, y, c.PEASHOOTER, c.PLANT_HEALTH, bullet_group) self.shoot_timer = 0 - + self.isShooter = True def attacking(self): - if (self.current_time - self.shoot_timer) > 2000: + if (self.current_time - self.shoot_timer) > 2000 / c.ATK_TIME_UP: + if(main.Menu().isClickedSound()) : + self.attack_sound.play() #소리 재생 self.bullet_group.add(Bullet(self.rect.right, self.rect.y, self.rect.y, c.BULLET_PEA, c.BULLET_DAMAGE_NORMAL, False)) self.shoot_timer = self.current_time @@ -283,9 +325,12 @@ class RepeaterPea(Plant): def __init__(self, x, y, bullet_group): Plant.__init__(self, x, y, c.REPEATERPEA, c.PLANT_HEALTH, bullet_group) self.shoot_timer = 0 + self.isShooter = True def attacking(self): - if (self.current_time - self.shoot_timer) > 2000: + if (self.current_time - self.shoot_timer) > 2000 / c.ATK_TIME_UP: + if(main.Menu().isClickedSound()) : + self.attack_sound.play() #소리 재생 self.bullet_group.add(Bullet(self.rect.right, self.rect.y, self.rect.y, c.BULLET_PEA, c.BULLET_DAMAGE_NORMAL, False)) self.bullet_group.add(Bullet(self.rect.right + 40, self.rect.y, self.rect.y, @@ -298,9 +343,12 @@ def __init__(self, x, y, bullet_groups, map_y): self.shoot_timer = 0 self.map_y = map_y self.bullet_groups = bullet_groups + self.isShooter = True def attacking(self): - if (self.current_time - self.shoot_timer) > 2000: + if (self.current_time - self.shoot_timer) > 2000 / c.ATK_TIME_UP: + if(main.Menu().isClickedSound()) : + self.attack_sound.play() #소리 재생 offset_y = 9 # modify bullet in the same y position with bullets of other plants for i in range(3): tmp_y = self.map_y + (i - 1) @@ -315,9 +363,12 @@ class SnowPeaShooter(Plant): def __init__(self, x, y, bullet_group): Plant.__init__(self, x, y, c.SNOWPEASHOOTER, c.PLANT_HEALTH, bullet_group) self.shoot_timer = 0 + self.isShooter = True def attacking(self): - if (self.current_time - self.shoot_timer) > 2000: + if (self.current_time - self.shoot_timer) > 2000 / c.ATK_TIME_UP: + if(main.Menu().isClickedSound()) : + self.attack_sound.play() #소리 재생 self.bullet_group.add(Bullet(self.rect.right, self.rect.y, self.rect.y, c.BULLET_PEA_ICE, c.BULLET_DAMAGE_NORMAL, True)) self.shoot_timer = self.current_time @@ -446,6 +497,8 @@ def digest(self): elif (self.current_time - self.digest_timer) > self.digest_interval: self.digest_timer = 0 self.attack_zombie.kill() + #식물쪽에서 좀비를 죽이는거 카운트 + tool.GameManager.getInstance().addKillZombieCount() self.setIdle() class PuffShroom(Plant): @@ -570,6 +623,8 @@ def attacking(self): self.zombie_group.remove(self.attack_zombie) if (self.frame_index + 1) == self.frame_num: self.attack_zombie.kill() + #식물쪽에서 좀비를 죽이는거 카운트 + tool.GameManager.getInstance().addKillZombieCount() self.health = 0 elif self.aim_timer == 0: self.aim_timer = self.current_time @@ -847,8 +902,8 @@ def idling(self): self.move_timer = self.current_time elif (self.current_time - self.move_timer) >= self.move_interval: self.rotate_degree = (self.rotate_degree - 30) % 360 - self.init_rect.x += self.vel_x - self.init_rect.y += self.vel_y + self.init_rect.x += self.vel_x * c.DELTA_TIME + self.init_rect.y += self.vel_y * c.DELTA_TIME self.handleMapYPosition() if self.shouldChangeDirection(): self.changeDirection(-1) @@ -940,7 +995,7 @@ def idling(self): self.move_timer = self.current_time elif (self.current_time - self.move_timer) >= self.move_interval: self.rotate_degree = (self.rotate_degree - 30) % 360 - self.init_rect.x += self.vel_x + self.init_rect.x += self.vel_x * c.DELTA_TIME if self.init_rect.x > c.SCREEN_WIDTH: self.health = 0 self.move_timer += self.move_interval diff --git a/source/component/zombie.py b/source/component/zombie.py index 73780f13..42bb417e 100644 --- a/source/component/zombie.py +++ b/source/component/zombie.py @@ -1,8 +1,11 @@ __author__ = 'marble_xu' +import os import pygame as pg from .. import tool from .. import constants as c +from ..state import mainmenu as main + class Zombie(pg.sprite.Sprite): def __init__(self, x, y, name, health, head_group=None, damage=1): @@ -19,6 +22,12 @@ def __init__(self, x, y, name, health, head_group=None, damage=1): self.rect.centerx = x self.rect.bottom = y + self.sound_dir = os.path.join('source','sound') #경로 추가 + self.dying_sound = pg.mixer.Sound(os.path.join(self.sound_dir, '좀비가죽을때.mp3')) #좀비가 죽는 소리 + self.headDrop_sound = pg.mixer.Sound(os.path.join(self.sound_dir, '좀비머리가떨어질때.mp3')) #좀비 머리가 떨어질 때 소리 + self.dying_sound.set_volume(0.5) + self.headDrop_sound.set_volume(0.5) + self.health = health self.damage = damage self.dead = False @@ -34,7 +43,7 @@ def __init__(self, x, y, name, health, head_group=None, damage=1): self.ice_slow_ratio = 1 self.ice_slow_timer = 0 self.hit_timer = 0 - self.speed = 1 + self.speed = 1 self.freeze_timer = 0 self.is_hypno = False # the zombie is hypo and attack other zombies when it ate a HypnoShroom @@ -78,9 +87,9 @@ def walking(self): if (self.current_time - self.walk_timer) > (c.ZOMBIE_WALK_INTERVAL * self.getTimeRatio()): self.walk_timer = self.current_time if self.is_hypno: - self.rect.x += self.speed + self.rect.x += self.speed * c.DELTA_TIME else: - self.rect.x -= self.speed + self.rect.x -= self.speed * c.DELTA_TIME def attacking(self): if self.health <= 0: @@ -104,6 +113,7 @@ def attacking(self): self.setWalk() def dying(self): + pass def freezing(self): @@ -120,6 +130,9 @@ def freezing(self): def setLostHead(self): self.losHead = True + if(main.Menu().isClickedSound()) : + self.headDrop_sound.play() #소리를 재생합니다 + if self.head_group is not None: self.head_group.add(ZombieHead(self.rect.centerx, self.rect.bottom)) @@ -203,9 +216,12 @@ def setAttack(self, prey, is_plant=True): self.changeFrames(self.attack_frames) def setDie(self): + if(main.Menu().isClickedSound()) : + self.dying_sound.play() #소리를 재생합니다 self.state = c.DIE self.animate_interval = 200 self.changeFrames(self.die_frames) + tool.GameManager.getInstance().addKillZombieCount() def setBoomDie(self): self.state = c.DIE diff --git a/source/constants.py b/source/constants.py index 0c4e2b6e..91a684eb 100644 --- a/source/constants.py +++ b/source/constants.py @@ -1,6 +1,6 @@ __author__ = 'marble_xu' -START_LEVEL_NUM = 1 +START_LEVEL_NUM = 0 ORIGINAL_CAPTION = 'Plant VS Zombies Game' @@ -41,6 +41,33 @@ OPTION_ADVENTURE = 'Adventure' GAME_LOOSE_IMAGE = 'GameLoose' GAME_VICTORY_IMAGE = 'GameVictory' +OPTION_GAMEOFF = 'GameOff' + +SOUND_MUTE_IMAGE = 'muteSound' +CLICKED_MUTE_IMAGE = 'ClickedMuteSound' +SOUND_IMAGE = 'Sound' +CLICKED_SOUND_IMAGE = 'ClickedSound' + +EASY_IMAGE = 'EasyMode' +CLICKED_EASY = 'ClickedEasy' +NORMAL_IMAGE = 'NormalMode' +CLICKED_NORMAL = 'ClickedNormal' +HARD_IMAGE = 'HardMode' +CLICKED_HARD = 'ClickedHard' + +GAMEFINISHED_MAINMENU_BUTTON = 'MainMenuBtn' +GAMEFINISHED_NEXTSTAGE_BUTTON = 'NextStageBtn' + +SPEED_UP_BUTTON_1 = "speedup1" +SPEED_UP_BUTTON_2 = "speedup2" +SPEED_UP_BUTTON_3 = "speedup3" + +ITEM_1_1 = "Item1_1" +ITEM_1_2 = "Item1_2" + +ITEM_2_1 = "Item2_1" +ITEM_2_2 = "Item2_2" + #MAP COMPONENTS BACKGROUND_NAME = 'Background' @@ -177,4 +204,23 @@ #BACKGROUND BACKGROUND_DAY = 0 -BACKGROUND_NIGHT = 1 \ No newline at end of file +BACKGROUND_NIGHT = 1 + +#이중화 배속 기능 +DELTA_TIME = 1.0 +#식물들 공속 업 +#기본 1 아이템 눌렀을 때 2 일정시간 지나면 다시 1 +ATK_TIME_UP = 1 +#햇빛 많이 떨어지는 아이템 +#눌렀을 때 10 +SUN_TIME_UP = 1 + +#Shovel for remove planted plants +SHOVEL_IMAGE = 'Shovel' + +#중화 난이도 +#기본 1 메인화면에서 버튼 눌러서 변경 +LEVEL_DIFFICULTY = 1 + +#사운드 켜져있는지 아닌지 +SOUND_ON = True \ No newline at end of file diff --git a/source/data/map/level_1.json b/source/data/map/level_1.json index 59801a4d..2e0fa65d 100644 --- a/source/data/map/level_1.json +++ b/source/data/map/level_1.json @@ -1,13 +1,13 @@ { "background_type":0, - "init_sun_value":50, + "init_sun_value":150, "zombie_list":[ - {"time":20000, "map_y":0, "name":"Zombie"}, - {"time":40000, "map_y":2, "name":"FlagZombie"}, - {"time":50000, "map_y":4, "name":"Zombie"}, - {"time":70000, "map_y":3, "name":"Zombie"}, - {"time":72000, "map_y":1, "name":"FlagZombie"}, - {"time":74000, "map_y":2, "name":"Zombie"}, + {"time":60000, "map_y":0, "name":"Zombie"}, + {"time":60000, "map_y":2, "name":"FlagZombie"}, + {"time":70000, "map_y":4, "name":"Zombie"}, + {"time":80000, "map_y":3, "name":"Zombie"}, + {"time":82000, "map_y":1, "name":"FlagZombie"}, + {"time":84000, "map_y":2, "name":"Zombie"}, {"time":90000, "map_y":0, "name":"Zombie"}, {"time":91000, "map_y":1, "name":"FlagZombie"}, {"time":92000, "map_y":2, "name":"Zombie"}, diff --git a/source/data/map/level_e0.json b/source/data/map/level_e0.json new file mode 100644 index 00000000..c22fd757 --- /dev/null +++ b/source/data/map/level_e0.json @@ -0,0 +1,7 @@ +{ + "background_type":0, + "init_sun_value":500, + "zombie_list":[ + {"time":1000, "map_y":2, "name":"Zombie"} + ] +} \ No newline at end of file diff --git a/source/data/map/level_e1.json b/source/data/map/level_e1.json new file mode 100644 index 00000000..50655245 --- /dev/null +++ b/source/data/map/level_e1.json @@ -0,0 +1,16 @@ +{ + "background_type":0, + "init_sun_value":150, + "zombie_list":[ + {"time":60000, "map_y":0, "name":"Zombie"}, + {"time":60000, "map_y":2, "name":"FlagZombie"}, + {"time":70000, "map_y":4, "name":"Zombie"}, + {"time":80000, "map_y":3, "name":"Zombie"}, + {"time":82000, "map_y":1, "name":"FlagZombie"}, + {"time":84000, "map_y":2, "name":"Zombie"}, + {"time":91000, "map_y":1, "name":"FlagZombie"}, + {"time":93000, "map_y":3, "name":"FlagZombie"}, + {"time":94000, "map_y":0, "name":"Zombie"}, + {"time":95000, "map_y":4, "name":"FlagZombie"} + ] +} \ No newline at end of file diff --git a/source/data/map/level_e2.json b/source/data/map/level_e2.json new file mode 100644 index 00000000..999d80d6 --- /dev/null +++ b/source/data/map/level_e2.json @@ -0,0 +1,16 @@ +{ + "background_type":0, + "init_sun_value":50, + "zombie_list":[ + {"time":20000, "map_y":0, "name":"Zombie"}, + {"time":40000, "map_y":2, "name":"FlagZombie"}, + {"time":70000, "map_y":3, "name":"ConeheadZombie"}, + {"time":72000, "map_y":1, "name":"FlagZombie"}, + {"time":74000, "map_y":2, "name":"ConeheadZombie"}, + {"time":90000, "map_y":0, "name":"FlagZombie"}, + {"time":92000, "map_y":2, "name":"Zombie"}, + {"time":94000, "map_y":0, "name":"Zombie"}, + {"time":95000, "map_y":4, "name":"FlagZombie"}, + {"time":96000, "map_y":1, "name":"ConeheadZombie"} + ] +} \ No newline at end of file diff --git a/source/data/map/level_e3.json b/source/data/map/level_e3.json new file mode 100644 index 00000000..ad6f1f3f --- /dev/null +++ b/source/data/map/level_e3.json @@ -0,0 +1,17 @@ +{ + "background_type":1, + "init_sun_value":50, + "zombie_list":[ + {"time":20000, "map_y":0, "name":"Zombie"}, + {"time":40000, "map_y":2, "name":"ConeheadZombie"}, + {"time":70000, "map_y":3, "name":"BucketheadZombie"}, + {"time":72000, "map_y":1, "name":"FlagZombie"}, + {"time":74000, "map_y":2, "name":"ConeheadZombie"}, + {"time":91000, "map_y":1, "name":"ConeheadZombie"}, + {"time":92000, "map_y":2, "name":"Zombie"}, + {"time":94000, "map_y":0, "name":"Zombie"}, + {"time":95000, "map_y":4, "name":"FlagZombie"}, + {"time":96000, "map_y":1, "name":"BucketheadZombie"}, + {"time":97000, "map_y":1, "name":"FlagZombie"} + ] +} diff --git a/source/data/map/level_e4.json b/source/data/map/level_e4.json new file mode 100644 index 00000000..c781b6c0 --- /dev/null +++ b/source/data/map/level_e4.json @@ -0,0 +1,33 @@ +{ + "background_type":0, + "choosebar_type":1, + "card_pool":[ + {"name":"Peashooter"}, + {"name":"SnowPea"}, + {"name":"WallNut"}, + {"name":"CherryBomb"}, + {"name":"RepeaterPea"}, + {"name":"Chomper"}, + {"name":"PotatoMine"} + ], + "zombie_list":[ + {"time": 1000, "map_y":1, "name":"Zombie"}, + {"time": 6000, "map_y":3, "name":"FlagZombie"}, + {"time":10000, "map_y":0, "name":"ConeheadZombie"}, + {"time":14000, "map_y":2, "name":"NewspaperZombie"}, + {"time":18000, "map_y":4, "name":"BucketheadZombie"}, + {"time":22000, "map_y":0, "name":"Zombie"}, + {"time":26000, "map_y":3, "name":"BucketheadZombie"}, + {"time":30000, "map_y":4, "name":"Zombie"}, + {"time":32000, "map_y":3, "name":"NewspaperZombie"}, + {"time":34000, "map_y":1, "name":"FlagZombie"}, + {"time":36000, "map_y":2, "name":"ConeheadZombie"}, + {"time":38000, "map_y":0, "name":"BucketheadZombie"}, + {"time":40000, "map_y":1, "name":"ConeheadZombie"}, + {"time":42000, "map_y":1, "name":"NewspaperZombie"}, + {"time":60000, "map_y":4, "name":"Zombie"}, + {"time":61000, "map_y":3, "name":"NewspaperZombie"}, + {"time":62000, "map_y":1, "name":"FlagZombie"}, + {"time":63000, "map_y":2, "name":"Zombie"} + ] +} \ No newline at end of file diff --git a/source/data/map/level_e5.json b/source/data/map/level_e5.json new file mode 100644 index 00000000..e3f082b2 --- /dev/null +++ b/source/data/map/level_e5.json @@ -0,0 +1,29 @@ +{ + "background_type":4, + "choosebar_type":2, + "card_pool":[ + {"name":"WallNutBowling"}, + {"name":"RedWallNutBowling"} + ], + "zombie_list":[ + {"time": 1000, "map_y":1, "name":"Zombie"}, + {"time":10000, "map_y":3, "name":"FlagZombie"}, + {"time":12000, "map_y":0, "name":"ConeheadZombie"}, + {"time":14000, "map_y":2, "name":"NewspaperZombie"}, + {"time":18000, "map_y":4, "name":"BucketheadZombie"}, + {"time":22000, "map_y":3, "name":"Zombie"}, + {"time":26000, "map_y":1, "name":"BucketheadZombie"}, + {"time":30000, "map_y":4, "name":"Zombie"}, + {"time":32000, "map_y":3, "name":"NewspaperZombie"}, + {"time":34000, "map_y":1, "name":"FlagZombie"}, + {"time":36000, "map_y":2, "name":"ConeheadZombie"}, + {"time":40000, "map_y":1, "name":"ConeheadZombie"}, + {"time":42000, "map_y":1, "name":"NewspaperZombie"}, + {"time":50000, "map_y":4, "name":"Zombie"}, + {"time":54000, "map_y":3, "name":"NewspaperZombie"}, + {"time":58000, "map_y":1, "name":"FlagZombie"}, + {"time":62000, "map_y":2, "name":"Zombie"}, + {"time":64000, "map_y":1, "name":"ConeheadZombie"}, + {"time":66000, "map_y":2, "name":"Zombie"} + ] +} \ No newline at end of file diff --git a/source/data/map/level_h0.json b/source/data/map/level_h0.json new file mode 100644 index 00000000..c22fd757 --- /dev/null +++ b/source/data/map/level_h0.json @@ -0,0 +1,7 @@ +{ + "background_type":0, + "init_sun_value":500, + "zombie_list":[ + {"time":1000, "map_y":2, "name":"Zombie"} + ] +} \ No newline at end of file diff --git a/source/data/map/level_h1.json b/source/data/map/level_h1.json new file mode 100644 index 00000000..cc222a1e --- /dev/null +++ b/source/data/map/level_h1.json @@ -0,0 +1,32 @@ +{ + "background_type":0, + "init_sun_value":150, + "zombie_list":[ + {"time":60000, "map_y":0, "name":"NewspaperZombie"}, + {"time":70000, "map_y":4, "name":"Zombie"}, + {"time":75000, "map_y":2, "name":"ConeheadZombie"}, + {"time":80000, "map_y":3, "name":"Zombie"}, + {"time":82000, "map_y":1, "name":"FlagZombie"}, + {"time":84000, "map_y":2, "name":"Zombie"}, + {"time":90000, "map_y":0, "name":"Zombie"}, + {"time":91000, "map_y":1, "name":"FlagZombie"}, + {"time":92000, "map_y":2, "name":"NewspaperZombie"}, + {"time":93000, "map_y":3, "name":"FlagZombie"}, + {"time":94000, "map_y":0, "name":"Zombie"}, + {"time":95000, "map_y":4, "name":"FlagZombie"}, + {"time":96000, "map_y":1, "name":"Zombie"}, + + + {"time":97000, "map_y":4, "name":"ConeheadZombie"}, + {"time":97000, "map_y":2, "name":"Zombie"}, + {"time":97000, "map_y":3, "name":"FlagZombie"}, + {"time":98000, "map_y":1, "name":"FlagZombie"}, + {"time":98000, "map_y":2, "name":"ConeheadZombie"}, + {"time":98000, "map_y":0, "name":"FlagZombie"}, + {"time":99000, "map_y":3, "name":"ConeheadZombie"}, + {"time":99000, "map_y":4, "name":"FlagZombie"}, + {"time":100000, "map_y":0, "name":"ConeheadZombie"}, + {"time":101000, "map_y":1, "name":"ConeheadZombie"} + + ] +} \ No newline at end of file diff --git a/source/data/map/level_h2.json b/source/data/map/level_h2.json new file mode 100644 index 00000000..ea93c991 --- /dev/null +++ b/source/data/map/level_h2.json @@ -0,0 +1,31 @@ +{ + "background_type":0, + "init_sun_value":50, + "zombie_list":[ + {"time":20000, "map_y":0, "name":"Zombie"}, + {"time":40000, "map_y":2, "name":"FlagZombie"}, + {"time":50000, "map_y":4, "name":"ConeheadZombie"}, + {"time":70000, "map_y":3, "name":"ConeheadZombie"}, + {"time":72000, "map_y":1, "name":"FlagZombie"}, + {"time":74000, "map_y":2, "name":"ConeheadZombie"}, + {"time":90000, "map_y":0, "name":"FlagZombie"}, + {"time":91000, "map_y":1, "name":"ConeheadZombie"}, + {"time":92000, "map_y":2, "name":"Zombie"}, + {"time":93000, "map_y":3, "name":"ConeheadZombie"}, + {"time":94000, "map_y":0, "name":"Zombie"}, + {"time":95000, "map_y":4, "name":"FlagZombie"}, + {"time":96000, "map_y":1, "name":"ConeheadZombie"}, + + + {"time":97000, "map_y":4, "name":"BucketheadZombie"}, + {"time":97000, "map_y":2, "name":"Zombie"}, + {"time":97000, "map_y":3, "name":"FlagZombie"}, + {"time":98000, "map_y":1, "name":"FlagZombie"}, + {"time":98000, "map_y":2, "name":"BucketheadZombie"}, + {"time":98000, "map_y":0, "name":"FlagZombie"}, + {"time":99000, "map_y":3, "name":"BucketheadZombie"}, + {"time":99000, "map_y":4, "name":"FlagZombie"}, + {"time":100000, "map_y":0, "name":"BucketheadZombie"}, + {"time":101000, "map_y":1, "name":"BucketheadZombie"} + ] +} \ No newline at end of file diff --git a/source/data/map/level_h3.json b/source/data/map/level_h3.json new file mode 100644 index 00000000..2e31ca24 --- /dev/null +++ b/source/data/map/level_h3.json @@ -0,0 +1,31 @@ +{ + "background_type":1, + "init_sun_value":50, + "zombie_list":[ + {"time":20000, "map_y":0, "name":"Zombie"}, + {"time":40000, "map_y":2, "name":"ConeheadZombie"}, + {"time":50000, "map_y":4, "name":"BucketheadZombie"}, + {"time":70000, "map_y":3, "name":"BucketheadZombie"}, + {"time":72000, "map_y":1, "name":"FlagZombie"}, + {"time":74000, "map_y":2, "name":"ConeheadZombie"}, + {"time":90000, "map_y":0, "name":"BucketheadZombie"}, + {"time":91000, "map_y":1, "name":"ConeheadZombie"}, + {"time":92000, "map_y":2, "name":"Zombie"}, + {"time":93000, "map_y":3, "name":"BucketheadZombie"}, + {"time":94000, "map_y":0, "name":"Zombie"}, + {"time":95000, "map_y":4, "name":"FlagZombie"}, + {"time":96000, "map_y":1, "name":"BucketheadZombie"}, + {"time":97000, "map_y":1, "name":"FlagZombie"}, + + {"time":97000, "map_y":4, "name":"BucketheadZombie"}, + {"time":97000, "map_y":2, "name":"Zombie"}, + {"time":97000, "map_y":3, "name":"FlagZombie"}, + {"time":98000, "map_y":1, "name":"FlagZombie"}, + {"time":98000, "map_y":2, "name":"BucketheadZombie"}, + {"time":98000, "map_y":0, "name":"FlagZombie"}, + {"time":99000, "map_y":3, "name":"BucketheadZombie"}, + {"time":99000, "map_y":4, "name":"FlagZombie"}, + {"time":100000, "map_y":0, "name":"BucketheadZombie"}, + {"time":101000, "map_y":1, "name":"BucketheadZombie"} + ] +} \ No newline at end of file diff --git a/source/data/map/level_h4.json b/source/data/map/level_h4.json new file mode 100644 index 00000000..95d08d4a --- /dev/null +++ b/source/data/map/level_h4.json @@ -0,0 +1,53 @@ +{ + "background_type":0, + "choosebar_type":1, + "card_pool":[ + {"name":"Peashooter"}, + {"name":"SnowPea"}, + {"name":"WallNut"}, + {"name":"CherryBomb"}, + {"name":"RepeaterPea"}, + {"name":"Chomper"}, + {"name":"PotatoMine"} + ], + "zombie_list":[ + {"time": 1000, "map_y":1, "name":"Zombie"}, + {"time": 6000, "map_y":3, "name":"FlagZombie"}, + {"time":10000, "map_y":0, "name":"ConeheadZombie"}, + {"time":14000, "map_y":2, "name":"NewspaperZombie"}, + {"time":18000, "map_y":4, "name":"BucketheadZombie"}, + {"time":22000, "map_y":0, "name":"Zombie"}, + {"time":26000, "map_y":3, "name":"BucketheadZombie"}, + {"time":30000, "map_y":4, "name":"Zombie"}, + {"time":32000, "map_y":3, "name":"NewspaperZombie"}, + {"time":34000, "map_y":1, "name":"FlagZombie"}, + {"time":36000, "map_y":2, "name":"ConeheadZombie"}, + {"time":38000, "map_y":0, "name":"BucketheadZombie"}, + {"time":40000, "map_y":1, "name":"ConeheadZombie"}, + {"time":42000, "map_y":1, "name":"NewspaperZombie"}, + {"time":60000, "map_y":4, "name":"Zombie"}, + {"time":61000, "map_y":3, "name":"NewspaperZombie"}, + {"time":62000, "map_y":1, "name":"FlagZombie"}, + {"time":63000, "map_y":2, "name":"Zombie"}, + {"time":64000, "map_y":0, "name":"BucketheadZombie"}, + {"time":65000, "map_y":1, "name":"ConeheadZombie"}, + {"time":66000, "map_y":2, "name":"Zombie"}, + {"time":67000, "map_y":4, "name":"BucketheadZombie"}, + {"time":68000, "map_y":3, "name":"NewspaperZombie"}, + {"time":69000, "map_y":1, "name":"FlagZombie"}, + {"time":70000, "map_y":4, "name":"BucketheadZombie"}, + {"time":71000, "map_y":0, "name":"FlagZombie"}, + + + {"time":97000, "map_y":4, "name":"BucketheadZombie"}, + {"time":97000, "map_y":2, "name":"Zombie"}, + {"time":97000, "map_y":3, "name":"FlagZombie"}, + {"time":98000, "map_y":1, "name":"FlagZombie"}, + {"time":98000, "map_y":2, "name":"BucketheadZombie"}, + {"time":98000, "map_y":0, "name":"FlagZombie"}, + {"time":99000, "map_y":3, "name":"BucketheadZombie"}, + {"time":99000, "map_y":4, "name":"FlagZombie"}, + {"time":100000, "map_y":0, "name":"BucketheadZombie"}, + {"time":101000, "map_y":1, "name":"BucketheadZombie"} + ] +} \ No newline at end of file diff --git a/source/data/map/level_h5.json b/source/data/map/level_h5.json new file mode 100644 index 00000000..eb7df45a --- /dev/null +++ b/source/data/map/level_h5.json @@ -0,0 +1,44 @@ +{ + "background_type":4, + "choosebar_type":2, + "card_pool":[ + {"name":"WallNutBowling"}, + {"name":"RedWallNutBowling"} + ], + "zombie_list":[ + {"time": 1000, "map_y":1, "name":"Zombie"}, + {"time":10000, "map_y":3, "name":"FlagZombie"}, + {"time":12000, "map_y":0, "name":"ConeheadZombie"}, + {"time":14000, "map_y":2, "name":"NewspaperZombie"}, + {"time":18000, "map_y":4, "name":"BucketheadZombie"}, + {"time":22000, "map_y":3, "name":"Zombie"}, + {"time":26000, "map_y":1, "name":"BucketheadZombie"}, + {"time":30000, "map_y":4, "name":"Zombie"}, + {"time":32000, "map_y":3, "name":"NewspaperZombie"}, + {"time":34000, "map_y":1, "name":"FlagZombie"}, + {"time":36000, "map_y":2, "name":"ConeheadZombie"}, + {"time":40000, "map_y":1, "name":"ConeheadZombie"}, + {"time":42000, "map_y":1, "name":"NewspaperZombie"}, + {"time":50000, "map_y":4, "name":"Zombie"}, + {"time":54000, "map_y":3, "name":"NewspaperZombie"}, + {"time":58000, "map_y":1, "name":"FlagZombie"}, + {"time":62000, "map_y":2, "name":"Zombie"}, + {"time":64000, "map_y":1, "name":"ConeheadZombie"}, + {"time":66000, "map_y":2, "name":"Zombie"}, + {"time":68000, "map_y":3, "name":"NewspaperZombie"}, + {"time":70000, "map_y":1, "name":"FlagZombie"}, + {"time":72000, "map_y":4, "name":"BucketheadZombie"}, + {"time":74000, "map_y":0, "name":"FlagZombie"}, + + {"time":97000, "map_y":4, "name":"BucketheadZombie"}, + {"time":97000, "map_y":2, "name":"Zombie"}, + {"time":97000, "map_y":3, "name":"FlagZombie"}, + {"time":98000, "map_y":1, "name":"FlagZombie"}, + {"time":98000, "map_y":2, "name":"BucketheadZombie"}, + {"time":98000, "map_y":0, "name":"FlagZombie"}, + {"time":99000, "map_y":3, "name":"BucketheadZombie"}, + {"time":99000, "map_y":4, "name":"FlagZombie"}, + {"time":100000, "map_y":0, "name":"BucketheadZombie"}, + {"time":101000, "map_y":1, "name":"BucketheadZombie"} + ] +} \ No newline at end of file diff --git "a/source/sound/\352\262\214\354\236\204\354\213\234\354\236\221\353\262\204\355\212\274.mp3" "b/source/sound/\352\262\214\354\236\204\354\213\234\354\236\221\353\262\204\355\212\274.mp3" new file mode 100644 index 00000000..db994950 Binary files /dev/null and "b/source/sound/\352\262\214\354\236\204\354\213\234\354\236\221\353\262\204\355\212\274.mp3" differ diff --git "a/source/sound/\353\260\260\352\262\275\354\235\214\354\225\205.mp3" "b/source/sound/\353\260\260\352\262\275\354\235\214\354\225\205.mp3" new file mode 100644 index 00000000..48068f91 Binary files /dev/null and "b/source/sound/\353\260\260\352\262\275\354\235\214\354\225\205.mp3" differ diff --git "a/source/sound/\353\271\233\354\227\220\353\204\210\354\247\200.mp3" "b/source/sound/\353\271\233\354\227\220\353\204\210\354\247\200.mp3" new file mode 100644 index 00000000..961ee9ab Binary files /dev/null and "b/source/sound/\353\271\233\354\227\220\353\204\210\354\247\200.mp3" differ diff --git "a/source/sound/\354\213\235\353\254\274\354\235\264\352\263\265\352\262\251\355\225\230\353\212\224\354\206\214\353\246\254.mp3" "b/source/sound/\354\213\235\353\254\274\354\235\264\352\263\265\352\262\251\355\225\230\353\212\224\354\206\214\353\246\254.mp3" new file mode 100644 index 00000000..c3be4c7c Binary files /dev/null and "b/source/sound/\354\213\235\353\254\274\354\235\264\352\263\265\352\262\251\355\225\230\353\212\224\354\206\214\353\246\254.mp3" differ diff --git "a/source/sound/\354\236\224\353\224\224\352\271\216\354\235\264\353\217\214\354\247\204.mp3" "b/source/sound/\354\236\224\353\224\224\352\271\216\354\235\264\353\217\214\354\247\204.mp3" new file mode 100644 index 00000000..218e754a Binary files /dev/null and "b/source/sound/\354\236\224\353\224\224\352\271\216\354\235\264\353\217\214\354\247\204.mp3" differ diff --git "a/source/sound/\354\242\200\353\271\204\352\260\200\354\243\275\354\235\204\353\225\214.mp3" "b/source/sound/\354\242\200\353\271\204\352\260\200\354\243\275\354\235\204\353\225\214.mp3" new file mode 100644 index 00000000..7025b67d Binary files /dev/null and "b/source/sound/\354\242\200\353\271\204\352\260\200\354\243\275\354\235\204\353\225\214.mp3" differ diff --git "a/source/sound/\354\242\200\353\271\204\353\250\270\353\246\254\352\260\200\353\226\250\354\226\264\354\247\210\353\225\214.mp3" "b/source/sound/\354\242\200\353\271\204\353\250\270\353\246\254\352\260\200\353\226\250\354\226\264\354\247\210\353\225\214.mp3" new file mode 100644 index 00000000..d78c5cec Binary files /dev/null and "b/source/sound/\354\242\200\353\271\204\353\250\270\353\246\254\352\260\200\353\226\250\354\226\264\354\247\210\353\225\214.mp3" differ diff --git a/source/state/__pycache__/__init__.cpython-37.pyc b/source/state/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 00000000..0ecd1eb1 Binary files /dev/null and b/source/state/__pycache__/__init__.cpython-37.pyc differ diff --git a/source/state/__pycache__/__init__.cpython-39.pyc b/source/state/__pycache__/__init__.cpython-39.pyc new file mode 100644 index 00000000..afb1b578 Binary files /dev/null and b/source/state/__pycache__/__init__.cpython-39.pyc differ diff --git a/source/state/__pycache__/level.cpython-37.pyc b/source/state/__pycache__/level.cpython-37.pyc new file mode 100644 index 00000000..82e1b5c6 Binary files /dev/null and b/source/state/__pycache__/level.cpython-37.pyc differ diff --git a/source/state/__pycache__/level.cpython-39.pyc b/source/state/__pycache__/level.cpython-39.pyc new file mode 100644 index 00000000..3da9e99b Binary files /dev/null and b/source/state/__pycache__/level.cpython-39.pyc differ diff --git a/source/state/__pycache__/mainmenu.cpython-37.pyc b/source/state/__pycache__/mainmenu.cpython-37.pyc new file mode 100644 index 00000000..3939272b Binary files /dev/null and b/source/state/__pycache__/mainmenu.cpython-37.pyc differ diff --git a/source/state/__pycache__/mainmenu.cpython-39.pyc b/source/state/__pycache__/mainmenu.cpython-39.pyc new file mode 100644 index 00000000..fddf232e Binary files /dev/null and b/source/state/__pycache__/mainmenu.cpython-39.pyc differ diff --git a/source/state/__pycache__/screen.cpython-37.pyc b/source/state/__pycache__/screen.cpython-37.pyc new file mode 100644 index 00000000..bba2fcf2 Binary files /dev/null and b/source/state/__pycache__/screen.cpython-37.pyc differ diff --git a/source/state/__pycache__/screen.cpython-39.pyc b/source/state/__pycache__/screen.cpython-39.pyc new file mode 100644 index 00000000..e467b09b Binary files /dev/null and b/source/state/__pycache__/screen.cpython-39.pyc differ diff --git a/source/state/level.py b/source/state/level.py index 133cc28a..7a4792b0 100644 --- a/source/state/level.py +++ b/source/state/level.py @@ -7,28 +7,82 @@ from .. import constants as c from ..component import map, plant, zombie, menubar +#식물 선택, 맵 로드 하는 곳? + + class Level(tool.State): def __init__(self): tool.State.__init__(self) - + def startup(self, current_time, persist): self.game_info = persist self.persist = self.game_info self.game_info[c.CURRENT_TIME] = current_time self.map_y_len = c.GRID_Y_LEN self.map = map.Map(c.GRID_X_LEN, self.map_y_len) - + self.loadMap() self.setupBackground() self.initState() + self.setUpItemImage() + + #배속버튼, 아이템들 초기화 + def setUpItemImage(self): + speedup = [0, 0, 59, 54] + if(c.DELTA_TIME == 1): + self.speedupIMG = tool.get_image( + tool.GFX[c.SPEED_UP_BUTTON_1], *speedup) + elif(c.DELTA_TIME == 2): + self.speedupIMG = tool.get_image( + tool.GFX[c.SPEED_UP_BUTTON_2], *speedup) + elif(c.DELTA_TIME == 3): + self.speedupIMG = tool.get_image( + tool.GFX[c.SPEED_UP_BUTTON_3], *speedup) + self.speedupRect = self.speedupIMG.get_rect() + self.speedupRect.x = 540 + self.speedupRect.y = 10 + + #아이템1 초기화 부분 + item_1 = [0, 0, 59, 54] + self.itemImg_1 = tool.get_image( + tool.GFX[c.ITEM_1_1], *item_1) + self.itemRect_1 = self.itemImg_1.get_rect() + self.itemRect_1.x = 605 + self.itemRect_1.y = 10 + #0안클릭 1클릭이벤트 2클릭x + self.isItem_1_Clicked = 0 + self.Item_1_Timer = 5000 + + #아이템2 초기화 부분 + item_2 = [0, 0, 59, 54] + self.itemImg_2 = tool.get_image( + tool.GFX[c.ITEM_2_1], *item_2) + self.itemRect_2 = self.itemImg_2.get_rect() + self.itemRect_2.x = 675 + self.itemRect_2.y = 10 + #0안클릭 1클릭이벤트 2클릭x + self.isItem_2_Clicked = 0 + self.Item_2_Timer = 5000 + + #추가로 삽 버튼 관련 속성 여기에 초기화함 - 12/04 홍성민 + shovel = [0, 0, 59, 54] + self.shovelIMG = tool.get_image(tool.GFX[c.SHOVEL_IMAGE], *shovel) + self.shovelRect = self.shovelIMG.get_rect() + self.shovelRect.x = 740 + self.shovelRect.y = 9 def loadMap(self): - map_file = 'level_' + str(self.game_info[c.LEVEL_NUM]) + '.json' + if(c.LEVEL_DIFFICULTY == 1): + map_file = 'level_e' + str(self.game_info[c.LEVEL_NUM]) + '.json' + elif(c.LEVEL_DIFFICULTY == 2): + map_file = 'level_' + str(self.game_info[c.LEVEL_NUM]) + '.json' + elif(c.LEVEL_DIFFICULTY == 3): + map_file = 'level_h' + str(self.game_info[c.LEVEL_NUM]) + '.json' file_path = os.path.join('source', 'data', 'map', map_file) f = open(file_path) self.map_data = json.load(f) f.close() - + def setupBackground(self): img_index = self.map_data[c.BACKGROUND_TYPE] self.background_type = img_index @@ -38,28 +92,29 @@ def setupBackground(self): self.level = pg.Surface((self.bg_rect.w, self.bg_rect.h)).convert() self.viewport = tool.SCREEN.get_rect(bottom=self.bg_rect.bottom) self.viewport.x += c.BACKGROUND_OFFSET_X - + def setupGroups(self): self.sun_group = pg.sprite.Group() self.head_group = pg.sprite.Group() self.plant_groups = [] self.zombie_groups = [] - self.hypno_zombie_groups = [] #zombies who are hypno after eating hypnoshroom + self.hypno_zombie_groups = [] # zombies who are hypno after eating hypnoshroom self.bullet_groups = [] for i in range(self.map_y_len): self.plant_groups.append(pg.sprite.Group()) self.zombie_groups.append(pg.sprite.Group()) self.hypno_zombie_groups.append(pg.sprite.Group()) self.bullet_groups.append(pg.sprite.Group()) - + def setupZombies(self): def takeTime(element): return element[0] self.zombie_list = [] for data in self.map_data[c.ZOMBIE_LIST]: - self.zombie_list.append((data['time'], data['name'], data['map_y'])) + self.zombie_list.append( + (data['time'], data['name'], data['map_y'])) self.zombie_start_time = 0 self.zombie_list.sort(key=takeTime) @@ -76,7 +131,7 @@ def update(self, surface, current_time, mouse_pos, mouse_click): elif self.state == c.PLAY: self.play(mouse_pos, mouse_click) - self.draw(surface) + self.draw(surface, mouse_pos) def initBowlingMap(self): print('initBowlingMap') @@ -100,7 +155,8 @@ def initState(self): def initChoose(self): self.state = c.CHOOSE - self.panel = menubar.Panel(menubar.all_card_list, self.map_data[c.INIT_SUN_NAME]) + self.panel = menubar.Panel( + menubar.all_card_list, self.map_data[c.INIT_SUN_NAME]) def choose(self, mouse_pos, mouse_click): if mouse_pos and mouse_click[0]: @@ -111,7 +167,8 @@ def choose(self, mouse_pos, mouse_click): def initPlay(self, card_list): self.state = c.PLAY if self.bar_type == c.CHOOSEBAR_STATIC: - self.menubar = menubar.MenuBar(card_list, self.map_data[c.INIT_SUN_NAME]) + self.menubar = menubar.MenuBar( + card_list, self.map_data[c.INIT_SUN_NAME]) else: self.menubar = menubar.MoveBar(card_list) self.drag_plant = False @@ -127,13 +184,23 @@ def initPlay(self, card_list): self.setupGroups() self.setupZombies() self.setupCars() + #중화 타이머 + tool.GameManager.getInstance().reSetTimer() + #마우스 포인터 대신 띄워지는 삽 이미지 + self.shovel_pointer_IMG = None + self.shovelActivate = False def play(self, mouse_pos, mouse_click): + + #중화 타이머 + tool.GameManager.getInstance().addTimer() + #print(tool.GameManager.getInstance().getTimer()) + if self.zombie_start_time == 0: self.zombie_start_time = self.current_time elif len(self.zombie_list) > 0: data = self.zombie_list[0] - if data[0] <= (self.current_time - self.zombie_start_time): + if data[0] <= (self.current_time - self.zombie_start_time): self.createZombie(data[1], data[2]) self.zombie_list.remove(data) @@ -148,8 +215,8 @@ def play(self, mouse_pos, mouse_click): self.head_group.update(self.game_info) self.sun_group.update(self.game_info) - - if not self.drag_plant and mouse_pos and mouse_click[0]: + + if not self.drag_plant and mouse_pos and mouse_click[0] and self.shovelActivate == False: result = self.menubar.checkCardClick(mouse_pos) if result: self.setupMouseImage(result[0], result[1]) @@ -163,9 +230,9 @@ def play(self, mouse_pos, mouse_click): self.addPlant() elif mouse_pos is None: self.setupHintImage() - + if self.produce_sun: - if(self.current_time - self.sun_timer) > c.PRODUCE_SUN_INTERVAL: + if(self.current_time - self.sun_timer) > c.PRODUCE_SUN_INTERVAL / c.SUN_TIME_UP: self.sun_timer = self.current_time map_x, map_y = self.map.getRandomMapIndex() x, y = self.map.getMapGridPos(map_x, map_y) @@ -189,20 +256,25 @@ def play(self, mouse_pos, mouse_click): def createZombie(self, name, map_y): x, y = self.map.getMapGridPos(0, map_y) if name == c.NORMAL_ZOMBIE: - self.zombie_groups[map_y].add(zombie.NormalZombie(c.ZOMBIE_START_X, y, self.head_group)) + self.zombie_groups[map_y].add(zombie.NormalZombie( + c.ZOMBIE_START_X, y, self.head_group)) elif name == c.CONEHEAD_ZOMBIE: - self.zombie_groups[map_y].add(zombie.ConeHeadZombie(c.ZOMBIE_START_X, y, self.head_group)) + self.zombie_groups[map_y].add(zombie.ConeHeadZombie( + c.ZOMBIE_START_X, y, self.head_group)) elif name == c.BUCKETHEAD_ZOMBIE: - self.zombie_groups[map_y].add(zombie.BucketHeadZombie(c.ZOMBIE_START_X, y, self.head_group)) + self.zombie_groups[map_y].add(zombie.BucketHeadZombie( + c.ZOMBIE_START_X, y, self.head_group)) elif name == c.FLAG_ZOMBIE: - self.zombie_groups[map_y].add(zombie.FlagZombie(c.ZOMBIE_START_X, y, self.head_group)) + self.zombie_groups[map_y].add(zombie.FlagZombie( + c.ZOMBIE_START_X, y, self.head_group)) elif name == c.NEWSPAPER_ZOMBIE: - self.zombie_groups[map_y].add(zombie.NewspaperZombie(c.ZOMBIE_START_X, y, self.head_group)) + self.zombie_groups[map_y].add(zombie.NewspaperZombie( + c.ZOMBIE_START_X, y, self.head_group)) def canSeedPlant(self): x, y = pg.mouse.get_pos() return self.map.showPlant(x, y) - + def addPlant(self): pos = self.canSeedPlant() if pos is None: @@ -269,7 +341,7 @@ def setupHintImage(self): pos = self.canSeedPlant() if pos and self.mouse_image: if (self.hint_image and pos[0] == self.hint_rect.x and - pos[1] == self.hint_rect.y): + pos[1] == self.hint_rect.y): return width, height = self.mouse_rect.w, self.mouse_rect.h image = pg.Surface([width, height]) @@ -298,11 +370,12 @@ def setupMouseImage(self, plant_name, select_plant): plant_name == c.SPIKEWEED or plant_name == c.JALAPENO or plant_name == c.SCAREDYSHROOM or plant_name == c.SUNSHROOM or plant_name == c.ICESHROOM or plant_name == c.HYPNOSHROOM or - plant_name == c.WALLNUTBOWLING or plant_name == c.REDWALLNUTBOWLING): + plant_name == c.WALLNUTBOWLING or plant_name == c.REDWALLNUTBOWLING): color = c.WHITE else: color = c.BLACK - self.mouse_image = tool.get_image(frame_list[0], x, y, width, height, color, 1) + self.mouse_image = tool.get_image( + frame_list[0], x, y, width, height, color, 1) self.mouse_rect = self.mouse_image.get_rect() pg.mouse.set_visible(False) self.drag_plant = True @@ -321,11 +394,12 @@ def checkBulletCollisions(self): for i in range(self.map_y_len): for bullet in self.bullet_groups[i]: if bullet.state == c.FLY: - zombie = pg.sprite.spritecollideany(bullet, self.zombie_groups[i], collided_func) + zombie = pg.sprite.spritecollideany( + bullet, self.zombie_groups[i], collided_func) if zombie and zombie.state != c.DIE: zombie.setDamage(bullet.damage, bullet.ice) bullet.setExplode() - + def checkZombieCollisions(self): if self.bar_type == c.CHOSSEBAR_BOWLING: ratio = 0.6 @@ -337,7 +411,8 @@ def checkZombieCollisions(self): for zombie in self.zombie_groups[i]: if zombie.state != c.WALK: continue - plant = pg.sprite.spritecollideany(zombie, self.plant_groups[i], collided_func) + plant = pg.sprite.spritecollideany( + zombie, self.plant_groups[i], collided_func) if plant: if plant.name == c.WALLNUTBOWLING: if plant.canHit(i): @@ -353,7 +428,7 @@ def checkZombieCollisions(self): if hypno_zombie.health <= 0: continue zombie_list = pg.sprite.spritecollide(hypno_zombie, - self.zombie_groups[i], False,collided_func) + self.zombie_groups[i], False, collided_func) for zombie in zombie_list: if zombie.state == c.DIE: continue @@ -365,7 +440,8 @@ def checkZombieCollisions(self): def checkCarCollisions(self): collided_func = pg.sprite.collide_circle_ratio(0.8) for car in self.cars: - zombies = pg.sprite.spritecollide(car, self.zombie_groups[car.map_y], False, collided_func) + zombies = pg.sprite.spritecollide( + car, self.zombie_groups[car.map_y], False, collided_func) for zombie in zombies: if zombie and zombie.state != c.DIE: car.setWalk() @@ -394,15 +470,16 @@ def killPlant(self, plant): self.map.setMapGridType(map_x, map_y, c.MAP_EMPTY) if (plant.name == c.CHERRYBOMB or plant.name == c.JALAPENO or (plant.name == c.POTATOMINE and not plant.is_init) or - plant.name == c.REDWALLNUTBOWLING): + plant.name == c.REDWALLNUTBOWLING): self.boomZombies(plant.rect.centerx, map_y, plant.explode_y_range, - plant.explode_x_range) + plant.explode_x_range) elif plant.name == c.ICESHROOM and plant.state != c.SLEEP: self.freezeZombies(plant) elif plant.name == c.HYPNOSHROOM and plant.state != c.SLEEP: zombie = plant.kill_zombie zombie.setHypno() - _, map_y = self.map.getMapIndex(zombie.rect.centerx, zombie.rect.bottom) + _, map_y = self.map.getMapIndex( + zombie.rect.centerx, zombie.rect.bottom) self.zombie_groups[map_y].remove(zombie) self.hypno_zombie_groups[map_y].add(zombie) plant.kill() @@ -498,7 +575,7 @@ def checkVictory(self): if len(self.zombie_groups[i]) > 0: return False return True - + def checkLose(self): for i in range(self.map_y_len): for zombie in self.zombie_groups[i]: @@ -527,12 +604,124 @@ def drawZombieFreezeTrap(self, i, surface): for zombie in self.zombie_groups[i]: zombie.drawFreezeTrap(surface) - def draw(self, surface): + #중화 배속 버튼 + def drawSpeedUpButton(self, surface): + surface.blit(self.speedupIMG, self.speedupRect) + + def CheckSpeedUpButtonClicked(self, mouse_pos): + x, y = mouse_pos + if(x >= self.speedupRect.x and x <= self.speedupRect.right and + y >= self.speedupRect.y and y <= self.speedupRect.bottom): + self.SpeedUpButtonClickEvent() + + def SpeedUpButtonClickEvent(self): + speedup = [0, 0, 59, 54] + if(c.DELTA_TIME == 1): + self.speedupIMG = tool.get_image( + tool.GFX[c.SPEED_UP_BUTTON_2], *speedup) + c.DELTA_TIME = 2 + elif(c.DELTA_TIME == 2): + self.speedupIMG = tool.get_image( + tool.GFX[c.SPEED_UP_BUTTON_3], *speedup) + c.DELTA_TIME = 3 + elif(c.DELTA_TIME == 3): + self.speedupIMG = tool.get_image( + tool.GFX[c.SPEED_UP_BUTTON_1], *speedup) + c.DELTA_TIME = 1 + tool.GameManager.getInstance().reSetStartTimer() + tool.GameManager.getInstance().reSetCurrentTimer() + + def drawItem(self, surface): + surface.blit(self.itemImg_1, self.itemRect_1) + surface.blit(self.itemImg_2, self.itemRect_2) + + def CheckItemButtonClicked(self, mouse_pos): + x, y = mouse_pos + if(x >= self.itemRect_1.x and x <= self.itemRect_1.right and + y >= self.itemRect_1.y and y <= self.itemRect_1.bottom and self.isItem_1_Clicked == 0): + self.Item_1_StartEvent() + if(x >= self.itemRect_2.x and x <= self.itemRect_2.right and + y >= self.itemRect_2.y and y <= self.itemRect_2.bottom and self.isItem_2_Clicked == 0): + self.Item_2_StartEvent() + + def Item_1_StartEvent(self): + self.isItem_1_Clicked = 1 + self.Item_1_Timer += self.current_time + c.ATK_TIME_UP = 2 + temp = [0, 0, 59, 54] + self.itemImg_1 = tool.get_image( + tool.GFX[c.ITEM_1_2], *temp) + + def Item_1_EndEvent(self): + if(self.Item_1_Timer < self.current_time): + c.ATK_TIME_UP = 1 + self.isItem_1_Clicked = 2 + + def Item_2_StartEvent(self): + self.isItem_2_Clicked = 1 + self.Item_2_Timer += self.current_time + c.SUN_TIME_UP = 10 + temp = [0, 0, 59, 54] + self.itemImg_2 = tool.get_image( + tool.GFX[c.ITEM_2_2], *temp) + + def Item_2_EndEvent(self): + if(self.Item_2_Timer < self.current_time): + c.SUN_TIME_UP = 1 + self.isItem_2_Clicked = 2 + + #홍성민 삽 버튼 관련 함수들 + def drawShovelButton(self, surface): + surface.blit(self.shovelIMG, self.shovelRect) + + def checkShovelButtonClicked(self, mouse_pos): + x, y = mouse_pos + shovel_pointer = [0, 0, 59, 54] + if(x >= self.shovelRect.x - 10 and x <= self.shovelRect.right + 10 and + y >= self.shovelRect.y - 10 and y <= self.shovelRect.bottom + 10): + print("shovel clicked") + # 이곳에 마우스포인터 삽 이미지 및 기능 활성화. 판정은 shovel pointer img가 none인지 아닌지로 한다. + if (self.shovel_pointer_IMG == None): + self.shovel_pointer_IMG = tool.get_image( + tool.GFX[c.SHOVEL_IMAGE], *shovel_pointer) + pg.mouse.set_visible(False) + self.shovelActivate = True + print( + "shovel clicked, and shovelpointer img was none. Now mouse set_visible is False, and IMG got his image") + # 이미지 및 기능 비활성화, 원래대로 + elif (self.shovel_pointer_IMG != None): + print( + "shovel clicked, and shovelpointer img was had something, Now mouse and IMG get back") + pg.mouse.set_visible(True) + self.shovel_pointer_IMG = None + self.shovelActivate = False + self.removeMouseImage() + # If you want to set IMG to member, use this code. + # self.shovel_pointer_IMG = tool.get_image(tool.GFX[c.SHOVEL_IMAGE], *shovel_pointer) + + #마우스 포인터 위치에 삽 이미지를 띄우게 하는 메소드 + def drawShovelMouseShow(self, surface): + surface.blit(self.shovel_pointer_IMG, pg.mouse.get_pos()) + + # plant를 넘겨받아 삽으로 클릭한 식물을 지우는 메소드 + def removePlantByShovel(self, plant): + x, y = plant.getPosition() + map_x, map_y = self.map.getMapIndex(x, y) + if self.bar_type != c.CHOSSEBAR_BOWLING: + self.map.setMapGridType(map_x, map_y, c.MAP_EMPTY) + plant.kill() + + def draw(self, surface, mouse_pos): self.level.blit(self.background, self.viewport, self.viewport) - surface.blit(self.level, (0,0), self.viewport) + surface.blit(self.level, (0, 0), self.viewport) if self.state == c.CHOOSE: self.panel.draw(surface) elif self.state == c.PLAY: + #추가 이미지 그려주는 + self.drawSpeedUpButton(surface) + self.drawItem(surface) + self.drawShovelButton(surface) + self.menubar.draw(surface) for i in range(self.map_y_len): self.plant_groups[i].draw(surface) @@ -545,5 +734,29 @@ def draw(self, surface): self.head_group.draw(surface) self.sun_group.draw(surface) + if(mouse_pos != None): + #다른 아이템 이미지 클릭 이벤트 여기에 + self.CheckSpeedUpButtonClicked(mouse_pos) + self.CheckItemButtonClicked(mouse_pos) + self.checkShovelButtonClicked(mouse_pos) + if(self.isItem_1_Clicked == 1): + self.Item_1_EndEvent() + if(self.isItem_2_Clicked == 1): + self.Item_2_EndEvent() if self.drag_plant: - self.drawMouseShow(surface) \ No newline at end of file + self.drawMouseShow(surface) + + # self.shovel_pointer_IMG에 이미지가 추가되어 삽 기능이 작동하는 상태. if문의 조건문은 checkShovelButtonClicekd를 참조 + if (self.shovel_pointer_IMG != None): + self.drawShovelMouseShow(surface) + for i in range(self.map_y_len): + for plant in self.plant_groups[i]: + plant_pos_x, plant_pos_y = plant.getPosition() + shovel_clicked_x, shovel_clicked_y = pg.mouse.get_pos() + shovel_isClicked = [False, False, False] + shovel_isClicked = pg.mouse.get_pressed() + plant_pos_y -= 100 + if(shovel_isClicked[0] == True and plant_pos_x - 35 <= shovel_clicked_x and shovel_clicked_x <= plant_pos_x + 35 + and plant_pos_y - 20 <= shovel_clicked_y and shovel_clicked_y <= plant_pos_y + 40): + print("Plants is Clicked with Shovel") + self.removePlantByShovel(plant) diff --git a/source/state/mainmenu.py b/source/state/mainmenu.py index 6ac345fe..93b7749a 100644 --- a/source/state/mainmenu.py +++ b/source/state/mainmenu.py @@ -1,60 +1,294 @@ __author__ = 'marble_xu' - +import os import pygame as pg from .. import tool from .. import constants as c - class Menu(tool.State): + isClickedSoundBtn = True def __init__(self): tool.State.__init__(self) - + self.sound_dir = os.path.join('source', 'sound') # 경로 추가 + self.start_sound = pg.mixer.Sound(os.path.join( + self.sound_dir, '게임시작버튼.mp3')) # 버튼을 누르는 소리 + self.start_sound.set_volume(2) # 소리크기 설정 def startup(self, current_time, persist): self.next = c.LEVEL self.persist = persist self.game_info = persist - self.setupBackground() + self.setupMuteSound() + #self.ClickedMuteSound() + self.setupSound() + # self.ClickedSound() + self.setupEasyMode() + # self.ClickedEasyMode() + self.setupNormalMode() + #self.ClickedNormalMode() + self.setupHardMode() + #self.ClickedHardMode() self.setupOption() - def setupBackground(self): frame_rect = [80, 0, 800, 600] - self.bg_image = tool.get_image(tool.GFX[c.MAIN_MENU_IMAGE], *frame_rect) + self.bg_image = tool.get_image( + tool.GFX[c.MAIN_MENU_IMAGE], *frame_rect) self.bg_rect = self.bg_image.get_rect() self.bg_rect.x = 0 self.bg_rect.y = 0 - + gameoff_rect = [0, 0, 165, 60] + self.gameoff_img = tool.get_image( + tool.GFX[c.OPTION_GAMEOFF], *gameoff_rect) + self.gameoff_img_rect = self.gameoff_img.get_rect() + self.gameoff_img_rect.x = 450 + self.gameoff_img_rect.y = 340 + self.gameOffclicked = False + + def setupMuteSound(self): + mutesound_rect = [0, 0, 99, 55] + self.mutesound_img = tool.get_image( + tool.GFX[c.SOUND_MUTE_IMAGE], *mutesound_rect) + if(c.SOUND_ON == True): + self.mutesound_img = tool.get_image( + tool.GFX[c.SOUND_MUTE_IMAGE], *mutesound_rect) + else: + self.mutesound_img = tool.get_image( + tool.GFX[c.CLICKED_MUTE_IMAGE], *mutesound_rect) + self.mutesound_img_rect = self.mutesound_img.get_rect() + self.mutesound_img_rect.x = 440 + self.mutesound_img_rect.y = 265 + #사운드 버튼 만드는 법 + #처음에는 한쪽은 켜져있고 한쪽은 꺼져있는 상태 + #사운드 키는 버튼을 눌렀을 때 -> Clicked 이미지로 변경, 뮤트 이미지는 클릭 안한 이미지로 변경 + #사운드 끄는 버튼을 눌렀을 때 -> 위에꺼 반대로 + #self.muteSoundClicked = False + # def ClickedMuteSound(self): + # clickedMutesound_rect = [0, 0, 99, 55] + # self.clickedMutesound_img = tool.get_image(tool.GFX[c.CLICKED_MUTE_IMAGE],*clickedMutesound_rect) + # self.clickedMutesound_img_rect = self.clickedMutesound_img.get_rect() + # self.clickedMutesound_img_rect.x = 440 + # self.clickedMutesound_img_rect.y = 265 + + def setupSound(self): + sound_rect = [0, 0, 99, 55] + self.sound_img = tool.get_image( + tool.GFX[c.CLICKED_SOUND_IMAGE], *sound_rect) + if(c.SOUND_ON == True): + self.sound_img = tool.get_image( + tool.GFX[c.CLICKED_SOUND_IMAGE], *sound_rect) + else: + self.sound_img = tool.get_image( + tool.GFX[c.SOUND_IMAGE], *sound_rect) + self.sound_img_rect = self.sound_img.get_rect() + self.sound_img_rect.x = 550 + self.sound_img_rect.y = 275 + #self.soundClicked = False + # def ClickedSound(self): + # clickedsound_rect = [0, 0, 99, 55] + # self.clickedSound_img = tool.get_image(tool.GFX[c.CLICKED_SOUND_IMAGE],*clickedsound_rect) + # self.clickedSound_img_rect = self.clickedSound_img.get_rect() + # self.clickedSound_img_rect.x = 550 + # self.clickedSound_img_rect.y = 275 + + def setupEasyMode(self): + easyMode_rect = [0, 0, 99, 55] + self.easyMode_img = tool.get_image( + tool.GFX[c.CLICKED_NORMAL], *easyMode_rect) + if(c.LEVEL_DIFFICULTY == 1): + self.easyMode_img = tool.get_image( + tool.GFX[c.CLICKED_EASY], *easyMode_rect) + else: + self.easyMode_img = tool.get_image( + tool.GFX[c.EASY_IMAGE], *easyMode_rect) + self.easyMode_img_rect = self.easyMode_img.get_rect() + self.easyMode_img_rect.x = 410 + self.easyMode_img_rect.y = 190 + #self.easyClicked = False + # def ClickedEasyMode(self): + # clickedEasy_rect = [0, 0, 99, 55] + # self.clickedEasy_img = tool.get_image(tool.GFX[c.CLICKED_EASY],*clickedEasy_rect) + # self.clickedEasy_img_rect = self.clickedEasy_img.get_rect() + # self.clickedEasy_img_rect.x = 410 + # self.clickedEasy_img_rect.y = 190 + + def setupNormalMode(self): + normalMode_rect = [0, 0, 99, 55] + self.normalMode_img = tool.get_image( + tool.GFX[c.NORMAL_IMAGE], *normalMode_rect) + if(c.LEVEL_DIFFICULTY == 2): + self.normalMode_img = tool.get_image( + tool.GFX[c.CLICKED_NORMAL], *normalMode_rect) + else: + self.normalMode_img = tool.get_image( + tool.GFX[c.NORMAL_IMAGE], *normalMode_rect) + self.normalMode_img_rect = self.normalMode_img.get_rect() + self.normalMode_img_rect.x = 510 + self.normalMode_img_rect.y = 200 + # self.normalClicked = False + # def ClickedNormalMode(self): + # clickedNormal_rect = [0, 0, 99, 55] + # self.clickedNormal_img = tool.get_image(tool.GFX[c.CLICKED_NORMAL],*clickedNormal_rect) + # self.clickedNormal_img_rect = self.clickedNormal_img.get_rect() + # self.clickedNormal_img_rect.x = 510 + # self.clickedNormal_img_rect.y = 200 + + def setupHardMode(self): + hardMode_rect = [0, 0, 99, 55] + self.hardMode_img = tool.get_image( + tool.GFX[c.HARD_IMAGE], *hardMode_rect) + if(c.LEVEL_DIFFICULTY == 3): + self.hardMode_img = tool.get_image( + tool.GFX[c.CLICKED_HARD], *hardMode_rect) + else: + self.hardMode_img = tool.get_image( + tool.GFX[c.HARD_IMAGE], *hardMode_rect) + self.hardMode_img_rect = self.hardMode_img.get_rect() + self.hardMode_img_rect.x = 610 + self.hardMode_img_rect.y = 210 + # self.hardClicked = False + # def ClickedHardMode(self): + # clickedHard_rect = [0, 0, 99, 55] + # self.clickedHard_img = tool.get_image(tool.GFX[c.CLICKED_HARD],*clickedHard_rect) + # self.clickedHard_img_rect = self.clickedHard_img.get_rect() + # self.clickedHard_img_rect.x = 610 + # self.clickedHard_img_rect.y = 210 def setupOption(self): self.option_frames = [] frame_names = [c.OPTION_ADVENTURE + '_0', c.OPTION_ADVENTURE + '_1'] - frame_rect = [0, 0, 165, 77] - + frame_rect = [0, 0, 165, 70] for name in frame_names: - self.option_frames.append(tool.get_image(tool.GFX[name], *frame_rect, c.BLACK, 1.7)) - + self.option_frames.append(tool.get_image( + tool.GFX[name], *frame_rect, c.BLACK, 1.7)) self.option_frame_index = 0 self.option_image = self.option_frames[self.option_frame_index] self.option_rect = self.option_image.get_rect() self.option_rect.x = 435 self.option_rect.y = 75 - self.option_start = 0 self.option_timer = 0 self.option_clicked = False - def checkOptionClick(self, mouse_pos): x, y = mouse_pos if(x >= self.option_rect.x and x <= self.option_rect.right and y >= self.option_rect.y and y <= self.option_rect.bottom): self.option_clicked = True + if(self.isClickedSoundBtn) : + self.start_sound.play() self.option_timer = self.option_start = self.current_time return False - + def checkGameOffClick(self, mouse_pos): + x, y = mouse_pos + if(x >= self.gameoff_img_rect.x and x <= self.gameoff_img_rect.right and + y >= self.gameoff_img_rect.y and y <= self.gameoff_img_rect.bottom): + self.gameOffclicked = True + def checkMuteSoundClick(self, mouse_pos): + x, y = mouse_pos + if(x >= self.mutesound_img_rect.x and x <= self.mutesound_img_rect.right and + y >= self.mutesound_img_rect.y and y <= self.mutesound_img_rect.bottom): + sound_rect = [0, 0, 99, 55] + self.sound_img = tool.get_image( + tool.GFX[c.SOUND_IMAGE], *sound_rect) + self.mutesound_img = tool.get_image( + tool.GFX[c.CLICKED_MUTE_IMAGE], *sound_rect) + pg.mixer.music.pause() + c.SOUND_ON = False + Menu.isClickedSoundBtn = False + + def checkSoundClick(self, mouse_pos): + x, y = mouse_pos + if(x >= self.sound_img_rect.x and x <= self.sound_img_rect.right and + y >= self.sound_img_rect.y and y <= self.sound_img_rect.bottom): + sound_rect = [0, 0, 99, 55] + self.sound_img = tool.get_image( + tool.GFX[c.CLICKED_SOUND_IMAGE], *sound_rect) + self.mutesound_img = tool.get_image( + tool.GFX[c.SOUND_MUTE_IMAGE], *sound_rect) + pg.mixer.music.unpause() + c.SOUND_ON = True + Menu.isClickedSoundBtn = True + + def checkEasyClick(self, mouse_pos): + x, y = mouse_pos + if(x >= self.easyMode_img_rect.x and x <= self.easyMode_img_rect.right and + y >= self.easyMode_img_rect.y and y <= self.easyMode_img_rect.bottom): + rect = [0, 0, 99, 55] + self.easyMode_img = tool.get_image(tool.GFX[c.CLICKED_EASY], *rect) + self.normalMode_img = tool.get_image(tool.GFX[c.NORMAL_IMAGE], *rect) + self.normalMode_img = tool.get_image( + tool.GFX[c.NORMAL_IMAGE], *rect) + self.hardMode_img = tool.get_image(tool.GFX[c.HARD_IMAGE], *rect) + self.easyConfig() + + def checkNormalClick(self, mouse_pos): + x, y = mouse_pos + if(x >= self.normalMode_img_rect.x and x <= self.normalMode_img_rect.right and + y >= self.normalMode_img_rect.y and y <= self.normalMode_img_rect.bottom): + rect = [0, 0, 99, 55] + self.easyMode_img = tool.get_image(tool.GFX[c.EASY_IMAGE], *rect) + self.normalMode_img = tool.get_image(tool.GFX[c.CLICKED_NORMAL], *rect) + self.normalMode_img = tool.get_image( + tool.GFX[c.CLICKED_NORMAL], *rect) + self.hardMode_img = tool.get_image(tool.GFX[c.HARD_IMAGE], *rect) + self.normalConfig() + + def checkHardClick(self, mouse_pos): + x, y = mouse_pos + if(x >= self.hardMode_img_rect.x and x <= self.hardMode_img_rect.right and + y >= self.hardMode_img_rect.y and y <= self.hardMode_img_rect.bottom): + rect = [0, 0, 99, 55] + self.easyMode_img = tool.get_image(tool.GFX[c.EASY_IMAGE], *rect) + self.normalMode_img = tool.get_image(tool.GFX[c.NORMAL_IMAGE], *rect) + self.normalMode_img = tool.get_image( + tool.GFX[c.NORMAL_IMAGE], *rect) + self.hardMode_img = tool.get_image(tool.GFX[c.CLICKED_HARD], *rect) + self.hardConfig() + + + def easyConfig(self): + c.SUN_VALUE = 30 + c.PLANT_HEALTH = 10 + c.LOSTHEAD_HEALTH = 3 + c.NORMAL_HEALTH = 5 + c.FLAG_HEALTH = 8 + c.CONEHEAD_HEALTH = 10 + c.BUCKETHEAD_HEALTH = 15 + c.NEWSPAPER_HEALTH = 8 + c.LEVEL_DIFFICULTY = 1 + + def normalConfig(self): + c.SUN_VALUE = 25 + c.WALLNUT_HEALTH = 15 + c.LOSTHEAD_HEALTH = 5 + c.NORMAL_HEALTH = 10 + c.FLAG_HEALTH = 15 + c.CONEHEAD_HEALTH = 20 + c.BUCKETHEAD_HEALTH = 30 + c.NEWSPAPER_HEALTH = 18 + #다시 1로 돌아갈수있으니 이건 좀 아닌듯~ + #c.DELTA_TIME = 2.0 + c.ICE_SLOW_TIME = 5000 + c.LEVEL_DIFFICULTY = 2 + def hardConfig(self): + c.SUN_VALUE = 20 + c.WALLNUT_HEALTH = 20 + c.LOSTHEAD_HEALTH = 7 + c.NORMAL_HEALTH = 15 + c.FLAG_HEALTH = 22 + c.CONEHEAD_HEALTH = 30 + c.BUCKETHEAD_HEALTH = 45 + c.NEWSPAPER_HEALTH = 22 + #c.DELTA_TIME = 2.0 + c.ICE_SLOW_TIME = 5000 + c.LEVEL_DIFFICULTY = 3 def update(self, surface, current_time, mouse_pos, mouse_click): self.current_time = self.game_info[c.CURRENT_TIME] = current_time - if not self.option_clicked: if mouse_pos: self.checkOptionClick(mouse_pos) + self.checkGameOffClick(mouse_pos) + self.checkSoundClick(mouse_pos) + self.checkMuteSoundClick(mouse_pos) + self.checkEasyClick(mouse_pos) + self.checkNormalClick(mouse_pos) + self.checkHardClick(mouse_pos) else: if(self.current_time - self.option_timer) > 200: self.option_frame_index += 1 @@ -62,8 +296,60 @@ def update(self, surface, current_time, mouse_pos, mouse_click): self.option_frame_index = 0 self.option_timer = self.current_time self.option_image = self.option_frames[self.option_frame_index] + #클릭후 1.3초후 self.done = True + #self.done이 True가 되면? + #1. tool.py 의 Update에서 걸림 + #2. flip_state()함수에서 현재 state를 다음 state로 넘겨 다른 state.update()가 호출 + #즉!!! State를 상속받은 클래스는 done을 true해주면 무조건 다음 state로 넘어감!! if(self.current_time - self.option_start) > 1300: self.done = True - surface.blit(self.bg_image, self.bg_rect) - surface.blit(self.option_image, self.option_rect) \ No newline at end of file + surface.blit(self.option_image, self.option_rect) + #게임 종료 + if(self.gameOffclicked == False): + surface.blit(self.gameoff_img, self.gameoff_img_rect) + else: + pg.quit() + #이미지만 변경하므로 기본적으로 계속 그려줌 + surface.blit(self.sound_img, self.sound_img_rect) + surface.blit(self.mutesound_img, self.mutesound_img_rect) + #여기서 사운드를 꺼주거나 켜주기를 하면 update문이기 때문에 계속 실행되는 문제 + #소리 설정 + # if(self.muteSoundClicked == False and self.soundClicked == False): + # surface.blit(self.sound_img, self.sound_img_rect) + # surface.blit(self.mutesound_img, self.mutesound_img_rect) + # elif(self.muteSoundClicked == True and self.soundClicked == False): + # surface.blit(self.clickedMutesound_img, self.clickedMutesound_img_rect) + # surface.blit(self.sound_img, self.sound_img_rect) + # pg.mixer.music.pause() + # self.muteSoundClicked = False + # elif(self.muteSoundClicked == False and self.soundClicked == True): + # surface.blit(self.clickedSound_img, self.clickedSound_img_rect) + # surface.blit(self.mutesound_img, self.mutesound_img_rect) + # pg.mixer.music.unpause() + # self.soundClicked = False + surface.blit(self.easyMode_img, self.easyMode_img_rect) + surface.blit(self.normalMode_img, self.normalMode_img_rect) + surface.blit(self.hardMode_img, self.hardMode_img_rect) + #난이도 설정 + #여기서 easyConfig()같은 함수 계속 호출X!!! -> 클릭 이벤트에서 한 번만 호출! + #이미지만 변경해주면 되기때문에 눌렀는지 안눌렀는지 체크하는 Bool변수 필요X!!! + # if(self.easyClicked == False): + # surface.blit(self.easyMode_img, self.easyMode_img_rect) + # else: + # surface.blit(self.clickedEasy_img, self.clickedEasy_img_rect) + # self.easyConfig() + # if(self.normalClicked == False): + # surface.blit(self.normalMode_img, self.normalMode_img_rect) + # else: + # surface.blit(self.clickedNormal_img, self.clickedNormal_img_rect) + # #self.normalConfig() + # if(self.hardClicked == False): + # surface.blit(self.hardMode_img, self.hardMode_img_rect) + # else: + # surface.blit(self.clickedHard_img, self.clickedHard_img_rect) + # self.hardConfig() + + + def isClickedSound(self) : + return Menu.isClickedSoundBtn \ No newline at end of file diff --git a/source/state/screen.py b/source/state/screen.py index a6244602..2d3a060b 100644 --- a/source/state/screen.py +++ b/source/state/screen.py @@ -17,7 +17,7 @@ def startup(self, current_time, persist): name = self.getImageName() self.setupImage(name) self.next = self.set_next_state() - + def getImageName(self): pass @@ -32,11 +32,9 @@ def setupImage(self, name): self.rect.y = 0 def update(self, surface, current_time, mouse_pos, mouse_click): - if(current_time - self.start_time) < self.end_time: - surface.fill(c.WHITE) - surface.blit(self.image, self.rect) - else: - self.done = True + # Displaying component when the game ended. + surface.fill(c.WHITE) + surface.blit(self.image, self.rect) class GameVictoryScreen(Screen): def __init__(self): @@ -48,12 +46,124 @@ def getImageName(self): def set_next_state(self): return c.LEVEL + # Mouse Position checking method + def checkNextStageButtonClicked(self, mouse_pos): + x, y = mouse_pos + if(x >= self.nextStageButton_IMG_rect.x and x <= self.nextStageButton_IMG_rect.right and + y >= self.nextStageButton_IMG_rect.y and y <= self.nextStageButton_IMG_rect.bottom): + self.isNextStageClicked = True + + def checkMainMenuButtonClicked(self, mouse_pos): + x, y = mouse_pos + if(x >= self.mainMenuButton_IMG_rect.x and x <= self.mainMenuButton_IMG_rect.right and + y >= self.mainMenuButton_IMG_rect.y and y <= self.mainMenuButton_IMG_rect.bottom): + self.isMainMenuClicked = True + + def startup(self, current_time, persist): + super().startup(current_time, persist) + #텍스트 추가 + font = pg.font.SysFont("arial",30,True,True) #폰트 설정 + self.text = font.render("KILL ZOMBIES : " + str(tool.GameManager.getInstance().getKillZombieCount()),True,(0,0,0)) #텍스트가 표시된 Surface 를 만듬 + #self.textForTime = font.render("PLAY TIME : " + str(int(tool.GameManager.getInstance().getTimer())) + "SECOND",True,(0,0,0)) + minuteForRenderStr = 0 + secondForRenderStr = 0 + if int(tool.GameManager.getInstance().getTimer()) >= 60 : + minuteForRenderStr = int(tool.GameManager.getInstance().getTimer()) / 60 + secondForRenderStr = int(tool.GameManager.getInstance().getTimer()) % 60 + self.textForTime = font.render("PLAY TIME : " + str(int(minuteForRenderStr)) + " MINUTE " + str(secondForRenderStr) + " SECOND",True,(0,0,0)) + self.textPos = [170, 330] + elif int(tool.GameManager.getInstance().getTimer()) < 60 : + self.textForTime = font.render("PLAY TIME : " + str(int(tool.GameManager.getInstance().getTimer())) + " SECOND",True,(0,0,0)) + self.textPos = [250, 330] + + + def setupImage(self, name): + super().setupImage(name) + # Setup For MainMenu Button + mainMenu_Button = [0, 0, 150, 80] + self.mainMenuButton_IMG = tool.get_image(tool.GFX[c.GAMEFINISHED_MAINMENU_BUTTON],*mainMenu_Button) + self.mainMenuButton_IMG_rect = self.mainMenuButton_IMG.get_rect() + self.mainMenuButton_IMG_rect.x = 235 + self.mainMenuButton_IMG_rect.y = 380 + self.isMainMenuClicked = False + + # Setup For NextStage Button + nextStage_Button = [0, 0, 150, 80] + self.nextStageButton_IMG = tool.get_image(tool.GFX[c.GAMEFINISHED_NEXTSTAGE_BUTTON],*nextStage_Button) + self.nextStageButton_IMG_rect = self.nextStageButton_IMG.get_rect() + self.nextStageButton_IMG_rect.x = 435 + self.nextStageButton_IMG_rect.y = 380 + self.isNextStageClicked = False + + def update(self, surface, current_time, mouse_pos, mouse_click): + super().update(surface, current_time, mouse_pos, mouse_click) + if mouse_pos: + self.checkMainMenuButtonClicked(mouse_pos) + self.checkNextStageButtonClicked(mouse_pos) + if self.isMainMenuClicked : + if self.game_info[c.LEVEL_NUM] == 1 : + self.game_info[c.LEVEL_NUM] -= 1 + elif self.game_info[c.LEVEL_NUM] == 2: + self.game_info[c.LEVEL_NUM] -= 2 + elif self.game_info[c.LEVEL_NUM] == 3: + self.game_info[c.LEVEL_NUM] -= 3 + elif self.game_info[c.LEVEL_NUM] == 4: + self.game_info[c.LEVEL_NUM] -= 4 + elif self.game_info[c.LEVEL_NUM] == 5: + self.game_info[c.LEVEL_NUM] -= 5 + self.next = c.MAIN_MENU + tool.GameManager.getInstance().resetKillZombieCount() + self.done = True + elif self.isNextStageClicked : + tool.GameManager.getInstance().resetKillZombieCount() + self.done = True + + surface.blit(self.text,(290,280)) + surface.blit(self.textForTime, self.textPos) + surface.blit(self.mainMenuButton_IMG, self.mainMenuButton_IMG_rect) + surface.blit(self.nextStageButton_IMG, self.nextStageButton_IMG_rect) + class GameLoseScreen(Screen): def __init__(self): + #0은 테스트하기위한 스테이지임 + c.START_LEVEL_NUM = 1 Screen.__init__(self) def getImageName(self): return c.GAME_LOOSE_IMAGE def set_next_state(self): - return c.MAIN_MENU \ No newline at end of file + return c.MAIN_MENU + + def checkMainMenuButtonClicked(self, mouse_pos): + x, y = mouse_pos + if(x >= self.mainMenuButton_IMG_rect.x and x <= self.mainMenuButton_IMG_rect.right and + y >= self.mainMenuButton_IMG_rect.y and y <= self.mainMenuButton_IMG_rect.bottom): + self.isMainMenuClicked = True + + def startup(self, current_time, persist): + super().startup(current_time, persist) + #텍스트 추가 + font = pg.font.SysFont("arial",30,True,True) #폰트 설정 + self.text = font.render("KILL ZOMBIES : " + str(tool.GameManager.getInstance().getKillZombieCount()),True,(0,0,0)) #텍스트가 표시된 Surface 를 만듬 + + def setupImage(self, name): + super().setupImage(name) + # Setup For MainMenu Button + mainMenu_Button = [0, 0, 150, 80] + self.mainMenuButton_IMG = tool.get_image(tool.GFX[c.GAMEFINISHED_MAINMENU_BUTTON],*mainMenu_Button) + self.mainMenuButton_IMG_rect = self.mainMenuButton_IMG.get_rect() + self.mainMenuButton_IMG_rect.x = 310 + self.mainMenuButton_IMG_rect.y = 380 + self.isMainMenuClicked = False + + def update(self, surface, current_time, mouse_pos, mouse_click): + super().update(surface, current_time, mouse_pos, mouse_click) + if mouse_pos: + self.checkMainMenuButtonClicked(mouse_pos) + if self.isMainMenuClicked : + tool.GameManager.getInstance().resetKillZombieCount() + self.done = True + + surface.blit(self.text,(280,300)) + surface.blit(self.mainMenuButton_IMG, self.mainMenuButton_IMG_rect) \ No newline at end of file diff --git a/source/tool.py b/source/tool.py index 1a319c8c..d5dc8879 100644 --- a/source/tool.py +++ b/source/tool.py @@ -1,11 +1,70 @@ +from pygame.locals import * __author__ = 'marble_xu' import os import json from abc import abstractmethod import pygame as pg +import sys from . import constants as c +mainClock = pg.time.Clock() +#싱글톤 패턴으로 어디서든 호출할 수 있도록 만듬 + + +class GameManager(object): + __instance = None + + def __init__(self): + self.killZombieCount = 0 + self.startTimer = 0.0 + self.timer = 0.0 + self.score = 0 + self.timeBuf = 0.0 + + self.current_time = 0.0 + self.current_startTimer = 0.0 + self.current_timeBuf = 0.0 + @classmethod + def getInstance(cls): + if not cls.__instance: + cls.__instance = GameManager() + return cls.__instance + + def getKillZombieCount(self): + return self.killZombieCount + + def addKillZombieCount(self): + self.killZombieCount += 1 + + def resetKillZombieCount(self): + self.killZombieCount = 0 + + def getTimer(self): + return self.timer + def addTimer(self): + self.timer = ((pg.time.get_ticks()-self.startTimer) / (1000/c.DELTA_TIME)) + self.timeBuf + def getTimerToTicks(self): + return self.timer * 1000 + def reSetTimer(self): + self.startTimer = pg.time.get_ticks() + self.timeBuf = 0.0 + def reSetStartTimer(self): + self.startTimer = pg.time.get_ticks() + self.timeBuf = self.timer + + def getCurrentTimer(self): + return self.current_time + def setCurrentTimer(self): + self.current_time = pg.time.get_ticks() + self.current_timeBuf = 0.0 + def addCurrentTimer(self): + self.current_time = ((pg.time.get_ticks()-self.current_startTimer) * c.DELTA_TIME) + self.current_timeBuf + def reSetCurrentTimer(self): + self.current_startTimer = pg.time.get_ticks() + self.current_timeBuf = self.current_time + + class State(): def __init__(self): self.start_time = 0.0 @@ -13,7 +72,7 @@ def __init__(self): self.done = False self.next = None self.persist = {} - + @abstractmethod def startup(self, current_time, persist): '''abstract method''' @@ -21,11 +80,12 @@ def startup(self, current_time, persist): def cleanup(self): self.done = False return self.persist - + @abstractmethod def update(self, surface, keys, current_time): '''abstract method''' + class Control(): def __init__(self): self.screen = pg.display.get_surface() @@ -34,14 +94,16 @@ def __init__(self): self.fps = 60 self.keys = pg.key.get_pressed() self.mouse_pos = None - self.mouse_click = [False, False] # value:[left mouse click, right mouse click] + # value:[left mouse click, right mouse click] + self.mouse_click = [False, False] self.current_time = 0.0 self.state_dict = {} self.state_name = None self.state = None - self.game_info = {c.CURRENT_TIME:0.0, - c.LEVEL_NUM:c.START_LEVEL_NUM} - + self.game_info = {c.CURRENT_TIME: 0.0, + c.LEVEL_NUM: c.START_LEVEL_NUM} + GameManager.getInstance().setCurrentTimer() + def setup_states(self, state_dict, start_state): self.state_dict = state_dict self.state_name = start_state @@ -49,21 +111,34 @@ def setup_states(self, state_dict, start_state): self.state.startup(self.current_time, self.game_info) def update(self): - self.current_time = pg.time.get_ticks() + #self.current_time = pg.time.get_ticks() * c.DELTA_TIME + GameManager.getInstance().addCurrentTimer() + self.current_time = GameManager.getInstance().getCurrentTimer() + #print(self.current_time) + if self.state.done: self.flip_state() - self.state.update(self.screen, self.current_time, self.mouse_pos, self.mouse_click) + self.state.update(self.screen, self.current_time, + self.mouse_pos, self.mouse_click) self.mouse_pos = None self.mouse_click[0] = False self.mouse_click[1] = False def flip_state(self): + #화면 직접적으로 바꾸어 주는 부분 + #현재 state를 state.next로 바꾸어 줌 + #state.next는 State 자식클래스들 startup()에서 지정 + #한 씬에서 여러가지 씬으로 변경할수 있는경우에는 어떻게 처리해야 할지? + #->level.py에 def checkGameState(self) 함수 참고 previous, self.state_name = self.state_name, self.state.next persist = self.state.cleanup() self.state = self.state_dict[self.state_name] self.state.startup(self.current_time, persist) - def event_loop(self): + """def event_loop(self): + #SCREEN = pg.display.set_mode(c.SCREEN_SIZE, pg.RESIZABLE) + #SCREEN.fill((0, 0, 50)) + for event in pg.event.get(): if event.type == pg.QUIT: self.done = True @@ -74,33 +149,87 @@ def event_loop(self): elif event.type == pg.MOUSEBUTTONDOWN: self.mouse_pos = pg.mouse.get_pos() self.mouse_click[0], _, self.mouse_click[1] = pg.mouse.get_pressed() + print('pos:', self.mouse_pos, ' mouse:', self.mouse_click)""" + + def event_loop(self): + fullscreen = False + for event in pg.event.get(): + if event.type == pg.QUIT: + self.done = True + if event.type == pg.VIDEORESIZE: + if not fullscreen: + SCREEN = pg.display.set_mode( + (event.w, event.h), pg.RESIZABLE) + if event.type == pg.KEYDOWN: + #self.keys = pg.key.get_pressed() + if event.key == pg.K_ESCAPE: + pg.quit() + sys.exit() + if event.key == pg.K_f: + fullscreen = not fullscreen + if fullscreen: + SCREEN = pg.display.set_mode( + monitor_size, pg.FULLSCREEN) + else: + SCREEN = pg.display.set_mode( + (SCREEN.get_width(), SCREEN.get_height()), pg.RESIZABLE) + if event.type == pg.KEYUP: + self.keys = pg.key.get_pressed() + if event.type == pg.MOUSEBUTTONDOWN: + self.mouse_pos = pg.mouse.get_pos() + self.mouse_click[0], _, self.mouse_click[1] = pg.mouse.get_pressed( + ) print('pos:', self.mouse_pos, ' mouse:', self.mouse_click) + def setBackGroundMusic(self): + self.sound_dir = os.path.join('source', 'sound') # 경로 추가 + pg.mixer.music.load(os.path.join( + self.sound_dir, '배경음악.mp3')) # 배경음악 로드 + def main(self): + + self.setBackGroundMusic() + pg.mixer.music.play(-1) # 게임이 시작하면 노래를 재생합니다 + while not self.done: self.event_loop() self.update() pg.display.update() self.clock.tick(self.fps) + pg.mixer.music.fadeout(500) # 게임이 끝나면 노래를 종료합니다 print('game over') + +def get_image(sheet, x, y, width, height, colorkey=c.BLACK, scale=1): + image = pg.Surface([width, height]) + rect = image.get_rect() + + image.blit(sheet, (0, 0), (x, y, width, height)) + image.set_colorkey(colorkey) + image = pg.transform.scale(image, + (int(rect.width*scale), + int(rect.height*scale))) + return image + + def get_image(sheet, x, y, width, height, colorkey=c.BLACK, scale=1): - image = pg.Surface([width, height]) - rect = image.get_rect() + image = pg.Surface([width, height]) + rect = image.get_rect() + + image.blit(sheet, (0, 0), (x, y, width, height)) + image.set_colorkey(colorkey) + image = pg.transform.scale(image, + (int(rect.width*scale), + int(rect.height*scale))) + return image - image.blit(sheet, (0, 0), (x, y, width, height)) - image.set_colorkey(colorkey) - image = pg.transform.scale(image, - (int(rect.width*scale), - int(rect.height*scale))) - return image def load_image_frames(directory, image_name, colorkey, accept): frame_list = [] tmp = {} # image_name is "Peashooter", pic name is 'Peashooter_1', get the index 1 - index_start = len(image_name) + 1 - frame_num = 0; + index_start = len(image_name) + 1 + frame_num = 0 for pic in os.listdir(directory): name, ext = os.path.splitext(pic) if ext.lower() in accept: @@ -111,13 +240,14 @@ def load_image_frames(directory, image_name, colorkey, accept): else: img = img.convert() img.set_colorkey(colorkey) - tmp[index]= img + tmp[index] = img frame_num += 1 for i in range(frame_num): frame_list.append(tmp[i]) return frame_list + def load_all_gfx(directory, colorkey=c.WHITE, accept=('.png', '.jpg', '.bmp', '.gif')): graphics = {} for name1 in os.listdir(directory): @@ -127,21 +257,23 @@ def load_all_gfx(directory, colorkey=c.WHITE, accept=('.png', '.jpg', '.bmp', '. for name2 in os.listdir(dir1): dir2 = os.path.join(dir1, name2) if os.path.isdir(dir2): - # e.g. subfolders under the folder resources\graphics\Zombies + # e.g. subfolders under the folder resources\graphics\Zombies for name3 in os.listdir(dir2): dir3 = os.path.join(dir2, name3) # e.g. subfolders or pics under the folder resources\graphics\Zombies\ConeheadZombie if os.path.isdir(dir3): # e.g. it's the folder resources\graphics\Zombies\ConeheadZombie\ConeheadZombieAttack image_name, _ = os.path.splitext(name3) - graphics[image_name] = load_image_frames(dir3, image_name, colorkey, accept) + graphics[image_name] = load_image_frames( + dir3, image_name, colorkey, accept) else: # e.g. pics under the folder resources\graphics\Plants\Peashooter image_name, _ = os.path.splitext(name2) - graphics[image_name] = load_image_frames(dir2, image_name, colorkey, accept) + graphics[image_name] = load_image_frames( + dir2, image_name, colorkey, accept) break else: - # e.g. pics under the folder resources\graphics\Screen + # e.g. pics under the folder resources\graphics\Screen name, ext = os.path.splitext(name2) if ext.lower() in accept: img = pg.image.load(dir2) @@ -153,6 +285,7 @@ def load_all_gfx(directory, colorkey=c.WHITE, accept=('.png', '.jpg', '.bmp', '. graphics[name] = img return graphics + def loadZombieImageRect(): file_path = os.path.join('source', 'data', 'entity', 'zombie.json') f = open(file_path) @@ -160,6 +293,7 @@ def loadZombieImageRect(): f.close() return data[c.ZOMBIE_IMAGE_RECT] + def loadPlantImageRect(): file_path = os.path.join('source', 'data', 'entity', 'plant.json') f = open(file_path) @@ -167,10 +301,12 @@ def loadPlantImageRect(): f.close() return data[c.PLANT_IMAGE_RECT] + pg.init() pg.display.set_caption(c.ORIGINAL_CAPTION) -SCREEN = pg.display.set_mode(c.SCREEN_SIZE) - -GFX = load_all_gfx(os.path.join("resources","graphics")) +monitor_size = [pg.display.Info().current_w, pg.display.Info().current_h] +SCREEN = pg.display.set_mode(c.SCREEN_SIZE, pg.RESIZABLE) +GFX = load_all_gfx(os.path.join("resources", "graphics")) ZOMBIE_RECT = loadZombieImageRect() PLANT_RECT = loadPlantImageRect() +mainClock.tick(60)