コード例 #1
0
ファイル: game3.py プロジェクト: Steven24K/PygamePython
    def __init__(self, title, width, height):
        self.Title = title
        self.Height = height
        self.Width = width
        self.Screen = pygame.display.set_mode((self.Width, self.Height))

        #This is to initialize the framerate (fps)
        self.Clock = pygame.time.Clock()

        #This color is a refrence to the color object, in there all different colors are defined
        self.Color = clr.Color()
        self.DefaultFont = pygame.font.SysFont(None, 30)

        #Initialize text messages
        self.StartText = Text.Text(
            self.Color.Black, self.DefaultFont,
            "Make the player move on the screen, up, down, left and right!")
        self.NextLine = Text.Text(
            self.Color.Black, self.DefaultFont,
            "Why do the same thing over and over again when it allready exists!!!"
        )

        #Create all game characters here
        self.Player1 = c.Component(c.Position(400, 100), "enemy.png")
        self.Apple = c.Component(c.Position(0, 0), "apple.png")

        self.AppleCounter = 0
        self.Score = Text.Text(self.Color.Black, self.DefaultFont,
                               "Apple Counter: " + str(self.AppleCounter))
コード例 #2
0
    def update(self):
        #Your update logic here
        keys = pygame.key.get_pressed()

        if keys[pygame.K_LEFT]:
            self.Car.update(-10, 0)
        if keys[pygame.K_RIGHT]:
            self.Car.update(10, 0)

        self.Car.horizontal_screen_wrap(self.Width)

        if len(self.Obstacles) < 1:
            self.Obstacles.append(
                c.Component(c.Position(random.randint(20, self.Width - 40), 0),
                            "truck.jpg"))

        for obstacle in self.Obstacles:
            obstacle.update(0, 20)
            if obstacle.ImageRect.y > self.Height:
                self.Obstacles.remove(obstacle)
            if self.Car.intersection(obstacle.ImageRect.x,
                                     obstacle.ImageRect.y,
                                     obstacle.ImageRect.height,
                                     obstacle.ImageRect.height):
                print("Game Over")
                sys.exit()
コード例 #3
0
ファイル: game1.py プロジェクト: Steven24K/PygamePython
    def __init__(self, title, width, height):
        self.Title = title
        self.Height = height
        self.Width = width
        self.Screen = pygame.display.set_mode((self.Width, self.Height))

        #This is to initialize the framerate (fps)
        self.Clock = pygame.time.Clock()

        #This color is a refrence to the color object, in there all different colors are defined
        self.Color = clr.Color()
        self.DefaultFont = pygame.font.SysFont(None, 30)

        #Initialize text messages
        self.StartText = Text.Text(self.Color.Black, self.DefaultFont,
                                   "Welcom to my pygame template!!!")

        #Initialize the soundprovider
        self.BackgroundMusic = sp.SoundProvider(
            "9th_Symphony_Finale_by_Beethoven.mp3")
        #Set the background music to play
        self.BackgroundMusic.Play(5)

        #Create all game characters here
        self.Player1 = c.Component(c.Position(400, 100), "enemy.png")

        #Create a button
        self.ExitButton = button.Button(
            300, 250, 50, 200, self.Color.Red,
            Text.Text(self.Color.Black, self.DefaultFont, "Exit"),
            lambda: sys.exit())
        self.StartButton = button.Button(
            600, 250, 50, 200, self.Color.Green,
            Text.Text(self.Color.Black, self.DefaultFont, "Start"))
