Beginning Space Invaders Code and Requiring Assistance with a part of itHow to make a pygame sprite group move?Update display all at one time PyGamePygame - Space Invaders AliensSpace Invaders projectSpace invaders game bugPyGame Space Invaders Game - Making aliens move togetherDraw shape given x and y coordinates pygameRender numpy array on screen in pygameSpace Invaders - pygame - AttributeErrorPython: Space Invaders Score SystemAble to get image to move in Pygame; but I have to keep on pressing the button to make it move

How to innovate in OR

Exploiting the delay when a festival ticket is scanned

How do discovery writers hibernate?

PCB design using code instead of clicking a mouse?

Just how much information should you share with a former client?

Why don't short runways use ramps for takeoff?

How to choose using Collection<Id> rather than Collection<String>, or the opposite?

When does the Homunculus die, exactly?

Can a US President, after impeachment and removal, be re-elected or re-appointed?

What Marvel character has this 'W' symbol?

Complaints from (junior) developers against solution architects: how can we show the benefits of our work and improve relationships?

Was the Psych theme song written for the show?

If the Moon were impacted by a suitably sized meteor, how long would it take to impact the Earth?

What language is Raven using for her attack in the new 52?

What are the cons of stateless password generators?

Bouncing map back into its bounds, after user dragged it out

Can machine learning learn a function like finding maximum from a list?

Was Donald Trump at ground zero helping out on 9-11?

How to prevent a single-element caster from being useless against immune foes?

What is the highest achievable score in Catan

How did the SysRq key get onto modern keyboards if it's rarely used?

Rampant sharing of authorship among colleagues in the name of "collaboration". Is not taking part in it a death knell for a future in academia?

What is my clock telling me to do?

Microgravity indicators



Beginning Space Invaders Code and Requiring Assistance with a part of it


How to make a pygame sprite group move?Update display all at one time PyGamePygame - Space Invaders AliensSpace Invaders projectSpace invaders game bugPyGame Space Invaders Game - Making aliens move togetherDraw shape given x and y coordinates pygameRender numpy array on screen in pygameSpace Invaders - pygame - AttributeErrorPython: Space Invaders Score SystemAble to get image to move in Pygame; but I have to keep on pressing the button to make it move






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I am beginning to code a space invaders game and trying to just get the ship down and let it move back and forth across the screen. I'm very beginner status so it is a big challenge for me. Whenever I try to run it it tells me that I'm requiring another positional argument in my update function but I don't understand what I'm supposed to do.



I've tried moving around the variable initialization for keys but it hasn't changed anything. If anyone wants to take a look at my code and tell me what I could do it would be amazing.



import pygame, sys
from pygame import *
pygame.init()
screen = pygame.display.set_mode((800,600))
pygame.display.set_caption("Space Invaders")
pygame.mouse.set_visible(0)
WIDTH = 800
vel = 5
width = 64
keys = pygame.key.get_pressed()
BLACK = (0, 0, 0)

all_sprites = pygame.sprite.Group()
class Player(pygame.sprite.Sprite):
def _init_(self):
pygame.sprite.Sprite._init_(self)
self.image = pygame.image.load("imagesship.png")
self.rect = self.image.get_rect()
self.rect.center = (WIDTH/2, 40)
def update(self, keys, *args):
if keys[pygame.K_LEFT] and self.rect.x > vel:
self.rect.x -= vel
if keys[pygame.K_RIGHT] and self.rect.x < 800 - width - vel:
self.rect.x += vel
screen.blit(self.image, self.rect)

player = Player()
all_sprites.add(player)

run = True
while run:
pygame.time.delay(100)
pygame.display.update()
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
all_sprites.update()

screen.fill(BLACK)
all_sprites.draw(screen)

pygame.display


pygame.quit()


I know this is just the beginning but I can't figure out what I'm missing here.










share|improve this question
























  • def update(self, keys, *args): vs all_sprites.update() .. which calls your sprites update function but does not get any params to pass around.

    – Patrick Artner
    Mar 26 at 21:32






  • 1





    It has to be __init__ rather than _init_

    – Rabbid76
    Mar 26 at 21:33











  • how-to-make-a-pygame-sprite-group-move

    – Patrick Artner
    Mar 26 at 21:33


















0















