diff --git a/Birdy Game.ttf b/Birdy Game.ttf new file mode 100644 index 00000000..922e46c8 Binary files /dev/null and b/Birdy Game.ttf differ diff --git a/Boing.ogg b/Boing.ogg new file mode 100644 index 00000000..8120eedf Binary files /dev/null and b/Boing.ogg differ diff --git a/Bread_Left.png b/Bread_Left.png new file mode 100644 index 00000000..04bf556c Binary files /dev/null and b/Bread_Left.png differ diff --git a/Bread_Right.png b/Bread_Right.png new file mode 100644 index 00000000..16edacac Binary files /dev/null and b/Bread_Right.png differ diff --git a/Butter.png b/Butter.png new file mode 100644 index 00000000..7fafde50 Binary files /dev/null and b/Butter.png differ diff --git a/CakeTexture.jpeg b/CakeTexture.jpeg new file mode 100644 index 00000000..1a3df3f1 Binary files /dev/null and b/CakeTexture.jpeg differ diff --git a/Celery.png b/Celery.png new file mode 100644 index 00000000..cd9b39a2 Binary files /dev/null and b/Celery.png differ diff --git a/Chase1.png b/Chase1.png new file mode 100644 index 00000000..01e1cc9b Binary files /dev/null and b/Chase1.png differ diff --git a/Chase2.png b/Chase2.png new file mode 100644 index 00000000..06b46fef Binary files /dev/null and b/Chase2.png differ diff --git a/Chocolate.png b/Chocolate.png new file mode 100644 index 00000000..f81e1d85 Binary files /dev/null and b/Chocolate.png differ diff --git a/CremeBrulee.jpg b/CremeBrulee.jpg new file mode 100644 index 00000000..db2bab96 Binary files /dev/null and b/CremeBrulee.jpg differ diff --git a/Custard.jpg b/Custard.jpg new file mode 100644 index 00000000..70b13134 Binary files /dev/null and b/Custard.jpg differ diff --git a/EggWorld.ipynb b/EggWorld.ipynb new file mode 100644 index 00000000..f8fb6724 --- /dev/null +++ b/EggWorld.ipynb @@ -0,0 +1,1052 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "import pygame\n", + "import random\n", + "\n", + "class keys:\n", + " \"\"\"Saves the buttons pressed once per every round of the main While loop.\"\"\"\n", + " def __init__(self, event= None):\n", + " self.last_pressed = \"\"\n", + " self.string = \"Pressed:\"\n", + " if event.key == pygame.K_UP:\n", + " self.UP = True\n", + " self.string += \"UP\"\n", + " else:\n", + " self.UP = False\n", + " if event.key == pygame.K_DOWN:\n", + " self.DOWN = True\n", + " self.string += \"DOWN\"\n", + " else:\n", + " self.DOWN = False\n", + " if event.key == pygame.K_RIGHT:\n", + " self.RIGHT = True\n", + " self.string += \"RIGHT\"\n", + " self.last_pressed = \"RIGHT\"\n", + " else:\n", + " self.RIGHT = False \n", + " if event.key == pygame.K_LEFT:\n", + " self.LEFT = True\n", + " self.string += \"LEFT\"\n", + " self.last_pressed = \"LEFT\"\n", + " else:\n", + " self.LEFT = False \n", + " \n", + " def __str__(self):\n", + " return self.string\n", + " \n", + " \n", + "def xy_position_to_pixels(Rectangle, window_size, virtual_window):\n", + " \"\"\"Takes:In-game coordinate rectangle\n", + " Converts in-game coordinates to pixels. Also, note that the in-game position refers to the LOWER RIGHT hand\n", + " corner of the sprite. \n", + " Returns: rectangle in pixel coordinates\"\"\"\n", + " x = Rectangle[0]\n", + " y = Rectangle[1]\n", + " width = Rectangle[2]\n", + " height = Rectangle[3]\n", + " pixel_x = int(float(x/virtual_window[0])*window_size[0])\n", + " pixel_y = window_size[1] - int(float(y/virtual_window[1])*window_size[1])\n", + " pixel_width = int(float(width/virtual_window[0])*window_size[0])\n", + " pixel_height = int(float(height/virtual_window[1])*window_size[1])\n", + " pixel_y -= pixel_height\n", + " return (pixel_x, pixel_y, pixel_width, pixel_height)\n", + "\n", + "\n", + "\n", + "class position:\n", + " \"\"\"Class holds position/size/speed values of the character as well as a function that updates \n", + " the position every loop.\"\"\"\n", + " def __init__(self, current_x = 0, current_y = 0, current_xs = 0, current_ys = 0, floor = 0, button=None,\n", + " character_width = 30, character_height = 30, wall_speed = .3):\n", + " self.current_x = current_x\n", + " self.current_y = current_y\n", + " self.current_xs = current_xs\n", + " self.current_ys = current_ys\n", + " self.button = button\n", + " self.floor = floor\n", + " self.last_pressed = None\n", + " self.jump = False\n", + " self.character_width = character_width\n", + " self.character_height = character_height\n", + " self.wall = None\n", + " self.wall_speed = wall_speed\n", + " self.maintain = False\n", + " \n", + " def __str__(self):\n", + " return str(self.current_x)+\" \"+str(self.current_y)+\" \"+str(self.current_xs)+\" \"+str(self.current_ys)\n", + " \n", + " def give_next_position(self, floor, wall): #fix button \n", + " #print(\"The give next position function has run.\")\n", + " #print(\"Button:\", button)\n", + " self.floor = floor\n", + " self.wall = wall\n", + " \n", + " \n", + " if self.current_y <= self.floor:\n", + " self.current_ys = 0\n", + " self.jump = False\n", + " if not self.jump: \n", + " self.current_xs = -1*self.wall_speed\n", + " if self.current_y > self.floor:\n", + " self.current_ys -= .3\n", + " \n", + " if self.button != None: \n", + " #print(\"AH I SENSE MOVEMENT!\")\n", + " if self.current_y == self.floor:\n", + " if self.button.UP:\n", + " pygame.mixer.Sound.play(jump_sound) #HERE\n", + " self.current_ys = 7\n", + " if self.last_pressed == \"RIGHT\":\n", + " self.current_xs = 1\n", + " self.jump = True\n", + " if wall[1] != None:\n", + " if self.current_x+self.character_width+1 >= wall[1]:\n", + " self.current_xs = 0\n", + " elif self.last_pressed == \"LEFT\":\n", + " self.current_xs = -1 - self.wall_speed\n", + " self.jump = True\n", + " if wall[0] != None:\n", + " if self.current_x <= wall[0]:\n", + " self.current_xs = 0\n", + " \n", + " if self.button.RIGHT:\n", + " self.current_xs = 1\n", + " if wall[1] != None:\n", + " if self.current_x+self.character_width+1 >= wall[1]:\n", + " self.current_xs = 0\n", + " elif self.button.LEFT:\n", + " self.current_xs = -1 - self.wall_speed\n", + " if wall[0] != None:\n", + " if self.current_x <= wall[0]:\n", + " self.current_xs = 0\n", + " self.last_pressed = self.button.last_pressed\n", + " \n", + " self.current_x += self.current_xs\n", + " self.current_y += self.current_ys\n", + " \n", + " #collision effects\n", + " if wall[0] != None:\n", + " if self.current_x <= wall[0]:\n", + " self.current_x = wall[0]+1\n", + " \n", + " if wall[1] != None:\n", + " \n", + " #print(\"I am at x position \", str(self.current_x+self.character_width))\n", + " \n", + " if self.current_x+self.character_width >= wall[1]:\n", + " self.current_x = wall[1]-self.character_width-1\n", + " \n", + " if self.current_x+self.character_width+1 >= wall[1]:\n", + " self.current_x -= self.wall_speed\n", + " \n", + " if self.current_y < self.floor:\n", + " self.current_y = self.floor\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "###PLATFORMS###\n", + "class platform:\n", + " def __init__(self, x1, x2, height):\n", + " self.leftX = x1\n", + " self.rightX = x2\n", + " self.height = height\n", + "\n", + "platform_generation_list = [(120,200,50)]\n", + "\n", + "def generate_list_of_platform_objects(platform_generation_list):\n", + " \"\"\"Takes a list of tuples that include (x1,x2,height) and makes them into a list of platform objects.\"\"\"\n", + " list_of_platforms = []\n", + " for i in platform_generation_list:\n", + " platform_temp = platform(i[0], i[1], i[2])\n", + " list_of_platforms.append(platform_temp)\n", + " return list_of_platforms\n", + "\n", + "def generate_list_of_platforms_on_screen(list_of_platforms, virtual_window):\n", + " \"\"\"Takes a list of all platform objects and creates a new list of only the ones that will appear on-screen.\"\"\"\n", + " list_of_platforms.sort(key = lambda plat: plat.leftX) ###SORT BY LEFTX\n", + " list_of_platforms_on_screen = []\n", + " for i in list_of_platforms:\n", + " if i.rightX < 0:\n", + " continue\n", + " list_of_platforms_on_screen.append(i)\n", + " if i.leftX > virtual_window[0]:\n", + " break\n", + " return list_of_platforms_on_screen\n", + "\n", + "def blit_platform(platform, window_size, virtual_window):\n", + " rectangle = (platform.leftX, platform.height - 5, platform.rightX-platform.leftX, 5)\n", + " pixel_rectangle = xy_position_to_pixels(rectangle, window_size, virtual_window)\n", + " screen.blit(texture_scaled,pixel_rectangle,pixel_rectangle)\n", + " \n", + " contrast_rectangle = (platform.leftX, platform.height - 3, platform.rightX-platform.leftX, 2)\n", + " pixel_contrast_rectangle = xy_position_to_pixels(contrast_rectangle, window_size, virtual_window)\n", + " pygame.draw.rect(screen,(212, 78, 77),pixel_contrast_rectangle)\n", + " \n", + " icing_rectangle = (platform.leftX, platform.height - 2, platform.rightX-platform.leftX, 2)\n", + " pixel_icing_rectangle = xy_position_to_pixels(icing_rectangle, window_size, virtual_window)\n", + " pygame.draw.rect(screen,(255, 205, 205),pixel_icing_rectangle)\n", + " \n", + " \n", + "\n", + "\n", + "###BLOCKS###\n", + "class block:\n", + " def __init__(self, x, y, width, height):\n", + " self.leftX = x\n", + " self.rightX = x+width\n", + " self.height = y + height\n", + " self.bot = y\n", + " self.text = \"(\" + str(x)+ \", \" + str(y)+ \", \" + str(width)+ \", \" + str(height)+\")\" \n", + " \n", + "\n", + "def generate_list_of_block_objects(block_generation_list):\n", + " list_of_blocks = []\n", + " for i in block_generation_list:\n", + " block_temp = block(i[0],i[1], i[2], i[3])\n", + " list_of_blocks.append(block_temp)\n", + " return list_of_blocks\n", + "\n", + "def generate_list_of_blocks_on_screen(list_of_blocks, virtual_window):\n", + " list_of_blocks.sort(key = lambda bl: bl.leftX) ###SORT BY LEFTX\n", + " list_of_blocks_on_screen = []\n", + " for i in list_of_blocks:\n", + " if i.rightX < 0:\n", + " continue\n", + " list_of_blocks_on_screen.append(i)\n", + " if i.leftX > virtual_window[0]:\n", + " break\n", + " return list_of_blocks_on_screen\n", + "\n", + "def blit_block(block, window_size, virtual_window, font):\n", + " rectangle = (block.leftX, block.bot, block.rightX-block.leftX, block.height-block.bot)\n", + " pixel_rectangle = xy_position_to_pixels(rectangle, window_size, virtual_window)\n", + " screen.blit(texture_scaled,pixel_rectangle,pixel_rectangle)\n", + " \n", + " shadow_rectangle = (block.leftX,block.height-4, block.rightX-block.leftX, 2)\n", + " pixel_shadow_rectangle = xy_position_to_pixels(shadow_rectangle, window_size, virtual_window)\n", + " pygame.draw.rect(screen,(226, 168, 85), pixel_shadow_rectangle)\n", + " \n", + " contrast_rectangle = (block.leftX,block.height-3, block.rightX-block.leftX, 2)\n", + " pixel_contrast_rectangle = xy_position_to_pixels(contrast_rectangle, window_size, virtual_window)\n", + " pygame.draw.rect(screen,(212, 78, 77), pixel_contrast_rectangle)\n", + " \n", + " icing_rectangle = (block.leftX-2,block.height-2, block.rightX-block.leftX+2, 2)\n", + " pixel_icing_rectangle = xy_position_to_pixels(icing_rectangle, window_size, virtual_window)\n", + " pygame.draw.rect(screen,(255, 205, 205), pixel_icing_rectangle)\n", + " \n", + " #textsurface = font.render(block.text, False, (0, 0, 0))\n", + " #xy_position_of_text = (pixel_rectangle[0],pixel_rectangle[1])\n", + " #screen.blit(textsurface,xy_position_of_text)\n", + " \n", + "def scroll_everything_left(list_of_platforms, list_of_blocks, list_of_badbreads, list_of_ingredients, world_speed):\n", + " for platform in list_of_platforms:\n", + " platform.rightX -= world_speed\n", + " platform.leftX -= world_speed\n", + " for block in list_of_blocks:\n", + " block.rightX -= world_speed\n", + " block.leftX -= world_speed\n", + " for badbread in list_of_badbreads:\n", + " badbread.startx -= world_speed\n", + " badbread.endx -= world_speed\n", + " badbread.current_bread_x -= world_speed\n", + " for ingredient in list_of_ingredients:\n", + " ingredient.ingredient_position_x -= world_speed \n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "class badbread:\n", + " def __init__(self, startx, starty, endx, speed = .5):\n", + " self.startx = startx\n", + " self.starty = starty\n", + " self.endx = endx\n", + " self.speed = speed\n", + " self.current_bread_x = startx\n", + " self.size = 40\n", + " \n", + " def move_badbread(self):\n", + " if self.current_bread_x < self.startx:\n", + " self.speed = abs(self.speed)\n", + " if self.current_bread_x > self.endx:\n", + " self.speed = -1*abs(self.speed)\n", + " self.current_bread_x += self.speed\n", + "\n", + "def generate_list_of_badbreads(badbread_generation_list):\n", + " list_of_badbreads = []\n", + " for i in badbread_generation_list:\n", + " badbread_temp = badbread(i[0], i[1], i[2])\n", + " list_of_badbreads.append(badbread_temp)\n", + " return list_of_badbreads\n", + "\n", + "def generate_list_of_badbreads_on_screen(list_of_badbreads, virtual_window):\n", + " list_of_badbreads.sort(key = lambda bl: bl.startx) \n", + " list_of_badbreads_on_screen = []\n", + " for i in list_of_badbreads:\n", + " if i.endx+i.size < 0:\n", + " continue\n", + " list_of_badbreads_on_screen.append(i)\n", + " if i.startx > virtual_window[0]:\n", + " break\n", + " return list_of_badbreads_on_screen\n", + "\n", + "def blit_badbread(badbread, window_size, virtual_window):\n", + " rectangle = (badbread.current_bread_x, badbread.starty, badbread.size, badbread.size)\n", + " pixel_rectangle = xy_position_to_pixels(rectangle, window_size, virtual_window)\n", + " if badbread.speed > 0:\n", + " screen.blit(bread_right_scaled,pixel_rectangle)\n", + " else:\n", + " screen.blit(bread_left_scaled,pixel_rectangle)\n", + "\n", + "def generate_badbread_collisions(list_of_badbreads_on_screen, list_of_badbreads, current_position):\n", + " badbread_collisions = []\n", + " current_position_rectangle = pygame.Rect(\n", + " xy_position_to_pixels((current_position.current_x, current_position.current_y,\n", + " current_position.character_width, current_position.character_height), virtual_window, window_size))\n", + " for i in list_of_badbreads_on_screen:\n", + " badbread_rectange = pygame.Rect(xy_position_to_pixels(\n", + " (i.current_bread_x + 5, i.starty, i.size-5, i.size-10), \n", + " virtual_window, window_size))\n", + " if current_position_rectangle.colliderect(badbread_rectange):\n", + " if current_position.maintain == False:\n", + " collision_temp = collision(\"badbread\", 0)\n", + " badbread_collisions.append(collision_temp)\n", + " print(\"hit a badbread\")\n", + " current_position.maintain = True\n", + " else:\n", + " current_position.maintain = False\n", + " #print(\"disengaged\")\n", + " return badbread_collisions\n", + "##HERE\n" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "class ingredient:\n", + " def __init__(self, ingredient_type, ingredient_position_x,ingredient_position_y, size = 20):\n", + " self.ingredient_type = ingredient_type\n", + " self.ingredient_position_x = ingredient_position_x\n", + " self.ingredient_position_y = ingredient_position_y\n", + " self.size = size\n", + " \n", + "def generate_list_of_ingredients(ingredient_generation_list):\n", + " list_of_ingredients = []\n", + " for i in ingredient_generation_list:\n", + " ingredient_temp = ingredient(i[0], i[1], i[2])\n", + " list_of_ingredients.append(ingredient_temp)\n", + " return list_of_ingredients\n", + "\n", + "def generate_list_of_ingredients_on_screen(list_of_ingredients, virtual_window):\n", + " list_of_ingredients.sort(key = lambda bl: bl.ingredient_position_x) \n", + " list_of_ingredients_on_screen = []\n", + " for i in list_of_ingredients:\n", + " if i.ingredient_position_x+i.size < 0:\n", + " continue\n", + " list_of_ingredients_on_screen.append(i)\n", + " if i.ingredient_position_x > virtual_window[0]:\n", + " break\n", + " return list_of_ingredients_on_screen\n", + "\n", + "def blit_ingredient(ingredient, window_size, virtual_window):\n", + " if ingredient.ingredient_type == \"milk\":\n", + " rectangle = (ingredient.ingredient_position_x, ingredient.ingredient_position_y, ingredient.size, ingredient.size)\n", + " pixel_rectangle = xy_position_to_pixels(rectangle, window_size, virtual_window)\n", + " screen.blit(milk_scaled,pixel_rectangle)\n", + " elif ingredient.ingredient_type == \"celery\":\n", + " rectangle = (ingredient.ingredient_position_x, ingredient.ingredient_position_y, ingredient.size, ingredient.size)\n", + " pixel_rectangle = xy_position_to_pixels(rectangle, window_size, virtual_window)\n", + " screen.blit(celery_scaled,pixel_rectangle)\n", + " elif ingredient.ingredient_type == \"chocolate\":\n", + " rectangle = (ingredient.ingredient_position_x, ingredient.ingredient_position_y, ingredient.size, ingredient.size)\n", + " pixel_rectangle = xy_position_to_pixels(rectangle, window_size, virtual_window)\n", + " screen.blit(chocolate_scaled,pixel_rectangle)\n", + " elif ingredient.ingredient_type == \"vanilla\":\n", + " rectangle = (ingredient.ingredient_position_x, ingredient.ingredient_position_y, ingredient.size, ingredient.size)\n", + " pixel_rectangle = xy_position_to_pixels(rectangle, window_size, virtual_window)\n", + " screen.blit(vanilla_scaled,pixel_rectangle)\n", + " elif ingredient.ingredient_type == \"flour\":\n", + " rectangle = (ingredient.ingredient_position_x, ingredient.ingredient_position_y, ingredient.size, ingredient.size)\n", + " pixel_rectangle = xy_position_to_pixels(rectangle, window_size, virtual_window)\n", + " screen.blit(flour_scaled,pixel_rectangle)\n", + " elif ingredient.ingredient_type == \"sugar\":\n", + " rectangle = (ingredient.ingredient_position_x, ingredient.ingredient_position_y, ingredient.size, ingredient.size)\n", + " pixel_rectangle = xy_position_to_pixels(rectangle, window_size, virtual_window)\n", + " screen.blit(sugar_scaled,pixel_rectangle)\n", + " elif ingredient.ingredient_type == \"butter\":\n", + " rectangle = (ingredient.ingredient_position_x, ingredient.ingredient_position_y, ingredient.size, ingredient.size)\n", + " pixel_rectangle = xy_position_to_pixels(rectangle, window_size, virtual_window)\n", + " screen.blit(butter_scaled,pixel_rectangle)" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def give_floor_value(current_position, blocks_on_screen, platforms_on_screen):\n", + " list_of_floors_under = []\n", + " for i in blocks_on_screen:\n", + " if i.rightX < current_position.current_x+10:\n", + " continue\n", + " if i.leftX > current_position.current_x+current_position.character_width:\n", + " break\n", + " if i.leftX < current_position.current_x+current_position.character_width -10 and current_position.current_x < i.rightX:\n", + " list_of_floors_under.append(i)\n", + " \n", + " for i in platforms_on_screen:\n", + " if i.rightX < current_position.current_x+10:\n", + " continue\n", + " if i.leftX > current_position.current_x+current_position.character_width:\n", + " break\n", + " if i.leftX <= current_position.current_x+current_position.character_width-10 and current_position.current_x +10 <= i.rightX:\n", + " list_of_floors_under.append(i)\n", + " list_of_floors_under.sort(key = lambda structures: structures.height, reverse = True)\n", + " if list_of_floors_under != []:\n", + " list_of_floors_under.sort(key = lambda fl: fl.height, reverse = True)\n", + " #print(\"y= \",current_position.current_y)\n", + " for i in list_of_floors_under:\n", + " if i.height <= current_position.current_y:\n", + " #print(\"floor =\",i.height)\n", + " return i.height\n", + " return -500\n", + "\n", + "def give_wall_value(current_position, blocks_on_screen):\n", + " level_with_character = []\n", + " for i in blocks_on_screen:\n", + " if i.bot > current_position.current_y+current_position.character_height: #HERE\n", + " continue\n", + " if i.height < current_position.current_y:\n", + " continue\n", + " level_with_character.append(i)\n", + " closest_left = None\n", + " closest_right = None\n", + " if level_with_character != []:\n", + " level_with_character.sort(key=lambda blocks: blocks.rightX)\n", + " for i in level_with_character:\n", + " if i.rightX-10 < current_position.current_x:\n", + " closest_left = i.rightX-10\n", + " level_with_character.sort(key=lambda blocks: blocks.leftX, reverse = True)\n", + " for i in level_with_character:\n", + " if i.leftX+10 > current_position.current_x+current_position.character_width:\n", + " closest_right = i.leftX+10 \n", + " return (closest_left, closest_right)\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "class items:\n", + " def __init__(self):\n", + " self.milk = 0\n", + " self.sugar = 0\n", + " self.celery = 0\n", + " self.butter = 0\n", + " self.flour = 0\n", + " self.vanilla = 0\n", + " self.chocolate = 0\n", + " \n", + " def __str__(self):\n", + " return \"Milk:\"+str(self.milk)+\"\\nSugar:\"+str(self.sugar) \n", + " \n", + " def total(self):\n", + " return self.milk+self.sugar+self.celery+self.chocolate+self.vanilla+self.butter+self.flour\n", + " \n", + " def remove_random(self):\n", + " #print(\"entered remove function\")\n", + " \n", + " items_present = []\n", + " if self.milk > 0:\n", + " items_present.append(1)\n", + " if self.sugar > 0:\n", + " items_present.append(2)\n", + " if self.celery > 0:\n", + " items_present.append(3)\n", + " if self.butter > 0:\n", + " items_present.append(4)\n", + " if self.flour > 0:\n", + " items_present.append(5)\n", + " if self.vanilla > 0:\n", + " items_present.append(6)\n", + " if self.chocolate > 0:\n", + " items_present.append(7)\n", + " \n", + " if items_present:\n", + " subtract = random.choice(items_present)\n", + " if subtract == 1:\n", + " self.milk -=1\n", + " elif subtract == 2:\n", + " self.sugar -=1\n", + " elif subtract == 3:\n", + " self.celery -=1\n", + " elif subtract == 4:\n", + " self.butter -=1\n", + " elif subtract == 5:\n", + " self.flour -=1\n", + " elif subtract == 6:\n", + " self.vanilla -=1\n", + " elif subtract == 7:\n", + " self.chocolate -=1\n", + " else:\n", + " pygame.mixer.Sound.play(lose_sound)\n", + " global finish_line\n", + " finish_line = True\n", + " \n", + " \n", + "class collision:\n", + " def __init__(self, collision_type, stage):\n", + " self.collision_type = collision_type\n", + " self.stage = stage\n", + "\n", + "\n", + "def generate_ingredient_collisions(list_of_ingredients_on_screen, list_of_ingredients, current_position):\n", + " ingredient_collisions = []\n", + " current_position_rectangle = pygame.Rect(\n", + " xy_position_to_pixels((current_position.current_x, current_position.current_y,\n", + " current_position.character_width, current_position.character_height), virtual_window, window_size))\n", + " for i in list_of_ingredients_on_screen:\n", + " ingredient_rectange = pygame.Rect(xy_position_to_pixels(\n", + " (i.ingredient_position_x, i.ingredient_position_y, i.size, i.size), \n", + " virtual_window, window_size))\n", + " if current_position_rectangle.colliderect(ingredient_rectange):\n", + " collision_temp = collision(i.ingredient_type, 0)\n", + " ingredient_collisions.append(collision_temp)\n", + " #print(\"added to ingredient collisions list\")\n", + " list_of_ingredients.remove(i)\n", + " return ingredient_collisions\n", + "\n", + "\n", + "def process_collision_lists(position, list_of_ingredient_collisions, list_of_badbread_collisions, items):\n", + " if list_of_ingredient_collisions:\n", + " for i in list_of_ingredient_collisions:\n", + " if i.stage == 0:\n", + " if i.collision_type == \"milk\":\n", + " items.milk += 1\n", + " elif i.collision_type == \"sugar\":\n", + " items.sugar += 1\n", + " elif i.collision_type == \"celery\":\n", + " items.celery += 1\n", + " elif i.collision_type == \"butter\":\n", + " items.butter += 1\n", + " elif i.collision_type == \"flour\":\n", + " items.flour += 1\n", + " elif i.collision_type == \"vanilla\":\n", + " items.vanilla += 1\n", + " elif i.collision_type == \"chocolate\":\n", + " items.chocolate += 1\n", + " i.stage += 1\n", + " \n", + " if list_of_badbread_collisions:\n", + " for i in list_of_badbread_collisions:\n", + " items.remove_random()\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def calculate_locations(left_bar, window_size, virtual_window):\n", + " list_of_rectangles = []\n", + " gap = float(virtual_window[1]-140)/8\n", + " for i in range(7):\n", + " rectangle = (left_bar,virtual_window[1]-((i+1)*gap + ((i+1)*20)), 20, 20)#IMAGE SIZE HARD CODED IN Y POSITON\n", + " print(str(rectangle))\n", + " pixel_rectangle = xy_position_to_pixels(rectangle, window_size, virtual_window)\n", + " list_of_rectangles.append(pixel_rectangle)\n", + " return list_of_rectangles\n", + "\n", + "def blit_items(item_class, locations, font):\n", + " if item_class.milk > 0:\n", + " #print(\"bliting milk\")\n", + " screen.blit(milk_scaled,locations[0])\n", + " textsurface = font.render(\"x\"+str(item_class.milk), False, (255, 0, 193))\n", + " xy_position_of_text = (locations[0][0]+130,locations[0][1]+20)\n", + " screen.blit(textsurface,xy_position_of_text) \n", + " if item_class.chocolate > 0:\n", + " screen.blit(chocolate_scaled,locations[1])\n", + " textsurface = font.render(\"x\"+str(item_class.chocolate), False, (255, 0, 193))\n", + " xy_position_of_text = (locations[1][0]+130,locations[1][1]+20)\n", + " screen.blit(textsurface,xy_position_of_text)\n", + " if item_class.sugar > 0:\n", + " screen.blit(sugar_scaled,locations[2])\n", + " textsurface = font.render(\"x\"+str(item_class.sugar), False, (255, 0, 193))\n", + " xy_position_of_text = (locations[2][0]+130,locations[2][1]+20)\n", + " screen.blit(textsurface,xy_position_of_text)\n", + " if item_class.celery > 0:\n", + " screen.blit(celery_scaled,locations[3])\n", + " textsurface = font.render(\"x\"+str(item_class.celery), False, (255, 0, 193))\n", + " xy_position_of_text = (locations[3][0]+130,locations[3][1]+20)\n", + " screen.blit(textsurface,xy_position_of_text)\n", + " if item_class.butter > 0:\n", + " screen.blit(butter_scaled,locations[4])\n", + " textsurface = font.render(\"x\"+str(item_class.butter), False, (255, 0, 193))\n", + " xy_position_of_text = (locations[4][0]+130,locations[4][1]+20)\n", + " screen.blit(textsurface,xy_position_of_text)\n", + " if item_class.flour > 0:\n", + " screen.blit(flour_scaled,locations[5])\n", + " textsurface = font.render(\"x\"+str(item_class.flour), False, (255, 0, 193))\n", + " xy_position_of_text = (locations[5][0]+130,locations[5][1]+20)\n", + " screen.blit(textsurface,xy_position_of_text)\n", + " if item_class.vanilla > 0:\n", + " screen.blit(vanilla_scaled,locations[6])\n", + " textsurface = font.render(\"x\"+str(item_class.vanilla), False, (255, 0, 193))\n", + " xy_position_of_text = (locations[6][0]+130,locations[6][1]+20)\n", + " screen.blit(textsurface, xy_position_of_text)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "class animation:\n", + " def __init__(self, rectangles_left, rectangles_right, rectangle_forward):\n", + " self.right = 0\n", + " self.left = 0\n", + " self.rectangles_left = rectangles_left\n", + " self.rectangles_right = rectangles_right\n", + " self.rectangle_forward = rectangle_forward\n", + " \n", + "def create_character_rectangles(spritesheet_xy, direction):\n", + " character_pixels = (spritesheet_xy[0]/4, spritesheet_xy[1]/8)\n", + " rectangle_list = []\n", + " if direction == \"left\":\n", + " for i in range(4):\n", + " rectangle_list.append((i*character_pixels[0], 0, character_pixels[0], character_pixels[1]))\n", + " for i in range(4):\n", + " rectangle_list.append((i*character_pixels[0], character_pixels[1], character_pixels[0], character_pixels[1]))\n", + " return rectangle_list\n", + " elif direction == \"right\":\n", + " for i in range(4):\n", + " rectangle_list.append((i*character_pixels[0],character_pixels[1]*4, character_pixels[0], character_pixels[1]))\n", + " for i in range(4):\n", + " rectangle_list.append((i*character_pixels[0], character_pixels[1]*5, character_pixels[0], character_pixels[1]))\n", + " return rectangle_list\n", + " elif direction == \"forward\":\n", + " rectangle_list.append((0*character_pixels[0],character_pixels[1]*2, character_pixels[0], character_pixels[1]))\n", + " return rectangle_list\n", + "def blit_character(current_position, window_size, virtual_window, animation_stage):\n", + " character_position = xy_position_to_pixels(\n", + " (current_position.current_x, current_position.current_y-2,current_position.character_width,current_position.character_height), window_size, virtual_window)\n", + " if current_position.current_xs + current_position.wall_speed > 0:\n", + " screen.blit(eggrika_spritesheet_scaled, character_position, animation_stage.rectangles_right[animation_stage.right])\n", + " if animation_stage.right < 7:\n", + " animation_stage.right += 1\n", + " else:\n", + " animation_stage.right = 0\n", + " if current_position.current_xs + current_position.wall_speed < 0:\n", + " screen.blit(eggrika_spritesheet_scaled, character_position, animation_stage.rectangles_left[animation_stage.left])\n", + " if animation_stage.left < 7:\n", + " animation_stage.left += 1\n", + " else:\n", + " animation_stage.left = 0\n", + " if current_position.current_xs + current_position.wall_speed == 0:\n", + " screen.blit(eggrika_spritesheet_scaled, character_position, animation_stage.rectangle_forward[0])\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(250, 172.5, 20, 20)\n", + "(250, 145.0, 20, 20)\n", + "(250, 117.5, 20, 20)\n", + "(250, 90.0, 20, 20)\n", + "(250, 62.5, 20, 20)\n", + "(250, 35.0, 20, 20)\n", + "(250, 7.5, 20, 20)\n", + "hit a badbread\n", + "hit a badbread\n", + "hit a badbread\n", + "hit a badbread\n" + ] + } + ], + "source": [ + "virtual_window = (300,200)\n", + "pygame.mixer.pre_init(44100, -16, 1, 512)\n", + "pygame.init()\n", + "pygame.font.init()\n", + "pygame.mixer.init()\n", + "window_size = (pygame.display.Info().current_w -50, pygame.display.Info().current_h - 50)\n", + "screen = pygame.display.set_mode(window_size)\n", + "pygame.display.set_caption(\"Egg World\")\n", + "global done\n", + "done = False\n", + "clock = pygame.time.Clock()\n", + "\n", + "wall = None\n", + "block_generation_list = [(0,0,630,20),(390,110,20,40),(370,70,60,40),\n", + " (350,30,100,40),(330,0,140,30),(680,0,120,20),(800,0,180,60),(980,0,320,10),(1300,0,250,50),\n", + " (1300,100,300,50),\n", + " (1400,150,40,50), (1550,0,50,30),\n", + " (1600,0,200,10),(1830,0,30,130),(1910,0,30,160),(1990,0,30,170),(2070, 80, 100, 50),(2070,0,530,20),\n", + " (2500,0,120,70),(2620,0,380,20)]\n", + "\n", + "list_of_blocks = generate_list_of_block_objects(block_generation_list)\n", + "\n", + "platform_generation_list = [(150,200,100),(500,600,120),(1050,1100,120),(1100,1190,70),(1190,1240,120),(1700,1770,90),\n", + " (2830,2900,100)]\n", + "\n", + "list_of_platforms = generate_list_of_platform_objects(platform_generation_list)\n", + "\n", + "badbread_generation_list = [(150,20,280),(470,20,570),(800,60,900),(1600,10,1770),(2070,20,2400)]\n", + "\n", + "list_of_badbreads = generate_list_of_badbreads(badbread_generation_list)\n", + "\n", + "ingredient_generation_list = [(\"milk\", 200, 130), (\"celery\", 250, 180), (\"sugar\", 340, 80), (\"chocolate\", 390, 160),\n", + " (\"vanilla\", 440, 80), (\"butter\", 550, 30), (\"flour\", 650, 100), (\"milk\", 770, 30),\n", + " (\"celery\", 830, 150),(\"butter\", 860, 150),(\"milk\", 890, 150), (\"chocolate\",1130,180),\n", + " (\"butter\",1130,80), (\"milk\", 1320, 160), (\"milk\", 1350, 160),(\"milk\", 1380, 160), \n", + " (\"sugar\", 1450, 70),(\"celery\", 1560, 160), (\"chocolate\", 1720,30), (\"sugar\",1830,140),\n", + " (\"sugar\",1910,170),(\"sugar\",1990,180), (\"flour\", 2290, 100), (\"milk\",2410,80)]\n", + "\n", + "list_of_ingredients = generate_list_of_ingredients(ingredient_generation_list)\n", + "wall = None\n", + "world_speed = .5\n", + "\n", + "in_title_screen = True\n", + "title_text = pygame.image.load('Title.png')\n", + "title_scaled = pygame.transform.scale(title_text, window_size)\n", + "title_block = block(0, 0, virtual_window[0],20)\n", + "scroll = 0\n", + "chase_animation = 0\n", + "chase_image1 = pygame.image.load('Chase1.png')\n", + "chase_rectangle = (2835, 108, 60, 60)\n", + "pixel_chase_rectangle = xy_position_to_pixels(chase_rectangle, window_size, virtual_window)\n", + "chase_pixel_size = (pixel_chase_rectangle[2], pixel_chase_rectangle[3])\n", + "chase_image1_transform = pygame.transform.scale(chase_image1, chase_pixel_size)\n", + "chase_image2 = pygame.image.load('Chase2.png')\n", + "chase_image2_transform = pygame.transform.scale(chase_image2, chase_pixel_size)\n", + "global finish_line\n", + "finish_line = False\n", + "start_over = False\n", + "\n", + "itembar = items()\n", + "\n", + "current_position = position(current_y= virtual_window[1], current_x = 20, wall_speed = world_speed) \n", + "title_position = position(current_y= 20, wall_speed = 0, current_xs = 5) \n", + "\n", + "myfont = pygame.font.Font('Birdy Game.ttf', 30)\n", + "myfontlarge = pygame.font.Font('Birdy Game.ttf', 80)\n", + "gradient = pygame.image.load('Gradient.jpeg')\n", + "gradient_scaled = pygame.transform.scale(gradient, window_size)\n", + "texture = pygame.image.load('CakeTexture.jpeg')\n", + "texture_scaled = pygame.transform.scale(texture, window_size)\n", + "\n", + "resize_material_rectangle = xy_position_to_pixels((0,0,20,20), window_size, virtual_window)\n", + "materials_size = (resize_material_rectangle[2], resize_material_rectangle[3])\n", + "butter_picture = pygame.image.load('Butter.png')\n", + "butter_scaled = pygame.transform.scale(butter_picture, materials_size)\n", + "milk_picture = pygame.image.load('Milk.png')\n", + "milk_scaled = pygame.transform.scale(milk_picture, materials_size)\n", + "vanilla_picture = pygame.image.load('Vanilla.png')\n", + "vanilla_scaled = pygame.transform.scale(vanilla_picture, materials_size)\n", + "celery_picture = pygame.image.load('Celery.png')\n", + "celery_scaled = pygame.transform.scale(celery_picture, materials_size)\n", + "chocolate_picture = pygame.image.load('Chocolate.png')\n", + "chocolate_scaled = pygame.transform.scale(chocolate_picture, materials_size)\n", + "sugar_picture = pygame.image.load('Sugar.png')\n", + "sugar_scaled = pygame.transform.scale(sugar_picture, materials_size)\n", + "flour_picture = pygame.image.load('Flour.png')\n", + "flour_scaled = pygame.transform.scale(flour_picture, materials_size)\n", + "resize_bread_rectangle = xy_position_to_pixels((0,0,45,45), window_size, virtual_window)\n", + "bread_size = (resize_bread_rectangle[2], resize_bread_rectangle[3])\n", + "bread_left = pygame.image.load('Bread_Left.png')\n", + "bread_left_scaled = pygame.transform.scale(bread_left, bread_size)\n", + "bread_right = pygame.image.load('Bread_Right.png')\n", + "bread_right_scaled = pygame.transform.scale(bread_right, bread_size)\n", + "custard_image = pygame.image.load('Custard.jpg')\n", + "custard_scaled = pygame.transform.scale(custard_image, window_size)\n", + "omelette_image = pygame.image.load('Omelette.jpg')\n", + "omelette_scaled = pygame.transform.scale(omelette_image, window_size)\n", + "quiche_image = pygame.image.load('Quiche.jpg')\n", + "quiche_scaled = pygame.transform.scale(quiche_image, window_size)\n", + "creme_image = pygame.image.load('CremeBrulee.jpg')\n", + "creme_scaled = pygame.transform.scale(custard_image, window_size)\n", + "pudding_image = pygame.image.load('Pudding.jpg')\n", + "pudding_scaled = pygame.transform.scale(pudding_image, window_size)\n", + "lose_image = pygame.image.load('Lose.jpg')\n", + "lose_scaled = pygame.transform.scale(lose_image, window_size)\n", + "\n", + "left_bar = virtual_window[0]-50\n", + "spacing = 10\n", + "locations = calculate_locations(left_bar, window_size, virtual_window)\n", + "\n", + "eggrika_spritesheet = pygame.image.load(\"EggrikaSpriteSheet.png\")\n", + "spritesheet_size = xy_position_to_pixels((0,0,current_position.character_width*4, \n", + " current_position.character_height*8), window_size, virtual_window)\n", + "spritesheet_xy = (spritesheet_size[2], spritesheet_size[3])\n", + "eggrika_spritesheet_scaled = pygame.transform.scale(eggrika_spritesheet, (spritesheet_size[2], spritesheet_size[3]))\n", + "\n", + "rectangles_right = create_character_rectangles(spritesheet_xy, 'right')\n", + "rectangles_left = create_character_rectangles(spritesheet_xy, 'left')\n", + "rectangle_forward = create_character_rectangles(spritesheet_xy, 'forward')\n", + "animation_stage = animation(rectangles_left, rectangles_right, rectangle_forward)\n", + "\n", + "\n", + "jump_sound = pygame.mixer.Sound('Boing.ogg')\n", + "yay_bool = False\n", + "yay_sound = pygame.mixer.Sound('Yay.ogg')\n", + "theme_sound = pygame.mixer.Sound('Theme.ogg')\n", + "lose_sound = pygame.mixer.Sound('LoseAudio.ogg')\n", + "pygame.mixer.Sound.set_volume(theme_sound, .2)\n", + "pygame.mixer.Sound.set_volume(jump_sound, .1)\n", + "pygame.mixer.Sound.play(theme_sound, loops = -1)\n", + "\n", + "while not done:\n", + " \n", + " while in_title_screen:\n", + " for event in pygame.event.get():\n", + " if event.type == pygame.QUIT:\n", + " pygame.quit()\n", + " if event.type == pygame.KEYDOWN:\n", + " if event.key == pygame.K_SPACE or event.key == pygame.K_ESCAPE:\n", + " in_title_screen = False\n", + " screen.blit(gradient_scaled,(0,0))\n", + " blit_character(title_position, window_size, virtual_window, animation_stage)\n", + " screen.blit(title_scaled,(0,0))\n", + " blit_block(title_block, window_size, virtual_window, myfont)\n", + " pygame.display.flip()\n", + " if title_position.current_x < virtual_window[0]:\n", + " title_position.current_x += title_position.current_xs\n", + " if title_position.current_x >= virtual_window[0]:\n", + " title_position.current_x = 0 - title_position.current_x - title_position.character_width\n", + " \n", + " #####\n", + " \n", + " if scroll <= 2730:\n", + " scroll_everything_left(list_of_platforms, list_of_blocks, list_of_badbreads,list_of_ingredients, world_speed)\n", + " chase_rectangle = (chase_rectangle[0]-world_speed,chase_rectangle[1], 50,50)\n", + " scroll+=world_speed\n", + " else:\n", + " current_position.wall_speed = 0\n", + " \n", + " clock.tick(50)\n", + " \n", + " for event in pygame.event.get():\n", + " if event.type == pygame.QUIT:\n", + " done = True\n", + " if event.type == pygame.KEYDOWN:\n", + " if event.key == pygame.K_ESCAPE:\n", + " done = True\n", + " #print(\"KEY DOWN!\")\n", + " current_position.button = keys(event)\n", + " #print(current_position.button)\n", + " break\n", + " if event.type == pygame.KEYUP:\n", + " #print(\"KEY UP!\")\n", + " current_position.button = None\n", + " break\n", + " \n", + " blocks_on_screen = generate_list_of_blocks_on_screen(list_of_blocks, virtual_window)\n", + " platforms_on_screen = generate_list_of_platforms_on_screen(list_of_platforms, virtual_window)\n", + " wall = give_wall_value(current_position, blocks_on_screen)\n", + " floor = give_floor_value(current_position, blocks_on_screen, platforms_on_screen)\n", + " badbreads_on_screen = generate_list_of_badbreads_on_screen(list_of_badbreads, virtual_window)\n", + " ingredients_on_screen = generate_list_of_ingredients_on_screen(list_of_ingredients, virtual_window)\n", + "\n", + " \n", + " #Check If On-Screen\n", + " if current_position.current_x < -150:\n", + " itembar.remove_random()\n", + " if current_position.current_y < -200:\n", + " itembar.remove_random()\n", + " \n", + " \n", + " #Collisions\n", + " current_position.give_next_position(floor = floor, wall = wall)\n", + " list_of_ingredient_collisions = generate_ingredient_collisions(ingredients_on_screen, list_of_ingredients, current_position)\n", + " list_of_badbread_collisions = generate_badbread_collisions(badbreads_on_screen,\n", + " list_of_badbreads, current_position)\n", + " \n", + " process_collision_lists(current_position, list_of_ingredient_collisions, list_of_badbread_collisions, itembar)\n", + " \n", + " #Blit Sky\n", + " screen.blit(gradient_scaled,(0,0))\n", + "\n", + "\n", + " \n", + " #Blit Structures/Enemies\n", + " for i in blocks_on_screen:\n", + " blit_block(i, window_size, virtual_window, myfont)\n", + " for i in platforms_on_screen:\n", + " blit_platform(i, window_size, virtual_window)\n", + " for i in badbreads_on_screen:\n", + " i.move_badbread()\n", + " blit_badbread(i, window_size, virtual_window)\n", + " for i in ingredients_on_screen:\n", + " blit_ingredient(i, window_size, virtual_window)\n", + " \n", + " #Blit Items\n", + " blit_items(itembar, locations, myfontlarge)\n", + " \n", + " #Chase:\n", + " pixel_chase_rectangle = xy_position_to_pixels(chase_rectangle, window_size, virtual_window)\n", + " if chase_animation < 30:\n", + " screen.blit(chase_image1_transform, pixel_chase_rectangle)\n", + " chase_animation+=1\n", + " elif chase_animation < 60:\n", + " screen.blit(chase_image2_transform, pixel_chase_rectangle)\n", + " chase_animation+=1\n", + " else:\n", + " screen.blit(chase_image2_transform, pixel_chase_rectangle)\n", + " chase_animation = 0\n", + " \n", + " #Test Stuff\n", + " #current_position.current_x = 100\n", + " #current_position.current_y = 150\n", + " \n", + " if current_position.current_x>chase_rectangle[0]:\n", + " if yay_bool == False:\n", + " pygame.mixer.Sound.play(yay_sound)\n", + " yay_bool == True\n", + " finish_line = True\n", + " \n", + " #Character\n", + " blit_character(current_position, window_size, virtual_window, animation_stage)\n", + " \n", + " pygame.display.flip()\n", + " \n", + " \n", + " while finish_line == True:\n", + " for event in pygame.event.get():\n", + " if event.type == pygame.QUIT:\n", + " pygame.quit()\n", + " if event.type == pygame.KEYDOWN:\n", + " print(itembar)\n", + " if event.key == pygame.K_SPACE or event.key == pygame.K_ESCAPE:\n", + " start_over = True\n", + " finish_line = False\n", + " total = itembar.total()\n", + " if total >= 23 and itembar.celery >= 3 and itembar.flour >=1:\n", + " screen.blit(quiche_scaled, (0,0))\n", + " elif total >=23 and itembar.celery >= 2:\n", + " screen.blit(omelette_scaled, (0,0))\n", + " elif total >= 20 and itembar.vanilla >= 1:\n", + " screen.blit(creme_scaled, (0,0))\n", + " elif total >= 15 and itembar.chocolate >= 3:\n", + " screen.blit(pudding_scaled, (0,0)) \n", + " elif total >= 5 and itembar.milk >= 1 and itembar.butter>=1 and itembar.flour >= 1:\n", + " screen.blit(custard_scaled, (0,0))\n", + " else:\n", + " screen.blit(lose_scaled, (0,0))\n", + " \n", + " pygame.display.flip()\n", + " \n", + " if start_over == True:\n", + " wall = None\n", + " block_generation_list = [(0,0,630,20),(390,110,20,40),(370,70,60,40),\n", + " (350,30,100,40),(330,0,140,30),(680,0,120,20),(800,0,180,60),(980,0,320,10),(1300,0,250,50),\n", + " (1300,100,300,50),\n", + " (1400,150,40,50), (1550,0,50,30),\n", + " (1600,0,200,10),(1830,0,30,130),(1910,0,30,160),(1990,0,30,170),(2070, 80, 100, 50),(2070,0,530,20),\n", + " (2500,0,120,70),(2620,0,380,20)]\n", + "\n", + " list_of_blocks = generate_list_of_block_objects(block_generation_list)\n", + "\n", + " platform_generation_list = [(150,200,100),(500,600,120),(1050,1100,120),(1100,1190,70),(1190,1240,120),(1700,1770,90),\n", + " (2830,2900,100)]\n", + "\n", + " list_of_platforms = generate_list_of_platform_objects(platform_generation_list)\n", + "\n", + " badbread_generation_list = [(150,20,280),(470,20,570),(800,60,900),(1600,10,1770),(2070,20,2400)]\n", + "\n", + " list_of_badbreads = generate_list_of_badbreads(badbread_generation_list)\n", + "\n", + " ingredient_generation_list = [(\"milk\", 200, 130), (\"celery\", 250, 180), (\"sugar\", 340, 80), (\"chocolate\", 390, 160),\n", + " (\"vanilla\", 440, 80), (\"butter\", 550, 30), (\"flour\", 650, 100), (\"milk\", 770, 30),\n", + " (\"celery\", 830, 150),(\"butter\", 860, 150),(\"milk\", 890, 150), (\"chocolate\",1130,180),\n", + " (\"butter\",1130,80), (\"milk\", 1320, 160), (\"milk\", 1350, 160),(\"milk\", 1380, 160), \n", + " (\"sugar\", 1450, 70),(\"celery\", 1560, 160), (\"chocolate\", 1720,30), (\"sugar\",1830,140),\n", + " (\"sugar\",1910,170),(\"sugar\",1990,180), (\"flour\", 2290, 100), (\"milk\",2410,80)]\n", + "\n", + " list_of_ingredients = generate_list_of_ingredients(ingredient_generation_list)\n", + " wall = None\n", + " in_title_screen = True\n", + " scroll = 0\n", + " itembar = items()\n", + " chase_rectangle = (2835, 108, 60, 60)\n", + " current_position = position(current_y= virtual_window[1], wall_speed = world_speed) \n", + " title_position = position(current_y= 20, current_x = 20, wall_speed = 0, current_xs = 5) \n", + " start_over = False\n", + " \n", + "pygame.quit()\n", + "\n" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/EggrikaSpriteSheet.png b/EggrikaSpriteSheet.png new file mode 100644 index 00000000..8c9352c3 Binary files /dev/null and b/EggrikaSpriteSheet.png differ diff --git a/Flour.png b/Flour.png new file mode 100644 index 00000000..8dac3220 Binary files /dev/null and b/Flour.png differ diff --git a/Gradient.jpeg b/Gradient.jpeg new file mode 100644 index 00000000..53e9a724 Binary files /dev/null and b/Gradient.jpeg differ diff --git a/Lose.jpg b/Lose.jpg new file mode 100644 index 00000000..4b78b388 Binary files /dev/null and b/Lose.jpg differ diff --git a/LoseAudio.ogg b/LoseAudio.ogg new file mode 100644 index 00000000..0fae454b Binary files /dev/null and b/LoseAudio.ogg differ diff --git a/Milk.png b/Milk.png new file mode 100644 index 00000000..eec1a964 Binary files /dev/null and b/Milk.png differ diff --git a/Omelette.jpg b/Omelette.jpg new file mode 100644 index 00000000..bcde6b8f Binary files /dev/null and b/Omelette.jpg differ diff --git a/Project 4 Write Up.pdf b/Project 4 Write Up.pdf new file mode 100644 index 00000000..581d5038 Binary files /dev/null and b/Project 4 Write Up.pdf differ diff --git a/ProjectProposal.ipynb b/ProjectProposal.ipynb new file mode 100644 index 00000000..3271fff7 --- /dev/null +++ b/ProjectProposal.ipynb @@ -0,0 +1,57 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Your proposal document should address:\n", + "\n", + "What is the main idea of your project? What topics will you explore and what will you generate? What is your minimum viable product? What is a stretch goal?\n", + "What are your learning goals for this project (for each member)?\n", + "What libraries are you planning to use? (if you don’t know enough yet, please outline how you will decide this question during the beginning phase of the project).\n", + "What do you plan to accomplish by the mid-project check-in? (See below for some generic goals; edit to suit your particular project)\n", + "What do you view as the biggest risks to you being successful on this project?\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "________________________________________________________________\n", + "\n", + "Main Idea: Scrolling world game (think simplified Super Mario Bros)\n", + "Minimal Viable Product: Game with platforms and ground to jump/move around. Ends when reach finish line. \n", + "Stretch goal: Good graphics, sprite animation, many types of platforms, moving enemies, multiple outcomes\n", + "\n", + "Learning goals:\n", + "\n", + "Both of us have used Pygame before. Chase's learning goal is to better understand how to better optimize and simplify the code. Erika's goal is similar; she also wants to understand Github a little better. \n", + "\n", + "We hope to have a better idea of the scope of our project (MVP vs stretch goal) by out mid-project check_in.\n", + "\n", + "We think our biggest risk is getting caught up in coding problems and running out of time. " + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/Pudding.jpg b/Pudding.jpg new file mode 100644 index 00000000..f49004d8 Binary files /dev/null and b/Pudding.jpg differ diff --git a/PyGame_Test.ipynb b/PyGame_Test.ipynb new file mode 100644 index 00000000..abbb78eb --- /dev/null +++ b/PyGame_Test.ipynb @@ -0,0 +1,1063 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "import pygame\n", + "import random\n", + "\n", + "class keys:\n", + " def __init__(self, event= None):\n", + " self.last_pressed = \"\"\n", + " self.string = \"Pressed:\"\n", + " if event.key == pygame.K_UP:\n", + " self.UP = True\n", + " self.string += \"UP\"\n", + " else:\n", + " self.UP = False\n", + " if event.key == pygame.K_DOWN:\n", + " self.DOWN = True\n", + " self.string += \"DOWN\"\n", + " else:\n", + " self.DOWN = False\n", + " if event.key == pygame.K_RIGHT:\n", + " self.RIGHT = True\n", + " self.string += \"RIGHT\"\n", + " self.last_pressed = \"RIGHT\"\n", + " else:\n", + " self.RIGHT = False \n", + " if event.key == pygame.K_LEFT:\n", + " self.LEFT = True\n", + " self.string += \"LEFT\"\n", + " self.last_pressed = \"LEFT\"\n", + " else:\n", + " self.LEFT = False \n", + " \n", + " def __str__(self):\n", + " return self.string\n", + " \n", + " \n", + "def xy_position_to_pixels(Rectangle, window_size, virtual_window):\n", + " \"\"\"Takes:In-game coordinate rectangle\n", + " Converts in game coordinates to pixels. Also, note that the in-game position refers to the LOWER RIGHT hand\n", + " corner of the sprite. \n", + " Returns: rectangle in pixel coordinates\"\"\"\n", + " x = Rectangle[0]\n", + " y = Rectangle[1]\n", + " width = Rectangle[2]\n", + " height = Rectangle[3]\n", + " pixel_x = int(float(x/virtual_window[0])*window_size[0])\n", + " pixel_y = window_size[1] - int(float(y/virtual_window[1])*window_size[1])\n", + " pixel_width = int(float(width/virtual_window[0])*window_size[0])\n", + " pixel_height = int(float(height/virtual_window[1])*window_size[1])\n", + " pixel_y -= pixel_height\n", + " return (pixel_x, pixel_y, pixel_width, pixel_height)\n", + "\n", + "\n", + "\n", + "class position:\n", + " def __init__(self, current_x = 0, current_y = 0, current_xs = 0, current_ys = 0, floor = 0, button=None,\n", + " character_width = 30, character_height = 30, wall_speed = .3):\n", + " self.current_x = current_x\n", + " self.current_y = current_y\n", + " self.current_xs = current_xs\n", + " self.current_ys = current_ys\n", + " self.button = button\n", + " self.floor = floor\n", + " self.last_pressed = None\n", + " self.jump = False\n", + " self.character_width = character_width\n", + " self.character_height = character_height\n", + " self.wall = None\n", + " self.wall_speed = wall_speed\n", + " self.maintain = False\n", + " \n", + " def __str__(self):\n", + " return str(self.current_x)+\" \"+str(self.current_y)+\" \"+str(self.current_xs)+\" \"+str(self.current_ys)\n", + " \n", + " def give_next_position(self, floor, wall): #fix button \n", + " #print(\"The give next position function has run.\")\n", + " #print(\"Button:\", button)\n", + " self.floor = floor\n", + " self.wall = wall\n", + " \n", + " \n", + " if self.current_y <= self.floor:\n", + " self.current_ys = 0\n", + " self.jump = False\n", + " if not self.jump: \n", + " self.current_xs = -1*self.wall_speed\n", + " if self.current_y > self.floor:\n", + " self.current_ys -= .3\n", + " \n", + " if self.button != None: \n", + " #print(\"AH I SENSE MOVEMENT!\")\n", + " if self.current_y == self.floor:\n", + " if self.button.UP:\n", + " pygame.mixer.Sound.play(jump_sound) #HERE\n", + " self.current_ys = 7\n", + " if self.last_pressed == \"RIGHT\":\n", + " self.current_xs = 1\n", + " self.jump = True\n", + " if wall[1] != None:\n", + " if self.current_x+self.character_width+1 >= wall[1]:\n", + " self.current_xs = 0\n", + " elif self.last_pressed == \"LEFT\":\n", + " self.current_xs = -1 - self.wall_speed\n", + " self.jump = True\n", + " if wall[0] != None:\n", + " if self.current_x <= wall[0]:\n", + " self.current_xs = 0\n", + " \n", + " if self.button.RIGHT:\n", + " self.current_xs = 1\n", + " if wall[1] != None:\n", + " if self.current_x+self.character_width+1 >= wall[1]:\n", + " self.current_xs = 0\n", + " elif self.button.LEFT:\n", + " self.current_xs = -1 - self.wall_speed\n", + " if wall[0] != None:\n", + " if self.current_x <= wall[0]:\n", + " self.current_xs = 0\n", + " self.last_pressed = self.button.last_pressed\n", + " \n", + " self.current_x += self.current_xs\n", + " self.current_y += self.current_ys\n", + " \n", + " #collision effects\n", + " if wall[0] != None:\n", + " if self.current_x <= wall[0]:\n", + " self.current_x = wall[0]+1\n", + " \n", + " if wall[1] != None:\n", + " \n", + " #print(\"I am at x position \", str(self.current_x+self.character_width))\n", + " \n", + " if self.current_x+self.character_width >= wall[1]:\n", + " self.current_x = wall[1]-self.character_width-1\n", + " \n", + " if self.current_x+self.character_width+1 >= wall[1]:\n", + " self.current_x -= self.wall_speed\n", + " \n", + " if self.current_y < self.floor:\n", + " self.current_y = self.floor\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "###PLATFORMS###\n", + "class platform:\n", + " def __init__(self, x1, x2, height):\n", + " self.leftX = x1\n", + " self.rightX = x2\n", + " self.height = height\n", + "\n", + "platform_generation_list = [(120,200,50)]\n", + "\n", + "def generate_list_of_platform_objects(platform_generation_list):\n", + " list_of_platforms = []\n", + " for i in platform_generation_list:\n", + " platform_temp = platform(i[0], i[1], i[2])\n", + " list_of_platforms.append(platform_temp)\n", + " return list_of_platforms\n", + "\n", + "def generate_list_of_platforms_on_screen(list_of_platforms, virtual_window):\n", + " list_of_platforms.sort(key = lambda plat: plat.leftX) ###SORT BY LEFTX\n", + " list_of_platforms_on_screen = []\n", + " for i in list_of_platforms:\n", + " if i.rightX < 0:\n", + " continue\n", + " list_of_platforms_on_screen.append(i)\n", + " if i.leftX > virtual_window[0]:\n", + " break\n", + " return list_of_platforms_on_screen\n", + "\n", + "def blit_platform(platform, window_size, virtual_window):\n", + " rectangle = (platform.leftX, platform.height - 5, platform.rightX-platform.leftX, 5)\n", + " pixel_rectangle = xy_position_to_pixels(rectangle, window_size, virtual_window)\n", + " screen.blit(texture_scaled,pixel_rectangle,pixel_rectangle)\n", + " \n", + " contrast_rectangle = (platform.leftX, platform.height - 3, platform.rightX-platform.leftX, 2)\n", + " pixel_contrast_rectangle = xy_position_to_pixels(contrast_rectangle, window_size, virtual_window)\n", + " pygame.draw.rect(screen,(212, 78, 77),pixel_contrast_rectangle)\n", + " \n", + " icing_rectangle = (platform.leftX, platform.height - 2, platform.rightX-platform.leftX, 2)\n", + " pixel_icing_rectangle = xy_position_to_pixels(icing_rectangle, window_size, virtual_window)\n", + " pygame.draw.rect(screen,(255, 205, 205),pixel_icing_rectangle)\n", + " \n", + " \n", + "\n", + "\n", + "###BLOCKS###\n", + "class block:\n", + " def __init__(self, x, y, width, height):\n", + " self.leftX = x\n", + " self.rightX = x+width\n", + " self.height = y + height\n", + " self.bot = y\n", + " self.text = \"(\" + str(x)+ \", \" + str(y)+ \", \" + str(width)+ \", \" + str(height)+\")\" \n", + " \n", + "\n", + "def generate_list_of_block_objects(block_generation_list):\n", + " list_of_blocks = []\n", + " for i in block_generation_list:\n", + " block_temp = block(i[0],i[1], i[2], i[3])\n", + " list_of_blocks.append(block_temp)\n", + " return list_of_blocks\n", + "\n", + "def generate_list_of_blocks_on_screen(list_of_blocks, virtual_window):\n", + " list_of_blocks.sort(key = lambda bl: bl.leftX) ###SORT BY LEFTX\n", + " list_of_blocks_on_screen = []\n", + " for i in list_of_blocks:\n", + " if i.rightX < 0:\n", + " continue\n", + " list_of_blocks_on_screen.append(i)\n", + " if i.leftX > virtual_window[0]:\n", + " break\n", + " return list_of_blocks_on_screen\n", + "\n", + "def blit_block(block, window_size, virtual_window, font):\n", + " rectangle = (block.leftX, block.bot, block.rightX-block.leftX, block.height-block.bot)\n", + " pixel_rectangle = xy_position_to_pixels(rectangle, window_size, virtual_window)\n", + " screen.blit(texture_scaled,pixel_rectangle,pixel_rectangle)\n", + " \n", + " shadow_rectangle = (block.leftX,block.height-4, block.rightX-block.leftX, 2)\n", + " pixel_shadow_rectangle = xy_position_to_pixels(shadow_rectangle, window_size, virtual_window)\n", + " pygame.draw.rect(screen,(226, 168, 85), pixel_shadow_rectangle)\n", + " \n", + " contrast_rectangle = (block.leftX,block.height-3, block.rightX-block.leftX, 2)\n", + " pixel_contrast_rectangle = xy_position_to_pixels(contrast_rectangle, window_size, virtual_window)\n", + " pygame.draw.rect(screen,(212, 78, 77), pixel_contrast_rectangle)\n", + " \n", + " icing_rectangle = (block.leftX-2,block.height-2, block.rightX-block.leftX+2, 2)\n", + " pixel_icing_rectangle = xy_position_to_pixels(icing_rectangle, window_size, virtual_window)\n", + " pygame.draw.rect(screen,(255, 205, 205), pixel_icing_rectangle)\n", + " \n", + " #textsurface = font.render(block.text, False, (0, 0, 0))\n", + " #xy_position_of_text = (pixel_rectangle[0],pixel_rectangle[1])\n", + " #screen.blit(textsurface,xy_position_of_text)\n", + " \n", + "def scroll_everything_left(list_of_platforms, list_of_blocks, list_of_badbreads, list_of_ingredients, world_speed):\n", + " for platform in list_of_platforms:\n", + " platform.rightX -= world_speed\n", + " platform.leftX -= world_speed\n", + " for block in list_of_blocks:\n", + " block.rightX -= world_speed\n", + " block.leftX -= world_speed\n", + " for badbread in list_of_badbreads:\n", + " badbread.startx -= world_speed\n", + " badbread.endx -= world_speed\n", + " badbread.current_bread_x -= world_speed\n", + " for ingredient in list_of_ingredients:\n", + " ingredient.ingredient_position_x -= world_speed \n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "class badbread:\n", + " def __init__(self, startx, starty, endx, speed = .5):\n", + " self.startx = startx\n", + " self.starty = starty\n", + " self.endx = endx\n", + " self.speed = speed\n", + " self.current_bread_x = startx\n", + " self.size = 40\n", + " \n", + " def move_badbread(self):\n", + " if self.current_bread_x < self.startx:\n", + " self.speed = abs(self.speed)\n", + " if self.current_bread_x > self.endx:\n", + " self.speed = -1*abs(self.speed)\n", + " self.current_bread_x += self.speed\n", + "\n", + "def generate_list_of_badbreads(badbread_generation_list):\n", + " list_of_badbreads = []\n", + " for i in badbread_generation_list:\n", + " badbread_temp = badbread(i[0], i[1], i[2])\n", + " list_of_badbreads.append(badbread_temp)\n", + " return list_of_badbreads\n", + "\n", + "def generate_list_of_badbreads_on_screen(list_of_badbreads, virtual_window):\n", + " list_of_badbreads.sort(key = lambda bl: bl.startx) \n", + " list_of_badbreads_on_screen = []\n", + " for i in list_of_badbreads:\n", + " if i.endx+i.size < 0:\n", + " continue\n", + " list_of_badbreads_on_screen.append(i)\n", + " if i.startx > virtual_window[0]:\n", + " break\n", + " return list_of_badbreads_on_screen\n", + "\n", + "def blit_badbread(badbread, window_size, virtual_window):\n", + " rectangle = (badbread.current_bread_x, badbread.starty, badbread.size, badbread.size)\n", + " pixel_rectangle = xy_position_to_pixels(rectangle, window_size, virtual_window)\n", + " if badbread.speed > 0:\n", + " screen.blit(bread_right_scaled,pixel_rectangle)\n", + " else:\n", + " screen.blit(bread_left_scaled,pixel_rectangle)\n", + "\n", + "def generate_badbread_collisions(list_of_badbreads_on_screen, list_of_badbreads, current_position):\n", + " badbread_collisions = []\n", + " current_position_rectangle = pygame.Rect(\n", + " xy_position_to_pixels((current_position.current_x, current_position.current_y,\n", + " current_position.character_width, current_position.character_height), virtual_window, window_size))\n", + " for i in list_of_badbreads_on_screen:\n", + " badbread_rectange = pygame.Rect(xy_position_to_pixels(\n", + " (i.current_bread_x + 5, i.starty, i.size-5, i.size-10), \n", + " virtual_window, window_size))\n", + " if current_position_rectangle.colliderect(badbread_rectange):\n", + " if current_position.maintain == False:\n", + " collision_temp = collision(\"badbread\", 0)\n", + " badbread_collisions.append(collision_temp)\n", + " print(\"hit a badbread\")\n", + " current_position.maintain = True\n", + " else:\n", + " current_position.maintain = False\n", + " #print(\"disengaged\")\n", + " return badbread_collisions\n", + "##HERE\n" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "class ingredient:\n", + " def __init__(self, ingredient_type, ingredient_position_x,ingredient_position_y, size = 20):\n", + " self.ingredient_type = ingredient_type\n", + " self.ingredient_position_x = ingredient_position_x\n", + " self.ingredient_position_y = ingredient_position_y\n", + " self.size = size\n", + " \n", + "def generate_list_of_ingredients(ingredient_generation_list):\n", + " list_of_ingredients = []\n", + " for i in ingredient_generation_list:\n", + " ingredient_temp = ingredient(i[0], i[1], i[2])\n", + " list_of_ingredients.append(ingredient_temp)\n", + " return list_of_ingredients\n", + "\n", + "def generate_list_of_ingredients_on_screen(list_of_ingredients, virtual_window):\n", + " list_of_ingredients.sort(key = lambda bl: bl.ingredient_position_x) \n", + " list_of_ingredients_on_screen = []\n", + " for i in list_of_ingredients:\n", + " if i.ingredient_position_x+i.size < 0:\n", + " continue\n", + " list_of_ingredients_on_screen.append(i)\n", + " if i.ingredient_position_x > virtual_window[0]:\n", + " break\n", + " return list_of_ingredients_on_screen\n", + "\n", + "def blit_ingredient(ingredient, window_size, virtual_window):\n", + " if ingredient.ingredient_type == \"milk\":\n", + " rectangle = (ingredient.ingredient_position_x, ingredient.ingredient_position_y, ingredient.size, ingredient.size)\n", + " pixel_rectangle = xy_position_to_pixels(rectangle, window_size, virtual_window)\n", + " screen.blit(milk_scaled,pixel_rectangle)\n", + " elif ingredient.ingredient_type == \"celery\":\n", + " rectangle = (ingredient.ingredient_position_x, ingredient.ingredient_position_y, ingredient.size, ingredient.size)\n", + " pixel_rectangle = xy_position_to_pixels(rectangle, window_size, virtual_window)\n", + " screen.blit(celery_scaled,pixel_rectangle)\n", + " elif ingredient.ingredient_type == \"chocolate\":\n", + " rectangle = (ingredient.ingredient_position_x, ingredient.ingredient_position_y, ingredient.size, ingredient.size)\n", + " pixel_rectangle = xy_position_to_pixels(rectangle, window_size, virtual_window)\n", + " screen.blit(chocolate_scaled,pixel_rectangle)\n", + " elif ingredient.ingredient_type == \"vanilla\":\n", + " rectangle = (ingredient.ingredient_position_x, ingredient.ingredient_position_y, ingredient.size, ingredient.size)\n", + " pixel_rectangle = xy_position_to_pixels(rectangle, window_size, virtual_window)\n", + " screen.blit(vanilla_scaled,pixel_rectangle)\n", + " elif ingredient.ingredient_type == \"flour\":\n", + " rectangle = (ingredient.ingredient_position_x, ingredient.ingredient_position_y, ingredient.size, ingredient.size)\n", + " pixel_rectangle = xy_position_to_pixels(rectangle, window_size, virtual_window)\n", + " screen.blit(flour_scaled,pixel_rectangle)\n", + " elif ingredient.ingredient_type == \"sugar\":\n", + " rectangle = (ingredient.ingredient_position_x, ingredient.ingredient_position_y, ingredient.size, ingredient.size)\n", + " pixel_rectangle = xy_position_to_pixels(rectangle, window_size, virtual_window)\n", + " screen.blit(sugar_scaled,pixel_rectangle)\n", + " elif ingredient.ingredient_type == \"butter\":\n", + " rectangle = (ingredient.ingredient_position_x, ingredient.ingredient_position_y, ingredient.size, ingredient.size)\n", + " pixel_rectangle = xy_position_to_pixels(rectangle, window_size, virtual_window)\n", + " screen.blit(butter_scaled,pixel_rectangle)" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def give_floor_value(current_position, blocks_on_screen, platforms_on_screen):\n", + " list_of_floors_under = []\n", + " for i in blocks_on_screen:\n", + " if i.rightX < current_position.current_x+10:\n", + " continue\n", + " if i.leftX > current_position.current_x+current_position.character_width:\n", + " break\n", + " if i.leftX < current_position.current_x+current_position.character_width -10 and current_position.current_x < i.rightX:\n", + " list_of_floors_under.append(i)\n", + " \n", + " for i in platforms_on_screen:\n", + " if i.rightX < current_position.current_x+10:\n", + " continue\n", + " if i.leftX > current_position.current_x+current_position.character_width:\n", + " break\n", + " if i.leftX <= current_position.current_x+current_position.character_width-10 and current_position.current_x +10 <= i.rightX:\n", + " list_of_floors_under.append(i)\n", + " list_of_floors_under.sort(key = lambda structures: structures.height, reverse = True)\n", + " if list_of_floors_under != []:\n", + " list_of_floors_under.sort(key = lambda fl: fl.height, reverse = True)\n", + " #print(\"y= \",current_position.current_y)\n", + " for i in list_of_floors_under:\n", + " if i.height <= current_position.current_y:\n", + " #print(\"floor =\",i.height)\n", + " return i.height\n", + " return -500\n", + "\n", + "def give_wall_value(current_position, blocks_on_screen):\n", + " level_with_character = []\n", + " for i in blocks_on_screen:\n", + " if i.bot > current_position.current_y+current_position.character_height: #HERE\n", + " continue\n", + " if i.height < current_position.current_y:\n", + " continue\n", + " level_with_character.append(i)\n", + " closest_left = None\n", + " closest_right = None\n", + " if level_with_character != []:\n", + " level_with_character.sort(key=lambda blocks: blocks.rightX)\n", + " for i in level_with_character:\n", + " if i.rightX-10 < current_position.current_x:\n", + " closest_left = i.rightX-10\n", + " level_with_character.sort(key=lambda blocks: blocks.leftX, reverse = True)\n", + " for i in level_with_character:\n", + " if i.leftX+10 > current_position.current_x+current_position.character_width:\n", + " closest_right = i.leftX+10 \n", + " return (closest_left, closest_right)\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "class items:\n", + " def __init__(self):\n", + " self.milk = 0\n", + " self.sugar = 0\n", + " self.celery = 0\n", + " self.butter = 0\n", + " self.flour = 0\n", + " self.vanilla = 0\n", + " self.chocolate = 0\n", + " \n", + " def __str__(self):\n", + " return \"Milk:\"+str(self.milk)+\"\\nSugar:\"+str(self.sugar) \n", + " \n", + " def total(self):\n", + " return self.milk+self.sugar+self.celery+self.chocolate+self.vanilla+self.butter+self.flour\n", + " \n", + " def remove_random(self):\n", + " #print(\"entered remove function\")\n", + " \n", + " items_present = []\n", + " if self.milk > 0:\n", + " items_present.append(1)\n", + " if self.sugar > 0:\n", + " items_present.append(2)\n", + " if self.celery > 0:\n", + " items_present.append(3)\n", + " if self.butter > 0:\n", + " items_present.append(4)\n", + " if self.flour > 0:\n", + " items_present.append(5)\n", + " if self.vanilla > 0:\n", + " items_present.append(6)\n", + " if self.chocolate > 0:\n", + " items_present.append(7)\n", + " \n", + " if items_present:\n", + " subtract = random.choice(items_present)\n", + " if subtract == 1:\n", + " self.milk -=1\n", + " elif subtract == 2:\n", + " self.sugar -=1\n", + " elif subtract == 3:\n", + " self.celery -=1\n", + " elif subtract == 4:\n", + " self.butter -=1\n", + " elif subtract == 5:\n", + " self.flour -=1\n", + " elif subtract == 6:\n", + " self.vanilla -=1\n", + " elif subtract == 7:\n", + " self.chocolate -=1\n", + " else:\n", + " pygame.mixer.Sound.play(lose_sound)\n", + " global finish_line\n", + " finish_line = True\n", + " \n", + " \n", + "class collision:\n", + " def __init__(self, collision_type, stage):\n", + " self.collision_type = collision_type\n", + " self.stage = stage\n", + "\n", + "\n", + "def generate_ingredient_collisions(list_of_ingredients_on_screen, list_of_ingredients, current_position):\n", + " ingredient_collisions = []\n", + " current_position_rectangle = pygame.Rect(\n", + " xy_position_to_pixels((current_position.current_x, current_position.current_y,\n", + " current_position.character_width, current_position.character_height), virtual_window, window_size))\n", + " for i in list_of_ingredients_on_screen:\n", + " ingredient_rectange = pygame.Rect(xy_position_to_pixels(\n", + " (i.ingredient_position_x, i.ingredient_position_y, i.size, i.size), \n", + " virtual_window, window_size))\n", + " if current_position_rectangle.colliderect(ingredient_rectange):\n", + " collision_temp = collision(i.ingredient_type, 0)\n", + " ingredient_collisions.append(collision_temp)\n", + " #print(\"added to ingredient collisions list\")\n", + " list_of_ingredients.remove(i)\n", + " return ingredient_collisions\n", + "\n", + "\n", + "def process_collision_lists(position, list_of_ingredient_collisions, list_of_badbread_collisions, items):\n", + " if list_of_ingredient_collisions:\n", + " for i in list_of_ingredient_collisions:\n", + " if i.stage == 0:\n", + " if i.collision_type == \"milk\":\n", + " items.milk += 1\n", + " elif i.collision_type == \"sugar\":\n", + " items.sugar += 1\n", + " elif i.collision_type == \"celery\":\n", + " items.celery += 1\n", + " elif i.collision_type == \"butter\":\n", + " items.butter += 1\n", + " elif i.collision_type == \"flour\":\n", + " items.flour += 1\n", + " elif i.collision_type == \"vanilla\":\n", + " items.vanilla += 1\n", + " elif i.collision_type == \"chocolate\":\n", + " items.chocolate += 1\n", + " i.stage += 1\n", + " \n", + " if list_of_badbread_collisions:\n", + " for i in list_of_badbread_collisions:\n", + " items.remove_random()\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def calculate_locations(left_bar, window_size, virtual_window):\n", + " list_of_rectangles = []\n", + " gap = float(virtual_window[1]-140)/8\n", + " for i in range(7):\n", + " rectangle = (left_bar,virtual_window[1]-((i+1)*gap + ((i+1)*20)), 20, 20)#IMAGE SIZE HARD CODED IN Y POSITON\n", + " print(str(rectangle))\n", + " pixel_rectangle = xy_position_to_pixels(rectangle, window_size, virtual_window)\n", + " list_of_rectangles.append(pixel_rectangle)\n", + " return list_of_rectangles\n", + "\n", + "def blit_items(item_class, locations, font):\n", + " if item_class.milk > 0:\n", + " #print(\"bliting milk\")\n", + " screen.blit(milk_scaled,locations[0])\n", + " textsurface = font.render(\"x\"+str(item_class.milk), False, (255, 0, 193))\n", + " xy_position_of_text = (locations[0][0]+130,locations[0][1]+20)\n", + " screen.blit(textsurface,xy_position_of_text) \n", + " if item_class.chocolate > 0:\n", + " screen.blit(chocolate_scaled,locations[1])\n", + " textsurface = font.render(\"x\"+str(item_class.chocolate), False, (255, 0, 193))\n", + " xy_position_of_text = (locations[1][0]+130,locations[1][1]+20)\n", + " screen.blit(textsurface,xy_position_of_text)\n", + " if item_class.sugar > 0:\n", + " screen.blit(sugar_scaled,locations[2])\n", + " textsurface = font.render(\"x\"+str(item_class.sugar), False, (255, 0, 193))\n", + " xy_position_of_text = (locations[2][0]+130,locations[2][1]+20)\n", + " screen.blit(textsurface,xy_position_of_text)\n", + " if item_class.celery > 0:\n", + " screen.blit(celery_scaled,locations[3])\n", + " textsurface = font.render(\"x\"+str(item_class.celery), False, (255, 0, 193))\n", + " xy_position_of_text = (locations[3][0]+130,locations[3][1]+20)\n", + " screen.blit(textsurface,xy_position_of_text)\n", + " if item_class.butter > 0:\n", + " screen.blit(butter_scaled,locations[4])\n", + " textsurface = font.render(\"x\"+str(item_class.butter), False, (255, 0, 193))\n", + " xy_position_of_text = (locations[4][0]+130,locations[4][1]+20)\n", + " screen.blit(textsurface,xy_position_of_text)\n", + " if item_class.flour > 0:\n", + " screen.blit(flour_scaled,locations[5])\n", + " textsurface = font.render(\"x\"+str(item_class.flour), False, (255, 0, 193))\n", + " xy_position_of_text = (locations[5][0]+130,locations[5][1]+20)\n", + " screen.blit(textsurface,xy_position_of_text)\n", + " if item_class.vanilla > 0:\n", + " screen.blit(vanilla_scaled,locations[6])\n", + " textsurface = font.render(\"x\"+str(item_class.vanilla), False, (255, 0, 193))\n", + " xy_position_of_text = (locations[6][0]+130,locations[6][1]+20)\n", + " screen.blit(textsurface, xy_position_of_text)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "class animation:\n", + " def __init__(self, rectangles_left, rectangles_right, rectangle_forward):\n", + " self.right = 0\n", + " self.left = 0\n", + " self.rectangles_left = rectangles_left\n", + " self.rectangles_right = rectangles_right\n", + " self.rectangle_forward = rectangle_forward\n", + " \n", + "def create_character_rectangles(spritesheet_xy, direction):\n", + " character_pixels = (spritesheet_xy[0]/4, spritesheet_xy[1]/8)\n", + " rectangle_list = []\n", + " if direction == \"left\":\n", + " for i in range(4):\n", + " rectangle_list.append((i*character_pixels[0], 0, character_pixels[0], character_pixels[1]))\n", + " for i in range(4):\n", + " rectangle_list.append((i*character_pixels[0], character_pixels[1], character_pixels[0], character_pixels[1]))\n", + " return rectangle_list\n", + " elif direction == \"right\":\n", + " for i in range(4):\n", + " rectangle_list.append((i*character_pixels[0],character_pixels[1]*4, character_pixels[0], character_pixels[1]))\n", + " for i in range(4):\n", + " rectangle_list.append((i*character_pixels[0], character_pixels[1]*5, character_pixels[0], character_pixels[1]))\n", + " return rectangle_list\n", + " elif direction == \"forward\":\n", + " rectangle_list.append((0*character_pixels[0],character_pixels[1]*2, character_pixels[0], character_pixels[1]))\n", + " return rectangle_list\n", + "def blit_character(current_position, window_size, virtual_window, animation_stage):\n", + " character_position = xy_position_to_pixels(\n", + " (current_position.current_x, current_position.current_y-2,current_position.character_width,current_position.character_height), window_size, virtual_window)\n", + " if current_position.current_xs + current_position.wall_speed > 0:\n", + " screen.blit(eggrika_spritesheet_scaled, character_position, animation_stage.rectangles_right[animation_stage.right])\n", + " if animation_stage.right < 7:\n", + " animation_stage.right += 1\n", + " else:\n", + " animation_stage.right = 0\n", + " if current_position.current_xs + current_position.wall_speed < 0:\n", + " screen.blit(eggrika_spritesheet_scaled, character_position, animation_stage.rectangles_left[animation_stage.left])\n", + " if animation_stage.left < 7:\n", + " animation_stage.left += 1\n", + " else:\n", + " animation_stage.left = 0\n", + " if current_position.current_xs + current_position.wall_speed == 0:\n", + " screen.blit(eggrika_spritesheet_scaled, character_position, animation_stage.rectangle_forward[0])\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(250, 172.5, 20, 20)\n", + "(250, 145.0, 20, 20)\n", + "(250, 117.5, 20, 20)\n", + "(250, 90.0, 20, 20)\n", + "(250, 62.5, 20, 20)\n", + "(250, 35.0, 20, 20)\n", + "(250, 7.5, 20, 20)\n", + "Milk:0\n", + "Sugar:0\n", + "Milk:0\n", + "Sugar:0\n", + "hit a badbread\n", + "hit a badbread\n", + "hit a badbread\n", + "Milk:0\n", + "Sugar:0\n" + ] + }, + { + "ename": "error", + "evalue": "display Surface quit", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31merror\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 266\u001b[0m \u001b[0mscreen\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mblit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcustard_scaled\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 267\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 268\u001b[0;31m \u001b[0mscreen\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mblit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlose_scaled\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 269\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 270\u001b[0m \u001b[0mpygame\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdisplay\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mflip\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31merror\u001b[0m: display Surface quit" + ] + } + ], + "source": [ + "virtual_window = (300,200)\n", + "pygame.mixer.pre_init(44100, -16, 1, 512)\n", + "pygame.init()\n", + "pygame.font.init()\n", + "pygame.mixer.init()\n", + "window_size = (pygame.display.Info().current_w -50, pygame.display.Info().current_h - 50)\n", + "screen = pygame.display.set_mode(window_size)\n", + "pygame.display.set_caption(\"Egg World\")\n", + "global done\n", + "done = False\n", + "clock = pygame.time.Clock()\n", + "\n", + "wall = None\n", + "block_generation_list = [(0,0,630,20),(390,110,20,40),(370,70,60,40),\n", + " (350,30,100,40),(330,0,140,30),(680,0,120,20),(800,0,180,60),(980,0,320,10),(1300,0,250,50),\n", + " (1300,100,300,50),\n", + " (1400,150,40,50), (1550,0,50,30),\n", + " (1600,0,200,10),(1830,0,30,130),(1910,0,30,160),(1990,0,30,170),(2070, 80, 100, 50),(2070,0,530,20),\n", + " (2500,0,120,70),(2620,0,380,20)]\n", + "\n", + "list_of_blocks = generate_list_of_block_objects(block_generation_list)\n", + "\n", + "platform_generation_list = [(150,200,100),(500,600,120),(1050,1100,120),(1100,1190,70),(1190,1240,120),(1700,1770,90),\n", + " (2830,2900,100)]\n", + "\n", + "list_of_platforms = generate_list_of_platform_objects(platform_generation_list)\n", + "\n", + "badbread_generation_list = [(150,20,280),(470,20,570),(800,60,900),(1600,10,1770),(2070,20,2400)]\n", + "\n", + "list_of_badbreads = generate_list_of_badbreads(badbread_generation_list)\n", + "\n", + "ingredient_generation_list = [(\"milk\", 200, 130), (\"celery\", 250, 180), (\"sugar\", 340, 80), (\"chocolate\", 390, 160),\n", + " (\"vanilla\", 440, 80), (\"butter\", 550, 30), (\"flour\", 650, 100), (\"milk\", 770, 30),\n", + " (\"celery\", 830, 150),(\"butter\", 860, 150),(\"milk\", 890, 150), (\"chocolate\",1130,180),\n", + " (\"butter\",1130,80), (\"milk\", 1320, 160), (\"milk\", 1350, 160),(\"milk\", 1380, 160), \n", + " (\"sugar\", 1450, 70),(\"celery\", 1560, 160), (\"chocolate\", 1720,30), (\"sugar\",1830,140),\n", + " (\"sugar\",1910,170),(\"sugar\",1990,180), (\"flour\", 2290, 100), (\"milk\",2410,80)]\n", + "\n", + "list_of_ingredients = generate_list_of_ingredients(ingredient_generation_list)\n", + "wall = None\n", + "world_speed = .5\n", + "\n", + "in_title_screen = True\n", + "title_text = pygame.image.load('Title.png')\n", + "title_scaled = pygame.transform.scale(title_text, window_size)\n", + "title_block = block(0, 0, virtual_window[0],20)\n", + "scroll = 0\n", + "chase_animation = 0\n", + "chase_image1 = pygame.image.load('Chase1.png')\n", + "chase_rectangle = (2835, 108, 60, 60)\n", + "pixel_chase_rectangle = xy_position_to_pixels(chase_rectangle, window_size, virtual_window)\n", + "chase_pixel_size = (pixel_chase_rectangle[2], pixel_chase_rectangle[3])\n", + "chase_image1_transform = pygame.transform.scale(chase_image1, chase_pixel_size)\n", + "chase_image2 = pygame.image.load('Chase2.png')\n", + "chase_image2_transform = pygame.transform.scale(chase_image2, chase_pixel_size)\n", + "global finish_line\n", + "finish_line = False\n", + "start_over = False\n", + "\n", + "itembar = items()\n", + "\n", + "current_position = position(current_y= virtual_window[1], current_x = 20, wall_speed = world_speed) \n", + "title_position = position(current_y= 20, wall_speed = 0, current_xs = 5) \n", + "\n", + "myfont = pygame.font.Font('Birdy Game.ttf', 30)\n", + "myfontlarge = pygame.font.Font('Birdy Game.ttf', 80)\n", + "gradient = pygame.image.load('Gradient.jpeg')\n", + "gradient_scaled = pygame.transform.scale(gradient, window_size)\n", + "texture = pygame.image.load('CakeTexture.jpeg')\n", + "texture_scaled = pygame.transform.scale(texture, window_size)\n", + "\n", + "resize_material_rectangle = xy_position_to_pixels((0,0,20,20), window_size, virtual_window)\n", + "materials_size = (resize_material_rectangle[2], resize_material_rectangle[3])\n", + "butter_picture = pygame.image.load('Butter.png')\n", + "butter_scaled = pygame.transform.scale(butter_picture, materials_size)\n", + "milk_picture = pygame.image.load('Milk.png')\n", + "milk_scaled = pygame.transform.scale(milk_picture, materials_size)\n", + "vanilla_picture = pygame.image.load('Vanilla.png')\n", + "vanilla_scaled = pygame.transform.scale(vanilla_picture, materials_size)\n", + "celery_picture = pygame.image.load('Celery.png')\n", + "celery_scaled = pygame.transform.scale(celery_picture, materials_size)\n", + "chocolate_picture = pygame.image.load('Chocolate.png')\n", + "chocolate_scaled = pygame.transform.scale(chocolate_picture, materials_size)\n", + "sugar_picture = pygame.image.load('Sugar.png')\n", + "sugar_scaled = pygame.transform.scale(sugar_picture, materials_size)\n", + "flour_picture = pygame.image.load('Flour.png')\n", + "flour_scaled = pygame.transform.scale(flour_picture, materials_size)\n", + "resize_bread_rectangle = xy_position_to_pixels((0,0,45,45), window_size, virtual_window)\n", + "bread_size = (resize_bread_rectangle[2], resize_bread_rectangle[3])\n", + "bread_left = pygame.image.load('Bread_Left.png')\n", + "bread_left_scaled = pygame.transform.scale(bread_left, bread_size)\n", + "bread_right = pygame.image.load('Bread_Right.png')\n", + "bread_right_scaled = pygame.transform.scale(bread_right, bread_size)\n", + "custard_image = pygame.image.load('Custard.jpg')\n", + "custard_scaled = pygame.transform.scale(custard_image, window_size)\n", + "omelette_image = pygame.image.load('Omelette.jpg')\n", + "omelette_scaled = pygame.transform.scale(omelette_image, window_size)\n", + "quiche_image = pygame.image.load('Quiche.jpg')\n", + "quiche_scaled = pygame.transform.scale(quiche_image, window_size)\n", + "creme_image = pygame.image.load('CremeBrulee.jpg')\n", + "creme_scaled = pygame.transform.scale(custard_image, window_size)\n", + "pudding_image = pygame.image.load('Pudding.jpg')\n", + "pudding_scaled = pygame.transform.scale(pudding_image, window_size)\n", + "lose_image = pygame.image.load('Lose.jpg')\n", + "lose_scaled = pygame.transform.scale(lose_image, window_size)\n", + "\n", + "left_bar = virtual_window[0]-50\n", + "spacing = 10\n", + "locations = calculate_locations(left_bar, window_size, virtual_window)\n", + "\n", + "eggrika_spritesheet = pygame.image.load(\"EggrikaSpriteSheet.png\")\n", + "spritesheet_size = xy_position_to_pixels((0,0,current_position.character_width*4, \n", + " current_position.character_height*8), window_size, virtual_window)\n", + "spritesheet_xy = (spritesheet_size[2], spritesheet_size[3])\n", + "eggrika_spritesheet_scaled = pygame.transform.scale(eggrika_spritesheet, (spritesheet_size[2], spritesheet_size[3]))\n", + "\n", + "rectangles_right = create_character_rectangles(spritesheet_xy, 'right')\n", + "rectangles_left = create_character_rectangles(spritesheet_xy, 'left')\n", + "rectangle_forward = create_character_rectangles(spritesheet_xy, 'forward')\n", + "animation_stage = animation(rectangles_left, rectangles_right, rectangle_forward)\n", + "\n", + "\n", + "jump_sound = pygame.mixer.Sound('Boing.ogg')\n", + "yay_bool = False\n", + "yay_sound = pygame.mixer.Sound('Yay.ogg')\n", + "theme_sound = pygame.mixer.Sound('Theme.ogg')\n", + "lose_sound = pygame.mixer.Sound('LoseAudio.ogg')\n", + "pygame.mixer.Sound.set_volume(theme_sound, .2)\n", + "pygame.mixer.Sound.set_volume(jump_sound, .1)\n", + "pygame.mixer.Sound.play(theme_sound, loops = -1)\n", + "\n", + "while not done:\n", + " \n", + " while in_title_screen:\n", + " for event in pygame.event.get():\n", + " if event.type == pygame.QUIT:\n", + " pygame.quit()\n", + " if event.type == pygame.KEYDOWN:\n", + " if event.key == pygame.K_SPACE or event.key == pygame.K_ESCAPE:\n", + " in_title_screen = False\n", + " screen.blit(gradient_scaled,(0,0))\n", + " blit_character(title_position, window_size, virtual_window, animation_stage)\n", + " screen.blit(title_scaled,(0,0))\n", + " blit_block(title_block, window_size, virtual_window, myfont)\n", + " pygame.display.flip()\n", + " if title_position.current_x < virtual_window[0]:\n", + " title_position.current_x += title_position.current_xs\n", + " if title_position.current_x >= virtual_window[0]:\n", + " title_position.current_x = 0 - title_position.current_x - title_position.character_width\n", + " \n", + " #####\n", + " \n", + " if scroll <= 2730:\n", + " scroll_everything_left(list_of_platforms, list_of_blocks, list_of_badbreads,list_of_ingredients, world_speed)\n", + " chase_rectangle = (chase_rectangle[0]-world_speed,chase_rectangle[1], 50,50)\n", + " scroll+=world_speed\n", + " else:\n", + " current_position.wall_speed = 0\n", + " \n", + " clock.tick(50)\n", + " \n", + " for event in pygame.event.get():\n", + " if event.type == pygame.QUIT:\n", + " done = True\n", + " if event.type == pygame.KEYDOWN:\n", + " if event.key == pygame.K_ESCAPE:\n", + " done = True\n", + " #print(\"KEY DOWN!\")\n", + " current_position.button = keys(event)\n", + " #print(current_position.button)\n", + " break\n", + " if event.type == pygame.KEYUP:\n", + " #print(\"KEY UP!\")\n", + " current_position.button = None\n", + " break\n", + " \n", + " blocks_on_screen = generate_list_of_blocks_on_screen(list_of_blocks, virtual_window)\n", + " platforms_on_screen = generate_list_of_platforms_on_screen(list_of_platforms, virtual_window)\n", + " wall = give_wall_value(current_position, blocks_on_screen)\n", + " floor = give_floor_value(current_position, blocks_on_screen, platforms_on_screen)\n", + " badbreads_on_screen = generate_list_of_badbreads_on_screen(list_of_badbreads, virtual_window)\n", + " ingredients_on_screen = generate_list_of_ingredients_on_screen(list_of_ingredients, virtual_window)\n", + "\n", + " \n", + " #Check If On-Screen\n", + " if current_position.current_x < -150:\n", + " itembar.remove_random()\n", + " if current_position.current_y < -200:\n", + " itembar.remove_random()\n", + " \n", + " \n", + " #Collisions\n", + " current_position.give_next_position(floor = floor, wall = wall)\n", + " list_of_ingredient_collisions = generate_ingredient_collisions(ingredients_on_screen, list_of_ingredients, current_position)\n", + " list_of_badbread_collisions = generate_badbread_collisions(badbreads_on_screen,\n", + " list_of_badbreads, current_position)\n", + " \n", + " process_collision_lists(current_position, list_of_ingredient_collisions, list_of_badbread_collisions, itembar)\n", + " \n", + " #Blit Sky\n", + " screen.blit(gradient_scaled,(0,0))\n", + "\n", + "\n", + " \n", + " #Blit Structures/Enemies\n", + " for i in blocks_on_screen:\n", + " blit_block(i, window_size, virtual_window, myfont)\n", + " for i in platforms_on_screen:\n", + " blit_platform(i, window_size, virtual_window)\n", + " for i in badbreads_on_screen:\n", + " i.move_badbread()\n", + " blit_badbread(i, window_size, virtual_window)\n", + " for i in ingredients_on_screen:\n", + " blit_ingredient(i, window_size, virtual_window)\n", + " \n", + " #Blit Items\n", + " blit_items(itembar, locations, myfontlarge)\n", + " \n", + " #Chase:\n", + " pixel_chase_rectangle = xy_position_to_pixels(chase_rectangle, window_size, virtual_window)\n", + " if chase_animation < 30:\n", + " screen.blit(chase_image1_transform, pixel_chase_rectangle)\n", + " chase_animation+=1\n", + " elif chase_animation < 60:\n", + " screen.blit(chase_image2_transform, pixel_chase_rectangle)\n", + " chase_animation+=1\n", + " else:\n", + " screen.blit(chase_image2_transform, pixel_chase_rectangle)\n", + " chase_animation = 0\n", + " \n", + " #Test Stuff\n", + " #current_position.current_x = 100\n", + " #current_position.current_y = 150\n", + " \n", + " if current_position.current_x>chase_rectangle[0]:\n", + " if yay_bool == False:\n", + " pygame.mixer.Sound.play(yay_sound)\n", + " yay_bool == True\n", + " finish_line = True\n", + " \n", + " #Character\n", + " blit_character(current_position, window_size, virtual_window, animation_stage)\n", + " \n", + " pygame.display.flip()\n", + " \n", + " \n", + " while finish_line == True:\n", + " for event in pygame.event.get():\n", + " if event.type == pygame.QUIT:\n", + " pygame.quit()\n", + " if event.type == pygame.KEYDOWN:\n", + " print(itembar)\n", + " if event.key == pygame.K_SPACE or event.key == pygame.K_ESCAPE:\n", + " start_over = True\n", + " finish_line = False\n", + " total = itembar.total()\n", + " if total >= 23 and itembar.celery >= 3 and itembar.flour >=1:\n", + " screen.blit(quiche_scaled, (0,0))\n", + " elif total >=23 and itembar.celery >= 2:\n", + " screen.blit(omelette_scaled, (0,0))\n", + " elif total >= 20 and itembar.vanilla >= 1:\n", + " screen.blit(creme_scaled, (0,0))\n", + " elif total >= 15 and itembar.chocolate >= 3:\n", + " screen.blit(pudding_scaled, (0,0)) \n", + " elif total >= 5 and itembar.milk >= 1 and itembar.butter>=1 and itembar.flour >= 1:\n", + " screen.blit(custard_scaled, (0,0))\n", + " else:\n", + " screen.blit(lose_scaled, (0,0))\n", + " \n", + " pygame.display.flip()\n", + " \n", + " if start_over == True:\n", + " wall = None\n", + " block_generation_list = [(0,0,630,20),(390,110,20,40),(370,70,60,40),\n", + " (350,30,100,40),(330,0,140,30),(680,0,120,20),(800,0,180,60),(980,0,320,10),(1300,0,250,50),\n", + " (1300,100,300,50),\n", + " (1400,150,40,50), (1550,0,50,30),\n", + " (1600,0,200,10),(1830,0,30,130),(1910,0,30,160),(1990,0,30,170),(2070, 80, 100, 50),(2070,0,530,20),\n", + " (2500,0,120,70),(2620,0,380,20)]\n", + "\n", + " list_of_blocks = generate_list_of_block_objects(block_generation_list)\n", + "\n", + " platform_generation_list = [(150,200,100),(500,600,120),(1050,1100,120),(1100,1190,70),(1190,1240,120),(1700,1770,90),\n", + " (2830,2900,100)]\n", + "\n", + " list_of_platforms = generate_list_of_platform_objects(platform_generation_list)\n", + "\n", + " badbread_generation_list = [(150,20,280),(470,20,570),(800,60,900),(1600,10,1770),(2070,20,2400)]\n", + "\n", + " list_of_badbreads = generate_list_of_badbreads(badbread_generation_list)\n", + "\n", + " ingredient_generation_list = [(\"milk\", 200, 130), (\"celery\", 250, 180), (\"sugar\", 340, 80), (\"chocolate\", 390, 160),\n", + " (\"vanilla\", 440, 80), (\"butter\", 550, 30), (\"flour\", 650, 100), (\"milk\", 770, 30),\n", + " (\"celery\", 830, 150),(\"butter\", 860, 150),(\"milk\", 890, 150), (\"chocolate\",1130,180),\n", + " (\"butter\",1130,80), (\"milk\", 1320, 160), (\"milk\", 1350, 160),(\"milk\", 1380, 160), \n", + " (\"sugar\", 1450, 70),(\"celery\", 1560, 160), (\"chocolate\", 1720,30), (\"sugar\",1830,140),\n", + " (\"sugar\",1910,170),(\"sugar\",1990,180), (\"flour\", 2290, 100), (\"milk\",2410,80)]\n", + "\n", + " list_of_ingredients = generate_list_of_ingredients(ingredient_generation_list)\n", + " wall = None\n", + " in_title_screen = True\n", + " scroll = 0\n", + " itembar = items()\n", + " chase_rectangle = (2835, 108, 60, 60)\n", + " current_position = position(current_y= virtual_window[1], wall_speed = world_speed) \n", + " title_position = position(current_y= 20, current_x = 20, wall_speed = 0, current_xs = 5) \n", + " start_over = False\n", + " \n", + "pygame.quit()\n", + "\n" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/PyGame_Test.py b/PyGame_Test.py new file mode 100644 index 00000000..e56fd02c --- /dev/null +++ b/PyGame_Test.py @@ -0,0 +1,961 @@ + +# coding: utf-8 + +# In[1]: + + +import pygame +import random + +class keys: + def __init__(self, event= None): + self.last_pressed = "" + self.string = "Pressed:" + if event.key == pygame.K_UP: + self.UP = True + self.string += "UP" + else: + self.UP = False + if event.key == pygame.K_DOWN: + self.DOWN = True + self.string += "DOWN" + else: + self.DOWN = False + if event.key == pygame.K_RIGHT: + self.RIGHT = True + self.string += "RIGHT" + self.last_pressed = "RIGHT" + else: + self.RIGHT = False + if event.key == pygame.K_LEFT: + self.LEFT = True + self.string += "LEFT" + self.last_pressed = "LEFT" + else: + self.LEFT = False + + def __str__(self): + return self.string + + +def xy_position_to_pixels(Rectangle, window_size, virtual_window): + """Takes:In-game coordinate rectangle + Converts in game coordinates to pixels. Also, note that the in-game position refers to the LOWER RIGHT hand + corner of the sprite. + Returns: rectangle in pixel coordinates""" + x = Rectangle[0] + y = Rectangle[1] + width = Rectangle[2] + height = Rectangle[3] + pixel_x = int(float(x/virtual_window[0])*window_size[0]) + pixel_y = window_size[1] - int(float(y/virtual_window[1])*window_size[1]) + pixel_width = int(float(width/virtual_window[0])*window_size[0]) + pixel_height = int(float(height/virtual_window[1])*window_size[1]) + pixel_y -= pixel_height + return (pixel_x, pixel_y, pixel_width, pixel_height) + + + +class position: + def __init__(self, current_x = 0, current_y = 0, current_xs = 0, current_ys = 0, floor = 0, button=None, + character_width = 30, character_height = 30, wall_speed = .3): + self.current_x = current_x + self.current_y = current_y + self.current_xs = current_xs + self.current_ys = current_ys + self.button = button + self.floor = floor + self.last_pressed = None + self.jump = False + self.character_width = character_width + self.character_height = character_height + self.wall = None + self.wall_speed = wall_speed + self.maintain = False + + def __str__(self): + return str(self.current_x)+" "+str(self.current_y)+" "+str(self.current_xs)+" "+str(self.current_ys) + + def give_next_position(self, floor, wall): #fix button + #print("The give next position function has run.") + #print("Button:", button) + self.floor = floor + self.wall = wall + + + if self.current_y <= self.floor: + self.current_ys = 0 + self.jump = False + if not self.jump: + self.current_xs = -1*self.wall_speed + if self.current_y > self.floor: + self.current_ys -= .3 + + if self.button != None: + #print("AH I SENSE MOVEMENT!") + if self.current_y == self.floor: + if self.button.UP: + pygame.mixer.Sound.play(jump_sound) #HERE + self.current_ys = 7 + if self.last_pressed == "RIGHT": + self.current_xs = 1 + self.jump = True + if wall[1] != None: + if self.current_x+self.character_width+1 >= wall[1]: + self.current_xs = 0 + elif self.last_pressed == "LEFT": + self.current_xs = -1 - self.wall_speed + self.jump = True + if wall[0] != None: + if self.current_x <= wall[0]: + self.current_xs = 0 + + if self.button.RIGHT: + self.current_xs = 1 + if wall[1] != None: + if self.current_x+self.character_width+1 >= wall[1]: + self.current_xs = 0 + elif self.button.LEFT: + self.current_xs = -1 - self.wall_speed + if wall[0] != None: + if self.current_x <= wall[0]: + self.current_xs = 0 + self.last_pressed = self.button.last_pressed + + self.current_x += self.current_xs + self.current_y += self.current_ys + + #collision effects + if wall[0] != None: + if self.current_x <= wall[0]: + self.current_x = wall[0]+1 + + if wall[1] != None: + + #print("I am at x position ", str(self.current_x+self.character_width)) + + if self.current_x+self.character_width >= wall[1]: + self.current_x = wall[1]-self.character_width-1 + + if self.current_x+self.character_width+1 >= wall[1]: + self.current_x -= self.wall_speed + + if self.current_y < self.floor: + self.current_y = self.floor + + + +# In[2]: + + +###PLATFORMS### +class platform: + def __init__(self, x1, x2, height): + self.leftX = x1 + self.rightX = x2 + self.height = height + +platform_generation_list = [(120,200,50)] + +def generate_list_of_platform_objects(platform_generation_list): + list_of_platforms = [] + for i in platform_generation_list: + platform_temp = platform(i[0], i[1], i[2]) + list_of_platforms.append(platform_temp) + return list_of_platforms + +def generate_list_of_platforms_on_screen(list_of_platforms, virtual_window): + list_of_platforms.sort(key = lambda plat: plat.leftX) ###SORT BY LEFTX + list_of_platforms_on_screen = [] + for i in list_of_platforms: + if i.rightX < 0: + continue + list_of_platforms_on_screen.append(i) + if i.leftX > virtual_window[0]: + break + return list_of_platforms_on_screen + +def blit_platform(platform, window_size, virtual_window): + rectangle = (platform.leftX, platform.height - 5, platform.rightX-platform.leftX, 5) + pixel_rectangle = xy_position_to_pixels(rectangle, window_size, virtual_window) + screen.blit(texture_scaled,pixel_rectangle,pixel_rectangle) + + contrast_rectangle = (platform.leftX, platform.height - 3, platform.rightX-platform.leftX, 2) + pixel_contrast_rectangle = xy_position_to_pixels(contrast_rectangle, window_size, virtual_window) + pygame.draw.rect(screen,(212, 78, 77),pixel_contrast_rectangle) + + icing_rectangle = (platform.leftX, platform.height - 2, platform.rightX-platform.leftX, 2) + pixel_icing_rectangle = xy_position_to_pixels(icing_rectangle, window_size, virtual_window) + pygame.draw.rect(screen,(255, 205, 205),pixel_icing_rectangle) + + + + +###BLOCKS### +class block: + def __init__(self, x, y, width, height): + self.leftX = x + self.rightX = x+width + self.height = y + height + self.bot = y + self.text = "(" + str(x)+ ", " + str(y)+ ", " + str(width)+ ", " + str(height)+")" + + +def generate_list_of_block_objects(block_generation_list): + list_of_blocks = [] + for i in block_generation_list: + block_temp = block(i[0],i[1], i[2], i[3]) + list_of_blocks.append(block_temp) + return list_of_blocks + +def generate_list_of_blocks_on_screen(list_of_blocks, virtual_window): + list_of_blocks.sort(key = lambda bl: bl.leftX) ###SORT BY LEFTX + list_of_blocks_on_screen = [] + for i in list_of_blocks: + if i.rightX < 0: + continue + list_of_blocks_on_screen.append(i) + if i.leftX > virtual_window[0]: + break + return list_of_blocks_on_screen + +def blit_block(block, window_size, virtual_window, font): + rectangle = (block.leftX, block.bot, block.rightX-block.leftX, block.height-block.bot) + pixel_rectangle = xy_position_to_pixels(rectangle, window_size, virtual_window) + screen.blit(texture_scaled,pixel_rectangle,pixel_rectangle) + + shadow_rectangle = (block.leftX,block.height-4, block.rightX-block.leftX, 2) + pixel_shadow_rectangle = xy_position_to_pixels(shadow_rectangle, window_size, virtual_window) + pygame.draw.rect(screen,(226, 168, 85), pixel_shadow_rectangle) + + contrast_rectangle = (block.leftX,block.height-3, block.rightX-block.leftX, 2) + pixel_contrast_rectangle = xy_position_to_pixels(contrast_rectangle, window_size, virtual_window) + pygame.draw.rect(screen,(212, 78, 77), pixel_contrast_rectangle) + + icing_rectangle = (block.leftX-2,block.height-2, block.rightX-block.leftX+2, 2) + pixel_icing_rectangle = xy_position_to_pixels(icing_rectangle, window_size, virtual_window) + pygame.draw.rect(screen,(255, 205, 205), pixel_icing_rectangle) + + #textsurface = font.render(block.text, False, (0, 0, 0)) + #xy_position_of_text = (pixel_rectangle[0],pixel_rectangle[1]) + #screen.blit(textsurface,xy_position_of_text) + +def scroll_everything_left(list_of_platforms, list_of_blocks, list_of_badbreads, list_of_ingredients, world_speed): + for platform in list_of_platforms: + platform.rightX -= world_speed + platform.leftX -= world_speed + for block in list_of_blocks: + block.rightX -= world_speed + block.leftX -= world_speed + for badbread in list_of_badbreads: + badbread.startx -= world_speed + badbread.endx -= world_speed + badbread.current_bread_x -= world_speed + for ingredient in list_of_ingredients: + ingredient.ingredient_position_x -= world_speed + + + +# In[3]: + + +class badbread: + def __init__(self, startx, starty, endx, speed = .5): + self.startx = startx + self.starty = starty + self.endx = endx + self.speed = speed + self.current_bread_x = startx + self.size = 40 + + def move_badbread(self): + if self.current_bread_x < self.startx: + self.speed = abs(self.speed) + if self.current_bread_x > self.endx: + self.speed = -1*abs(self.speed) + self.current_bread_x += self.speed + +def generate_list_of_badbreads(badbread_generation_list): + list_of_badbreads = [] + for i in badbread_generation_list: + badbread_temp = badbread(i[0], i[1], i[2]) + list_of_badbreads.append(badbread_temp) + return list_of_badbreads + +def generate_list_of_badbreads_on_screen(list_of_badbreads, virtual_window): + list_of_badbreads.sort(key = lambda bl: bl.startx) + list_of_badbreads_on_screen = [] + for i in list_of_badbreads: + if i.endx+i.size < 0: + continue + list_of_badbreads_on_screen.append(i) + if i.startx > virtual_window[0]: + break + return list_of_badbreads_on_screen + +def blit_badbread(badbread, window_size, virtual_window): + rectangle = (badbread.current_bread_x, badbread.starty, badbread.size, badbread.size) + pixel_rectangle = xy_position_to_pixels(rectangle, window_size, virtual_window) + if badbread.speed > 0: + screen.blit(bread_right_scaled,pixel_rectangle) + else: + screen.blit(bread_left_scaled,pixel_rectangle) + +def generate_badbread_collisions(list_of_badbreads_on_screen, list_of_badbreads, current_position): + badbread_collisions = [] + current_position_rectangle = pygame.Rect( + xy_position_to_pixels((current_position.current_x, current_position.current_y, + current_position.character_width, current_position.character_height), virtual_window, window_size)) + for i in list_of_badbreads_on_screen: + badbread_rectange = pygame.Rect(xy_position_to_pixels( + (i.current_bread_x + 5, i.starty, i.size-5, i.size-10), + virtual_window, window_size)) + if current_position_rectangle.colliderect(badbread_rectange): + if current_position.maintain == False: + collision_temp = collision("badbread", 0) + badbread_collisions.append(collision_temp) + print("hit a badbread") + current_position.maintain = True + else: + current_position.maintain = False + #print("disengaged") + return badbread_collisions +##HERE + + +# In[4]: + + +class ingredient: + def __init__(self, ingredient_type, ingredient_position_x,ingredient_position_y, size = 20): + self.ingredient_type = ingredient_type + self.ingredient_position_x = ingredient_position_x + self.ingredient_position_y = ingredient_position_y + self.size = size + +def generate_list_of_ingredients(ingredient_generation_list): + list_of_ingredients = [] + for i in ingredient_generation_list: + ingredient_temp = ingredient(i[0], i[1], i[2]) + list_of_ingredients.append(ingredient_temp) + return list_of_ingredients + +def generate_list_of_ingredients_on_screen(list_of_ingredients, virtual_window): + list_of_ingredients.sort(key = lambda bl: bl.ingredient_position_x) + list_of_ingredients_on_screen = [] + for i in list_of_ingredients: + if i.ingredient_position_x+i.size < 0: + continue + list_of_ingredients_on_screen.append(i) + if i.ingredient_position_x > virtual_window[0]: + break + return list_of_ingredients_on_screen + +def blit_ingredient(ingredient, window_size, virtual_window): + if ingredient.ingredient_type == "milk": + rectangle = (ingredient.ingredient_position_x, ingredient.ingredient_position_y, ingredient.size, ingredient.size) + pixel_rectangle = xy_position_to_pixels(rectangle, window_size, virtual_window) + screen.blit(milk_scaled,pixel_rectangle) + elif ingredient.ingredient_type == "celery": + rectangle = (ingredient.ingredient_position_x, ingredient.ingredient_position_y, ingredient.size, ingredient.size) + pixel_rectangle = xy_position_to_pixels(rectangle, window_size, virtual_window) + screen.blit(celery_scaled,pixel_rectangle) + elif ingredient.ingredient_type == "chocolate": + rectangle = (ingredient.ingredient_position_x, ingredient.ingredient_position_y, ingredient.size, ingredient.size) + pixel_rectangle = xy_position_to_pixels(rectangle, window_size, virtual_window) + screen.blit(chocolate_scaled,pixel_rectangle) + elif ingredient.ingredient_type == "vanilla": + rectangle = (ingredient.ingredient_position_x, ingredient.ingredient_position_y, ingredient.size, ingredient.size) + pixel_rectangle = xy_position_to_pixels(rectangle, window_size, virtual_window) + screen.blit(vanilla_scaled,pixel_rectangle) + elif ingredient.ingredient_type == "flour": + rectangle = (ingredient.ingredient_position_x, ingredient.ingredient_position_y, ingredient.size, ingredient.size) + pixel_rectangle = xy_position_to_pixels(rectangle, window_size, virtual_window) + screen.blit(flour_scaled,pixel_rectangle) + elif ingredient.ingredient_type == "sugar": + rectangle = (ingredient.ingredient_position_x, ingredient.ingredient_position_y, ingredient.size, ingredient.size) + pixel_rectangle = xy_position_to_pixels(rectangle, window_size, virtual_window) + screen.blit(sugar_scaled,pixel_rectangle) + elif ingredient.ingredient_type == "butter": + rectangle = (ingredient.ingredient_position_x, ingredient.ingredient_position_y, ingredient.size, ingredient.size) + pixel_rectangle = xy_position_to_pixels(rectangle, window_size, virtual_window) + screen.blit(butter_scaled,pixel_rectangle) + + +# In[5]: + + +def give_floor_value(current_position, blocks_on_screen, platforms_on_screen): + list_of_floors_under = [] + for i in blocks_on_screen: + if i.rightX < current_position.current_x+10: + continue + if i.leftX > current_position.current_x+current_position.character_width: + break + if i.leftX < current_position.current_x+current_position.character_width -10 and current_position.current_x < i.rightX: + list_of_floors_under.append(i) + + for i in platforms_on_screen: + if i.rightX < current_position.current_x+10: + continue + if i.leftX > current_position.current_x+current_position.character_width: + break + if i.leftX <= current_position.current_x+current_position.character_width-10 and current_position.current_x +10 <= i.rightX: + list_of_floors_under.append(i) + list_of_floors_under.sort(key = lambda structures: structures.height, reverse = True) + if list_of_floors_under != []: + list_of_floors_under.sort(key = lambda fl: fl.height, reverse = True) + #print("y= ",current_position.current_y) + for i in list_of_floors_under: + if i.height <= current_position.current_y: + #print("floor =",i.height) + return i.height + return -500 + +def give_wall_value(current_position, blocks_on_screen): + level_with_character = [] + for i in blocks_on_screen: + if i.bot > current_position.current_y+current_position.character_height: #HERE + continue + if i.height < current_position.current_y: + continue + level_with_character.append(i) + closest_left = None + closest_right = None + if level_with_character != []: + level_with_character.sort(key=lambda blocks: blocks.rightX) + for i in level_with_character: + if i.rightX-10 < current_position.current_x: + closest_left = i.rightX-10 + level_with_character.sort(key=lambda blocks: blocks.leftX, reverse = True) + for i in level_with_character: + if i.leftX+10 > current_position.current_x+current_position.character_width: + closest_right = i.leftX+10 + return (closest_left, closest_right) + + + +# In[6]: + + +class items: + def __init__(self): + self.milk = 0 + self.sugar = 0 + self.celery = 0 + self.butter = 0 + self.flour = 0 + self.vanilla = 0 + self.chocolate = 0 + + def __str__(self): + return "Milk:"+str(self.milk)+"\nSugar:"+str(self.sugar) + + def total(self): + return self.milk+self.sugar+self.celery+self.chocolate+self.vanilla+self.butter+self.flour + + def remove_random(self): + #print("entered remove function") + + items_present = [] + if self.milk > 0: + items_present.append(1) + if self.sugar > 0: + items_present.append(2) + if self.celery > 0: + items_present.append(3) + if self.butter > 0: + items_present.append(4) + if self.flour > 0: + items_present.append(5) + if self.vanilla > 0: + items_present.append(6) + if self.chocolate > 0: + items_present.append(7) + + if items_present: + subtract = random.choice(items_present) + if subtract == 1: + self.milk -=1 + elif subtract == 2: + self.sugar -=1 + elif subtract == 3: + self.celery -=1 + elif subtract == 4: + self.butter -=1 + elif subtract == 5: + self.flour -=1 + elif subtract == 6: + self.vanilla -=1 + elif subtract == 7: + self.chocolate -=1 + else: + pygame.mixer.Sound.play(lose_sound) + global finish_line + finish_line = True + + +class collision: + def __init__(self, collision_type, stage): + self.collision_type = collision_type + self.stage = stage + + +def generate_ingredient_collisions(list_of_ingredients_on_screen, list_of_ingredients, current_position): + ingredient_collisions = [] + current_position_rectangle = pygame.Rect( + xy_position_to_pixels((current_position.current_x, current_position.current_y, + current_position.character_width, current_position.character_height), virtual_window, window_size)) + for i in list_of_ingredients_on_screen: + ingredient_rectange = pygame.Rect(xy_position_to_pixels( + (i.ingredient_position_x, i.ingredient_position_y, i.size, i.size), + virtual_window, window_size)) + if current_position_rectangle.colliderect(ingredient_rectange): + collision_temp = collision(i.ingredient_type, 0) + ingredient_collisions.append(collision_temp) + #print("added to ingredient collisions list") + list_of_ingredients.remove(i) + return ingredient_collisions + + +def process_collision_lists(position, list_of_ingredient_collisions, list_of_badbread_collisions, items): + if list_of_ingredient_collisions: + for i in list_of_ingredient_collisions: + if i.stage == 0: + if i.collision_type == "milk": + items.milk += 1 + elif i.collision_type == "sugar": + items.sugar += 1 + elif i.collision_type == "celery": + items.celery += 1 + elif i.collision_type == "butter": + items.butter += 1 + elif i.collision_type == "flour": + items.flour += 1 + elif i.collision_type == "vanilla": + items.vanilla += 1 + elif i.collision_type == "chocolate": + items.chocolate += 1 + i.stage += 1 + + if list_of_badbread_collisions: + for i in list_of_badbread_collisions: + items.remove_random() + + + +# In[7]: + + +def calculate_locations(left_bar, window_size, virtual_window): + list_of_rectangles = [] + gap = float(virtual_window[1]-140)/8 + for i in range(7): + rectangle = (left_bar,virtual_window[1]-((i+1)*gap + ((i+1)*20)), 20, 20)#IMAGE SIZE HARD CODED IN Y POSITON + print(str(rectangle)) + pixel_rectangle = xy_position_to_pixels(rectangle, window_size, virtual_window) + list_of_rectangles.append(pixel_rectangle) + return list_of_rectangles + +def blit_items(item_class, locations, font): + if item_class.milk > 0: + #print("bliting milk") + screen.blit(milk_scaled,locations[0]) + textsurface = font.render("x"+str(item_class.milk), False, (255, 0, 193)) + xy_position_of_text = (locations[0][0]+130,locations[0][1]+20) + screen.blit(textsurface,xy_position_of_text) + if item_class.chocolate > 0: + screen.blit(chocolate_scaled,locations[1]) + textsurface = font.render("x"+str(item_class.chocolate), False, (255, 0, 193)) + xy_position_of_text = (locations[1][0]+130,locations[1][1]+20) + screen.blit(textsurface,xy_position_of_text) + if item_class.sugar > 0: + screen.blit(sugar_scaled,locations[2]) + textsurface = font.render("x"+str(item_class.sugar), False, (255, 0, 193)) + xy_position_of_text = (locations[2][0]+130,locations[2][1]+20) + screen.blit(textsurface,xy_position_of_text) + if item_class.celery > 0: + screen.blit(celery_scaled,locations[3]) + textsurface = font.render("x"+str(item_class.celery), False, (255, 0, 193)) + xy_position_of_text = (locations[3][0]+130,locations[3][1]+20) + screen.blit(textsurface,xy_position_of_text) + if item_class.butter > 0: + screen.blit(butter_scaled,locations[4]) + textsurface = font.render("x"+str(item_class.butter), False, (255, 0, 193)) + xy_position_of_text = (locations[4][0]+130,locations[4][1]+20) + screen.blit(textsurface,xy_position_of_text) + if item_class.flour > 0: + screen.blit(flour_scaled,locations[5]) + textsurface = font.render("x"+str(item_class.flour), False, (255, 0, 193)) + xy_position_of_text = (locations[5][0]+130,locations[5][1]+20) + screen.blit(textsurface,xy_position_of_text) + if item_class.vanilla > 0: + screen.blit(vanilla_scaled,locations[6]) + textsurface = font.render("x"+str(item_class.vanilla), False, (255, 0, 193)) + xy_position_of_text = (locations[6][0]+130,locations[6][1]+20) + screen.blit(textsurface, xy_position_of_text) + + +# In[8]: + + +class animation: + def __init__(self, rectangles_left, rectangles_right, rectangle_forward): + self.right = 0 + self.left = 0 + self.rectangles_left = rectangles_left + self.rectangles_right = rectangles_right + self.rectangle_forward = rectangle_forward + +def create_character_rectangles(spritesheet_xy, direction): + character_pixels = (spritesheet_xy[0]/4, spritesheet_xy[1]/8) + rectangle_list = [] + if direction == "left": + for i in range(4): + rectangle_list.append((i*character_pixels[0], 0, character_pixels[0], character_pixels[1])) + for i in range(4): + rectangle_list.append((i*character_pixels[0], character_pixels[1], character_pixels[0], character_pixels[1])) + return rectangle_list + elif direction == "right": + for i in range(4): + rectangle_list.append((i*character_pixels[0],character_pixels[1]*4, character_pixels[0], character_pixels[1])) + for i in range(4): + rectangle_list.append((i*character_pixels[0], character_pixels[1]*5, character_pixels[0], character_pixels[1])) + return rectangle_list + elif direction == "forward": + rectangle_list.append((0*character_pixels[0],character_pixels[1]*2, character_pixels[0], character_pixels[1])) + return rectangle_list +def blit_character(current_position, window_size, virtual_window, animation_stage): + character_position = xy_position_to_pixels( + (current_position.current_x, current_position.current_y-2,current_position.character_width,current_position.character_height), window_size, virtual_window) + if current_position.current_xs + current_position.wall_speed > 0: + screen.blit(eggrika_spritesheet_scaled, character_position, animation_stage.rectangles_right[animation_stage.right]) + if animation_stage.right < 7: + animation_stage.right += 1 + else: + animation_stage.right = 0 + if current_position.current_xs + current_position.wall_speed < 0: + screen.blit(eggrika_spritesheet_scaled, character_position, animation_stage.rectangles_left[animation_stage.left]) + if animation_stage.left < 7: + animation_stage.left += 1 + else: + animation_stage.left = 0 + if current_position.current_xs + current_position.wall_speed == 0: + screen.blit(eggrika_spritesheet_scaled, character_position, animation_stage.rectangle_forward[0]) + + + +# In[9]: + + +virtual_window = (300,200) +pygame.mixer.pre_init(44100, -16, 1, 512) +pygame.init() +pygame.font.init() +pygame.mixer.init() +window_size = (pygame.display.Info().current_w -50, pygame.display.Info().current_h - 50) +screen = pygame.display.set_mode(window_size) +pygame.display.set_caption("Egg World") +global done +done = False +clock = pygame.time.Clock() + +wall = None +block_generation_list = [(0,0,630,20),(390,110,20,40),(370,70,60,40), + (350,30,100,40),(330,0,140,30),(680,0,120,20),(800,0,180,60),(980,0,320,10),(1300,0,250,50), + (1300,100,300,50), + (1400,150,40,50), (1550,0,50,30), + (1600,0,200,10),(1830,0,30,130),(1910,0,30,160),(1990,0,30,170),(2070, 80, 100, 50),(2070,0,530,20), + (2500,0,120,70),(2620,0,380,20)] + +list_of_blocks = generate_list_of_block_objects(block_generation_list) + +platform_generation_list = [(150,200,100),(500,600,120),(1050,1100,120),(1100,1190,70),(1190,1240,120),(1700,1770,90), + (2830,2900,100)] + +list_of_platforms = generate_list_of_platform_objects(platform_generation_list) + +badbread_generation_list = [(150,20,280),(470,20,570),(800,60,900),(1600,10,1770),(2070,20,2400)] + +list_of_badbreads = generate_list_of_badbreads(badbread_generation_list) + +ingredient_generation_list = [("milk", 200, 130), ("celery", 250, 180), ("sugar", 340, 80), ("chocolate", 390, 160), + ("vanilla", 440, 80), ("butter", 550, 30), ("flour", 650, 100), ("milk", 770, 30), + ("celery", 830, 150),("butter", 860, 150),("milk", 890, 150), ("chocolate",1130,180), + ("butter",1130,80), ("milk", 1320, 160), ("milk", 1350, 160),("milk", 1380, 160), + ("sugar", 1450, 70),("celery", 1560, 160), ("chocolate", 1720,30), ("sugar",1830,140), + ("sugar",1910,170),("sugar",1990,180), ("flour", 2290, 100), ("milk",2410,80)] + +list_of_ingredients = generate_list_of_ingredients(ingredient_generation_list) +wall = None +world_speed = .5 + +in_title_screen = True +title_text = pygame.image.load('Title.png') +title_scaled = pygame.transform.scale(title_text, window_size) +title_block = block(0, 0, virtual_window[0],20) +scroll = 0 +chase_animation = 0 +chase_image1 = pygame.image.load('Chase1.png') +chase_rectangle = (2835, 108, 60, 60) +pixel_chase_rectangle = xy_position_to_pixels(chase_rectangle, window_size, virtual_window) +chase_pixel_size = (pixel_chase_rectangle[2], pixel_chase_rectangle[3]) +chase_image1_transform = pygame.transform.scale(chase_image1, chase_pixel_size) +chase_image2 = pygame.image.load('Chase2.png') +chase_image2_transform = pygame.transform.scale(chase_image2, chase_pixel_size) +global finish_line +finish_line = False +start_over = False + +itembar = items() + +current_position = position(current_y= virtual_window[1], current_x = 20, wall_speed = world_speed) +title_position = position(current_y= 20, wall_speed = 0, current_xs = 5) + +myfont = pygame.font.Font('Birdy Game.ttf', 30) +myfontlarge = pygame.font.Font('Birdy Game.ttf', 80) +gradient = pygame.image.load('Gradient.jpeg') +gradient_scaled = pygame.transform.scale(gradient, window_size) +texture = pygame.image.load('CakeTexture.jpeg') +texture_scaled = pygame.transform.scale(texture, window_size) + +resize_material_rectangle = xy_position_to_pixels((0,0,20,20), window_size, virtual_window) +materials_size = (resize_material_rectangle[2], resize_material_rectangle[3]) +butter_picture = pygame.image.load('Butter.png') +butter_scaled = pygame.transform.scale(butter_picture, materials_size) +milk_picture = pygame.image.load('Milk.png') +milk_scaled = pygame.transform.scale(milk_picture, materials_size) +vanilla_picture = pygame.image.load('Vanilla.png') +vanilla_scaled = pygame.transform.scale(vanilla_picture, materials_size) +celery_picture = pygame.image.load('Celery.png') +celery_scaled = pygame.transform.scale(celery_picture, materials_size) +chocolate_picture = pygame.image.load('Chocolate.png') +chocolate_scaled = pygame.transform.scale(chocolate_picture, materials_size) +sugar_picture = pygame.image.load('Sugar.png') +sugar_scaled = pygame.transform.scale(sugar_picture, materials_size) +flour_picture = pygame.image.load('Flour.png') +flour_scaled = pygame.transform.scale(flour_picture, materials_size) +resize_bread_rectangle = xy_position_to_pixels((0,0,45,45), window_size, virtual_window) +bread_size = (resize_bread_rectangle[2], resize_bread_rectangle[3]) +bread_left = pygame.image.load('Bread_Left.png') +bread_left_scaled = pygame.transform.scale(bread_left, bread_size) +bread_right = pygame.image.load('Bread_Right.png') +bread_right_scaled = pygame.transform.scale(bread_right, bread_size) +custard_image = pygame.image.load('Custard.jpg') +custard_scaled = pygame.transform.scale(custard_image, window_size) +omelette_image = pygame.image.load('Omelette.jpg') +omelette_scaled = pygame.transform.scale(omelette_image, window_size) +quiche_image = pygame.image.load('Quiche.jpg') +quiche_scaled = pygame.transform.scale(quiche_image, window_size) +creme_image = pygame.image.load('CremeBrulee.jpg') +creme_scaled = pygame.transform.scale(custard_image, window_size) +pudding_image = pygame.image.load('Pudding.jpg') +pudding_scaled = pygame.transform.scale(pudding_image, window_size) +lose_image = pygame.image.load('Lose.jpg') +lose_scaled = pygame.transform.scale(lose_image, window_size) + +left_bar = virtual_window[0]-50 +spacing = 10 +locations = calculate_locations(left_bar, window_size, virtual_window) + +eggrika_spritesheet = pygame.image.load("EggrikaSpriteSheet.png") +spritesheet_size = xy_position_to_pixels((0,0,current_position.character_width*4, + current_position.character_height*8), window_size, virtual_window) +spritesheet_xy = (spritesheet_size[2], spritesheet_size[3]) +eggrika_spritesheet_scaled = pygame.transform.scale(eggrika_spritesheet, (spritesheet_size[2], spritesheet_size[3])) + +rectangles_right = create_character_rectangles(spritesheet_xy, 'right') +rectangles_left = create_character_rectangles(spritesheet_xy, 'left') +rectangle_forward = create_character_rectangles(spritesheet_xy, 'forward') +animation_stage = animation(rectangles_left, rectangles_right, rectangle_forward) + + +jump_sound = pygame.mixer.Sound('Boing.ogg') +yay_bool = False +yay_sound = pygame.mixer.Sound('Yay.ogg') +theme_sound = pygame.mixer.Sound('Theme.ogg') +lose_sound = pygame.mixer.Sound('LoseAudio.ogg') +pygame.mixer.Sound.set_volume(theme_sound, .2) +pygame.mixer.Sound.set_volume(jump_sound, .1) +pygame.mixer.Sound.play(theme_sound, loops = -1) + +while not done: + + while in_title_screen: + for event in pygame.event.get(): + if event.type == pygame.QUIT: + pygame.quit() + if event.type == pygame.KEYDOWN: + if event.key == pygame.K_SPACE or event.key == pygame.K_ESCAPE: + in_title_screen = False + screen.blit(gradient_scaled,(0,0)) + blit_character(title_position, window_size, virtual_window, animation_stage) + screen.blit(title_scaled,(0,0)) + blit_block(title_block, window_size, virtual_window, myfont) + pygame.display.flip() + if title_position.current_x < virtual_window[0]: + title_position.current_x += title_position.current_xs + if title_position.current_x >= virtual_window[0]: + title_position.current_x = 0 - title_position.current_x - title_position.character_width + + ##### + + if scroll <= 2730: + scroll_everything_left(list_of_platforms, list_of_blocks, list_of_badbreads,list_of_ingredients, world_speed) + chase_rectangle = (chase_rectangle[0]-world_speed,chase_rectangle[1], 50,50) + scroll+=world_speed + else: + current_position.wall_speed = 0 + + clock.tick(50) + + for event in pygame.event.get(): + if event.type == pygame.QUIT: + done = True + if event.type == pygame.KEYDOWN: + if event.key == pygame.K_ESCAPE: + done = True + #print("KEY DOWN!") + current_position.button = keys(event) + #print(current_position.button) + break + if event.type == pygame.KEYUP: + #print("KEY UP!") + current_position.button = None + break + + blocks_on_screen = generate_list_of_blocks_on_screen(list_of_blocks, virtual_window) + platforms_on_screen = generate_list_of_platforms_on_screen(list_of_platforms, virtual_window) + wall = give_wall_value(current_position, blocks_on_screen) + floor = give_floor_value(current_position, blocks_on_screen, platforms_on_screen) + badbreads_on_screen = generate_list_of_badbreads_on_screen(list_of_badbreads, virtual_window) + ingredients_on_screen = generate_list_of_ingredients_on_screen(list_of_ingredients, virtual_window) + + + #Check If On-Screen + if current_position.current_x < -150: + itembar.remove_random() + if current_position.current_y < -200: + itembar.remove_random() + + + #Collisions + current_position.give_next_position(floor = floor, wall = wall) + list_of_ingredient_collisions = generate_ingredient_collisions(ingredients_on_screen, list_of_ingredients, current_position) + list_of_badbread_collisions = generate_badbread_collisions(badbreads_on_screen, + list_of_badbreads, current_position) + + process_collision_lists(current_position, list_of_ingredient_collisions, list_of_badbread_collisions, itembar) + + #Blit Sky + screen.blit(gradient_scaled,(0,0)) + + + + #Blit Structures/Enemies + for i in blocks_on_screen: + blit_block(i, window_size, virtual_window, myfont) + for i in platforms_on_screen: + blit_platform(i, window_size, virtual_window) + for i in badbreads_on_screen: + i.move_badbread() + blit_badbread(i, window_size, virtual_window) + for i in ingredients_on_screen: + blit_ingredient(i, window_size, virtual_window) + + #Blit Items + blit_items(itembar, locations, myfontlarge) + + #Chase: + pixel_chase_rectangle = xy_position_to_pixels(chase_rectangle, window_size, virtual_window) + if chase_animation < 30: + screen.blit(chase_image1_transform, pixel_chase_rectangle) + chase_animation+=1 + elif chase_animation < 60: + screen.blit(chase_image2_transform, pixel_chase_rectangle) + chase_animation+=1 + else: + screen.blit(chase_image2_transform, pixel_chase_rectangle) + chase_animation = 0 + + #Test Stuff + #current_position.current_x = 100 + #current_position.current_y = 150 + + if current_position.current_x>chase_rectangle[0]: + if yay_bool == False: + pygame.mixer.Sound.play(yay_sound) + yay_bool == True + finish_line = True + + #Character + blit_character(current_position, window_size, virtual_window, animation_stage) + + pygame.display.flip() + + + while finish_line == True: + for event in pygame.event.get(): + if event.type == pygame.QUIT: + pygame.quit() + if event.type == pygame.KEYDOWN: + print(itembar) + if event.key == pygame.K_SPACE or event.key == pygame.K_ESCAPE: + start_over = True + finish_line = False + total = itembar.total() + if total >= 23 and itembar.celery >= 3 and itembar.flour >=1: + screen.blit(quiche_scaled, (0,0)) + elif total >=23 and itembar.celery >= 2: + screen.blit(omelette_scaled, (0,0)) + elif total >= 20 and itembar.vanilla >= 1: + screen.blit(omelette_scaled, (0,0)) + elif total >= 15 and itembar.chocolate >= 3: + screen.blit(pudding_scaled, (0,0)) + elif total >= 5 and itembar.milk >= 1 and itembar.butter>=1 and itembar.flour >= 1: + screen.blit(custard_scaled, (0,0)) + else: + screen.blit(lose_scaled, (0,0)) + + pygame.display.flip() + + if start_over == True: + wall = None + block_generation_list = [(0,0,630,20),(390,110,20,40),(370,70,60,40), + (350,30,100,40),(330,0,140,30),(680,0,120,20),(800,0,180,60),(980,0,320,10),(1300,0,250,50), + (1300,100,300,50), + (1400,150,40,50), (1550,0,50,30), + (1600,0,200,10),(1830,0,30,130),(1910,0,30,160),(1990,0,30,170),(2070, 80, 100, 50),(2070,0,530,20), + (2500,0,120,70),(2620,0,380,20)] + + list_of_blocks = generate_list_of_block_objects(block_generation_list) + + platform_generation_list = [(150,200,100),(500,600,120),(1050,1100,120),(1100,1190,70),(1190,1240,120),(1700,1770,90), + (2830,2900,100)] + + list_of_platforms = generate_list_of_platform_objects(platform_generation_list) + + badbread_generation_list = [(150,20,280),(470,20,570),(800,60,900),(1600,10,1770),(2070,20,2400)] + + list_of_badbreads = generate_list_of_badbreads(badbread_generation_list) + + ingredient_generation_list = [("milk", 200, 130), ("celery", 250, 180), ("sugar", 340, 80), ("chocolate", 390, 160), + ("vanilla", 440, 80), ("butter", 550, 30), ("flour", 650, 100), ("milk", 770, 30), + ("celery", 830, 150),("butter", 860, 150),("milk", 890, 150), ("chocolate",1130,180), + ("butter",1130,80), ("milk", 1320, 160), ("milk", 1350, 160),("milk", 1380, 160), + ("sugar", 1450, 70),("celery", 1560, 160), ("chocolate", 1720,30), ("sugar",1830,140), + ("sugar",1910,170),("sugar",1990,180), ("flour", 2290, 100), ("milk",2410,80)] + + list_of_ingredients = generate_list_of_ingredients(ingredient_generation_list) + wall = None + in_title_screen = True + scroll = 0 + itembar = items() + chase_rectangle = (2835, 108, 60, 60) + current_position = position(current_y= virtual_window[1], wall_speed = world_speed) + title_position = position(current_y= 20, current_x = 20, wall_speed = 0, current_xs = 5) + start_over = False + +pygame.quit() + + diff --git a/Quiche.jpg b/Quiche.jpg new file mode 100644 index 00000000..41716c08 Binary files /dev/null and b/Quiche.jpg differ diff --git a/README.md b/README.md index 5f822327..6fa80eea 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,4 @@ # InteractiveProgramming This is the base repo for the interactive programming project for Software Design, Spring 2018 at Olin College. + +Project Write Up is in 'Project 4 Write Up.pdf'. diff --git a/Sugar.png b/Sugar.png new file mode 100644 index 00000000..c335a171 Binary files /dev/null and b/Sugar.png differ diff --git a/Theme.ogg b/Theme.ogg new file mode 100644 index 00000000..dcf00cd1 Binary files /dev/null and b/Theme.ogg differ diff --git a/Title.png b/Title.png new file mode 100644 index 00000000..e7bff6a6 Binary files /dev/null and b/Title.png differ diff --git a/Unicorn Scribbles.otf b/Unicorn Scribbles.otf new file mode 100644 index 00000000..6646cd40 Binary files /dev/null and b/Unicorn Scribbles.otf differ diff --git a/Vanilla.png b/Vanilla.png new file mode 100644 index 00000000..dfb0f68f Binary files /dev/null and b/Vanilla.png differ diff --git a/Yay.ogg b/Yay.ogg new file mode 100644 index 00000000..5142f43c Binary files /dev/null and b/Yay.ogg differ