56 lines
1.2 KiB
Python
56 lines
1.2 KiB
Python
import pygame
|
|
|
|
from input import Input
|
|
from kart import Kart
|
|
|
|
Vec2 = pygame.Vector2
|
|
|
|
kart_image = pygame.surface.Surface((10, 10))
|
|
|
|
player = Kart(
|
|
name = "epsilon",
|
|
pos = Vec2(0, 0),
|
|
vel = Vec2(2, 0),
|
|
dir = 0,
|
|
speed_max = 3,
|
|
)
|
|
|
|
clock = pygame.Clock()
|
|
|
|
def main():
|
|
pygame.init()
|
|
|
|
input = Input()
|
|
width, height = 800, 600
|
|
screen = pygame.display.set_mode((width, height))
|
|
pygame.display.set_caption("Pygame Window Example")
|
|
|
|
kart = Kart(
|
|
name = "jerry",
|
|
pos = Vec2(0.0, 0.0),
|
|
vel = Vec2(0.0, 0.0),
|
|
dir = 0.0,
|
|
speed_max = 10.0
|
|
)
|
|
|
|
|
|
while not input.close:
|
|
input.poll()
|
|
kart.tick(input)
|
|
|
|
# Draw game:
|
|
screen.fill((0, 125, 0))
|
|
pygame.draw.rect(screen, (255, 0, 0), pygame.Rect(kart.pos.x - 5, kart.pos.y - 5, 5, 5))
|
|
pygame.draw.line(screen, (0, 0, 0), kart.pos, kart.pos + Vec2(100, 0).rotate(kart.dir))
|
|
|
|
pygame.draw.rect(screen, (0, 0, 255), pygame.Rect(kart.pos.x - 5, kart.pos.y - 5, 5, 5))
|
|
pygame.draw.line(screen, (0, 0, 0), kart.pos, kart.pos + Vec2(100, 0).rotate(kart.dir))
|
|
|
|
pygame.display.flip()
|
|
|
|
clock.tick(60)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|