Files
arcade/main.py
T

65 lines
1.8 KiB
Python

import arcade
import math
from tank import Tank
from map import Map
from bullet import Bullet
from bonus import Bonus
SCREEN_WIDTH = 768
SCREEN_HEIGHT = 576
class MainView(arcade.View):
def __init__(self):
super().__init__()
self.background_color = (100,100,200)
self.block_list = arcade.SpriteList()
self.map = Map(SCREEN_WIDTH,SCREEN_HEIGHT,64,64)
self.player = list(filter(lambda tank: tank.type=='player', Tank.ls))[0]
self.physics_engine = arcade.PymunkPhysicsEngine(gravity=(0, 0),damping=0.01)
#self.physics_engine.add_sprite(self.player.get_sprite(), friction=0.5, mass=1.0)
#self.physics_engine.add_sprite_list(Map.block_list, friction=0.5, collision_type="wall")
def on_draw(self):
self.clear()
self.map.draw()
Tank.draw()
Bonus.draw()
Bullet.draw()
def on_update(self,time_delta):
#self.physics_engine.step()
Tank.update()
Bonus.update_list(time_delta)
Bullet.update_list()
def on_mouse_motion(self,x,y,dx,dy):
self.player.gun_to_xy(x,y)
def on_key_press(self,key,mod):
if key == arcade.key.A:
self.last_key = key
self.player.move(-1,0)
#self.player.move_engine(self.physics_engine,-1,0)
elif key == arcade.key.D:
self.last_key = key
self.player.move(1,0)
elif key == arcade.key.W:
self.last_key = key
self.player.move(0,1)
elif key == arcade.key.S:
self.last_key = key
self.player.move(0,-1)
def on_key_release(self,key,mod):
if self.last_key == key:
self.player.move(0,0)
def on_mouse_press(self,x,y,but,mod):
if but == 1:
self.player.shoot()
if __name__ == '__main__':
window = arcade.Window(SCREEN_WIDTH,SCREEN_HEIGHT,"Моя игра")
view = MainView()
window.show_view(view)
arcade.run()