Browse Source

Merge branch 'devel'

master
rf 7 months ago
parent
commit
1f75b4dd5c
7 changed files with 9 additions and 92 deletions
  1. +0
    -1
      Pipfile
  2. +1
    -9
      Pipfile.lock
  3. +5
    -7
      README.md
  4. +0
    -0
      asteroids/__init__.py
  5. +3
    -3
      asteroids/util.py
  6. +0
    -72
      intro.py
  7. BIN
      intro_ball.gif

+ 0
- 1
Pipfile View File

@@ -9,7 +9,6 @@ verify_ssl = true
pygame = "*"
recordclass = "*"
numpy = "*"
pgzero = "*"
cx-freeze = "*"

[requires]

+ 1
- 9
Pipfile.lock View File

@@ -1,7 +1,7 @@
{
"_meta": {
"hash": {
"sha256": "c9a4cccbea7ca8611b6c6a2478992e922854161d9a8fd93deea36ea090ebd7af"
"sha256": "132659c70bd418ab7a89ef3d76271a97f52769fc89829d0ba083a431d0e55402"
},
"pipfile-spec": 6,
"requires": {
@@ -58,14 +58,6 @@
"index": "pypi",
"version": "==1.16.4"
},
"pgzero": {
"hashes": [
"sha256:91e641d545c6235a24719dea0fd83c8429e92a8b5ab1756bef145128e8db9017",
"sha256:f90d1e61cb6945ad55bd1cb2a4a13ca6f1a3850a31c173dce3a739df9b024b8f"
],
"index": "pypi",
"version": "==1.2"
},
"pygame": {
"hashes": [
"sha256:0480fe82cd41a43e3eea497fa2c059c72ac54cb5d003d5aa2ed06a04541c384e",

+ 5
- 7
README.md View File

@@ -1,4 +1,4 @@
# pygame-playground
# Asteroids game

## Install

@@ -12,15 +12,13 @@ pipenv install
pipenv shell
```

#### run examples
## Run

```
ls -la $VIRTUAL_ENV/lib/python3.7/site-packages/pygame/examples/
python -m pygame.examples.eventlist
python3 ./asteroids/game.py
```

## Projects

### asteroids/game.py
## Development

- feckin' shoot asteroids


+ 0
- 0
asteroids/__init__.py View File


+ 3
- 3
asteroids/util.py View File

@@ -71,12 +71,12 @@ class Util:
Util.fonts[size] = pygame.font.Font(None, size)
return Util.fonts[size]

game_dir = os.path.dirname(__file__)
asset_folder = "data"
ext = {"image": ('.png', 'jpg', '.jpeg', '.gif', '.bmp')}

def asset_path(name, type=None, subfolder=""):
pathname = os.path.join(Util.asset_folder, subfolder, name)
pathname = os.path.join(Util.game_dir, Util.asset_folder, subfolder, name)

if type == None:
fullname = pathname
@@ -87,7 +87,7 @@ class Util:
fullname = pathname + e
break

if not os.path.isfile(fullname):
if not fullname or not os.path.isfile(fullname):
print('Cannot find asset:', pathname)
raise FileNotFoundError(errno.ENOENT, \
os.strerror(errno.ENOENT), pathname)

+ 0
- 72
intro.py View File

@@ -1,72 +0,0 @@
#!/usr/bin/env python

import sys
import pygame

from recordclass import RecordClass
import random
# import numpy
from operator import sub

pygame.init()

size = width, height = 800, 600
speed = [2, 2]
black = 0, 0, 0

screen = pygame.display.set_mode(size)

clock = pygame.time.Clock()

ballimg = pygame.image.load("intro_ball.gif")
ballrect = ballimg.get_rect()

class Point(RecordClass):
x: int
y: int

class Ball:
def __init__(self, rect, sx, sy):
self.rect = rect
self.speed = Point(sx, sy)

def move(self):
self.rect = self.rect.move(self.speed)

def collide_bounds(self, bounds):
if (self.speed.x < 0 and self.rect.left < bounds.left) \
or (self.speed.x > 0 and self.rect.right > bounds.width):
self.speed.x = -self.speed.x

if (self.speed.y < 0 and self.rect.top < bounds.top) \
or (self.speed.y > 0 and self.rect.bottom > bounds.height):
self.speed.y = -self.speed.y

self.rect.clamp(bounds)

def draw(self, screen, img, font):
screen.blit(img, self.rect)
if font:
ren = font.render("Ball", 1, (255,255,255))
screen.blit(ren, tuple(map(sub, self.rect.center, ren.get_rect().center)))

speeds =(-3, -2, -1, 1, 2, 3)
balls = [Ball(ballimg.get_rect(), random.choice(speeds), random.choice(speeds)) for i in range(5)]

font = pygame.font.Font(None, 16)

while True:
for event in pygame.event.get():
if event.type == pygame.QUIT: sys.exit()

for ball in balls:
ball.move()
ball.collide_bounds(screen.get_rect())

screen.fill(black)

for ball in balls:
ball.draw(screen, ballimg, font)

pygame.display.flip()
clock.tick(60)

BIN
intro_ball.gif View File

Before After
Width: 111  |  Height: 111  |  Size: 4.9KB

Loading…
Cancel
Save