pygame

How to turn the sprite in pygame while moving with the keys

放肆的年华 提交于 2020-12-23 12:14:51
问题 So basically ive been hoping it would be possible to effectively turn your sprite while moving it around with W A S D . Any ideas because im certainly stumped, thanks! 回答1: See How do I rotate an image around its center using PyGame? for rotating a surface. If you want to rotate an image around a center point ( cx , cy ) you can just do that: rotated_car = pygame.transform.rotate(car, angle) window.blit(rotated_car, rotated_car.get_rect(center = (cx, cy)) Use pygame.math.Vector2 to store the

Can't understand how to make character face mouse in PyGame

烈酒焚心 提交于 2020-12-23 12:10:53
问题 Below is what I have so far. At the moment, the player moves, and all I want it to do now is face the mouse cursor at all times (think Hotline Miami or other top-down games). I've used some code involving atan2 that I found online, but I barely understand what it does (finds the distance between the player and mouse somehow...) and my character just spins wildly offscreen until I get an 'Out of memory' error. Any help would be much appreciated, I've looked all over the internet and can't find

Can't understand how to make character face mouse in PyGame

雨燕双飞 提交于 2020-12-23 12:09:07
问题 Below is what I have so far. At the moment, the player moves, and all I want it to do now is face the mouse cursor at all times (think Hotline Miami or other top-down games). I've used some code involving atan2 that I found online, but I barely understand what it does (finds the distance between the player and mouse somehow...) and my character just spins wildly offscreen until I get an 'Out of memory' error. Any help would be much appreciated, I've looked all over the internet and can't find

Can't understand how to make character face mouse in PyGame

非 Y 不嫁゛ 提交于 2020-12-23 12:08:54
问题 Below is what I have so far. At the moment, the player moves, and all I want it to do now is face the mouse cursor at all times (think Hotline Miami or other top-down games). I've used some code involving atan2 that I found online, but I barely understand what it does (finds the distance between the player and mouse somehow...) and my character just spins wildly offscreen until I get an 'Out of memory' error. Any help would be much appreciated, I've looked all over the internet and can't find

Can't understand how to make character face mouse in PyGame

余生颓废 提交于 2020-12-23 12:07:21
问题 Below is what I have so far. At the moment, the player moves, and all I want it to do now is face the mouse cursor at all times (think Hotline Miami or other top-down games). I've used some code involving atan2 that I found online, but I barely understand what it does (finds the distance between the player and mouse somehow...) and my character just spins wildly offscreen until I get an 'Out of memory' error. Any help would be much appreciated, I've looked all over the internet and can't find

Can't understand how to make character face mouse in PyGame

女生的网名这么多〃 提交于 2020-12-23 12:07:15
问题 Below is what I have so far. At the moment, the player moves, and all I want it to do now is face the mouse cursor at all times (think Hotline Miami or other top-down games). I've used some code involving atan2 that I found online, but I barely understand what it does (finds the distance between the player and mouse somehow...) and my character just spins wildly offscreen until I get an 'Out of memory' error. Any help would be much appreciated, I've looked all over the internet and can't find

Python制作推箱子小游戏

谁说胖子不能爱 提交于 2020-12-22 19:55:39
开发工具 Python版本:3.6.4 相关模块: pygame模块; 以及一些Python自带的模块。 相关文件 关注公众号:Python学习指南,回复“推箱子”即可获取 环境搭建 安装Python并添加到环境变量,pip安装需要的相关模块即可。 原理简介 游戏简介 经典的推箱子是一个来自日本的古老游戏,目的是在训练你的逻辑思考能力。在一个狭小的仓库中,要求把木箱放到指定的位置,稍不小心就会出现箱子无法移动或者通道被堵住的情况,所以需要巧妙的利用有限的空间和通道,合理安排移动的次序和位置,才能顺利的完成任务。 控制方式: ↑↓←→键 控制人物行动, r键 重新开始本关。 逐步实现: Step1:定义游戏精灵类 由于游戏涉及到碰撞检测,所以我们先来定义一些游戏精灵类,包括推箱子的人、箱子、墙和目标位置指示标记。 首先我们来定义一下推箱子的人这个精灵类: 他需要拥有可以移动的能力,这里设置了一个模拟移动的选项,是为了通过模拟移动判断他是否可以向上/下/左/右移动。 因为地图上的其他东西性质类似,所以我们把它们定义成同一个精灵类(T_T其实性质都类似,但是感觉还是有必要区分一下人和物的): 其中箱子需要拥有可以移动的能力,其他则不能移动。模拟移动选项的功能与之前类似。 Step2:定义游戏地图类 这里我们定义一个游戏地图类,目的是用该类来创建任意的游戏地图。因此

How to detect when a rectangular object, image or sprite is clicked

妖精的绣舞 提交于 2020-12-21 04:11:28
问题 I'm trying to tell when a sprite, which must be part of a particular group ( pygame.sprite.Group() ), is clicked on. Currently I've tried creating a sprite which is just the mouses position and totally invisible, adding it to its own group, and using this code: clickedList = pygame.sprite.spritecollide(guess1, mice, False) where guess1 is the sprite getting clicked on and mice is the group containing the sprite that has the position of the mouse. When I try this, I am told that "Group has no

How to detect when a rectangular object, image or sprite is clicked

感情迁移 提交于 2020-12-21 04:10:07
问题 I'm trying to tell when a sprite, which must be part of a particular group ( pygame.sprite.Group() ), is clicked on. Currently I've tried creating a sprite which is just the mouses position and totally invisible, adding it to its own group, and using this code: clickedList = pygame.sprite.spritecollide(guess1, mice, False) where guess1 is the sprite getting clicked on and mice is the group containing the sprite that has the position of the mouse. When I try this, I am told that "Group has no

How do I convert an OpenCV (cv2) image (BGR and BGRA) to a pygame.Surface object

∥☆過路亽.° 提交于 2020-12-19 04:25:08
问题 I created images from OpenCV/opencv-python (numpy.array) and I want to convert them to a pygame.Surface object: def cv2ImageToSurface(cv2Image): pygameSurface = # ? create from "cv2Image" return pygameSurface surface = cv2ImageToSurface(cv2Image) Some of the images have 3 channels ( BGR ) and some of the images also have an alpha channel ( BGRA ). What do I have to do in cv2ImageToSurface to convert images with one of the formats into a pygame.Surface object? 回答1: The shape attribute of a