コード例 #4
0
    def update(self):
        #Get keyboard input, checks if a certain key is pressed or not and get mouse Position
        keys = pygame.key.get_pressed()

        #Player opperations
        self.Player1.gravity(self.Height, 10)
        if keys[pygame.K_SPACE] and self.Player1.ImageRect.y > 0:
            self.Player1.jump(20, self.Height)

        #Enemy opperations
        if len(self.Enemies) < 1:
            self.Enemies.append(
                c.Component(c.Position(self.Width - 100, 300), "knight.png"))

        for enemy in self.Enemies:
            enemy.gravity(self.Height, 10)
            enemy.update(-25, 0)

            if enemy.ImageRect.x < 0: self.Enemies.remove(enemy)
            if enemy.intersection(self.Player1.ImageRect.x,
                                  self.Player1.ImageRect.y,
                                  self.Player1.ImageRect.height,
                                  self.Player1.ImageRect.width):
                self.Player1.Score -= 1
                self.Player1.jump(200, self.Height)
            if enemy.ImageRect.x == self.Player1.ImageRect.x:
                self.Player1.Score += 1
コード例 #5
0
    def __init__(self, title, width, height):
        #The basic parameters wich make up the game
        self.Title = title
        self.Height = height
        self.Width = width
        self.Screen = pygame.display.set_mode((self.Width, self.Height))

        #This is to initialize the framerate (fps)
        self.Clock = pygame.time.Clock()

        #This color is a refrence to the color object, in there all different colors are defined
        self.Color = clr.Color()
        self.DefaultFont = pygame.font.SysFont(None, 30)

        self.InfoText = Text.Text(
            self.Color.Black, self.DefaultFont,
            "Score 3 points to go to the next level, press space to fly!")

        #Create all game characters here
        self.Player1 = c.Component(c.Position(400, 250), "enemy.png")

        #Empty list of enemies, this will be filled during the game
        #This is a special kind of list called an array, each element in the array has an unique Index
        #indeces start from 0, by calling Enemies[3] you call enemy in position number 3
        #!!!!BECAREFULL WITH THE BOUNDS: When the index does not exist you will get an error, always check if the IndexError
        #exists before calling it.
        self.Enemies = []
コード例 #6
0
    def __init__(self, title, width, height):
        self.Title = title
        self.Height = height
        self.Width = width
        self.Screen = pygame.display.set_mode((self.Width, self.Height))

        self.DefaultFont = pygame.font.SysFont(None, 30)

        #This color is a refrence to the color object, in there all different colors are defined
        self.Color = clr.Color()

        #Initlialize sound provider
        self.CrashSound = sp.SoundProvider("Crash.mp3")

        #Create all game characters here
        self.Player1 = c.Component(c.Position(200, 250), "knight.png")

        #This is a list/array of all enemies, at initialization there is only one enemy in the list
        self.Enemies = []
        self.Enemies.append(c.Component(c.Position(50, 250), "enemy.png"))
コード例 #7
0
ファイル: game7.py プロジェクト: Steven24K/PygamePython
    def __init__(self, title, width, height):
        self.Title = title
        self.Height = height
        self.Width = width
        self.Screen = pygame.display.set_mode((self.Width, self.Height))

        self.DefaultFont = pygame.font.SysFont(None, 30)

        #This color is a refrence to the color object, in there all different colors are defined
        self.Color = clr.Color()

        #Create all game characters here
        self.Player1 = c.Component(c.Position(200, 250), "giphy.gif")
コード例 #8
0
ファイル: main.py プロジェクト: RimorRes/6dof_rocket_sim
def main():
    initial_state = {
        "xpos": 0,
        "ypos": 0,
        "zpos": 0,
        "xvel": 0,
        "yvel": 0,
        "zvel": 0,
        "xacc": 0,
        "yacc": 0,
        "zacc": 0,
        "theta_roll": 0,
        "theta_pitch": 0,
        "theta_yaw": 0,
        "omega_roll": 0,
        "omega_pitch": 0,
        "omega_yaw": 0,
        "alpha_roll": 0,
        "alpha_pitch": 0,
        "alpha_yaw": 0,
        "time": 0,
    }
    vehicle_state = st.State(initial_state)

    # TODO add some sort of environment class

    # make the rocket object for position referencing
    vehicle = ro.Rocket(vehicle_state)
    # generate the structural components
    structure = co.Component(10, [.1, 0, 0], "structure")
    structure1 = co.Component(10, [.1, 0, 0], "structure1")
    structure2 = co.Component(10, [.1, 0, 0], "structure2")
    structure3 = co.Component(10, [.1, 0, 0], "structure3")
    vehicle.add_components(structure, structure1, structure2, structure3)
    sensor1 = co.Sensor('accel', [0, 10], structure2)
    vehicle.add_components(sensor1)
    print(vehicle.get_components())
    print(vehicle.get_state()['xpos'])
