Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
4
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
P
PythoCup
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
5
Issues
5
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Test Cases
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Bold Hearts
PythoCup
Commits
12a82da2
Commit
12a82da2
authored
Mar 09, 2019
by
gem2578
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix moment/collision system
parent
925b11b7
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
35 additions
and
17 deletions
+35
-17
config.py
config.py
+3
-0
sprite/ball.py
sprite/ball.py
+1
-8
sprite/player.py
sprite/player.py
+1
-8
sprite/round_sprite.py
sprite/round_sprite.py
+30
-1
No files found.
config.py
View file @
12a82da2
...
...
@@ -9,3 +9,6 @@ GOAL = os.path.join(path, "resource/goal.png")
BALL
=
(
100
,
100
,
100
)
LEFT
=
(
200
,
10
,
10
)
RIGHT
=
(
10
,
10
,
200
)
PLAYER_SPEED
=
5
BALL_SPEED
=
5
sprite/ball.py
View file @
12a82da2
...
...
@@ -4,8 +4,6 @@ import sprite.round_sprite as rs
class
Ball
(
rs
.
Round
):
max_speed
=
5
def
__init__
(
self
,
pos
):
super
().
__init__
(
20
,
config
.
BALL
)
self
.
start
=
pos
...
...
@@ -18,12 +16,7 @@ class Ball(rs.Round):
self
.
players
.
append
(
player
)
def
update
(
self
):
if
self
.
force
.
length
()
>
self
.
max_speed
:
self
.
force
.
scale_to_length
(
self
.
max_speed
)
self
.
rect
.
move_ip
(
self
.
force
)
while
self
.
collide
():
back
=
(
self
.
force
*
-
1
).
normalize
()
self
.
rect
.
move_ip
(
self
.
round_vector2
(
back
))
self
.
move_with_collision
(
config
.
BALL_SPEED
,
self
.
force
)
self
.
force
=
pygame
.
math
.
Vector2
()
def
reset
(
self
):
...
...
sprite/player.py
View file @
12a82da2
...
...
@@ -5,8 +5,6 @@ from model.side import Side
class
Player
(
rs
.
Round
):
max_speed
=
5
def
__init__
(
self
,
brain
,
pos
):
pos
=
pygame
.
math
.
Vector2
(
pos
)
self
.
brain
=
brain
...
...
@@ -29,12 +27,7 @@ class Player(rs.Round):
move
,
kick
=
self
.
brain
.
action
()
if
can_kick
:
self
.
ball
.
kick
(
kick
)
if
move
.
length
()
>
self
.
max_speed
:
move
.
scale_to_length
(
self
.
max_speed
)
self
.
rect
.
move_ip
(
move
)
while
self
.
collide
():
back
=
(
move
*
-
1
).
normalize
()
self
.
rect
.
move_ip
(
self
.
round_vector2
(
back
))
self
.
move_with_collision
(
config
.
PLAYER_SPEED
,
move
)
def
collide
(
self
):
for
player
in
self
.
self_team
:
...
...
sprite/round_sprite.py
View file @
12a82da2
from
abc
import
ABC
,
abstractmethod
import
pygame
class
Round
(
pygame
.
sprite
.
Sprite
):
class
Round
(
ABC
,
pygame
.
sprite
.
Sprite
):
def
__init__
(
self
,
diameter
,
colour
):
super
().
__init__
()
...
...
@@ -14,3 +15,31 @@ class Round(pygame.sprite.Sprite):
x
=
round
(
vect
[
0
])
y
=
round
(
vect
[
1
])
return
pygame
.
math
.
Vector2
(
x
,
y
)
@
abstractmethod
def
collide
(
self
):
raise
NotImplementedError
(
'collide() has not been setup'
)
def
move_with_collision
(
self
,
speed
,
move_force
):
#Set max_distance
move_force
=
self
.
round_vector2
(
move_force
)
if
move_force
.
length
()
>
speed
:
max_distance
=
speed
else
:
max_distance
=
int
(
move_force
.
length
())
distance_moved
=
1
# Get current state
start
=
self
.
rect
.
copy
()
end
=
self
.
rect
.
copy
()
# Test distance 1 to max
while
distance_moved
<=
max_distance
:
self
.
rect
=
start
.
copy
()
move_force
.
scale_to_length
(
distance_moved
)
self
.
rect
.
move_ip
(
self
.
round_vector2
(
move_force
))
if
self
.
collide
():
break
else
:
end
=
self
.
rect
.
copy
()
distance_moved
+=
1
# move to end point
self
.
rect
=
end
.
copy
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment