-1

Im a beginner pygameneer and im making this sweet space invaders type game called mooshalot escape, the point being that you will get to become a mooshalot and fight the evils that threaten the condition of the mooshalots, its a self project to help me become a better programmer, (of course its a free game so when done ill post it lols) The point being I'm having trouble opening my game, the code runs properly, but the screen is the main issue, I don't think I did a good job connecting the screen, could someone take a look would really appreciate the help and input in any shape or format, regards


import sys

import pygame

from settings import Settings
from Mooshipclassr import Mooship
from Mooshammo import Mooshammo


class MooshalotEscape:

    def __init__(self):
        pygame.init()
        self.settings = Settings()
        self.screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
        self.settings.screen_width = self.screen.get_rect().width
        self.settings.screen_height = self.screen.get_rect().height
        pygame.display.set_caption('Mooshalot Escape')
        self.bg_color = (106, 228, 241)
        self.mooship = Mooship(self)
        self.bullets = pygame.sprite.Group()

    def run_game(self):
        while True:
            self._check_events()
            self.mooship.update()
            self.bullets.update()
            self._update_screen()

    def _check_events(self):
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
            elif event.type == pygame.KEYDOWN:
                self._check_keydown_events(event)
            elif event.type == pygame.KEYUP:
                self._check_keyup_events(event)

    def _check_keydown_events(self, event):
        if event.key == pygame.K_RIGHT:
            self.mooship.moving_right = True
        elif event.key == pygame.K_LEFT:
            self.mooship.moving_left = True
        elif event.key == pygame.K_q:
            sys.exit()
        elif event.key == pygame.K_SPACE:
            self._fire_mooshammo()

    def _check_keyup_events(self, event):
        if event.key == pygame.K_RIGHT:
            self.mooship.moving_right = False
        elif event.key == pygame.K_LEFT:
            self.mooship.moving_left = False

    def _fire_mooshammo(self):
        new_mooshammo = Mooshammo(self)
        self.bullets.add(new_mooshammo)

    def _update_screen(self):
        self.screen.fill(self.bg_color)
        self.mooship.blitme()

        pygame.display.flip()


if __name__ == 'main':
    ai = MooshalotEscape()
    ai.run_game()


'''settings class'''

    class Settings:
    def __init__(self):
        self.screen_width = 1200
        self.screen_height = 800
        self.bg_color = (106, 228, 241)
        self.mooship_speed = 1.5
        self.mooshammo_speed = 1.0
        self.mooshammo_width = 3
        self.mooshammo_height = 15
        self.mooshammo_color = (60, 60, 60)


  • 1
    what exactly is the issue with the screen? what do you mean by _I don't think I did a good job connecting the screen_? – Matiiss Nov 15 '21 at 19:49
  • There is nothing wrong with this code (as far I can see). Do you get any error message? Is it a problem with your system? – Rabbid76 Nov 15 '21 at 19:51
  • Thought i might have had an error due to the screen it says '''pygame 2.1.0 (SDL 2.0.16, Python 3.9.7) Hello from the pygame community. https://www.pygame.org/contribute.html''' – LJ Castellanos Nov 15 '21 at 20:37
  • there's no errors with the code so far but the screen is just not opening, i looked through it for quite some hours now and yup nothing so far for the mooshalots – LJ Castellanos Nov 15 '21 at 20:41
  • 1
    So it's a problem with your system, not your code. – Rabbid76 Nov 15 '21 at 21:01
  • maybe first use `print()` to see which part of code is executed and what you have in variables - it is called `"print debuging"`. It can help you to see where can be the problem. – furas Nov 15 '21 at 21:21
  • damn bro, nothing works so far :/ I'll move on to system check – LJ Castellanos Nov 15 '21 at 22:46

0 Answers0