Created avocado module
parent
3ac4286668
commit
aa76ab2299
|
@ -0,0 +1,24 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import pygame, random
|
||||||
|
|
||||||
|
class Avocado:
|
||||||
|
|
||||||
|
def __init__(self, screensize):
|
||||||
|
screen_width, screen_height = screensize
|
||||||
|
self.x = random.randint(0,screen_width)
|
||||||
|
self.y = 0 # change this to start somewhere above the screen
|
||||||
|
self.w = 100
|
||||||
|
self.y = 100
|
||||||
|
|
||||||
|
def collides(self, click):
|
||||||
|
"""
|
||||||
|
Checks whether this object collides with the given position
|
||||||
|
in click
|
||||||
|
"""
|
||||||
|
return True
|
||||||
|
#if collision then self.destroy()
|
||||||
|
|
||||||
|
def destroy(self):
|
||||||
|
"""destroys this object"""
|
||||||
|
|
11
game.py
11
game.py
|
@ -5,8 +5,8 @@ Avocados and stuff
|
||||||
|
|
||||||
import os, random
|
import os, random
|
||||||
import pygame
|
import pygame
|
||||||
|
import avocado
|
||||||
from pygame.locals import *
|
from pygame.locals import *
|
||||||
|
|
||||||
from support.colors import *
|
from support.colors import *
|
||||||
from interface import hud
|
from interface import hud
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ def main():
|
||||||
|
|
||||||
score = 0
|
score = 0
|
||||||
time = 15
|
time = 15
|
||||||
|
level = 1
|
||||||
|
|
||||||
running = True
|
running = True
|
||||||
timeleft = time
|
timeleft = time
|
||||||
|
@ -49,9 +50,17 @@ def main():
|
||||||
chud = my_hud.draw_hud(score, displaytime, round(fps,2))
|
chud = my_hud.draw_hud(score, displaytime, round(fps,2))
|
||||||
screen.blit(chud, (10,10))
|
screen.blit(chud, (10,10))
|
||||||
|
|
||||||
|
# Initialize a number of avocados, depending on the level
|
||||||
|
avocados = []
|
||||||
|
for i in range(0, level):
|
||||||
|
a = avocado.Avocado((screen_width, screen_height))
|
||||||
|
avocados.append(a)
|
||||||
|
|
||||||
# Catch events
|
# Catch events
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if event.type == MOUSEBUTTONDOWN:
|
if event.type == MOUSEBUTTONDOWN:
|
||||||
|
for avo in avocados:
|
||||||
|
if avo.collides(pygame.mouse.get_pos()):
|
||||||
score += 100
|
score += 100
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
running = False
|
running = False
|
||||||
|
|
Loading…
Reference in New Issue