pygame

Pygame - Crashing when trying to shoot [closed]

一世执手 提交于 2021-01-20 08:51:17
问题 Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 21 days ago . Improve this question I am trying to learn Python and wanted to practice with Pygame. I am currently using Python 3.6.5 and running the code in Atom 1.27.2 and installed the atom-runner package. I have been following the KidsCanCode tutorial for Pygame on Youtube. I wanted to change

Pygame window not showing up

谁说我不能喝 提交于 2021-01-20 08:33:05
问题 I recently downloaded pygame on my Mac, but for some reason, the window does not pop up with the screen or anything. I don't get an error message, it just runs but doesn't actually pop up a display. import pygame, sys from pygame.locals import* pygame.init() SCREENWIDTH = 800 SCREENHEIGHT = 800 RED = (255,0,0) screen = pygame.display.set_mode((SCREENWIDTH, SCREENHEIGHT)) pygame.draw.rect(screen, RED, (400, 400, 20, 20),0) screen.fill(RED) pygame.display.update() 回答1: Your code is currently

Update during resize in Pygame

▼魔方 西西 提交于 2021-01-18 04:13:38
问题 I'm developing a grid based game in pygame, and want the window to be resizable. I accomplish this with the following init code: pygame.display.set_mode((740, 440), pygame.RESIZABLE) As well as the following in my event handler: elif event.type == pygame.VIDEORESIZE: game.screen = pygame.display.set_mode((event.w, event.h), pygame.RESIZABLE) # Code to re-size other important surfaces The problem I'm having is that it seems a pygame.VIDEORESIZE event is only pushed once the user is done

python游戏开发之俄罗斯方块(一):简版

安稳与你 提交于 2021-01-17 06:41:00
编程语言:python(3.6.4) 主要应用的模块:pygame (下面有源码,但是拒绝分享完整的源码,下面的代码整合起来就是完整的源码) 首先列出我的核心思路: 1,图像由“核心变量”完全控制,图像变化的本质是 变量的改变 2,自上而下式的思考,图像变化的问题将一步步转为 一系列具体的变量修改 3,“核心变量”在思考过程中并非不可变更,为了写函数方便,可以适当让步 正文开始: 核心变量到图像 首先看成品图预览图 从上图和游戏玩法可以得出以下两点: 1,方块位置十分有规律 2,两类方块(上面移动的,下方固定的 都比较有特点) 方块的大小都是固定的,只需要操心位置的问题,下面建坐标系 下一步, 坐标的储存方式 ###欢迎加群:725479218,完整源码,以及pygame的学习方法,都有 记录方式有两种:  1,横纵坐标做一个二元元组,再用一个列表装着一堆二元元组       例如:[(20,1),(20,2),(20,3),(20,4)]代表第20行的1~4列的四个方块   2,二维数组,一行是一个列表,用两个索引代表横纵坐标,值为1就代表有方块,0就是没有方块 例如:block[20][1] 值为1就表示20行第1列有方块,block[20][5] 为0表示20行第5列有没有方块 讲道理,两种记录方式没什么大区别,而且第一种似乎更好用 但后面会有这样的问题

How do I implement option buttons and change the button color in PyGame?

佐手、 提交于 2021-01-16 03:49:59
问题 Pls suggest how can I change the color of the button when I pressed it, and the color of the first button will be changed to the default color when I pressed the second button. For example, After I clicked the STRAIGHT Button, the button will become green color and when I click the LEFT button the LEFT button will change to green color and the STRAIGHT button will become the default color which is white color. Thanks in advance :) CODE: def draw_button(self): global clicked action = False #

How to render transparent text with alpha channel in PyGame?

点点圈 提交于 2021-01-15 18:40:49
问题 I am using pygame.font.Font.render() to render some text. I'd like the text to be translucent, ie have an alpha value other than 255, so I tried passing a color argument with an alpha value (eg (255, 0, 0, 150) ) as the color argument for pygame.font.Font.render() but it didn't have any effect. I also tried using pygame.Surface.convert_alpha() on the resulting Surface object, but that didn't do anything either. Any ideas? 回答1: When using the pygame.font module, the alpha channel of the text

