diff --git a/1.png b/1.png new file mode 100644 index 0000000..da7afd5 Binary files /dev/null and b/1.png differ diff --git a/10.png b/10.png new file mode 100644 index 0000000..fecd94e Binary files /dev/null and b/10.png differ diff --git a/15.png b/15.png new file mode 100644 index 0000000..e92d0d0 Binary files /dev/null and b/15.png differ diff --git a/16.png b/16.png new file mode 100644 index 0000000..0577a7b Binary files /dev/null and b/16.png differ diff --git a/17.png b/17.png new file mode 100644 index 0000000..7e992ed Binary files /dev/null and b/17.png differ diff --git a/18.png b/18.png new file mode 100644 index 0000000..90f0204 Binary files /dev/null and b/18.png differ diff --git a/2.png b/2.png new file mode 100644 index 0000000..33e759b Binary files /dev/null and b/2.png differ diff --git a/3.png b/3.png new file mode 100644 index 0000000..655eca3 Binary files /dev/null and b/3.png differ diff --git a/4.png b/4.png new file mode 100644 index 0000000..533306f Binary files /dev/null and b/4.png differ diff --git a/5.png b/5.png new file mode 100644 index 0000000..083e8d8 Binary files /dev/null and b/5.png differ diff --git a/6.png b/6.png new file mode 100644 index 0000000..54c5c06 Binary files /dev/null and b/6.png differ diff --git a/7.png b/7.png new file mode 100644 index 0000000..753123a Binary files /dev/null and b/7.png differ diff --git a/8.png b/8.png new file mode 100644 index 0000000..c0c96da Binary files /dev/null and b/8.png differ diff --git a/9.png b/9.png new file mode 100644 index 0000000..e546453 Binary files /dev/null and b/9.png differ diff --git a/BG.png b/BG.png new file mode 100644 index 0000000..b319f21 Binary files /dev/null and b/BG.png differ diff --git a/Bush (1).png b/Bush (1).png new file mode 100644 index 0000000..b920971 Binary files /dev/null and b/Bush (1).png differ diff --git a/Bush (2).png b/Bush (2).png new file mode 100644 index 0000000..489247b Binary files /dev/null and b/Bush (2).png differ diff --git a/Bush (3).png b/Bush (3).png new file mode 100644 index 0000000..0997a5c Binary files /dev/null and b/Bush (3).png differ diff --git a/Bush (4).png b/Bush (4).png new file mode 100644 index 0000000..b65a4ea Binary files /dev/null and b/Bush (4).png differ diff --git a/Crate.png b/Crate.png new file mode 100644 index 0000000..c149dd1 Binary files /dev/null and b/Crate.png differ diff --git a/Mushroom_1.png b/Mushroom_1.png new file mode 100644 index 0000000..ab8f71d Binary files /dev/null and b/Mushroom_1.png differ diff --git a/Mushroom_2.png b/Mushroom_2.png new file mode 100644 index 0000000..3d28c32 Binary files /dev/null and b/Mushroom_2.png differ diff --git a/Sign_1.png b/Sign_1.png new file mode 100644 index 0000000..9d9da0b Binary files /dev/null and b/Sign_1.png differ diff --git a/Sign_2.png b/Sign_2.png new file mode 100644 index 0000000..3e225e4 Binary files /dev/null and b/Sign_2.png differ diff --git a/Stone.png b/Stone.png new file mode 100644 index 0000000..6095d67 Binary files /dev/null and b/Stone.png differ diff --git a/Tree_1.png b/Tree_1.png new file mode 100644 index 0000000..33fe1e8 Binary files /dev/null and b/Tree_1.png differ diff --git a/Tree_2.png b/Tree_2.png new file mode 100644 index 0000000..bc8c0c1 Binary files /dev/null and b/Tree_2.png differ diff --git a/Tree_3.png b/Tree_3.png new file mode 100644 index 0000000..d48c66c Binary files /dev/null and b/Tree_3.png differ diff --git a/enemy.py b/enemy.py new file mode 100644 index 0000000..531e0cc --- /dev/null +++ b/enemy.py @@ -0,0 +1,29 @@ +import pygame +import os + +ALPHA = (0, 255, 0) +class Enemy(pygame.sprite.Sprite): + """Spawn an enemy""" + def __init__(self, x, y, img): + pygame.sprite.Sprite.__init__(self) + self.image = pygame.image.load(os.path.join('images', img)) + self.image.convert_alpha() + self.image.set_colorkey(ALPHA) + self.rect = self.image.get_rect() + self.rect.x = x + self.rect.y = y + self.counter = 0 + + def move(self): + """enemy movement""" + distance = 80 + speed = 8 + + if self.counter >= 0 and self.counter <= distance: + self.rect.x += speed + elif self.counter >= distance and self.counter <= distance*2: + self.rect.x -= speed + else: + self.counter = 0 + + self.counter += 1 diff --git a/game1.py b/game1.py new file mode 100644 index 0000000..6a56c05 --- /dev/null +++ b/game1.py @@ -0,0 +1,144 @@ +import pygame # load pygame keywords +import sys # let python use your file system +import os # help python identify your OS +import time +import random +from plyaer1 import Player +from enemy import Enemy +pygame.init() + +steps = 10 # how many pixels to move + +#basic_screen_settings +white = (255, 255, 255) +yellow = (255, 255, 102) +black = (0, 0, 0) +red = (213, 50, 80) +green = (0, 255, 0) +blue = (50, 153, 213) + +dis_width = 1050 +dis_height = 630 +a1=pygame.image.load("1.png") +a2=pygame.image.load("2.png") +a3=pygame.image.load("3.png") +a17=pygame.image.load("17.png") +a13=pygame.image.load("13.png") +a14=pygame.image.load("14.png") +a15=pygame.image.load("15.png") +a4=pygame.image.load("4.png") +a5=pygame.image.load("5.png") +a6=pygame.image.load("6.png") +t1=pygame.image.load("Tree_2.png") +t1 = pygame.transform.scale(t1, (100, 75+50)) +t2=pygame.image.load("Tree_3.png") +t2 = pygame.transform.scale(t2, (100, 75+50)) +b3=pygame.image.load("Bush (3).png") +b4=pygame.image.load("Bush (4).png") +c1=pygame.image.load("Crate.png") +background_image =pygame.image.load("BG.png") + +dis = pygame.display.set_mode((dis_width, dis_height)) +pygame.display.set_caption('Game') + +clock = pygame.time.Clock() +snake_block=10 +#text_display +font_style = pygame.font.SysFont("bahnschrift", 25) +score_font = pygame.font.SysFont("comicsansms", 35) +def message(msg, color): + mesg = font_style.render(msg, True, color) + dis.blit(mesg, [dis_width / 6, dis_height / 3]) + + +def gameLoop(): + game_over = False + game_close = False + player = Player() # spawn player + player.rect.x = 0 # go to x + player.rect.y = 30 # go to y + player_list = pygame.sprite.Group() + player_list.add(player) + steps = 10 + + + #foodx = round(random.randrange(0, dis_width - snake_block) / 10.0) * 10.0 + #foody = round(random.randrange(0, dis_height - snake_block) / 10.0) * 10.0 + + while not game_over: + #adding_tiles + dis.blit(background_image, [0, 0]) + dis.blit(a1, [0, 550]) + dis.blit(a2, [80, 550]) + dis.blit(a3, [160, 550]) + dis.blit(a17, [160+80, 575]) + + dis.blit(a13, [160, 150]) + dis.blit(a14, [160+80, 150]) + dis.blit(a15, [160+80+80, 150]) + + dis.blit(a4, [240+80, 550]) + dis.blit(a5, [240+80+80, 550]) + dis.blit(a6, [240+80+80+80, 550]) + + dis.blit(a1, [240+80, 550-80]) + dis.blit(a2, [240+80+80, 550-80]) + dis.blit(a3, [240+80+80+80,550-80]) + + #adding_trees + dis.blit(b3, [60, 550-40]) + dis.blit(b4, [140, 550-40]) + dis.blit(t1, [90, 550-120]) + dis.blit(c1, [250, 120]) + dis.blit(c1, [250+30, 120]) + dis.blit(c1, [265, 90]) + + + + while game_close == True: + for event in pygame.event.get(): + if event.type == pygame.QUIT: + pygame.quit() + try: + sys.exit() + finally: + game_over = False + + if event.type == pygame.KEYDOWN: + if event.key == ord('q'): + pygame.quit() + try: + sys.exit() + finally: + game_over = False + if event.key == pygame.K_LEFT or event.key == ord('a'): + player.control(-steps, 0) + if event.key == pygame.K_RIGHT or event.key == ord('d'): + player.control(steps, 0) + if event.key == pygame.K_UP or event.key == ord('w'): + print('jump') + + if event.type == pygame.KEYUP: + if event.key == pygame.K_LEFT or event.key == ord('a'): + player.control(steps, 0) + if event.key == pygame.K_RIGHT or event.key == ord('d'): + player.control(-steps, 0) + + + + + pygame.display.update() + player.update() + player_list.draw(dis) + enemy_list.draw(dis) + for e in enemy_list: + e.move() + pygame.display.flip() + clock.tick(fps) + + + pygame.quit() + quit() + + +gameLoop() diff --git a/game_functions.py b/game_functions.py new file mode 100644 index 0000000..71ae398 --- /dev/null +++ b/game_functions.py @@ -0,0 +1,29 @@ +import sys +import pygame + +def check_events(): + ""Respond to keypress and mouse events"" + for event in pygame.event.get(): + if event.type == pygame.QUIT: + sys.exit() + + elif event.type == pygame.KEYDOWN: + if event.type == pygame.K_RIGHT: + ship.moving_right= True + elif event.type == pygame.K_LEFT: + ship.moving_left= True + + + elif event.type == pygame.KEYUP: + if event.type == pygame.K_RIGHT: + ship.moving_right= False + elif event.type == pygame.K_LEFT: + ship.moving_leftt= False + +def update_screen(ai_settings, screen, ship): + screen.fill(ai_settings.bg_color) + ship.blitme() + + pygame.display.flip() + + diff --git a/level.py b/level.py new file mode 100644 index 0000000..e024d58 --- /dev/null +++ b/level.py @@ -0,0 +1,10 @@ +class Level(): + def bad(lvl, eloc): + if lvl == 1: + enemy = Enemy(eloc[0], eloc[1], 'walk-1.png') + enemy_list = pygame.sprite.Group() + enemy_list.add(enemy) + if lvl == 2: + print("Level " + str(lvl) ) + + return enemy_list \ No newline at end of file diff --git a/pengo_game.py b/pengo_game.py new file mode 100644 index 0000000..127b6f4 --- /dev/null +++ b/pengo_game.py @@ -0,0 +1,287 @@ +import pygame +import sys +import os + +''' +Variables +''' + +worldx = 1050 +worldy = 630 +fps = 40 +ani = 4 +dis = pygame.display.set_mode([worldx, worldy]) + +BLUE = (25, 25, 200) +BLACK = (23, 23, 23) +WHITE = (254, 254, 254) +ALPHA = (0, 255, 0) +jump= False +vel_x=10 +vel_y=10 + + +''' +Objects +''' + + +class Player(pygame.sprite.Sprite): + """ + Spawn a player + """ + + def __init__(self): + pygame.sprite.Sprite.__init__(self) + self.movex = 0 + self.movey = 0 + self.frame = 0 + self.health = 10 + self.images = [] + for i in range(1, 5): + img = pygame.image.load(os.path.join('images', 'walk-' + str(i) + '.png')).convert() + img.convert_alpha() + + self.images.append(img) + self.image = self.images[0] + img.set_colorkey(ALPHA) + self.rect = self.image.get_rect() + + + def control(self, x, y): + """ + control player movement + """ + self.movex += x + self.movey += y + + def update(self): + """ + Update sprite position + """ + + self.rect.x = self.rect.x + self.movex + self.rect.y = self.rect.y + self.movey + + # moving left + if self.movex < 0: + self.frame += 1 + if self.frame > 3*ani: + self.frame = 0 + self.image = pygame.transform.flip(self.images[self.frame // ani], True, False) + + # moving right + if self.movex > 0: + self.frame += 1 + if self.frame > 3*ani: + self.frame = 0 + self.image = self.images[self.frame//ani] + + hit_list = pygame.sprite.spritecollide(self, enemy_list, False) + for enemy in hit_list: + self.health -= 1 + print(self.health) + + +class Enemy(pygame.sprite.Sprite): + """ + Spawn an enemy + """ + def __init__(self, x, y, img): + pygame.sprite.Sprite.__init__(self) + self.image = pygame.image.load(os.path.join('images', img)) + self.image.convert_alpha() + self.image.set_colorkey(ALPHA) + self.rect = self.image.get_rect() + self.rect.x = x + self.rect.y = y + self.counter = 0 + + def move(self): + """ + enemy movement + """ + distance = 40 + speed = 3 + + if self.counter >= 0 and self.counter <= distance: + self.rect.x += speed + elif self.counter >= distance and self.counter <= distance*2: + self.rect.x -= speed + else: + self.counter = 0 + + self.counter += 1 + + +class Level(): + def bad(lvl, eloc): + if lvl == 1: + enemy = Enemy(eloc[0], eloc[1], 'walk-1.png') + enemy_list = pygame.sprite.Group() + enemy_list.add(enemy) + if lvl == 2: + print("Level " + str(lvl) ) + + return enemy_list + + +''' +Setup +''' + +backdrop = pygame.image.load(os.path.join('images', 'BG.png')) +clock = pygame.time.Clock() +pygame.init() +#backdropbox = world.get_rect() +main = True + +player = Player() # spawn player +player.rect.x = 100 # go to x +player.rect.y = 510 # go to y +player_list = pygame.sprite.Group() +player_list.add(player) +steps = 10 + +eloc = [] +eloc = [340, 430] +eloc1 = [] +eloc1 = [0,0] +enemy_list = Level.bad(1, eloc ) +enemy_list1 = Level.bad(1, eloc1 ) +#e2=Enemy(200, 100, 'walk-1.png') + +a1=pygame.image.load("1.png") +a2=pygame.image.load("2.png") +a3=pygame.image.load("3.png") +a17=pygame.image.load("17.png") +a13=pygame.image.load("13.png") +a14=pygame.image.load("14.png") +a15=pygame.image.load("15.png") +a4=pygame.image.load("4.png") +a5=pygame.image.load("5.png") +a6=pygame.image.load("6.png") +t1=pygame.image.load("Tree_2.png") +t1 = pygame.transform.scale(t1, (100, 75+50)) +t2=pygame.image.load("Tree_3.png") +t2 = pygame.transform.scale(t2, (100, 75+50)) +b3=pygame.image.load("Bush (3).png") +b4=pygame.image.load("Bush (4).png") +c1=pygame.image.load("Crate.png") +background_image =pygame.image.load("BG.png") + +#adding_tiles +#dis.blit(background_image, [0, 0]) + + + +''' +Main Loop +''' +gravity= -1 +while main: + dis.blit(background_image, [0, 0]) + dis.blit(a1, [0, 550]) + dis.blit(a2, [80, 550]) + dis.blit(a3, [160, 550]) + dis.blit(a17, [160+80, 575]) + + dis.blit(a13, [160, 150]) + dis.blit(a14, [160+80, 150]) + dis.blit(a15, [160+80+80, 150]) + + dis.blit(a4, [240+80, 550]) + dis.blit(a5, [240+80+80, 550]) + dis.blit(a6, [240+80+80+80, 550]) + + dis.blit(a1, [240+80, 550-80]) + dis.blit(a2, [240+80+80, 550-80]) + dis.blit(a3, [240+80+80+80,550-80]) + + #adding_trees + dis.blit(b3, [60, 550-40]) + dis.blit(b4, [140, 550-40]) + dis.blit(t1, [90, 550-120]) + dis.blit(c1, [250, 120]) + dis.blit(c1, [250+30, 120]) + dis.blit(c1, [265, 90]) + + + + #key_pressed = pygame.key.get_pressed() + #if key_pressed[pygame.K_SPACE]: + # jump=True + #if jump: + # player.movey -= vel_y + # vel_y -= gravity + # if vel_y <- 10: + # jump = False + # player.movey = 10 + + for event in pygame.event.get(): + if event.type == pygame.QUIT: + pygame.quit() + try: + sys.exit() + finally: + main = False + + if event.type == pygame.KEYDOWN: + if event.key == ord('q'): + pygame.quit() + try: + sys.exit() + finally: + main = False + if event.key == pygame.K_LEFT or event.key == ord('a'): + player.control(-steps, 0) + if event.key == pygame.K_RIGHT or event.key == ord('d'): + player.control(steps, 0) + + + + + if event.key == pygame.K_UP or event.key == ord('w'): + print('jump') + jump = True + + if jump is True: + player.movey -= vel_y + vel_y -= 1 + #if player.movey < -10: #any free move in the screen + if vel_y < -10: #only straight up + jump = False + vel_y = 10 + player.movey += 20 + + + + + + + if event.type == pygame.KEYUP: + if event.key == pygame.K_LEFT or event.key == ord('a'): + player.control(steps, 0) + if event.key == pygame.K_RIGHT or event.key == ord('d'): + player.control(-steps, 0) + + if event.key == pygame.K_UP or event.key == ord('w'): + print('jump') + jump = True + if jump is True: + player.movey -= vel_y + vel_y -= 1 + if vel_y < 10: + jump = False + vel_y = 10 + player.movey += 20 + + + #world.blit(backdrop, backdropbox) + player.update() + player_list.draw(dis) + enemy_list.draw(dis) + for e in enemy_list: + e.move() + pygame.display.flip() + clock.tick(fps) \ No newline at end of file diff --git a/player.py b/player.py new file mode 100644 index 0000000..aadc3e1 --- /dev/null +++ b/player.py @@ -0,0 +1,29 @@ +class Player: + def __init__(self): + #pygame.sprite.Sprite.__init__(self) + self.movex = 0 # move along X + self.movey = 0 # move along Y + self.frame = 0 # count frames + + def control(self,x,y): + """ control player movement """ + self.movex += x + self.movey += y + + def update(self): + """ Update sprite position""" + self.rect.x = self.rect.x + self.movex + self.rect.y = self.rect.y + self.movey + # moving left + if self.movex < 0: + self.frame += 1 + if self.frame > 3*ani: + self.frame = 0 + self.image = self.images[self.frame//ani] + + # moving right + if self.movex > 0: + self.frame += 1 + if self.frame > 3*ani: + self.frame = 0 + self.image = self.images[self.frame//ani] \ No newline at end of file diff --git a/player1.py b/player1.py new file mode 100644 index 0000000..1ec2832 --- /dev/null +++ b/player1.py @@ -0,0 +1,54 @@ +class Player(pygame.sprite.Sprite): + """ + Spawn a player + """ + + def __init__(self): + pygame.sprite.Sprite.__init__(self) + self.movex = 0 + self.movey = 0 + self.frame = 0 + self.health = 10 + self.images = [] + for i in range(1, 5): + img = pygame.image.load(os.path.join('images', 'walk-' + str(i) + '.png')).convert() + img.convert_alpha() + img.set_colorkey(ALPHA) + self.images.append(img) + self.image = self.images[0] + self.rect = self.image.get_rect() + + def control(self, x, y): + """ + control player movement + """ + self.movex += x + self.movey += y + + def update(self): + """ + Update sprite position + """ + + self.rect.x = self.rect.x + self.movex + self.rect.y = self.rect.y + self.movey + + # moving left + if self.movex < 0: + self.frame += 1 + if self.frame > 3*ani: + self.frame = 0 + self.image = pygame.transform.flip(self.images[self.frame // ani], True, False) + + # moving right + if self.movex > 0: + self.frame += 1 + if self.frame > 3*ani: + self.frame = 0 + self.image = self.images[self.frame//ani] + + hit_list = pygame.sprite.spritecollide(self, enemy_list, False) + for enemy in hit_list: + self.health -= 1 + print(self.health) + diff --git a/settings.py b/settings.py new file mode 100644 index 0000000..88a31d5 --- /dev/null +++ b/settings.py @@ -0,0 +1,10 @@ +import pygame +class Settings(): + """A class to store all settings for Alien Invasion.""" + def __init__(self): + """Initialize the game's settings.""" + # Screen settings + self.screen_width = 900 + self.screen_height = 600 + self.bg_color = (230, 230, 230) + self.ship_speed_factor= 1.5 \ No newline at end of file