I want to create a Luckman breed of Pac-Man for Android for phones and tablets. But I can't make a collision for the labyrinth.
I tried to do it as in these files https://drive.google.com/file/d/1pwCDpU1UPzB7V7TV7-WmbyDLkpIDODry/view. But due to the fact that my labyrinth is located not as a picture but as a drawn object in the .kv file, nothing happened.
Here is my program code
main.py
from kivy.app import App
from kivy.uix.screenmanager import Screen
from kivy.uix.widget import Widget
from kivy.uix.anchorlayout import AnchorLayout
from player import *
from kivy.clock import Clock
from kivy.core.window import Window
class GamePlay(Screen):
width = Window.width
height = Window.height
pacman = Player()
def __init__(self, **kwargs):
super(GamePlay,self).__init__(**kwargs)
def on_touch_down(self, touch):
self.start_pos = touch.pos
return True
def on_touch_move(self, touch):
# Calculate swipe distance and direction
swipe_distance_x = abs(touch.pos[0] - self.start_pos[0])
swipe_distance_y = abs(touch.pos[1] - self.start_pos[1])
swipe_threshold = 50 # Adjust threshold based on your needs
# Detect swipe directions
if swipe_distance_y > swipe_threshold:
if touch.pos[1] > self.start_pos[1]:
self.pacman.velocity = (0, 1)
self.pacman.number_update_pac_img = "up"
else:
self.pacman.velocity = (0, -1)
self.pacman.number_update_pac_img = "down"
elif swipe_distance_x > swipe_threshold:
if touch.pos[0] > self.start_pos[0]:
self.pacman.velocity = (1, 0)
self.pacman.number_update_pac_img = "right"
else:
self.pacman.velocity = (-1, 0)
self.pacman.number_update_pac_img = "left"
return True
def update(self, dt):
self.pacman.move()
class LuckmanApp(App):
def build(self):
game = GamePlay()
Clock.schedule_interval(game.update, 1.0/60.0)
return game
if __name__ == '__main__':
LuckmanApp().run()
luckman.kv
<Player>:
Image:
id: "pacman"
source: root.pac_img
allow_stretch: True
pos: root.pos
size: self.parent.width / 18, self.parent.height / 18
<GamePlay>:
canvas:
Rectangle:
source: "png/bg.png"
size: self.size
pacman: pacman_player
FloatLayout:
# ะะตัั
ะฝะธะน ะฒั
ะพะด
canvas:
Color:
rgb: [0, 0, 1]
# ะะตัั
ะฝะธะน ะฒั
ะพะด - ะฟัะฐะฒะฐั ััะตะฝะบะฐ
Rectangle:
pos: self.width / 1.79, self.height
size: self.width / -43.2, self.height / -6
# ะะตัั
ะฝะธะน ะฒั
ะพะด - ะปะตะฒะฐั ััะตะฝะบะฐ
Rectangle:
pos: self.width / 2.274, self.height
size: self.width / 43.2, self.height / -6
# ะะตัั
ะฝะธะน ะปะตะฒัะน ะบะฒะฐะดัะฐั ััะตะฝะพะบ
Rectangle:
pos: self.width / 2.274, self.height / 1.2
size: self.width / -15, self.height / 96
Rectangle:
pos: self.width / 2.52, self.height / 1.2
size: self.width / -43.2, self.height / 8
Rectangle:
pos: self.width / 2.52, self.height / 1.055
size: self.width / -2.85, self.height / 96
Rectangle:
pos: self.width / 15, self.height / 1.0444
size: self.width / -43.2, self.height / -4.7
Rectangle:
pos: self.width / 23.1, self.height / 1.34
size: self.width / 7.3, self.height / -96
Rectangle:
pos: self.width / 2.6, self.height / 1.34
size: self.width / -7.7, self.height / -96
Rectangle:
pos: self.width / 2.68, self.height / 1.359
size: self.width / 11, self.height / 16.2
# ะะตัั
ะฝะธะน ะปะตะฒัะน ััะตะดะฝะธะน ะบะฒะฐะดัะฐั
Rectangle:
pos: self.width / 7.29, self.height / 1.0948
size: self.width / 22, self.height / -7.6
Rectangle:
pos: self.width / 3.92, self.height / 1.0948
size: self.width / 22, self.height / -7.6
# ะะตัั
ะฝะธะน ะฟัะฐะฒัะน ะบะฒะฐะดัะฐั ััะตะฝะพะบ
Rectangle:
pos: self.width / 1.8, self.height / 1.2
size: self.width / 15, self.height / 96
Rectangle:
pos: self.width / 1.631, self.height / 1.2
size: self.width / 43.2, self.height / 8
Rectangle:
pos: self.width / 1.631, self.height / 1.055
size: self.width / 2.85, self.height / 96
Rectangle:
pos: self.width / 1.06, self.height / 1.0444
size: self.width / 43.2, self.height / -4.7
Rectangle:
pos: self.width / 1.035, self.height / 1.34
size: self.width / -7.3, self.height / -96
Rectangle:
pos: self.width / 1.6043, self.height / 1.34
size: self.width / 7.7, self.height / -96
Rectangle:
pos: self.width / 1.57, self.height / 1.359
size: self.width / -10, self.height / 16.2
# ะะตัั
ะฝะธะน ะฟัะฐะฒัะน ััะตะดะฝะธะน ะบะฒะฐะดัะฐั
Rectangle:
pos: self.width / 1.207, self.height / 1.0948
size: self.width / 22, self.height / -7.6
Rectangle:
pos: self.width / 1.324, self.height / 1.0948
size: self.width / -22, self.height / -7.6
# ะะธะถะฝะธะน ะฒั
ะพะด - ะฟัะฐะฒะฐั ััะตะฝะบะฐ
Rectangle:
pos: self.width / 1.79, self.height * 0
size: self.width / -43.2, self.height / 6
# ะะธะถะฝะธะน ะฒั
ะพะด - ะปะตะฒะฐั ััะตะฝะบะฐ
Rectangle:
pos: self.width / 2.274, self.height * 0
size: self.width / 43.2, self.height / 6
# ะะธะถะฝะธะน ะปะตะฒัะน ะบะฒะฐะดัะฐั ััะตะฝะพะบ
Rectangle:
pos: self.width / 2.274, self.height / 6.4
size: self.width / -15, self.height / 96
Rectangle:
pos: self.width / 2.52, self.height / 6
size: self.width / -43.2, self.height / -8
Rectangle:
pos: self.width / 2.52, self.height / 24
size: self.width / -2.85, self.height / 96
Rectangle:
pos: self.width / 15, self.height / 24
size: self.width / -43.2, self.height / 4.7
Rectangle:
pos: self.width / 23.1, self.height / 3.8
size: self.width / 7.25, self.height / -96
Rectangle:
pos: self.width / 2.6, self.height / 3.8
size: self.width / -7.7, self.height / -96
Rectangle:
pos: self.width / 2.68, self.height / 3.8
size: self.width / 11, self.height / -16.2
#ะะธะถะฝะธะน ะะตะฒัะน ััะตะดะฝะธะน ะบะฒะฐะดัะฐั
Rectangle:
pos: self.width / 7.29, self.height / 4.61
size: self.width / 22, self.height / -7.6
Rectangle:
pos: self.width / 3.92, self.height / 4.61
size: self.width / 22, self.height / -7.6
# ะะธะถะฝะธะน ะฟัะฐะฒัะน ะบะฒะฐะดัะฐั ััะตะฝะพะบ
Rectangle:
pos: self.width / 1.8, self.height / 6.4
size: self.width / 15, self.height / 96
Rectangle:
pos: self.width / 1.631, self.height / 6
size: self.width / 43.2, self.height / -8
Rectangle:
pos: self.width / 1.631, self.height / 24
size: self.width / 2.85, self.height / 96
Rectangle:
pos: self.width / 1.06, self.height / 24
size: self.width / 43.2, self.height / 4.7
Rectangle:
pos: self.width / 1.035, self.height / 3.8
size: self.width / -7.25, self.height / -96
Rectangle:
pos: self.width / 1.6043, self.height / 3.8
size: self.width / 7.6, self.height / -96
Rectangle:
id: stop
pos: self.width / 1.57, self.height / 3.8
size: self.width / -10, self.height / -16.2
#ะะธะถะฝะธะน ะฟัะฐะฒัะน ััะตะดะฝะธะน ะบะฒะฐะดัะฐั
Rectangle:
pos: self.width / 1.207, self.height / 4.61
size: self.width / 22, self.height / -7.6
Rectangle:
pos: self.width / 1.324, self.height / 4.61
size: self.width / -22, self.height / -7.6
#ะฆะตะฝััะฐะปัะฝัะต ััะพัะพะฝั
#ะฆะตะฝััะฐะปัะฝะฐั ะปะตะฒะฐั ะณะพัะธะทะพะฝัะฐะปัะฝะฐั ััะตะฝะบะฐ
Rectangle:
pos: self.width / 6.31, self.height / 1.34
size: self.width / 43.2, self.height / -2.05
#ะฆะตะฝััะฐะปัะฝะฐั ะฟัะฐะฒะฐั ะณะพัะธะทะพะฝัะฐะปัะฝะฐั ััะตะฝะบะฐ
Rectangle:
pos: self.width / 1.208, self.height / 1.34
size: self.width / 43.2, self.height / -2.05
#ะฆะตะฝัะฐะปัะฝะฐั ะฒะตัั
ะฝัั ััะตะฝะบะฐ
Rectangle:
pos: self.width / 3.92, self.height / 1.43
size: self.width / 2., self.height / -96
#ะฆะตะฝัั ัะฟะฐะฒะฝะฐ ะฟัะธะทัะฐะบะพะฒ
Rectangle:
pos: self.width / 2.68, self.height / 1.555
size: self.width / 11, self.height / 96
Rectangle:
pos: self.width / 1.57, self.height / 1.555
size: self.width / -10, self.height / 96
Rectangle:
pos: self.width / 2.68, self.height / 1.65
size: self.width / 43.2, self.height / 27
Rectangle:
pos: self.width / 1.57, self.height / 1.65
size: self.width / -43.2, self.height / 27
Rectangle:
pos: self.width / 2.68, self.height / 1.65
size: self.width / 3.79, self.height / -96
#ะฆะตะฝัะฐะปัะฝะฐั ััะตะดะฝัั ััะตะฝะบะฐ
Rectangle:
pos: self.width / 3.92, self.height / 1.786
size: self.width / 2, self.height / -96
#ะฆะตะฝััะฐะปัะฝะฐั ะฟัะฐะฒะฐั ะฒะตััะตะบะฐะปัะฝะฐั ััะตะฝะบะฐ
Rectangle:
pos: self.width / 1.324, self.height / 1.68
size: self.width / -22, self.height / 17.5
#ะฆะตะฝััะฐะปัะฝะฐั ะปะตะฒะฐั ะฒะตััะตะบะฐะปัะฝะฐั ััะตะฝะบะฐ
Rectangle:
pos: self.width / 3.92, self.height / 1.68
size: self.width / 22, self.height / 17.5
#ะฆะตะฝัะฐะปัะฝะฐั ะปะตะฒะฐั ะฝะธะถะฝัั ััะตะฝะบะฐ
Rectangle:
pos: self.width / 6.31, self.height / 1.945
size: self.width / 3.25, self.height / -96
#ะฆะตะฝัะฐะปัะฝัั ะฟัะฐะฒะฐั ะฝะธะถะฝัั ััะตะฝะบะฐ
Rectangle:
pos: self.width / 1.208, self.height / 1.945
size: self.width / -3.5, self.height / -96
#ะฆะตะฝััะฐะปัะฝะธะน ะฝะธะถะฝะธะน ะบะฒะฐะดัะฐั
Rectangle:
pos: self.width / 3.92, self.height / 3.8
size: self.width / 2, self.height / 4.85
Player:
id: pacman_player
pos: self.width / 2.13, self.height / 5.7
player.py
from kivy.uix.widget import Widget
from kivy.properties import StringProperty, NumericProperty, ReferenceListProperty
from kivy.vector import Vector
class Player(Widget):
pac_img = StringProperty("png/pacman/pacman_down.gif")
number_update_pac_img = "None"
velocity_x = NumericProperty(0)
velocity_y = NumericProperty(0)
velocity = ReferenceListProperty(velocity_x, velocity_y)
def move(self):
self.pos = Vector(*self.velocity) + self.pos
#update pacman gifts
if self.number_update_pac_img == "up":
self.pac_img = "png/pacman/pacman_up.gif"
if self.number_update_pac_img == "down":
self.pac_img = "png/pacman/pacman_down.gif"
if self.number_update_pac_img == "left":
self.pac_img = "png/pacman/pacman_left.gif"
if self.number_update_pac_img == "right":
self.pac_img = "png/pacman/pacman_right.gif"