I am beginning to code a space invaders game and trying to just get the ship down and let it move back and forth across the screen. I'm very beginner status so it is a big challenge for me. Whenever I try to run it it tells me that I'm requiring another positional argument in my update function but I don't understand what I'm supposed to do.



I've tried moving around the variable initialization for keys but it hasn't changed anything. If anyone wants to take a look at my code and tell me what I could do it would be amazing.



import pygame, sys
from pygame import *
pygame.init()
screen = pygame.display.set_mode((800,600))
pygame.display.set_caption("Space Invaders")
pygame.mouse.set_visible(0)
WIDTH = 800
vel = 5
width = 64
keys = pygame.key.get_pressed()
BLACK = (0, 0, 0)

all_sprites = pygame.sprite.Group()
class Player(pygame.sprite.Sprite):
def _init_(self):
pygame.sprite.Sprite._init_(self)
self.image = pygame.image.load("imagesship.png")
self.rect = self.image.get_rect()
self.rect.center = (WIDTH/2, 40)
def update(self, keys, *args):
if keys[pygame.K_LEFT] and self.rect.x > vel:
self.rect.x -= vel
if keys[pygame.K_RIGHT] and self.rect.x < 800 - width - vel:
self.rect.x += vel
screen.blit(self.image, self.rect)

player = Player()
all_sprites.add(player)

run = True
while run:
pygame.time.delay(100)
pygame.display.update()
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
all_sprites.update()

screen.fill(BLACK)
all_sprites.draw(screen)

pygame.display


pygame.quit()


I know this is just the beginning but I can't figure out what I'm missing here.










share|improve this question
























  • def update(self, keys, *args): vs all_sprites.update() .. which calls your sprites update function but does not get any params to pass around.

    – Patrick Artner
    Mar 26 at 21:32






  • 1





    It has to be __init__ rather than _init_

    – Rabbid76
    Mar 26 at 21:33











  • how-to-make-a-pygame-sprite-group-move

    – Patrick Artner
    Mar 26 at 21:33














0












0








0








I am beginning to code a space invaders game and trying to just get the ship down and let it move back and forth across the screen. I'm very beginner status so it is a big challenge for me. Whenever I try to run it it tells me that I'm requiring another positional argument in my update function but I don't understand what I'm supposed to do.



I've tried moving around the variable initialization for keys but it hasn't changed anything. If anyone wants to take a look at my code and tell me what I could do it would be amazing.



import pygame, sys
from pygame import *
pygame.init()
screen = pygame.display.set_mode((800,600))
pygame.display.set_caption("Space Invaders")
pygame.mouse.set_visible(0)
WIDTH = 800
vel = 5
width = 64
keys = pygame.key.get_pressed()
BLACK = (0, 0, 0)

all_sprites = pygame.sprite.Group()
class Player(pygame.sprite.Sprite):
def _init_(self):
pygame.sprite.Sprite._init_(self)
self.image = pygame.image.load("imagesship.png")
self.rect = self.image.get_rect()
self.rect.center = (WIDTH/2, 40)
def update(self, keys, *args):
if keys[pygame.K_LEFT] and self.rect.x > vel:
self.rect.x -= vel
if keys[pygame.K_RIGHT] and self.rect.x < 800 - width - vel:
self.rect.x += vel
screen.blit(self.image, self.rect)

player = Player()
all_sprites.add(player)

run = True
while run:
pygame.time.delay(100)
pygame.display.update()
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
all_sprites.update()

screen.fill(BLACK)
all_sprites.draw(screen)

pygame.display


pygame.quit()


I know this is just the beginning but I can't figure out what I'm missing here.










share|improve this question














I am beginning to code a space invaders game and trying to just get the ship down and let it move back and forth across the screen. I'm very beginner status so it is a big challenge for me. Whenever I try to run it it tells me that I'm requiring another positional argument in my update function but I don't understand what I'm supposed to do.



I've tried moving around the variable initialization for keys but it hasn't changed anything. If anyone wants to take a look at my code and tell me what I could do it would be amazing.



import pygame, sys
from pygame import *
pygame.init()
screen = pygame.display.set_mode((800,600))
pygame.display.set_caption("Space Invaders")
pygame.mouse.set_visible(0)
WIDTH = 800
vel = 5
width = 64
keys = pygame.key.get_pressed()
BLACK = (0, 0, 0)

