diff --git a/CPSled.py b/CPSled.py new file mode 100644 index 00000000..a1b3a463 --- /dev/null +++ b/CPSled.py @@ -0,0 +1,269 @@ +#THIS FILE IS DOPE +import pygame +from pygame.locals import * +import time +from random import * +clock = pygame.time.Clock() + +class Penguin(pygame.sprite.Sprite): + """ + Penguin is the sprite that the user controls using the left and right arrows + It moves up and down (respectively) the screen + """ + def __init__(self): + # Call the parent class (Sprite) constructor + super().__init__() + self.image = pygame.image.load("penguin_smol.png") + self.rect = self.image.get_rect() + self.rect.y = 170 + + def moveUp(self, pixels): + if self.rect.y <= 0: + self.rect.y = 0 + else: + self.rect.y -= pixels + def moveDown(self, pixels): + if self.rect.y >= 340: + self.rect.y = 340 + else: + self.rect.y += pixels + +class Obstacles(pygame.sprite.Sprite): + """ + Obstacles is the parent class of the many different types of obstacles + The obstacles continuously move towards the left of the screen (at varying speeds), + giving the impression that the penguin is moving towards the right of the screen + """ + def __init__(self, image_name, rect = None): + super().__init__() + self.image = pygame.image.load(image_name) + self.rect = self.image.get_rect() + if rect != None: + self.rect = rect + + def moveLeft(self, pixels = 7): + self.rect.x -= pixels + def slowDown(self, pixels = 3): + self.rect.x -= pixels + def speedUp(self, pixels = 10): + self.rect.x -= pixels + +class Powerups(Obstacles): + """ + PowerUps inherits from Obstacles and makes the obstacles move faster across the screen, + making it seem like the penguin is speeding up + """ + def speedUp(self, pixels = 10): + self.rect.x -= pixels + +class FinishLine(Obstacles): + pass + +class Bump(Obstacles): + pass + +class Log(Obstacles): + pass + +class Ramp(Obstacles): + pass + +class KeyController(object): + """ + allows the player to move the penguin using the left and right keys + """ + def __init__(self, model): + self.model = model + + def event_type(self, keys, state): #state determines whether the penguin hit an obstacle or powerup + if keys[pygame.K_LEFT] and state == 1: + #if penguin hits obstacle, prevent the player from moving off the obstacle by "disabling" the keyboard controls + self.model.penguin.moveUp(0) + if keys[pygame.K_RIGHT] and state == 1: + self.model.penguin.moveDown(0) + if keys[pygame.K_LEFT] and state == 2: + #if the penguin hits a powerup, the player can still potentially move off the powerup (just to add a bit more challenge) + self.model.penguin.moveUp(5) + if keys[pygame.K_RIGHT] and state == 2: + self.model.penguin.moveDown(5) + +class CPSledView(object): + """ + View class draws all the sprites/screens that the model class updates + """ + def __init__(self, model, width, height): + self.model = model + size = (width, height) #viewing frame is 500 x 400 pixels + self.model.WHITE = pygame.Color(255, 255, 255) + self.model.screen = pygame.display.set_mode(size) + + def draw(self, model, timer): + self.model = model + self.model.screen.blit(timer, (425, 20)) + self.model.boulders.draw(self.model.screen) + self.model.ice_patches.draw(self.model.screen) + self.model.bumps.draw(self.model.screen) + self.model.logs.draw(self.model.screen) + self.model.ramps.draw(self.model.screen) + self.model.all_penguins.draw(self.model.screen) + self.model.finish_line_group.draw(self.model.screen) + pygame.display.update() + +class CPSledModel(object): + """ + Model class updates as the player control the sprite + Creates all the sprites + Randomly generates a track of obstacles + """ + def __init__(self, width, height): + pygame.init() + size = (width, height) + self.WHITE = pygame.Color(255, 255, 255) + self.screen = pygame.display.set_mode(size) + self.height = height + self.width = width + + def loadSprites(self): + self.penguin = Penguin() + #self.penguin.image = pygame.transform.rotate(self.penguin.image, -30) + self.all_penguins = pygame.sprite.RenderPlain(self.penguin) + self.boulders = pygame.sprite.RenderPlain() + self.ice_patches = pygame.sprite.RenderPlain() + self.finish_line_group = pygame.sprite.RenderPlain() + self.bumps = pygame.sprite.RenderPlain() + self.logs = pygame.sprite.RenderPlain() + self.ramps = pygame.sprite.RenderPlain() + + for num_boulders in range(18): #creating 20 boulders + x_position = (num_boulders+1) * randint(410, 440) #randomly generate an x-position within a certain range + y_boulders = randint(1,3) #randomly decide how many boulders to put in a straight line + for i in range(y_boulders): + y_position = randrange(0, 340, 70) #randomly choose a y-position for each boulder + self.boulder = Obstacles("rock.png", pygame.Rect(x_position, y_position, 60, 60)) + self.boulder.rect.inflate(0, -10) + self.boulders.add(self.boulder) #add boulder to the boulder sprite group + + for num_ice_patches in range(13): + x_position = (num_ice_patches+1) * randint(640, 670) + y_position = randint(0, 340) + self.ice_patch = Powerups("ice_patch_flat.png", pygame.Rect(x_position, y_position, 280, 70)) + self.ice_patches.add(self.ice_patch) + + for num_bumps in range(12): + x_position = (num_bumps + 1) * randint(710, 730) + y_position = randint(0, 300) + self.bump = Bump("bump.png", pygame.Rect(x_position, y_position, 132, 98)) + self.bumps.add(self.bump) + + for num_logs in range(6): + x_position = (num_logs+1) * 1100 + y_position = 0 + self.log = Log("log.png", pygame.Rect(x_position, y_position, 170, 400)) + self.logs.add(self.log) + self.ramp = Ramp("log_jump_test.png", pygame.Rect(x_position, 110, 170, 167)) + self.ramps.add(self.ramp) + + self.finish_line = FinishLine("finish_line.png", pygame.Rect(8750, -2, 144, 404)) + self.finish_line_group.add(self.finish_line) + + def update(self): + self.all_penguins.update() + self.boulders.update() + self.ice_patches.update() + self.bumps.update() + self.screen.fill(self.WHITE) + +if __name__ == '__main__': + + def main_loop(): + pygame.init() + model = CPSledModel(500,400) + view = CPSledView(model, 500, 400) + controller = KeyController(model) + model.loadSprites() + #create a master list of all the randomly generated obstacles + list_of_obstacles = model.boulders.sprites() + list_of_obstacles.extend(model.ice_patches.sprites()) + list_of_obstacles.extend(model.bumps.sprites()) + list_of_obstacles.extend(model.logs.sprites()) + + #this loop parses through the master obstacle list and removes any obstacle that collides with another obstacle to minimize overlapping obstacles + index = 0 + while index < (len(list_of_obstacles) - 1): + j = index + 1 + while j < (len(list_of_obstacles) - 1): + if list_of_obstacles[index].rect.colliderect(list_of_obstacles[j].rect): + list_of_obstacles.pop(j) + j -= 1 + j += 1 + index += 1 + + list_of_obstacles.extend(model.ramps.sprites()) + list_of_obstacles.append(model.finish_line) + + font = pygame.font.Font(None, 32) + pygame.display.set_caption("Club Penguin Sledding Game") + running = True + while running: + #run a timer of how long the penguin takes to get to the finish line + current_time = str(pygame.time.get_ticks()/1000) + timer = font.render(current_time, True, (0,0,0)) + for event in pygame.event.get(): + if event.type is pygame.QUIT: + running = False + + #if peguin passes the finish line, then break out of loop + if model.penguin.rect.left > model.finish_line.rect.left+120: + while True: + for event in pygame.event.get(): + if event.type is pygame.QUIT: + pygame.quit() + running = False + + #different flags to identify which obstacle hit + hit = False + ice = False + finish = False + bump = False + ramp = False + for obstacle in list_of_obstacles: + if model.penguin.rect.colliderect(obstacle.rect): + hit = True + if type(obstacle) == Ramp: + ramp = True + if type(obstacle) == Powerups: + ice = True + elif type(obstacle) == FinishLine: + finish = True + elif type(obstacle) == Bump: + bump = True + + #using the flags, determine how the penguin responds to the obstacle hit + for obstacle in list_of_obstacles: + if ramp: + obstacle.moveLeft() + elif ice or finish: + obstacle.speedUp() + elif hit: + if bump: + obstacle.slowDown(5) + else: + obstacle.slowDown() + else: + obstacle.moveLeft() + if hit and not ice and not finish and not ramp: + if not bump: + model.penguin.image = pygame.image.load("fallen_penguin_smol_demanding_diego.png") + controller.event_type(pygame.key.get_pressed(), 1) + else: + controller.event_type(pygame.key.get_pressed(), 2) + else: + model.penguin.image = pygame.image.load("penguin_smol.png") + controller.event_type(pygame.key.get_pressed(), 2) + + model.update() + view.draw(model, timer) + clock.tick_busy_loop(60) + pygame.quit() + + main_loop() diff --git a/MP4 Club Penguin Reflection.pdf b/MP4 Club Penguin Reflection.pdf new file mode 100644 index 00000000..ee5ea1f9 Binary files /dev/null and b/MP4 Club Penguin Reflection.pdf differ diff --git a/MP4_Club_Penguin_Reflection.pdf b/MP4_Club_Penguin_Reflection.pdf new file mode 100644 index 00000000..ee5ea1f9 Binary files /dev/null and b/MP4_Club_Penguin_Reflection.pdf differ diff --git a/README.md b/README.md index 5f822327..d910c891 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,13 @@ # InteractiveProgramming -This is the base repo for the interactive programming project for Software Design, Spring 2018 at Olin College. +Club Penguin Sledding Game +In order to setup the environment to run this code, run the following in the terminal: + $ apt-get build-dep python-pygame + $ apt-get install mercurial python-dev python-numpy ffmpeg libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsmpeg-dev libsdl1.2-dev libportmidi-dev libswscale-dev libavformat-dev libavcodec-dev + $ pip install pygame + +In order to run the actual code, run the following in the terminal: + python CPSled.py + +[Project Reflection](MP4_Club_Penguin_Reflection.pdf) + +Enjoy! diff --git a/Soft Des MP4 Project Proposal.pdf b/Soft Des MP4 Project Proposal.pdf new file mode 100644 index 00000000..beebdb75 Binary files /dev/null and b/Soft Des MP4 Project Proposal.pdf differ diff --git a/bump(1).png b/bump(1).png new file mode 100644 index 00000000..79d05bca Binary files /dev/null and b/bump(1).png differ diff --git a/bump.png b/bump.png new file mode 100644 index 00000000..4fa7548f Binary files /dev/null and b/bump.png differ diff --git a/croproc.png b/croproc.png new file mode 100644 index 00000000..338f6200 Binary files /dev/null and b/croproc.png differ diff --git a/diego.py b/diego.py new file mode 100644 index 00000000..7f9fab7b --- /dev/null +++ b/diego.py @@ -0,0 +1,109 @@ +#THIS FILE IS DOPE +import pygame +from pygame.locals import * +import time +clock = pygame.time.Clock() + +class Penguin(pygame.sprite.Sprite): # code is from pygame documenta + # Constructor. Pass in the color of the block, + # and its x and y position + def __init__(self): + # Call the parent class (Sprite) constructor + super().__init__() + + # Create an image of the block, and fill it with a color + self.image = pygame.image.load("penguin_smol.png") + self.rect = self.image.get_rect() + def moveUp(self, pixels): + if self.rect.y <= 0: + self.rect.y = 0 + else: + self.rect.y -= pixels + + def moveDown(self, pixels): + if self.rect.y >= 340: + self.rect.y = 340 + else: + self.rect.y += pixels + + + +class Obstacles(pygame.sprite.Sprite): + def __init__(self, rect = None): + super().__init__() + self.image = pygame.image.load("rock.png") + self.rect = self.image.get_rect() + if rect != None: + self.rect = rect + + def moveLeft(self, pixels): + self.rect.x -= pixels +# class Model: +# def __init__(self): +# self.all_penguins = pygame.sprite.Group() +# penguin = Penguin() + + +class Sled_Main: + def __init__(self): + pygame.init() + size = (500, 400) + self.WHITE = pygame.Color(255, 255, 255) + self.screen = pygame.display.set_mode(size) + + def loadSprites(self): + self.penguin = Penguin() + self.all_penguins = pygame.sprite.RenderPlain(self.penguin) + + self.boulders = pygame.sprite.RenderPlain() + self.boulders.add(Obstacles(pygame.Rect(100, 100, 60, 60))) + + def main_loop(self): + self.loadSprites() + running = True + pygame.display.set_caption("Club Penguing Sledding Game") + while running: + #self._redraw() + for event in pygame.event.get(): + if event.type is pygame.QUIT: + running = False + keys = pygame.key.get_pressed() + if keys[pygame.K_LEFT]: + self.penguin.moveUp(15) + if keys[pygame.K_RIGHT]: + self.penguin.moveDown(15) + self.all_penguins.update() + + list_of_boulders = self.boulders.sprites() + + + if self.penguin.rect.colliderect(list_of_boulders[0].rect): + list_of_boulders[0].moveLeft(0) + else: + list_of_boulders[0].moveLeft(1) + self.boulders.update() + + self.screen.fill(self.WHITE) + self.boulders.draw(self.screen) + self.ice_patches.draw(self.screen) + self.all_penguins.draw(self.screen) + pygame.display.update() + clock.tick(60) + pygame.quit() + + + + +if __name__ == '__main__': + game = Sled_Main() + game.main_loop() + + + # running = True + # while running: + # for event in pygame.event.get(): + # if event.type == QUIT: + # running = False + # time.sleep(.001) + # + # pygame.quit() diff --git a/fallen_penguin.png b/fallen_penguin.png new file mode 100644 index 00000000..b86e3dde Binary files /dev/null and b/fallen_penguin.png differ diff --git a/fallen_penguin.v2.png b/fallen_penguin.v2.png new file mode 100644 index 00000000..39353466 Binary files /dev/null and b/fallen_penguin.v2.png differ diff --git a/fallen_penguin_smol.png b/fallen_penguin_smol.png new file mode 100644 index 00000000..4e7eb603 Binary files /dev/null and b/fallen_penguin_smol.png differ diff --git a/fallen_penguin_smol_demanding_diego.png b/fallen_penguin_smol_demanding_diego.png new file mode 100644 index 00000000..c81e0b59 Binary files /dev/null and b/fallen_penguin_smol_demanding_diego.png differ diff --git a/finish_line.png b/finish_line.png new file mode 100644 index 00000000..8ea6d09b Binary files /dev/null and b/finish_line.png differ diff --git a/ice_patch.png b/ice_patch.png new file mode 100644 index 00000000..53e84a26 Binary files /dev/null and b/ice_patch.png differ diff --git a/ice_patch_flat.png b/ice_patch_flat.png new file mode 100644 index 00000000..72bfee0f Binary files /dev/null and b/ice_patch_flat.png differ diff --git a/log(1).png b/log(1).png new file mode 100644 index 00000000..efc31f94 Binary files /dev/null and b/log(1).png differ diff --git a/log.png b/log.png new file mode 100644 index 00000000..d2826069 Binary files /dev/null and b/log.png differ diff --git a/log_jump.png b/log_jump.png new file mode 100644 index 00000000..4f80721a Binary files /dev/null and b/log_jump.png differ diff --git a/log_jump_test.png b/log_jump_test.png new file mode 100644 index 00000000..e05d4702 Binary files /dev/null and b/log_jump_test.png differ diff --git a/penguin.png b/penguin.png new file mode 100644 index 00000000..7b9fd616 Binary files /dev/null and b/penguin.png differ diff --git a/penguin_smol.png b/penguin_smol.png new file mode 100644 index 00000000..cbc01aa9 Binary files /dev/null and b/penguin_smol.png differ diff --git a/penguin_smoler.png b/penguin_smoler.png new file mode 100644 index 00000000..2c733e74 Binary files /dev/null and b/penguin_smoler.png differ diff --git a/rachel.py b/rachel.py new file mode 100644 index 00000000..430fd90f --- /dev/null +++ b/rachel.py @@ -0,0 +1,269 @@ +#THIS FILE IS DOPE +import pygame +from pygame.locals import * +import time +from random import * +clock = pygame.time.Clock() + +class Penguin(pygame.sprite.Sprite): + """ + Penguin is the sprite that the user controls using the left and right arrows + It moves up and down the screen + """ + def __init__(self): + # Call the parent class (Sprite) constructor + super().__init__() + self.image = pygame.image.load("penguin_smol.png") + self.rect = self.image.get_rect() + self.rect.y = 170 + + def moveUp(self, pixels): + if self.rect.y <= 0: + self.rect.y = 0 + else: + self.rect.y -= pixels + def moveDown(self, pixels): + if self.rect.y >= 340: + self.rect.y = 340 + else: + self.rect.y += pixels + +class Obstacles(pygame.sprite.Sprite): + """ + Obstacles is the parent class of the many different types of obstacles + The obstacles continuously move towards the left of the screen (at varying speeds), + giving the impression that the penguin is moving towards the right of the screen + """ + def __init__(self, image_name, rect = None): + super().__init__() + self.image = pygame.image.load(image_name) + self.rect = self.image.get_rect() + if rect != None: + self.rect = rect + + def moveLeft(self, pixels = 7): + self.rect.x -= pixels + def slowDown(self, pixels = 3): + self.rect.x -= pixels + def speedUp(self, pixels = 10): + self.rect.x -= pixels + +class Powerups(Obstacles): + """ + PowerUps inherits from Obstacles and makes the obstacles move faster across the screen, + making it seem like the penguin is speeding up + """ + def speedUp(self, pixels = 10): + self.rect.x -= pixels + +class FinishLine(Obstacles): + pass + +class Bump(Obstacles): + pass + +class Log(Obstacles): + pass + +class Ramp(Obstacles): + pass + +class KeyController(object): + """ + allows the player to move the penguin using the left and right keys + """ + def __init__(self, model): + self.model = model + + def event_type(self, keys, state): #state determines whether the penguin hit an obstacle or powerup + if keys[pygame.K_LEFT] and state == 1: + #if penguin hits obstacle, prevent the player from moving off the obstacle by "disabling" the keyboard controls + self.model.penguin.moveUp(0) + if keys[pygame.K_RIGHT] and state == 1: + self.model.penguin.moveDown(0) + if keys[pygame.K_LEFT] and state == 2: + #if the penguin hits a powerup, the player can still potentially move off the powerup (just to add a bit more challenge) + self.model.penguin.moveUp(5) + if keys[pygame.K_RIGHT] and state == 2: + self.model.penguin.moveDown(5) + +class CPSledView(object): + """ + View class draws all the sprites/screens that the model class updates + """ + def __init__(self, model, width, height): + self.model = model + size = (width, height) #viewing frame is 500 x 400 pixels + self.model.WHITE = pygame.Color(255, 255, 255) + self.model.screen = pygame.display.set_mode(size) + + def draw(self, model, timer): + self.model = model + self.model.screen.blit(timer, (425, 20)) + self.model.boulders.draw(self.model.screen) + self.model.ice_patches.draw(self.model.screen) + self.model.bumps.draw(self.model.screen) + self.model.logs.draw(self.model.screen) + self.model.ramps.draw(self.model.screen) + self.model.all_penguins.draw(self.model.screen) + self.model.finish_line_group.draw(self.model.screen) + pygame.display.update() + +class CPSledModel(object): + """ + Model class updates as the player control the sprite + Creates all the sprites + Randomly generates a track of obstacles + """ + def __init__(self, width, height): + pygame.init() + size = (width, height) + self.WHITE = pygame.Color(255, 255, 255) + self.screen = pygame.display.set_mode(size) + self.height = height + self.width = width + + def loadSprites(self): + self.penguin = Penguin() + #self.penguin.image = pygame.transform.rotate(self.penguin.image, -30) + self.all_penguins = pygame.sprite.RenderPlain(self.penguin) + self.boulders = pygame.sprite.RenderPlain() + self.ice_patches = pygame.sprite.RenderPlain() + self.finish_line_group = pygame.sprite.RenderPlain() + self.bumps = pygame.sprite.RenderPlain() + self.logs = pygame.sprite.RenderPlain() + self.ramps = pygame.sprite.RenderPlain() + + for num_boulders in range(18): #creating 20 boulders + x_position = (num_boulders+1) * randint(410, 440) #randomly generate an x-position within a certain range + y_boulders = randint(1,3) #randomly decide how many boulders to put in a straight line + for i in range(y_boulders): + y_position = randrange(0, 340, 70) #randomly choose a y-position for each boulder + self.boulder = Obstacles("rock.png", pygame.Rect(x_position, y_position, 60, 60)) + self.boulder.rect.inflate(0, -10) + self.boulders.add(self.boulder) #add boulder to the boulder sprite group + + for num_ice_patches in range(13): + x_position = (num_ice_patches+1) * randint(640, 670) + y_position = randint(0, 340) + self.ice_patch = Powerups("ice_patch_flat.png", pygame.Rect(x_position, y_position, 280, 70)) + self.ice_patches.add(self.ice_patch) + + for num_bumps in range(12): + x_position = (num_bumps + 1) * randint(710, 730) + y_position = randint(0, 300) + self.bump = Bump("bump.png", pygame.Rect(x_position, y_position, 132, 98)) + self.bumps.add(self.bump) + + for num_logs in range(6): + x_position = (num_logs+1) * 1100 + y_position = 0 + self.log = Log("log.png", pygame.Rect(x_position, y_position, 170, 400)) + self.logs.add(self.log) + self.ramp = Ramp("log_jump_test.png", pygame.Rect(x_position, 110, 170, 167)) + self.ramps.add(self.ramp) + + self.finish_line = FinishLine("finish_line.png", pygame.Rect(8750, -2, 144, 404)) + self.finish_line_group.add(self.finish_line) + + def update(self): + self.all_penguins.update() + self.boulders.update() + self.ice_patches.update() + self.bumps.update() + self.screen.fill(self.WHITE) + +if __name__ == '__main__': + + def main_loop(): + pygame.init() + model = CPSledModel(500,400) + view = CPSledView(model, 500, 400) + controller = KeyController(model) + model.loadSprites() + #create a master list of all the randomly generated obstacles + list_of_obstacles = model.boulders.sprites() + list_of_obstacles.extend(model.ice_patches.sprites()) + list_of_obstacles.extend(model.bumps.sprites()) + list_of_obstacles.extend(model.logs.sprites()) + + #this loop parses through the master obstacle list and removes any obstacle that collides with another obstacle to minimize overlapping obstacles + index = 0 + while index < (len(list_of_obstacles) - 1): + j = index + 1 + while j < (len(list_of_obstacles) - 1): + if list_of_obstacles[index].rect.colliderect(list_of_obstacles[j].rect): + list_of_obstacles.pop(j) + j -= 1 + j += 1 + index += 1 + + list_of_obstacles.extend(model.ramps.sprites()) + list_of_obstacles.append(model.finish_line) + + font = pygame.font.Font(None, 32) + pygame.display.set_caption("Club Penguin Sledding Game") + running = True + while running: + #run a timer of how long the penguin takes to get to the finish line + current_time = str(pygame.time.get_ticks()/1000) + timer = font.render(current_time, True, (0,0,0)) + for event in pygame.event.get(): + if event.type is pygame.QUIT: + running = False + + #if peguin passes the finish line, then break out of loop + if model.penguin.rect.left > model.finish_line.rect.left+120: + while True: + for event in pygame.event.get(): + if event.type is pygame.QUIT: + pygame.quit() + running = False + + #different flags to identify which obstacle hit + hit = False + ice = False + finish = False + bump = False + ramp = False + for obstacle in list_of_obstacles: + if model.penguin.rect.colliderect(obstacle.rect): + hit = True + if type(obstacle) == Ramp: + ramp = True + if type(obstacle) == Powerups: + ice = True + elif type(obstacle) == FinishLine: + finish = True + elif type(obstacle) == Bump: + bump = True + + #using the flags, determine how the penguin responds to the obstacle hit + for obstacle in list_of_obstacles: + if ramp: + obstacle.moveLeft() + elif ice or finish: + obstacle.speedUp() + elif hit: + if bump: + obstacle.slowDown(5) + else: + obstacle.slowDown() + else: + obstacle.moveLeft() + if hit and not ice and not finish and not ramp: + if not bump: + model.penguin.image = pygame.image.load("fallen_penguin_smol_demanding_diego.png") + controller.event_type(pygame.key.get_pressed(), 1) + else: + controller.event_type(pygame.key.get_pressed(), 2) + else: + model.penguin.image = pygame.image.load("penguin_smol.png") + controller.event_type(pygame.key.get_pressed(), 2) + + model.update() + view.draw(model, timer) + clock.tick_busy_loop(60) + pygame.quit() + + main_loop() diff --git a/rock.png b/rock.png new file mode 100644 index 00000000..a5bc381d Binary files /dev/null and b/rock.png differ diff --git a/standing_penguin.png b/standing_penguin.png new file mode 100644 index 00000000..948fc958 Binary files /dev/null and b/standing_penguin.png differ diff --git a/start.png b/start.png new file mode 100644 index 00000000..ab6bf522 Binary files /dev/null and b/start.png differ diff --git a/test.py b/test.py new file mode 100644 index 00000000..9432f98c --- /dev/null +++ b/test.py @@ -0,0 +1,69 @@ +import pygame, random +WHITE = (255, 255, 255) + +class Car(pygame.sprite.Sprite): + #This class represents a car. It derives from the "Sprite" class in Pygame. + + def __init__(self, color, width, height): + # Call the parent class (Sprite) constructor + super().__init__() + + # Pass in the color of the car, and its x and y position, width and height. + # Set the background color and set it to be transparent + self.image = pygame.image.load("penguin_smol.png").convert_alpha() + self.rect = self.image.get_rect() + +pygame.init() + +GREEN = (20, 255, 140) +GREY = (210, 210 ,210) +WHITE = (255, 255, 255) +RED = (255, 0, 0) +PURPLE = (255, 0, 255) + +SCREENWIDTH=400 +SCREENHEIGHT=500 + +size = (SCREENWIDTH, SCREENHEIGHT) +screen = pygame.display.set_mode(size) +pygame.display.set_caption("Club Penguin Sledding Game") + +#This will be a list that will contain all the sprites we intend to use in our game. +all_sprites_list = pygame.sprite.Group() + +playerCar = Car(RED, 20, 30) +playerCar.rect.x = 200 +playerCar.rect.y = 300 + +# Add the car to the list of objects +all_sprites_list.add(playerCar) + +#Allowing the user to close the window... +carryOn = True +clock=pygame.time.Clock() + +while carryOn: + for event in pygame.event.get(): + if event.type==pygame.QUIT: + carryOn=False + + #Game Logic + all_sprites_list.update() + + #Drawing on Screen + screen.fill(GREEN) + #Draw The Road + pygame.draw.rect(screen, GREY, [40,0, 200,300]) + #Draw Line painting on the road + pygame.draw.line(screen, WHITE, [140,0],[140,300],5) + + #Now let's draw all the sprites in one go. (For now we only have 1 sprite!) + all_sprites_list.draw(screen) + + #Refresh Screen + pygame.display.flip() + + #Number of frames per secong e.g. 60 + clock.tick(60) + +pygame.quit()