日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

JAVA碰撞检测无效_碰撞检测不适用于Pygame中的精灵

發布時間:2025/3/19 编程问答 48 豆豆
生活随笔 收集整理的這篇文章主要介紹了 JAVA碰撞检测无效_碰撞检测不适用于Pygame中的精灵 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我最近嘗試通過將我的基本 rect 和圖像更改為更高級的 Class 系統來升級我正在處理的游戲的代碼 . 但是,我似乎遇到了我的碰撞檢測問題,當我告訴我的精靈 hg 在與 floor (或任何輸入的 box )發生碰撞時停止下降時,它并沒有錯誤 . 我究竟做錯了什么?以下是我認為足夠的代碼可以幫助您和您需要的兩張圖片(如果您需要更多信息,請告訴我):

######## basic setup

import pygame, sys, time, random, threading, tkinter, ctypes

from threading import Timer

from pygame.locals import *

from tkinter import *

pygame.init()

WINDOWHEIGHT = 720

WINDOWWIDTH = 1280

windowSurface = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT), 0, 32)

pygame.display.set_caption('Hitman Grandma | vB1.0 (prealpha)')

white = (255,255,255)

red = (255,0,0)

black = (0,0,0)

green = (0,255,0)

blue = (0,0,255)

cyan = (0,255,255)

lightgrey = (198,198,198)

windowSurface.fill(lightgrey)

pygame.display.update()

mainClock = pygame.time.Clock()

########## variables

level = 0

touching = False

global x_speed

x_speed = 0

y_speed = 0

leftallowed = True

rightallowed = True

hgturnright = True

hgjumpallowed = True

########### the grandma d'awesome murder sorts

hgimage = pygame.image.load('hgfinal.png')

hgimage.convert_alpha()

class HG(object):

def __init__(self,x,y,image):

self.image = image

self.rect = self.image.get_rect()

self.x = x

self.y = y

def draw(self):

windowSurface.blit(self.image,(self.x,self.y))

def move(self):

self.x += x_speed

self.y += y_speed

def topcollide(self,box):

if not self.rect.colliderect(box.rect):

global y_speed

if y_speed < 20:

y_speed += 1

elif y_speed == 20:

y_speed = 20

print('shhoooo')

elif self.rect.colliderect(box.rect):

y_speed = 0

print('flop')

hg = HG(0,0,hgimage)

########### land and boundary

lands = pygame.image.load('hgland1.png')

floorland = pygame.transform.scale(lands,(1280,50))

sideedge = pygame.Rect(0,0,1,720),pygame.Rect(1279,0,1,720)

topedge = pygame.Rect(0,0,1280,1)

class Floor(object):

def __init__(self,x,y,image):

self.image = image

self.x = x

self.y = y

self.rect = self.image.get_rect()

self.rect.x = x

self.rect.y = y

def draw(self):

windowSurface.blit(self.image,(self.x,self.y))

class Ground(object):

def __init__(self,x,y,image):

self.image = image

self.x = x

self.y = y

self.rect = self.image.get_rect()

def draw(self):

windowSurface.blit(self.image,(self.x,self.y))

floor = Floor(0,670,floorland)

########### WHILE

while True:

########### background

windowSurface.fill(lightgrey)

########### hg movement

for event in pygame.event.get():

if event.type == KEYDOWN:

if event.key == K_LEFT and hg.x > 0 and leftallowed:

x_speed = -4

hgturnright = False

if event.key == K_RIGHT and (hg.x + 36) < WINDOWWIDTH and rightallowed:

x_speed = 4

hgturnright = True

if event.key == K_UP and hgjumpallowed:

y_speed = -17

if event.type == KEYUP:

if event.key == K_RIGHT:

x_speed = 0

if event.key == K_LEFT:

x_speed = 0

if event.type == KEYDOWN:

########### ctrl+q

if event.key == K_q and pygame.key.get_mods() & pygame.KMOD_CTRL:

pygame.quit()

sys.exit()

exit

########### [x]

if event.type == pygame.QUIT:

pygame.quit()

sys.exit()

exit

########### drawing and .move()

floor.draw()

hg.draw()

hg.move()

hg.topcollide(floor)

########### technicals

pygame.display.update()

mainClock.tick(40)

總結

以上是生活随笔為你收集整理的JAVA碰撞检测无效_碰撞检测不适用于Pygame中的精灵的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。