コード例 #1
0
    def move_box(self, pos: Point2d, vel: Vector2d,
                 size: Vector2d) -> Tuple[Point2d, Vector2d]:
        distance = vel.norm
        maximum = int(distance)

        if distance < 0:
            return pos, vel

        fraction = 1.0 / float(maximum + 1)

        for i in range(0, maximum + 1):
            new_pos = pos + vel * fraction  # type: Point2d
            if self.test_box(new_pos, size):
                hit = False
                if self.test_box(Point2d(pos.x, new_pos.y), size):
                    new_pos.y = pos.y
                    vel.y = 0
                    hit = True

                if self.test_box(Point2d(new_pos.x, pos.y), size):
                    new_pos.x = pos.x
                    vel.x = 0
                    hit = True

                if not hit:
                    new_pos = pos
                    vel = Vector2d(0, 0)

            pos = new_pos

        return pos, vel
コード例 #2
0
def move_camera(camera: Vector2d, focus: Point2d) -> None:
    # Objective 7: Find the correct value for half the window width
    # YOUR CODE HERE...
    half_win_width = 500

    # Objective 7: Uncomment and try out the different camera movements

    #1. always in center:
    camera.x = focus.x - half_win_width
コード例 #3
0
    def __init__(self, resources: Resources) -> None:
        self.camera = Vector2d(0, 0)
        self.stopwatch = Stopwatch(resources)

        # Objective 4: Create a Player
        self.player = Player(resources)

        # Objective 5: Create a Map
        self.map = Map(resources)
コード例 #4
0
from basic2d import Point2d, Vector2d
from controller import Controller, Input
from copy import copy
from sdl2 import SDL_FLIP_HORIZONTAL, SDL_FLIP_NONE
from sdl2.ext import Renderer, Resources, SpriteFactory, TextureSprite
from tilemap import Map
from typing import Optional


PLAYER_SIZE = Vector2d(64, 64)
INITIAL_POS = Point2d(170, 500)
ZERO_VEL = Vector2d(0, 0)


class Player:
    def __init__(self, resources: Resources) -> None:
        self.texture = None  # type: Optional[TextureSprite]
        self.texture_path = resources.get_path("player.png")
        self.pos = copy(INITIAL_POS)
        self.vel = copy(ZERO_VEL)
        self.restart()

    def restart(self) -> None:
        self.pos = copy(INITIAL_POS)
        self.vel = copy(ZERO_VEL)

    def update(self, controller: Controller, tilemap: Map) -> None:
        ground = tilemap.on_ground(self.pos, PLAYER_SIZE)
        new_vel = copy(self.vel)

        # new y velocity...
コード例 #5
0
 def __init__(self, resources: Resources) -> None:
     self.camera = Vector2d(0, 0)
     self.stopwatch = Stopwatch(resources)