How to render transparent text with alpha channel in PyGame?

[亡魂溺海] 提交于 2021-01-15 18:39:07
问题 I am using pygame.font.Font.render() to render some text. I'd like the text to be translucent, ie have an alpha value other than 255, so I tried passing a color argument with an alpha value (eg (255, 0, 0, 150) ) as the color argument for pygame.font.Font.render() but it didn't have any effect. I also tried using pygame.Surface.convert_alpha() on the resulting Surface object, but that didn't do anything either. Any ideas? 回答1: When using the pygame.font module, the alpha channel of the text

如何学习编程 我的编程学习之路

自古美人都是妖i 提交于 2021-01-14 13:34:19
##学习编程语言的语法 第一次接触到编程的感觉似乎是一种过电的畅爽感。对于编程有种美好的畅想感,似乎是打开了新的世界。但是却并不知道学习些什么。如果此时幸运的话能够找到一本学习编程语言基本语法的书籍,开始第一次的“hello world”之旅。但其中安装开发环境也是一大坑。 而后要是编程书籍选的不好便会陷入迷茫的状态,四处寻找着自己的方向,只学习了编程语法却并不知道如何运用。我在这个阶段耽搁了很久,每天看视频炫技似的开发各种功能,可是看完并没有太多的体会。编程的方法和过程一点也没有学到。 开始自己做一些小项目。说实话这走出舒适区的第一步就举步维艰。本来想自己独立开发一个五子棋小游戏,当时学习的是C语言,但是在开始就卡壳。于是转而开始找了一个教程,照抄了他的代码。做完以后稍微有点感觉了,自己又加了记录步数,悔棋,美化界面等边角料的与主功能不怎么相关的功能。当然这是一个命令行版本的。在最开始的几天兴奋过后,又觉得稍感无聊了。 ##学习编程的具体过程 五子棋游戏只有一个命令行窗口输入坐标,总感觉这样的程序不够酷。此时知乎开始兴起,逛了知乎之后,只感觉思路开阔不少。后来么,被洗脑开始学习python。用过c以后只感觉python是真的好,特别是比C语言的数列好用太多了。C语言开始时候并没有太多的数据结构的知识。只能用数列和结构体什么的对新手真是太不友好了,当时看链表根本搞不懂

How can I drag more than 2 images in PyGame?

牧云@^-^@ 提交于 2021-01-13 10:14:10
问题 i have this code but i wanna make this with other 4 images? import pygame from pygame.locals import * pygame.display.init() screen = pygame.display.set_mode((1143,677 )) img = pygame.image.load(r"C:\Users\ga-sa\Downloads\As.png") img1 = pygame.image.load(r"C:\Users\ga-sa\Downloads\03.png") imgPos = img.get_rect(topleft = (20, 20)) imgPos1 = img1.get_rect(topleft = (60, 20)) current_image = None LeftButton = 0 while 1: for e in pygame.event.get(): if e.type == QUIT: pygame.quit() exit(0) if e

How can I drag more than 2 images in PyGame?

你说的曾经没有我的故事 提交于 2021-01-13 10:13:34
问题 i have this code but i wanna make this with other 4 images? import pygame from pygame.locals import * pygame.display.init() screen = pygame.display.set_mode((1143,677 )) img = pygame.image.load(r"C:\Users\ga-sa\Downloads\As.png") img1 = pygame.image.load(r"C:\Users\ga-sa\Downloads\03.png") imgPos = img.get_rect(topleft = (20, 20)) imgPos1 = img1.get_rect(topleft = (60, 20)) current_image = None LeftButton = 0 while 1: for e in pygame.event.get(): if e.type == QUIT: pygame.quit() exit(0) if e