made level creation and configuration easier

This commit is contained in:
Felix Bargfeldt 2019-07-17 18:34:56 +02:00
parent c3cbaff936
commit 2bca2b1b65
No known key found for this signature in database
GPG key ID: 99184F5FDC589A67
3 changed files with 64 additions and 34 deletions

45
config.py Normal file
View file

@ -0,0 +1,45 @@
from level import Level
from obstacle import Obstacle
from vector import Point
WIDTH: int = 640
HEIGHT: int = 480
POPULATION_SIZE: int = 1000
LEVEL: Level = [
Level(
Point(WIDTH / 2, HEIGHT - 10), Point(WIDTH / 2, 10), [
Obstacle(
Point(0, HEIGHT / 2 - 5),
Point(WIDTH * 3 / 4, HEIGHT / 2 + 5)
)
], []
), Level(
Point(WIDTH / 2, HEIGHT - 10), Point(WIDTH / 2, 10), [
Obstacle(
Point(0, HEIGHT / 4 - 5),
Point(WIDTH * 3 / 4 + 5, HEIGHT / 4 + 5)
), Obstacle(
Point(WIDTH * 3 / 4 - 5, HEIGHT / 4 - 5),
Point(WIDTH * 3 / 4 + 5, HEIGHT * 5 / 8 - 5)
), Obstacle(
Point(WIDTH * 3 / 8, HEIGHT * 5 / 8 - 5),
Point(WIDTH * 3 / 4 + 5, HEIGHT * 5 / 8 + 5)
), Obstacle(
Point(WIDTH / 4, HEIGHT * 3 / 8 - 5),
Point(WIDTH * 5 / 8, HEIGHT * 3 / 8 + 5)
), Obstacle(
Point(WIDTH / 4 - 5, HEIGHT * 3 / 8 - 5),
Point(WIDTH / 4 + 5, HEIGHT * 3 / 4 + 5)
), Obstacle(
Point(WIDTH / 4 - 5, HEIGHT * 3 / 4 - 5),
Point(WIDTH, HEIGHT * 3 / 4 + 5)
)
], [
Point(WIDTH / 2, HEIGHT * 2.5 / 8),
Point(WIDTH / 2, HEIGHT * 4 / 8),
Point(WIDTH / 2, HEIGHT * 5.5 / 8)
]
)
][1]

16
level.py Normal file
View file

@ -0,0 +1,16 @@
from typing import List
from game import Game
from obstacle import Obstacle
from vector import Point
class Level:
def __init__(self, start: Point, goal: Point, obstacles: List[Obstacle], checkpoints: List[Point]):
self.start: Point = start
self.goal: Point = goal
self.obstacles: List[Obstacle] = obstacles
self.checkpoints: List[Point] = checkpoints
def make_game(self, width: float, height: float):
return Game(width, height, self.start, self.goal, self.obstacles, self.checkpoints)

View file

@ -4,9 +4,8 @@ from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from config import *
from dot import Dot
from game import Game
from obstacle import Obstacle
from population import Population
from vector import Point
@ -18,39 +17,9 @@ class SmartDots(QWidget):
super().__init__()
self.setWindowTitle("Smart Dots")
self.setFixedSize(640, 480)
self.setFixedSize(WIDTH, HEIGHT)
self.population: Population = Population(
Game(
self.width(), self.height(),
Point(self.width() / 2, self.height() - 10), Point(self.width() / 2, 10), [
Obstacle(
Point(0, self.height() / 4 - 5),
Point(self.width() * 3 / 4 + 5, self.height() / 4 + 5)
), Obstacle(
Point(self.width() * 3 / 4 - 5, self.height() / 4 - 5),
Point(self.width() * 3 / 4 + 5, self.height() * 5 / 8 - 5)
), Obstacle(
Point(self.width() * 3 / 8, self.height() * 5 / 8 - 5),
Point(self.width() * 3 / 4 + 5, self.height() * 5 / 8 + 5)
), Obstacle(
Point(self.width() / 4, self.height() * 3 / 8 - 5),
Point(self.width() * 5 / 8, self.height() * 3 / 8 + 5)
), Obstacle(
Point(self.width() / 4 - 5, self.height() * 3 / 8 - 5),
Point(self.width() / 4 + 5, self.height() * 3 / 4 + 5)
), Obstacle(
Point(self.width() / 4 - 5, self.height() * 3 / 4 - 5),
Point(self.width(), self.height() * 3 / 4 + 5)
)
], [
Point(self.width() / 2, self.height() * 2.5 / 8),
Point(self.width() / 2, self.height() * 4 / 8),
Point(self.width() / 2, self.height() * 5.5 / 8)
]
),
1000
)
self.population: Population = Population(LEVEL.make_game(WIDTH, HEIGHT), POPULATION_SIZE)
self.timer: QBasicTimer = QBasicTimer()
self.timer.start(10, self)