Amélioration du bot pour qu'il tire dans la zone la plus éloigné du joueur #4

Merged
raphael merged 10 commits from smart-bot into main 2024-01-05 17:03:16 +00:00
Showing only changes of commit 4d6c8d9799 - Show all commits

View file

@ -1,224 +0,0 @@
"""
Module d'exemple de l'utilisation du moteur de jeu.
"""
from engine import Scene, start_game
from engine.ecs import Entity, World
from engine.math import Vec2
from plugins import defaults, physics
from plugins import render
from plugins.inputs import Held
from plugins.render import (
Origin,
Position,
Scale,
SpriteBundle,
)
from plugins.timing import Delta
def lol(a: Entity, b: Entity, simul: bool = False):
if Bounce in b:
speed = a[physics.Velocity].length
a[physics.Velocity] = a[physics.Velocity].normalized
a[physics.Velocity].y = (a[Position].y - b[Position].y) * 0.005
a[physics.Velocity] = a[physics.Velocity].normalized * min(
(speed * 1.1), 1000.0
)
return True
class Bounce:
pass
def lol_simul(a: Entity, b: Entity):
lol(a, b, True)
return RightWall not in b
class Simulated:
pass
class Bar:
pass
class RightWall:
pass
class BallFollow(int):
pass
class Mine:
pass
def __initialize(world: World):
"""
Initialise les ressources pour le moteur de jeu.
"""
world.new_entity().set(
SpriteBundle(
"background.png",
-1,
scale=Vec2(render.WIDTH, render.HEIGHT),
),
)
# world.new_entity().set(
# SpriteBundle(
# "dodo.png",
# 0,
# position=Vec2(800, 500),
# origin=Vec2(0.5, 0.5),
# scale=Vec2(400, 300),
# ),
# physics.Solid(),
# )
world.new_entity().set(
SpriteBundle(
"dodo.png",
0,
position=Vec2(100, 100),
origin=Vec2(0, 0),
scale=Vec2(render.WIDTH - 200, 10),
),
physics.Solid(),
)
world.new_entity().set(
SpriteBundle(
"dodo.png",
0,
position=Vec2(100, render.HEIGHT - 100),
origin=Vec2(0, 1),
scale=Vec2(render.WIDTH - 200, 10),
),
physics.Solid(),
)
world.new_entity().set(
SpriteBundle(
"dodo.png",
0,
position=Vec2(render.WIDTH - 100, 100),
origin=Vec2(1, 0),
scale=Vec2(10, render.HEIGHT - 200),
),
physics.Solid(),
RightWall(),
)
world.new_entity().set(
SpriteBundle(
"dodo.png",
0,
position=Vec2(100, 100),
origin=Vec2(0, 0),
scale=Vec2(10, render.HEIGHT - 200),
),
physics.Solid(),
)
world.new_entity().set(
SpriteBundle(
"dodo.png",
0,
position=Vec2(render.WIDTH - 130, render.HEIGHT / 2),
origin=Vec2(0.5, 0.5),
scale=Vec2(10, 200),
),
physics.Solid(),
Bar(),
Bounce(),
)
world.new_entity().set(
SpriteBundle(
"dodo.png",
0,
position=Vec2(130, render.HEIGHT / 2),
origin=Vec2(0.5, 0.5),
scale=Vec2(10, 200),
),
physics.Solid(),
Mine(),
Bounce(),
)
world.new_entity().set(
SpriteBundle(
"dada.png",
1,
scale=Vec2(10),
position=Vec2(500, 500),
origin=Vec2(0.5, 0.5),
),
physics.Velocity(Vec2(200, 100)),
physics.CollisionHandler(lol),
)
for i in range(20):
world.new_entity().set(
SpriteBundle(
"dodo.png",
10,
scale=Vec2(10),
),
physics.CollisionHandler(lol),
BallFollow(i + 1),
# physics.CollisionHandler(lol_simul),
)
def __update(world: World):
"""
Test.
"""
for entity in world.query(Mine, Position):
if "z" in world[Held]:
entity[Position].y -= 300 * world[Delta]
if "s" in world[Held]:
entity[Position].y += 300 * world[Delta]
ball = max(
world.query(Position, physics.Velocity, physics.CollisionHandler),
key=lambda e: e[Position].x,
)
for bar in world.query(Bar):
bar.remove(physics.Solid)
entity = world.new_entity()
entity.set(
Position(ball[Position]),
Scale(ball[Scale]),
physics.Velocity(ball[physics.Velocity]),
Origin(ball[Origin]),
physics.CollisionHandler(lol_simul),
)
physics.move_entity(entity, entity[physics.Velocity] * 500)
target = entity[Position].y
for bar in world.query(Bar):
diff = target - bar[Position].y
# bar[Position].y += (diff / abs(diff)) * 300 * world[Delta]
bar[Position].y += diff
bar.set(physics.Solid())
entity.destroy()
for entity in world.query(BallFollow):
entity[Position] = Vec2(ball[Position])
entity[physics.Velocity] = Vec2(ball[physics.Velocity])
physics.move_entity(entity, entity[physics.Velocity] * entity[BallFollow] * 0.5)
del entity[physics.Velocity]
MENU = Scene(
[__initialize],
[__update],
[],
)
start_game(defaults.PLUGIN, MENU)