コード例 #9
0
    def __init__(self, title, width, height):
        self.Title = title
        self.Height = height
        self.Width = width
        self.Screen = pygame.display.set_mode((self.Width, self.Height))

        #This is to initialize the framerate (fps)
        self.Clock = pygame.time.Clock()

        #This color is a refrence to the color object, in there all different colors are defined
        self.Color = clr.Color()
        self.DefaultFont = pygame.font.SysFont(None, 30)

        #Images
        self.Car = c.Component(c.Position(500, 500), "car.jpg")
        self.Obstacles = []
コード例 #10
0
    def run(self):
        #Game does not have an end yet
        while True:
            for event in pygame.event.get():
                if event.type == pygame.QUIT: sys.exit()

            #Set the background color of the pygame window, HINT: See what happens when you remove this line
            self.Screen.fill(self.Color.White)

            #Get keyboard input, checks if a certain key is pressed or not
            keys = pygame.key.get_pressed()

            #Player opperations, draw, update, set gravity, wrap screen and display score
            self.Player1.draw(self.Screen)
            self.Player1.horizontal_screen_wrap(self.Width)
            self.Player1.vertical_screen_wrap(self.Height)
            self.Player1.display_score(self.Screen, self.DefaultFont,
                                       self.Color.Green)
            self.Player1.display_position(self.Screen, self.DefaultFont,
                                          self.Color.Blue)

            #Keyboard checks if a certain key is pressed the player will respond to that
            if keys[pygame.K_LEFT]:
                self.Player1.update(-2, 0)
            if keys[pygame.K_RIGHT]:
                self.Player1.update(2, 0)
            if keys[pygame.K_UP]:
                self.Player1.update(0, -2)
            if keys[pygame.K_DOWN]:
                self.Player1.update(0, 2)

            #This for-loop draws all enemies on the screen and checks for all enemies if the main player has an intersection with
            #on of them,
            for enemy in self.Enemies:
                enemy.draw(self.Screen)
                if self.Player1.intersection(enemy.ImageRect.x,
                                             enemy.ImageRect.y,
                                             enemy.ImageRect.height,
                                             enemy.ImageRect.width):
                    self.CrashSound.Play(1)
                    self.Player1.Score += 1
                    enemy.ImageRect.x = random.randint(
                        0, self.Width - enemy.ImageRect.width)
                    enemy.ImageRect.y = random.randint(
                        0, self.Height - enemy.ImageRect.height)
                    self.Enemies.append(
                        c.Component(
                            c.Position(
                                random.randint(
                                    0, self.Width - enemy.ImageRect.width),
                                random.randint(
                                    0, self.Height - enemy.ImageRect.height)),
                            "enemy.png"))

            #Clears the enemy list if it becomes to big, if there to many enemies the game will become slow,
            #Question to ask yourself: Why is the game becomming slow if there are to many enemies?
            #Todo: Is there a way to fix this?
            if len(self.Enemies) > 10:
                self.Enemies.clear()
                self.Enemies.append(
                    c.Component(
                        c.Position(
                            random.randint(0,
                                           self.Width - enemy.ImageRect.width),
                            random.randint(
                                0, self.Height - enemy.ImageRect.height)),
                        "enemy.png"))

            pygame.display.flip()
            pygame.display.set_caption(self.Title)
コード例 #11
0
 def get_component(self):
     return components.Component()