diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 94a25f7..b3561a0 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -2,5 +2,6 @@ + \ No newline at end of file diff --git a/8-bit wonder text files/8-BIT WONDER.TXT b/8-bit wonder text files/8-BIT WONDER.TXT new file mode 100644 index 0000000..7724218 --- /dev/null +++ b/8-bit wonder text files/8-BIT WONDER.TXT @@ -0,0 +1,22 @@ +=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + VIEW THIS USING A MONOSPACED FONT!!! +=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + + :: SPECIFIC INFO FOR THIS FONT :: + + Heh, I'm a big fan of 8-bit things, so I made an 8-bit font. The original plan + was to make it a pixel-perfect low resolution font, and that part does work as + well, but as an additional bonus it looks pretty interesting if used at bigger + sizes in italic mode. + + This font was made for making titles for my website and my pictures, so it has + certain specific optimizations. When used on-screen it will look the best with + font sizes starting with 9 and then any next 9. That is 9, 18, 27, 36, etc. + + Enjoy, and don't forget to send feedback and tell me what characters you would + like to see added. + +=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + + Revision: 0.80 | 26.01.2001 + [EOF] \ No newline at end of file diff --git a/8-bit wonder text files/README.TXT b/8-bit wonder text files/README.TXT new file mode 100644 index 0000000..b70f725 --- /dev/null +++ b/8-bit wonder text files/README.TXT @@ -0,0 +1,53 @@ +=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + VIEW THIS USING A MONOSPACED FONT!!! +=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + + :: INTRODUCTION :: + + Greetings, welcome to the readme file for my fonts. That's it. :) + +=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + + :: TERMS OF USE :: + + Currently all my fonts are freeware. That doesn't mean however, that you can + do whatever you want with them. Here are the rules for use and distribution: + + 1. You WILL NOT modify the fonts, the copyright notices, or this text file. + 2. You WILL NOT sell the fonts in ANY way. + 3. Whatever you do with it, you take full responsibility. + + Those are the rules you MUST follow to use or distribute these fonts. If you + disagree, stop using the fonts immediately. If I grow aware of any violations + of these terms, expect legal action to be taken. So, you have been warned. + + And, if you decide to use any of the fonts for commercial purposes, it would + be really nice to receive a product sample. I can make a special version of a + font exclusively for you as well. Just e-mail me if you are interested. +=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + + :: ABOUT ME :: + + Well, not much to say, really. I'm a guy from Latvia, called Joiro Hatagaya, + I like making fonts, 2D/3D graphics, music, games and programs and many other + things. Send me feedback to make me happy and give me energy to do more. :) + +=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + + :: CONTACT INFORMATION AND WEBSITES :: + + E-MAIL: JOIRO@HOTMAIL.COM | Please put "FONTS" in caps as the subject. Do not + send spam, or you WILL regret it. + + WEBSITE: JOIRO.THE3DSTUDIO.COM | Come here to see some of my 3D work and find + out what other things I do. + + NEW!!! + FONT WEBSITE: http://www.typesource.com/Presents/Hatagaya/Fonts.html | Yes! I + now have a special mini-website for my fonts only, where you can find all the + latest versions of these fonts and also brand new fonts. So go visit it! NOW! + +=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + + Revision: 1.20 | 05.01.2001 + [EOF] \ No newline at end of file diff --git a/__pycache__/settings.cpython-38.pyc b/__pycache__/settings.cpython-38.pyc new file mode 100644 index 0000000..1b67845 Binary files /dev/null and b/__pycache__/settings.cpython-38.pyc differ diff --git a/__pycache__/sprites.cpython-38.pyc b/__pycache__/sprites.cpython-38.pyc new file mode 100644 index 0000000..da78e96 Binary files /dev/null and b/__pycache__/sprites.cpython-38.pyc differ diff --git a/first.py b/first.py new file mode 100644 index 0000000..8f9dd89 --- /dev/null +++ b/first.py @@ -0,0 +1,195 @@ +import pygame +import random +import math +from pygame import mixer + +# initialize pygame +pygame.init() + +# screen resolutions +width = 800 +height = 425 +screen = pygame.display.set_mode((width, height)) # create screen + +# Background +background = pygame.image.load('img/background.jpg') + +# Soundtrack +mixer.music.load('31 Flashback.mp3') +mixer.music.play(-1) + +# Title and Icon +pygame.display.set_caption("You should be in quarantine!") +icon = pygame.image.load('img/icon.png') +pygame.display.set_icon(icon) + +# Player +playerImg = pygame.image.load('img/player.png') +playerX = 100 +playerY = 360 +playerX_change, playerY_change = 0, 0 +score = 0 + +# Enemy +enemyImg = [] +enemyX = [] +enemyY = [] +enemyX_change = [] +enemyY_change = [] +num_of_enemies = 6 + +for i in range(num_of_enemies): + enemyImg.append(pygame.image.load('img/enemy.png')) + enemyX.append(random.randint(150, width - 32)) + enemyY.append(360) + enemyX_change.append(-0.7) + enemyY_change.append(0) + +# Player spray Attack: Ready - spray attack isn't being seen / Fire - spray is moving +sprayImg = pygame.image.load('img/spray.png') +sprayX = 0 +sprayY = 360 +sprayX_change = 2 +spray_state = "ready" + +# Score text + +score_value = 0 +font = pygame.font.Font('8-BIT WONDER.ttf', 18) +textX, textY = 10, 10 + +# Game Over text +over_font = pygame.font.Font('8-BIT WONDER.ttf', 36) +game_over = False # game_over remains False until player loses the game + + +def show_score(x, y): + score = font.render("Score " + str(score_value), True, (245, 194, 66)) + screen.blit(score, (x, y)) + + +def game_over_text(): + over_text = over_font.render("GAME OVER", True, (0, 0, 0)) + screen.blit(over_text, (int(width / 2) - 160, int(height / 2) - 20)) + + +def player(x, y): + screen.blit(playerImg, (x, y)) + + +def enemy(x, y, i): + screen.blit(enemyImg[i], (x, y)) + + +def player_attack(x, y): + global spray_state + spray_state = "fire" + screen.blit(sprayImg, (x + 10, y + 10)) + + +def isCollision(x1, y1, x2, y2): + distance = math.sqrt((math.pow(x1 - x2, 2)) + (math.pow(y1 - y2, 2))) + if distance < 27: + return True + return False + + +# Game loop +running = True +while running: # leaves window opened + screen.fill((250, 152, 3)) # note: things appear on top of the things above it in the code + # background image + screen.blit(background, (0, 0)) + + for event in pygame.event.get(): + if event.type == pygame.QUIT: + running = False + + # when key is being pressed, below are all the game keys + if event.type == pygame.KEYDOWN and game_over is False: + if event.key == pygame.K_LEFT: + playerX_change = -1 + if event.key == pygame.K_RIGHT: + playerX_change = 1 + if event.key == pygame.K_UP: + playerY_change = -1 + if event.key == pygame.K_DOWN: + playerY_change = 1 + if event.key == pygame.K_z: + if spray_state is "ready": + # spray_sound = mixer.Sound('quickfart.wav') #later change .wav to the spray sound + # spray_sound.play() + # get's current x, y coordinate of the player + sprayX = playerX + sprayY = playerY + player_attack(sprayX, sprayY) + + if event.type == pygame.KEYUP: + if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT: + playerX_change = 0 + if event.key == pygame.K_UP or event.key == pygame.K_DOWN: + playerY_change = 0 + + if event.type == pygame.KEYDOWN: + if event.key == pygame.K_SPACE: + game_over = False + + playerX += playerX_change + playerY += playerY_change + + # set boundaries so player doesn't leave the screen + if playerX <= 0: + playerX = 0 + elif playerX >= width - 32: + playerX = width - 32 + if playerY <= 0: + playerY = 0 + elif playerY >= height - 32: + playerY = height - 32 + + # Enemy movement patterns + for i in range(num_of_enemies): + + # Game over + player_collision = isCollision(playerX, playerY, enemyX[i], enemyY[i]) + if player_collision: + score_value = 0 + game_over = True + + enemyX[i] += enemyX_change[i] + # set boundaries to define enemy movement + if enemyX[i] <= 0: # later change this value to any left boundary, like a wall on it's left + enemyX_change[i] = 0.7 + elif enemyX[i] >= width - 32: # later change this value to any right boundary, like a wall on it's right + enemyX_change[i] = -0.7 + + # Collision between attack and enemy + attack_collision = isCollision(enemyX[i], enemyY[i], sprayX, sprayY) + if attack_collision: + sprayY = height + spray_state = "ready" + score_value += 1 + enemyX[i] = random.randint(120, width - 32) + enemyY[i] = 360 + enemydeath_sound = mixer.Sound('quickfart.wav') # later change .wav to the player being attacked sound + enemydeath_sound.play() + + enemy(enemyX[i], enemyY[i], i) + + # Spray attack movement + if sprayX >= width: + sprayX = 0 + spray_state = "ready" + + if spray_state is "fire": + sprayX += sprayX_change + player_attack(sprayX, sprayY) + + # When player loses the game: + if game_over: + game_over_text() + + player(playerX, playerY) + show_score(textX, textY) + # note: things appear on top of the things above it in the code + pygame.display.update() diff --git a/background.jpg b/img/background.jpg similarity index 100% rename from background.jpg rename to img/background.jpg diff --git a/enemy.png b/img/enemy.png similarity index 100% rename from enemy.png rename to img/enemy.png diff --git a/icon.png b/img/icon.png similarity index 100% rename from icon.png rename to img/icon.png diff --git a/player.png b/img/player.png similarity index 100% rename from player.png rename to img/player.png diff --git a/spray.png b/img/spray.png similarity index 100% rename from spray.png rename to img/spray.png diff --git a/license.txt b/license.txt new file mode 100644 index 0000000..9dd33a2 --- /dev/null +++ b/license.txt @@ -0,0 +1,14 @@ + +############################################################################### + + Platformer graphics (Deluxe) by Kenney Vleugels (www.kenney.nl) + + ------------------------------ + + License (CC0) + http://creativecommons.org/publicdomain/zero/1.0/ + + You may use these graphics in personal and commercial projects. + Credit (Kenney or www.kenney.nl) would be nice but is not mandatory. + +############################################################################### \ No newline at end of file diff --git a/main.py b/main.py index 6de9ce0..3baada1 100644 --- a/main.py +++ b/main.py @@ -2,194 +2,87 @@ import pygame import random import math from pygame import mixer - -# initialize pygame -pygame.init() - -# screen resolutions -width = 800 -height = 425 -screen = pygame.display.set_mode((width, height)) # create screen - -# Background -background = pygame.image.load('background.jpg') - -# Soundtrack -mixer.music.load('31 Flashback.mp3') -mixer.music.play(-1) - -# Title and Icon -pygame.display.set_caption("You should be in quarantine!") -icon = pygame.image.load('icon.png') -pygame.display.set_icon(icon) - -# Player -playerImg = pygame.image.load('player.png') -playerX = 100 -playerY = 360 -playerX_change, playerY_change = 0, 0 -score = 0 - -# Enemy -enemyImg = [] -enemyX = [] -enemyY = [] -enemyX_change = [] -enemyY_change = [] -num_of_enemies = 6 - -for i in range(num_of_enemies): - enemyImg.append(pygame.image.load('enemy.png')) - enemyX.append(random.randint(150, width - 32)) - enemyY.append(360) - enemyX_change.append(-0.7) - enemyY_change.append(0) - -# Player spray Attack: Ready - spray attack isn't being seen / Fire - spray is moving -sprayImg = pygame.image.load('spray.png') -sprayX = 0 -sprayY = 360 -sprayX_change = 2 -spray_state = "ready" - -# Score text - -score_value = 0 -font = pygame.font.Font('8-BIT WONDER.ttf', 18) -textX, textY = 10, 10 - -# Game Over text -over_font = pygame.font.Font('8-BIT WONDER.ttf', 36) -game_over = False #game_over remains False until player loses the game - -def show_score(x, y): - score = font.render("Score " + str(score_value), True, (245, 194, 66)) - screen.blit(score, (x, y)) - - -def game_over_text(): - over_text = over_font.render("GAME OVER", True, (0, 0, 0)) - screen.blit(over_text, (int(width/2) - 160, int(height / 2)-20)) - - -def player(x, y): - screen.blit(playerImg, (x, y)) - - -def enemy(x, y, i): - screen.blit(enemyImg[i], (x, y)) - - -def player_attack(x, y): - global spray_state - spray_state = "fire" - screen.blit(sprayImg, (x + 10, y + 10)) - - -def isCollision(x1, y1, x2, y2): - distance = math.sqrt((math.pow(x1 - x2, 2)) + (math.pow(y1 - y2, 2))) - if distance < 27: - return True - #if x1 == playerX - - return False - - -# Game loop -running = True -while running: # leaves window opened - screen.fill((250, 152, 3)) # note: things appear on top of the things above it in the code - # background image - screen.blit(background, (0, 0)) - - for event in pygame.event.get(): - if event.type == pygame.QUIT: - running = False - - # when key is being pressed, below are all the game keys - if event.type == pygame.KEYDOWN and game_over is False: - if event.key == pygame.K_LEFT: - playerX_change = -1 - if event.key == pygame.K_RIGHT: - playerX_change = 1 - if event.key == pygame.K_UP: - playerY_change = -1 - if event.key == pygame.K_DOWN: - playerY_change = 1 - if event.key == pygame.K_z: - if spray_state is "ready": - # spray_sound = mixer.Sound('quickfart.wav') #later change .wav to the spray sound - # spray_sound.play() - # get's current x, y coordinate of the player - sprayX = playerX - sprayY = playerY - player_attack(sprayX, sprayY) - - if event.type == pygame.KEYUP: - if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT: - playerX_change = 0 - if event.key == pygame.K_UP or event.key == pygame.K_DOWN: - playerY_change = 0 - - if event.type == pygame.KEYDOWN: - if event.key == pygame.K_SPACE: - game_over = False - - playerX += playerX_change - playerY += playerY_change - - # set boundaries so player doesn't leave the screen - if playerX <= 0: - playerX = 0 - elif playerX >= width - 32: - playerX = width - 32 - if playerY <= 0: - playerY = 0 - elif playerY >= height - 32: - playerY = height - 32 - - # Enemy movement patterns - for i in range(num_of_enemies): - - # Game over - player_collision = isCollision(playerX, playerY, enemyX[i], enemyY[i]) - if player_collision: - game_over = True - - enemyX[i] += enemyX_change[i] - # set boundaries to define enemy movement - if enemyX[i] <= 0: # later change this value to any left boundary, like a wall on it's left - enemyX_change[i] = 0.7 - elif enemyX[i] >= width - 32: # later change this value to any right boundary, like a wall on it's right - enemyX_change[i] = -0.7 - - # Collision between attack and enemy - attack_collision = isCollision(enemyX[i], enemyY[i], sprayX, sprayY) - if attack_collision: - sprayY = height - spray_state = "ready" - score_value += 1 - enemyX[i] = random.randint(120, width - 32) - enemyY[i] = 360 - enemydeath_sound = mixer.Sound('quickfart.wav') # later change .wav to the player being attacked sound - enemydeath_sound.play() - - enemy(enemyX[i], enemyY[i], i) - - # Spray attack movement - if sprayX >= width: - sprayX = 0 - spray_state = "ready" - - if spray_state is "fire": - sprayX += sprayX_change - player_attack(sprayX, sprayY) - - # When player loses the game: - if game_over: - game_over_text() - - player(playerX, playerY) - show_score(textX, textY) - # note: things appear on top of the things above it in the code - pygame.display.update() +from settings import * +from sprites import * + + +class Game: + def __init__(self): + # initialize game window, etc + pygame.init() + pygame.mixer.init() + self.screen = pygame.display.set_mode(((width, height))) + + # Title and Icon + pygame.display.set_caption(title) + icon = pygame.image.load('img/icon.png') + pygame.display.set_icon(icon) + + self.clock = pygame.time.Clock() + self.running = True + + def new(self): + # starts a new game not a new program + self.all_sprites = pygame.sprite.Group() + self.platforms = pygame.sprite.Group() + self.player = Player(self) + self.all_sprites.add(self.player) + for plat in platform_list: + p = Platform(*plat) + self.all_sprites.add(p) + self.platforms.add(p) + self.run() + + def run(self): + # Game loop + self.playing = True + while self.playing: + self.clock.tick(fps) + self.events() + self.update() + self.draw() + + def update(self): + # Game loop - Update + self.all_sprites.update() + # check if player hits platform - only if falling + if self.player.vel.y > 0: + hits = pygame.sprite.spritecollide(self.player, self.platforms, False) + if hits: + self.player.pos.y = hits[0].rect.top + self.player.vel.y = 0 + + def events(self): + # Game loop - events + for event in pygame.event.get(): + if event.type == pygame.QUIT: + if self.playing: + self.playing = False + self.running = False + if event.type == pygame.KEYDOWN: + if event.key == pygame.K_UP: + self.player.jump() + + def draw(self): + # Game loop - draw/render + self.screen.blit(background, (0, 0)) + self.all_sprites.draw(self.screen) + pygame.display.flip() + + def show_start_screen(self): + # game start screen + pass + + def show_go_screen(self): + # game over screen + pass + + +g = Game() +g.show_start_screen() + +while g.running: + g.new() + g.show_go_screen() # go stands for Game Over + +pygame.quit() diff --git a/new_main.py b/new_main.py new file mode 100644 index 0000000..e69de29 diff --git a/settings.py b/settings.py new file mode 100644 index 0000000..34ebd5d --- /dev/null +++ b/settings.py @@ -0,0 +1,24 @@ +import os +import pygame + +width = 800 +height = 425 +fps = 30 + +title = "You should be in quarantine!" +# setup game assets (images/sounds) +game_folder = os.path.dirname(__file__) +img_folder = os.path.join(game_folder, "img") +sound_folder = os.path.join(game_folder, "sound") +background = pygame.image.load('img/background.jpg') +# Player properties +player_acc = 0.9 +player_friction = -0.12 +player_gravity = 1.2 + +# Starting platforms + +platform_list = [(0, height - 40, width, 40), + (width / 2, 250, 60, 20), + (90, height - 300, 115, 20)] + diff --git a/sneeze.png b/sneeze.png deleted file mode 100644 index 7aa3856..0000000 Binary files a/sneeze.png and /dev/null differ diff --git a/31 Flashback.mp3 b/sound/31 Flashback.mp3 similarity index 100% rename from 31 Flashback.mp3 rename to sound/31 Flashback.mp3 diff --git a/quickfart.wav b/sound/quickfart.wav similarity index 100% rename from quickfart.wav rename to sound/quickfart.wav diff --git a/soundtrack.aup b/sound/soundtrack.aup similarity index 100% rename from soundtrack.aup rename to sound/soundtrack.aup diff --git a/sprites.py b/sprites.py new file mode 100644 index 0000000..b82a06a --- /dev/null +++ b/sprites.py @@ -0,0 +1,56 @@ +# Sprite classes +from settings import * +import pygame + +vec = pygame.math.Vector2 + + +class Player(pygame.sprite.Sprite): + def __init__(self,game): + pygame.sprite.Sprite.__init__(self) + self.game = game + self.image = pygame.Surface((20, 40)) + self.image.fill((0, 0, 255)) + self.rect = self.image.get_rect() + self.rect.center = (width / 2, height / 2) + self.pos = vec(width / 2, height / 2) # x and y position + self.vel = vec(0, 0) # velocity in x and y axis + self.acc = vec(0, 0) # acceleration in x and y axis + + def jump(self): + # jump only if standing on a platform + self.rect.x += 1 + hits = pygame.sprite.spritecollide(self, self.game.platforms, False) + self.rect.x -= 1 + if hits: + self.vel.y = -20 + + def update(self): + self.acc = vec(0, player_gravity) + keys = pygame.key.get_pressed() + if keys[pygame.K_LEFT]: + self.acc.x = -player_acc + if keys[pygame.K_RIGHT]: + self.acc.x = player_acc + + # applies friction + self.acc.x += self.vel.x * player_friction + # equations of motion + self.vel += self.acc + self.pos += self.vel + 0.5 * self.acc + #wrap around the screen + if self.pos.x > width: + self.pos.x = 0 + elif self.pos.x < 0: + self.pos.x = width + + self.rect.midbottom = self.pos + +class Platform(pygame.sprite.Sprite): + def __init__(self, x, y, w, h): + pygame.sprite.Sprite.__init__(self) + self.image = pygame.Surface((w, h)) + self.image.fill((128, 128, 128)) + self.rect = self.image.get_rect() + self.rect.x = x + self.rect.y = y \ No newline at end of file