🎉 moving player.

main
bog 2024-04-06 14:24:08 +02:00
parent 20d8eb925a
commit 801b64b97f
8 changed files with 139 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
*~*
*\#*
__pycache__

25
actors/actor.py Normal file
View File

@ -0,0 +1,25 @@
import pygame
import numpy as np
class Actor:
def __init__(self, world):
self.world = world
self.pos = np.array([64.0, 64.0])
self.size = np.array([48.0, 48.0])
self.color = pygame.Color(0, 0, 255)
self.speed = 192.0
def draw(self, screen):
pygame.draw.rect(screen, self.color, (
self.pos[0] - self.size[0]/2,
self.pos[1] - self.size[1]/2,
self.size[0],
self.size[1]
))
def update(self, dt):
pass
def phy_update(self, dt):
pass

36
actors/player.py Normal file
View File

@ -0,0 +1,36 @@
import pygame
import numpy as np
from . import actor
class Player(actor.Actor):
def __init__(self, world):
super().__init__(world)
def phy_update(self, dt):
pass
def update(self, dt):
delta = np.array([0.0, 0.0])
keys = pygame.key.get_pressed()
if keys[pygame.K_z] or keys[pygame.K_w]:
delta[1] -= 1.0
if keys[pygame.K_s]:
delta[1] += 1.0
if keys[pygame.K_q] or keys[pygame.K_a]:
delta[0] -= 1.0
if keys[pygame.K_d]:
delta[0] += 1.0
norm = np.linalg.norm(delta)
if norm > 0:
delta /= norm
delta *= self.speed
self.pos += delta * dt

BIN
doc/brainstorming.vym Normal file

Binary file not shown.

22
doc/features.txt Normal file
View File

@ -0,0 +1,22 @@
* Actor can move
* Load Map
* Map Collision
* Actors can Shoot
* Actors can die
* NPC states
** Idle
** Purchasing
** Fighting
** Dead
* Part I: The Desert
** Follow Radar Instructions
** Kill Some Desert Snakes
** Enter the Bunker
* Part II: The Bunker
** Shoot at enemies
** Find and Activate Nuclear Weapons
* Part III: Enemies Waves
** Survive

33
main.py Normal file
View File

@ -0,0 +1,33 @@
import pygame
import world
pygame.init()
screen = pygame.display.set_mode((800, 600))
running = True
clock = pygame.time.Clock()
my_world = world.World()
dt = 0.0
phy_timer = 0.0
phy_time = 0.2
if __name__ == '__main__':
while running:
start = pygame.time.get_ticks()
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
screen.fill('black')
my_world.update(dt)
if phy_timer >= phy_time:
my_world.phy_update(phy_time)
phy_timer = 0.0
phy_timer += dt
my_world.draw(screen)
pygame.display.flip()
clock.tick(60)
dt = (pygame.time.get_ticks() - start)/1000.0

2
requirements.txt Normal file
View File

@ -0,0 +1,2 @@
numpy==1.26.4
pygame==2.5.2

18
world/__init__.py Normal file
View File

@ -0,0 +1,18 @@
import pygame
from actors import player
class World:
def __init__(self):
self.actors = [player.Player(self)]
def draw(self, screen):
for actor in self.actors:
actor.draw(screen)
def update(self, dt):
for actor in self.actors:
actor.update(dt)
def phy_update(self, dt):
for actor in self.actors:
actor.phy_update(dt)