all_sprites = pygame.sprite.Group()
class Player(pygame.sprite.Sprite):
def _init_(self):
pygame.sprite.Sprite._init_(self)
self.image = pygame.image.load("imagesship.png")
self.rect = self.image.get_rect()
self.rect.center = (WIDTH/2, 40)
def update(self, keys, *args):
if keys[pygame.K_LEFT] and self.rect.x > vel:
self.rect.x -= vel
if keys[pygame.K_RIGHT] and self.rect.x < 800 - width - vel:
self.rect.x += vel
screen.blit(self.image, self.rect)

player = Player()
all_sprites.add(player)

run = True
while run:
pygame.time.delay(100)
pygame.display.update()
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
all_sprites.update()

screen.fill(BLACK)
all_sprites.draw(screen)

pygame.display


pygame.quit()


I know this is just the beginning but I can't figure out what I'm missing here.







python keyboard pygame self






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 26 at 21:22









Naruto AbidalNaruto Abidal

324 bronze badges




324 bronze badges















  • def update(self, keys, *args): vs all_sprites.update() .. which calls your sprites update function but does not get any params to pass around.

    – Patrick Artner
    Mar 26 at 21:32






  • 1





    It has to be __init__ rather than _init_

    – Rabbid76
    Mar 26 at 21:33











  • how-to-make-a-pygame-sprite-group-move

    – Patrick Artner
    Mar 26 at 21:33


















  • def update(self, keys, *args): vs all_sprites.update() .. which calls your sprites update function but does not get any params to pass around.

    – Patrick Artner
    Mar 26 at 21:32






  • 1





    It has to be __init__ rather than _init_

    – Rabbid76
    Mar 26 at 21:33











  • how-to-make-a-pygame-sprite-group-move

    – Patrick Artner
    Mar 26 at 21:33

















def update(self, keys, *args): vs all_sprites.update() .. which calls your sprites update function but does not get any params to pass around.

– Patrick Artner
Mar 26 at 21:32





def update(self, keys, *args): vs all_sprites.update() .. which calls your sprites update function but does not get any params to pass around.

– Patrick Artner
Mar 26 at 21:32




1




1





It has to be __init__ rather than _init_

– Rabbid76
Mar 26 at 21:33





It has to be __init__ rather than _init_

– Rabbid76
Mar 26 at 21:33













how-to-make-a-pygame-sprite-group-move

– Patrick Artner
Mar 26 at 21:33






how-to-make-a-pygame-sprite-group-move

– Patrick Artner
Mar 26 at 21:33













1 Answer
1






active

oldest

votes


















1














You've to pass the current states of the keyboard buttons to .update().
Note, the arguments which are passed to all_sprites.update() are delegated to player.update(). all_sprites is pygame.sprite.Group object. The .update() method calls .update() on each contained sprite and pass the parameters through.



Get the states of the keyboard buttons by pygame.key.get_pressed() and pass it to .update:



keys = pygame.key.get_pressed()
all_sprites.update(keys)



The name of the constructor has to be __init__ rather than _init_ . See Class:



class Player(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
# [...]





share|improve this answer



























  • the error is still there unfortunately

    – Naruto Abidal
    Mar 26 at 22:06











  • Ah, there we go. Sorry I made a typo, thank you very much.

    – Naruto Abidal
    Mar 26 at 22:10











  • of course, new to this website as well.

    – Naruto Abidal
    Mar 26 at 22:15






  • 1





    @NarutoAbidal Thank you. You're welcome.

    – Rabbid76
    Mar 26 at 22:15










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55366391%2fbeginning-space-invaders-code-and-requiring-assistance-with-a-part-of-it%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














You've to pass the current states of the keyboard buttons to .update().
Note, the arguments which are passed to all_sprites.update() are delegated to player.update(). all_sprites is pygame.sprite.Group object. The .update() method calls .update() on each contained sprite and pass the parameters through.



Get the states of the keyboard buttons by pygame.key.get_pressed() and pass it to .update:



keys = pygame.key.get_pressed()
all_sprites.update(keys)



The name of the constructor has to be __init__ rather than _init_ . See Class:



class Player(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
# [...]





share|improve this answer



























  • the error is still there unfortunately

    – Naruto Abidal
    Mar 26 at 22:06











  • Ah, there we go. Sorry I made a typo, thank you very much.

    – Naruto Abidal
    Mar 26 at 22:10











  • of course, new to this website as well.

    – Naruto Abidal
    Mar 26 at 22:15






  • 1





    @NarutoAbidal Thank you. You're welcome.

    – Rabbid76
    Mar 26 at 22:15















1














You've to pass the current states of the keyboard buttons to .update().
Note, the arguments which are passed to all_sprites.update() are delegated to player.update(). all_sprites is pygame.sprite.Group object. The .update() method calls .update() on each contained sprite and pass the parameters through.



Get the states of the keyboard buttons by pygame.key.get_pressed() and pass it to .update:



keys = pygame.key.get_pressed()
all_sprites.update(keys)



The name of the constructor has to be __init__ rather than _init_ . See Class:



class Player(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
# [...]





share|improve this answer



























  • the error is still there unfortunately

    – Naruto Abidal
    Mar 26 at 22:06











  • Ah, there we go. Sorry I made a typo, thank you very much.

    – Naruto Abidal
    Mar 26 at 22:10











  • of course, new to this website as well.

    – Naruto Abidal
    Mar 26 at 22:15






  • 1





    @NarutoAbidal Thank you. You're welcome.

    – Rabbid76
    Mar 26 at 22:15













1












1








1







You've to pass the current states of the keyboard buttons to .update().
Note, the arguments which are passed to all_sprites.update() are delegated to player.update(). all_sprites is pygame.sprite.Group object. The .update() method calls .update() on each contained sprite and pass the parameters through.



Get the states of the keyboard buttons by pygame.key.get_pressed() and pass it to .update:



keys = pygame.key.get_pressed()
all_sprites.update(keys)



The name of the constructor has to be __init__ rather than _init_ . See Class:



class Player(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
# [...]





share|improve this answer















You've to pass the current states of the keyboard buttons to .update().
Note, the arguments which are passed to all_sprites.update() are delegated to player.update(). all_sprites is pygame.sprite.Group object. The .update() method calls .update() on each contained sprite and pass the parameters through.



Get the states of the keyboard buttons by pygame.key.get_pressed() and pass it to .update:



keys = pygame.key.get_pressed()
all_sprites.update(keys)



The name of the constructor has to be __init__ rather than _init_ . See Class:



class Player(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
# [...]






share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 26 at 22:35

























answered Mar 26 at 21:35









Rabbid76Rabbid76

55.8k12 gold badges37 silver badges67 bronze badges




55.8k12 gold badges37 silver badges67 bronze badges















  • the error is still there unfortunately

    – Naruto Abidal
    Mar 26 at 22:06











  • Ah, there we go. Sorry I made a typo, thank you very much.

    – Naruto Abidal
    Mar 26 at 22:10











  • of course, new to this website as well.

    – Naruto Abidal
    Mar 26 at 22:15






  • 1





    @NarutoAbidal Thank you. You're welcome.

    – Rabbid76
    Mar 26 at 22:15

















  • the error is still there unfortunately

    – Naruto Abidal
    Mar 26 at 22:06











  • Ah, there we go. Sorry I made a typo, thank you very much.

    – Naruto Abidal
    Mar 26 at 22:10











  • of course, new to this website as well.

    – Naruto Abidal
    Mar 26 at 22:15






  • 1





    @NarutoAbidal Thank you. You're welcome.

    – Rabbid76
    Mar 26 at 22:15
















the error is still there unfortunately

– Naruto Abidal
Mar 26 at 22:06





the error is still there unfortunately

– Naruto Abidal
Mar 26 at 22:06













Ah, there we go. Sorry I made a typo, thank you very much.

– Naruto Abidal
Mar 26 at 22:10





Ah, there we go. Sorry I made a typo, thank you very much.

– Naruto Abidal
Mar 26 at 22:10













of course, new to this website as well.

– Naruto Abidal
Mar 26 at 22:15





of course, new to this website as well.

– Naruto Abidal
Mar 26 at 22:15




1




1





@NarutoAbidal Thank you. You're welcome.

– Rabbid76
Mar 26 at 22:15





@NarutoAbidal Thank you. You're welcome.

– Rabbid76
Mar 26 at 22:15








Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55366391%2fbeginning-space-invaders-code-and-requiring-assistance-with-a-part-of-it%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현