space-invaders | A space invaders clone using Psykick2D
kandi X-RAY | space-invaders Summary
kandi X-RAY | space-invaders Summary
A space invaders clone using Psykick2D
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of space-invaders
space-invaders Key Features
space-invaders Examples and Code Snippets
Community Discussions
Trending Discussions on space-invaders
QUESTION
So I was trying to build this game using a free course on Youtube by Freecodeacademy(feel free to check them out) and after I finished I tried to add my own restart key log to the game. In the sense that I wanted that if people press R the game restarts.
I have tried the following methods
Put the game loop in a separate function and try to use recursion to replay the function over and over again but while the game does work, the images such as the bullet image or background does not load and hence it does not work properly
I have also tried creating a new python file in the same project and tried to import the main file over and over again using importlib.reload(main) but I can't seem to do that either.
I was wondering what else could the solution be and if there is a more efficient solution. I will leave my code down below and would appreciate any help.
Ps: I am only a armature in coding right now so I understand this problem might be small and stupid but I do want to learn from my failures and mistakes. Also I apologize if there is something wrong with anything in my question. This is my first question on stack overflow.
...ANSWER
Answered 2021-May-02 at 07:43Write a function that will reset any variables that change when the game is running:
QUESTION
So I have a command which allows you to create a channel and a role based on what the user gives. The problem arises when the channel name is over a word. For example:
>newrealm Space Invaders (emoji) (mention)
This command will raise an error because now it's assuming "Invaders" is the emoji.
Which is why I am now using something like this:
>newrealm Space-Invaders (emoji) (mention)
Now the problem with this command is that while creating the role, the name is Space-Invaders OP
. Is there a way to remove the -
in the role's name?
My code:
...ANSWER
Answered 2020-Nov-17 at 14:04There are several options that would solve this problem:
- encase the name in quotes so the function recognizes it as one argument.
- receive the name last with a special syntax:
QUESTION
I am new to Python and especially new to Pygame. Been working on a basic space invader type game to attempt to learn more about Pygame, but I cannot figure out the code for moving the user ship. Have looked up some tutorials on it, and I THINK my code looks good, but I might be looking over something. I am in Python version 3.8 and Pygame version 1.9.6.
...ANSWER
Answered 2020-Oct-13 at 01:05The issue is you're checking for an event.type
of pygame.K_d
, etc.
QUESTION
I made a game using pygame module of Python. I thought to make an executable installer of the file so that anyone could play that game without even having to install python or pygame. I used the module cx-freeze to create an executable for my game file. I stored the code for making an executable installer in file called setup.py and saved it in the same directory as of the game file and all other files which are required for the game like images, sounds, etc.
When I executed the command python setup.py build
to create an executable I started to get warnings and at the end this error occurred:
ANSWER
Answered 2020-Sep-29 at 15:09I have not used cxFreeze before, so I cannot directly help with your issue, but I would really recommend using pyinstaller
to package python programs. I have used it with pygame before and it has worked fine, and doesn't even require a setup file.
Pyinstaller can be installed using pip, and to package a file you call:
pyinstaller file.py
, along with any flags you may need. In general, I use pyinstaller file.py --onefile --noconsole
, which creates a single executable file.
Pyinstaller does not package asset files, so you must supply them with the project, but all python files used by the project (including libraries) are packaged, so no code needs to be supplied with the project.
Pyinstaller can be temperamental sometimes, so I'd recommend first creating a simple hello world file, and packaging it using pyinstaller helloworld.py --onefile
, and then running the file in the dist/
folder.
The docs are not always very helpful for pyinstaller, but I found that the best way to learn to package projects is slowly increase the complexity of the projects you try packaging, and check each project works after packaging.
If you use relative script and asset imports (e.g. pygame.image.load('image.png')
), you'll need to move the resulting .exe
to the original script's location (the .exe
is normally created in the dist/
folder, which will not work if you use relative imports and run the .exe
from there.
If you want to add an icon, you can use the --icon
flag like this: pyinstaller file.py --icon=image.ico
(the icon file must be a .ico
file - you can always you online converters if need be)
QUESTION
They pygame game i made has run into an error i cannot figure out how to fix. I am new to pygame. I am using pycharm and python version 3.
The error is stopping me from doing anything and it won't even let me run it
Here is the error
...ANSWER
Answered 2020-Jun-03 at 01:40I believe you are trying to do this:
c = sqrt(pow(a,2) + pow(b,2))
But your code has one pow() too many. Happens to me too, when I make I make game sounds in my head, while coding (pew pew pew)
Try to remove one pow()
from
math.pow(math.pow(enemyY - bulletY,2))
to
math.pow(enemyY - bulletY,2)
QUESTION
I am creating a game using pygame and have run into an error, I am new to pygame. I am using python 3.8 and pycharm community edition 2020.1
Here is the video i am making the game with: https://www.youtube.com/watch?v=FfWpgLFMI7w here is the error:
...ANSWER
Answered 2020-Jun-03 at 18:42enemyImg
is a list of images:
QUESTION
I'm new to javaFX and maven and I've been trying to configure a new project using IntelliJ and maven and openjfx dependency. I followed the instructions here: javaFX and IntelliJ -> modular with maven and I chose javafx-archetype-fxml over javafx-archetype-simple. and everything works fine with the sample code auto-created by the IDE. but as soon as I try to add a VBox
as my parent to the root I get exceptions. here is the code:
ANSWER
Answered 2020-May-27 at 14:24Your scene is not initialized according to code:
QUESTION
Blockquote I just started coding in this coronatime and I am running into a problem. The error code is enemy_icon = [i] NameError: name 'i' is not defined
And i'm not sure why. I having been looking online but couldn't find any answers. Hopefully this has given enough resources to be a good enough question.
...ANSWER
Answered 2020-Apr-25 at 13:44The error seems pretty clear. You have this line in you code:
QUESTION
import pygame
import random
pygame.init()
# create screen
screen = pygame.display.set_mode((1000, 600))
# Title + Logo
pygame.display.set_caption("Space Invader")
icon = pygame.image.load("chicken.png")
pygame.display.set_icon(icon)
# Player icon
player_icon = pygame.image.load("spaceship.png")
playerX = 400
playerY = 500
player_changeX = 0
player_changeY = 0
# enemy Player
enemy_icon = pygame.image.load("space-invaders.png")
enemyX = random.randint(0, 936)
enemyY = random.randint(-100, -50)
enemy_changeX = random.randint (0.1, 0.5)
enemy_changeY = random.randint (0.1, 0.5)
if enemyY >= 500:
print("Game over")
exit()
def player(x, y):
screen.blit(player_icon, (x, y))
def enemy(x, y):
screen.blit(enemy_icon, (x, y))
# game loop
running = True
while running:
# backround colour RGB
screen.fill((0, 0, 0))
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# If key pressed check whether its right or left
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
player_changeX = -1
if event.key == pygame.K_RIGHT:
player_changeX = 1
if event.key == pygame.K_UP:
player_changeY = -1
if event.key == pygame.K_DOWN:
player_changeY = 1
if event.type == pygame.KEYUP:
if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
player_changeX = 0
if event.key == pygame.K_UP or event.key == pygame.K_DOWN:
player_changeY = 0
# If player reaches boarder
if playerX >= 936:
playerX = 20
if playerX <= 0:
playerX = 936
if playerY <= 0:
playerY = 0
if playerY >= 550:
playerY = 550
# enemy control
if enemyX >= 936:
enemyX = 20
if enemyX <= 0:
enemyX = 936
if enemyY <= 0:
enemyY = 0
if enemyY >= 550:
enemyY = random.randint(-100, -50)
# Player change in coordinates
playerX += player_changeX
playerY += player_changeY
#enemy change in coordinates
enemyX += enemy_changeX
enemyY += enemy_changeY
#Results
player(playerX, playerY)
enemy(enemyX, enemyY)
pygame.display.update()
...ANSWER
Answered 2020-Apr-24 at 08:13First of all, you are requesting an integer between 0.1
and 0.5
, which is not possible for obvious reasons.
To get a float
you can use random.uniform(0.1, 0.5)
.
Although I have to note here, that pixels can't be float values, because there are no half pixels. Thus you have to think whether you really need a float value for a pixel change value.
QUESTION
I have tried putting the fill color before blit but it won't work. im using python 3.8.2, windows 10, and pygame 1.9.6. please help btw im following this tutorial (im new to pygame) and here's my code
...ANSWER
Answered 2020-Mar-07 at 08:36pygame.QUIT
is not a function - it's a constant, simply an integer representing a QUIT
event. You can't do if event.type == pygame.QUIT()
, you need to do if event.type == pygame.QUIT
, without parenthesis.
You also don't really need to call pygame.quit()
and exit()
at the end of the program - both pygame and the program itself will be terminated when the program reaches its end.
Apart from that your program works for me, images are showing. Make sure your image is visible over a black background and if it is and you are still having problems I'll try to help you with them.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install space-invaders
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page