У меня есть Образ Марио, который я хочу переместить в два полубесконечных массива. Когда я смотрю в интернет, они всегда используют "пигмею". Я не думаю, что мне разрешено использовать Pygame в этом назначении. Мне просто нужно установить движение игрока в: Def Go (ключ). Буду признателен за помощь, ребята.
import sys
import random
import time
from PIL import Image, ImageTk
from tkinter import Tk, Frame, Canvas, ALL, NW
# Definse size of board and other constants
BOARD_WIDTH = 1000 # In points px
BOARD_HEIGHT = 1000 # In points px
INFO_HEIGHT = 40 # Top info board in points px
STEP_SIZE = 40 # Size of objects in points px
def go(key):
'''
wasd: w up, a left, s down, d right
Input: key from keyboard as string
'''
def moveMario(self):
'''moves the Mario object'''
mario = self.find_withtag("mario")
jmario = self.find_withtag("jmario") # jumping mario
self.move(mario, self.moveX, self.moveY) # internal move function
self.move(jmario, self.moveX, self.moveY) # internal move function
def validStep(self): # <- True to go through walls
'''checks for wall collisions'''
walls = self.find_withtag("wall")
walls = walls + self.find_withtag("gate")
mario = self.getCurrentMario()
x1, y1, x2, y2 = self.bbox(mario)
x1, y1, x2, y2 = nextStep(x1, y1, x2, y2, self.moveX, self.moveY)
overlap = self.find_overlapping(x1, y1, x2, y2)
if (not self.specterMode):
for dot in walls:
for over in overlap:
if over == dot:
return(False)
# Check if you are finished and outside map
if y1 > BOARD_HEIGHT - STEP_SIZE:
self.inGame = False
return(True)
def onKeyPressed(self, e):
'''controls direction variables with cursor keys'''
key = e.keysym
self.moveX, self.moveY = go(key) # get direction to go
if key == 'h': #if jump
self.jump(True) # Set jump to True in jump function
if self.jump and (time.time() - self.jumptime > 0.3): # finished jump
self.jump(False) # Set jump to False in jump function
if key == 'S': # Capital s only, shift + s
self.specterMode = not self.specterMode
if self.validStep(): # If valid step
self.update() # Check for collisions
if self.life <= 0: # if dead
self.inGame = False
self.gameOver()