第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

我如何更改代碼以使播放器停在邊緣而不是環(huán)繞?

我如何更改代碼以使播放器停在邊緣而不是環(huán)繞?

慕姐8265434 2023-01-04 16:32:19
WIDTH = 800HEIGHT = 500background = Actor("background")player = Actor("player")player.x = 200player.y = 200def draw():screen.clear()background.draw()player.draw()def update():if keyboard.right:    player.x = player.x + 4if keyboard.left:    player.x = player.x - 4if keyboard.down:    player.y = player.y + 4if keyboard.up:    player.y = player.y - 4if player.x > WIDTH:    player.x = 0if player.x < 0:    player.x = WIDTHif player.y < 0:    player.y = HEIGHTif player.y > HEIGHT:    player.y = 0我想讓玩家停在邊緣而不是環(huán)繞并傳送到另一邊。幫助將不勝感激。
查看完整描述

2 回答

?
夢里花落0921

TA貢獻1772條經(jīng)驗 獲得超6個贊

你把它弄錯了:


if player.x > WIDTH:

    player.x = WIDTH

if player.x < 0:

    player.x = 0

if player.y < 0:

    player.y = 0

if player.y > HEIGHT:

    player.y = HEIGHT


查看完整回答
反對 回復 2023-01-04
?
犯罪嫌疑人X

TA貢獻2080條經(jīng)驗 獲得超4個贊

已經(jīng)有了答案,但我認為這段代碼會更有效率。


def update():

 if keyboard.right and player.x<=WIDTH-4:

  player.x = player.x + 4

 if keyboard.left and player.x>=4:

  player.x = player.x - 4

 if keyboard.down and player.y<=HEIGHT-4:

  player.y = player.y + 4

 if keyboard.up and player.y>=4:

  player.y = player.y - 4


查看完整回答
反對 回復 2023-01-04
  • 2 回答
  • 0 關注
  • 138 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號