ef:gameprojekt:gruppenseiten:gruppe4:start

Dies ist eine alte Version des Dokuments!


Jérôme, Michael, Joël

Breaking Bad Game Unser Plan ist es ein Spiel im Breaking Bad Theme zu machen, in dem man ähnlich wie in Super Mario Bros. Level bestreiten muss.

Quellen und Hilfsmittel https://www.remove.bg/de https://api.arcade.academy/en/latest/examples/pymunk_box_stacks.html#pymunk-box-stacks

import random import arcade import os #import pymunk import math

SPRITE_SCALING = 0.5 SCREEN_WIDTH = 1200 SCREEN_HEIGHT = 800 SCREEN_TITLE = „Walter_White“ BULLET_SPEED = 4

MOVEMENT_SPEED = 5

class Player(arcade.Sprite):

  def update(self):

self.center_x += self.change_x

      self.center_y += self.change_y

if self.left < 0:

          self.left = 0
      elif self.right > SCREEN_WIDTH - 1:
          self.right = SCREEN_WIDTH - 1

if self.bottom < 0:

          self.bottom = 0
      elif self.top > SCREEN_HEIGHT - 1:
          self.top = SCREEN_HEIGHT - 1

class Enemy(arcade.Sprite):

  def update(self):
      
      self.center_x += self.change_x
      self.center_y += self.change_y

if self.left < 0:

          self.left = 0
      elif self.right > SCREEN_WIDTH - 1:
          self.right = SCREEN_WIDTH - 1

if self.bottom < 0:

          self.bottom = 0
      elif self.top > SCREEN_HEIGHT - 1:
          self.top = SCREEN_HEIGHT - 1

class MyGame(arcade.Window):

def init(self, width, height, title):

      super().__init__(width, height, title)
      self.player_list = None
      self.player_sprite = None
      self.physics_engine = None
      self.background = None
      self.enemy_list = None
      self.enemy_sprite = None
      self.bullet_list = None
      self.frame_count = None
      
      """floor_height = 120
      body = pymunk.Body(body_type=pymunk.Body.STATIC)
      shape = pymunk.Segment(body, [0, floor_height], [SCREEN_WIDTH, floor_height], 0.0)
      shape.friction = 10
      self.space.add(shape, body)
      self.static_lines.append(shape)"""
  def setup(self):
      self.player_list = arcade.SpriteList()
      self.player_sprite = Player("walter.png", SPRITE_SCALING)
      self.player_sprite.center_x = 50
      self.player_sprite.center_y = 125
      self.player_list.append(self.player_sprite)
  
      self.background = arcade.load_texture(":resources:images/backgrounds/desert.jpg")
      self.enemy_list = arcade.SpriteList()
      self.enemy_sprite = arcade.Sprite("gus.png", SPRITE_SCALING)
      self.enemy_sprite.center_x = 750
      self.enemy_sprite.center_y = 120
      self.enemy_list.append(self.enemy_sprite)
      self.enemy_sprite.angle = 180
      self.bullet_list = arcade.SpriteList()
  def on_draw(self):
      self.clear()
      arcade.draw_lrwh_rectangle_textured(0, 0,
                                          SCREEN_WIDTH, SCREEN_HEIGHT,
                                          self.background)
      self.player_list.draw()
      self.enemy_list.draw()
      self.bullet_list.draw()
  def on_update(self, delta_time):
      self.player_list.update()
      self.enemy_list.update()
      self.frame_count += 1
      for self.enemy_sprite in self.enemy_list:
          start_x = self.enemy_sprite.center_x
          start_y = self.enemy_sprite.center_y
          dest_x = self.player_sprite.center_x
          dest_y = self.player_sprite.center_y
          x_diff = dest_x - start_x
          y_diff = dest_y - start_y
          angle = math.atan2(y_diff, x_diff)
          self.enemy_sprite.angle = math.degrees(angle) - 90
          if self.frame_count % 60 == 0:
              bullet = arcade.Sprite("bullet.png")
              bullet.center_x = start_x
              bullet.center_y = start_y
              bullet.angle = math.degrees(angle)
              bullet.change_x = math.cos(angle) * BULLET_SPEED
              bullet.change_y = math.sin(angle) * BULLET_SPEED
              self.bullet_list.append(bullet)
      for bullet in self.bullet_list:
          if bullet.top < 0:
              bullet.remove_from_SpriteList()
      self.bullet_list.update()
  def on_mouse_motion(self, x, y, dx, dy):
      self.player_sprite.center_x = x
      self.player_sprite.center_y = y

def on_key_press(self, symbol, modifiers):

      if symbol == arcade.key.UP:
          self.player_sprite.change_y = MOVEMENT_SPEED

elif symbol == arcade.key.DOWN:

          self.player_sprite.change_y = -MOVEMENT_SPEED

elif symbol == arcade.key.LEFT:

          self.player_sprite.change_x = -MOVEMENT_SPEED

elif symbol == arcade.key.RIGHT:

          self.player_sprite.change_x = MOVEMENT_SPEED

def on_key_release(self, symbol, modifiers):

  if symbol == arcade.key.UP or symbol == arcade.key.DOWN:
      self.player_sprite.change_y = 0
  elif symbol == arcade.key.LEFT or symbol == arcade.key.RIGHT:
      self.player_sprite.change_x = 0

def main():

  window = MyGame(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE)
  window.setup()
  arcade.run()

if name == „main“:

  main()    
  • ef/gameprojekt/gruppenseiten/gruppe4/start.1673357408.txt.gz
  • Zuletzt geändert: 2023/01/10 14:30
  • von siffertj