#YKYG WORM expansion ( Interview Question )
Anonymous Quiz
57%
Write once read many
34%
Write on RAM memory
9%
Write on ROM memory
AK Python
Photo
Game development tutorial video is in editing progress.Tommorow i will upload on YouTube channel so staytuned.
Subscribe..!
Subscribe..!
import arcade
# Constants
SCREEN_WIDTH = 1280
SCREEN_HEIGHT = 720
SCREEN_TITLE = "My Game"
# Constants used to scale our sprites from their original size
CHARACTER_SCALING = 0.8
TILE_SCALING = 0.5
COIN_SCALING = 0.7
# Movement speed of player, in pixels per frame
PLAYER_MOVEMENT_SPEED = 5
GRAVITY = 1
PLAYER_JUMP_SPEED = 20
# How many pixels to keep as a minimum margin between the character
# and the edge of the screen.
LEFT_VIEWPORT_MARGIN = 250
RIGHT_VIEWPORT_MARGIN = 250
BOTTOM_VIEWPORT_MARGIN = 50
TOP_VIEWPORT_MARGIN = 100
class MyGame(arcade.Window):
"""
Main application class.
"""
def init(self):
# Call the parent class and set up the window
super().init(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE)
# These are 'lists' that keep track of our sprites. Each sprite should
# go into a list.
self.coin_list = None
self.wall_list = None
self.player_list = None
self.exit_list= None
# Separate variable that holds the player sprite
self.player_sprite = None
# Our physics engine
self.physics_engine = None
# Used to keep track of our scrolling
self.view_bottom = 0
self.view_left = 0
# Keep track of the score
self.score = 0
# Load sounds
self.collect_coin_sound = arcade.load_sound(":resources:sounds/coin1.wav")
arcade.set_background_color(arcade.csscolor.POWDER_BLUE)
def setup(self):
""" Set up the game here. Call this function to restart the game. """
# Used to keep track of our scrolling
self.view_bottom = 0
self.view_left = 0
# Keep track of the score
self.score = 0
# Create the Sprite lists
self.player_list = arcade.SpriteList()
self.wall_list = arcade.SpriteList()
self.coin_list = arcade.SpriteList()
self.exit_list=arcade.SpriteList()
# Set up the player, specifically placing it at these coordinates.
image_source = ":resources:images/animated_characters/male_adventurer/maleAdventurer_walk1.png"
self.player_sprite = arcade.Sprite(image_source, CHARACTER_SCALING)
self.player_sprite.center_x = 3
self.player_sprite.center_y = 96
self.player_list.append(self.player_sprite)
exitimage=arcade.Sprite(":resources:images/items/flagGreen1.png")
exitimage.center_x=1280
exitimage.center_y=126
self.exit_list.append(exitimage)
# Create the ground
# This shows using a loop to place multiple sprites horizontally
for x in range(0, 1280,150):
wall = arcade.Sprite(":resources:images/tiles/grassMid.png", TILE_SCALING)
wall.center_x = x
wall.center_y = 32
self.wall_list.append(wall)
# Put some crates on the ground
# This shows using a coordinate list to place sprites
# Use a loop to place some coins for our character to pick up
for x in range(0, 1250, 254):
coin = arcade.Sprite(":resources:images/items/gemBlue.png", COIN_SCALING)
coin.center_x = x
coin.center_y = 80
self.coin_list.append(coin)
# Create the 'physics engine'
self.physics_engine = arcade.PhysicsEnginePlatformer(self.player_sprite,
self.wall_list,
GRAVITY)
def on_draw(self):
""" Render the screen. """
# Clear the screen to the background color
arcade.start_render()
# Draw our sprites
self.wall_list.draw()
self.coin_list.draw()
self.player_list.draw()
self.exit_list.draw()
# Draw our score on the screen, scrolling it with the viewport
score_text = f"Score: {self.score}"
arcade.draw_text(score_text, 10 + self.view_left, 10 + self.view_bottom,
arcade.csscolor.BLUE,18)
# Constants
SCREEN_WIDTH = 1280
SCREEN_HEIGHT = 720
SCREEN_TITLE = "My Game"
# Constants used to scale our sprites from their original size
CHARACTER_SCALING = 0.8
TILE_SCALING = 0.5
COIN_SCALING = 0.7
# Movement speed of player, in pixels per frame
PLAYER_MOVEMENT_SPEED = 5
GRAVITY = 1
PLAYER_JUMP_SPEED = 20
# How many pixels to keep as a minimum margin between the character
# and the edge of the screen.
LEFT_VIEWPORT_MARGIN = 250
RIGHT_VIEWPORT_MARGIN = 250
BOTTOM_VIEWPORT_MARGIN = 50
TOP_VIEWPORT_MARGIN = 100
class MyGame(arcade.Window):
"""
Main application class.
"""
def init(self):
# Call the parent class and set up the window
super().init(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE)
# These are 'lists' that keep track of our sprites. Each sprite should
# go into a list.
self.coin_list = None
self.wall_list = None
self.player_list = None
self.exit_list= None
# Separate variable that holds the player sprite
self.player_sprite = None
# Our physics engine
self.physics_engine = None
# Used to keep track of our scrolling
self.view_bottom = 0
self.view_left = 0
# Keep track of the score
self.score = 0
# Load sounds
self.collect_coin_sound = arcade.load_sound(":resources:sounds/coin1.wav")
arcade.set_background_color(arcade.csscolor.POWDER_BLUE)
def setup(self):
""" Set up the game here. Call this function to restart the game. """
# Used to keep track of our scrolling
self.view_bottom = 0
self.view_left = 0
# Keep track of the score
self.score = 0
# Create the Sprite lists
self.player_list = arcade.SpriteList()
self.wall_list = arcade.SpriteList()
self.coin_list = arcade.SpriteList()
self.exit_list=arcade.SpriteList()
# Set up the player, specifically placing it at these coordinates.
image_source = ":resources:images/animated_characters/male_adventurer/maleAdventurer_walk1.png"
self.player_sprite = arcade.Sprite(image_source, CHARACTER_SCALING)
self.player_sprite.center_x = 3
self.player_sprite.center_y = 96
self.player_list.append(self.player_sprite)
exitimage=arcade.Sprite(":resources:images/items/flagGreen1.png")
exitimage.center_x=1280
exitimage.center_y=126
self.exit_list.append(exitimage)
# Create the ground
# This shows using a loop to place multiple sprites horizontally
for x in range(0, 1280,150):
wall = arcade.Sprite(":resources:images/tiles/grassMid.png", TILE_SCALING)
wall.center_x = x
wall.center_y = 32
self.wall_list.append(wall)
# Put some crates on the ground
# This shows using a coordinate list to place sprites
# Use a loop to place some coins for our character to pick up
for x in range(0, 1250, 254):
coin = arcade.Sprite(":resources:images/items/gemBlue.png", COIN_SCALING)
coin.center_x = x
coin.center_y = 80
self.coin_list.append(coin)
# Create the 'physics engine'
self.physics_engine = arcade.PhysicsEnginePlatformer(self.player_sprite,
self.wall_list,
GRAVITY)
def on_draw(self):
""" Render the screen. """
# Clear the screen to the background color
arcade.start_render()
# Draw our sprites
self.wall_list.draw()
self.coin_list.draw()
self.player_list.draw()
self.exit_list.draw()
# Draw our score on the screen, scrolling it with the viewport
score_text = f"Score: {self.score}"
arcade.draw_text(score_text, 10 + self.view_left, 10 + self.view_bottom,
arcade.csscolor.BLUE,18)
π4
def on_key_press(self, key, modifiers):
"""Called whenever a key is pressed. """
if key == arcade.key.UP or key == arcade.key.W:
if self.physics_engine.can_jump():
self.player_sprite.change_y = PLAYER_JUMP_SPEED
elif key == arcade.key.LEFT or key == arcade.key.A:
self.player_sprite.change_x = -PLAYER_MOVEMENT_SPEED
elif key == arcade.key.RIGHT or key == arcade.key.D:
self.player_sprite.change_x = PLAYER_MOVEMENT_SPEED
def on_key_release(self, key, modifiers):
"""Called when the user releases a key. """
if key == arcade.key.LEFT or key == arcade.key.A:
self.player_sprite.change_x = 0
elif key == arcade.key.RIGHT or key == arcade.key.D:
self.player_sprite.change_x = 0
def on_update(self, delta_time):
""" Movement and game logic """
# Move the player with the physics engine
self.physics_engine.update()
# See if we hit any coins
coin_hit_list = arcade.check_for_collision_with_list(self.player_sprite,
self.coin_list)
# Loop through each coin we hit (if any) and remove it
for coin in coin_hit_list:
# Remove the coin
coin.remove_from_sprite_lists()
# Play a sound
arcade.play_sound(self.collect_coin_sound)
# Add one to the score
self.score += 1
# --- Manage Scrolling ---
# Track if we need to change the viewport
changed = False
# Scroll left
left_boundary = self.view_left + LEFT_VIEWPORT_MARGIN
if self.player_sprite.left < left_boundary:
self.view_left -= left_boundary - self.player_sprite.left
changed = True
# Scroll right
right_boundary = self.view_left + SCREEN_WIDTH - RIGHT_VIEWPORT_MARGIN
if self.player_sprite.right > right_boundary:
self.view_left += self.player_sprite.right - right_boundary
changed = True
# Scroll up
top_boundary = self.view_bottom + SCREEN_HEIGHT - TOP_VIEWPORT_MARGIN
if self.player_sprite.top > top_boundary:
self.view_bottom += self.player_sprite.top - top_boundary
changed = True
# Scroll down
bottom_boundary = self.view_bottom + BOTTOM_VIEWPORT_MARGIN
if self.player_sprite.bottom < bottom_boundary:
self.view_bottom -= bottom_boundary - self.player_sprite.bottom
changed = True
if changed:
# Only scroll to integers. Otherwise we end up with pixels that
# don't line up on the screen
self.view_bottom = int(self.view_bottom)
self.view_left = int(self.view_left)
# Do the scrolling
arcade.set_viewport(self.view_left,
SCREEN_WIDTH + self.view_left,
self.view_bottom,
SCREEN_HEIGHT + self.view_bottom)
def main():
""" Main method """
window = MyGame()
window.setup()
arcade.run()
if name == "main":
main()
"""Called whenever a key is pressed. """
if key == arcade.key.UP or key == arcade.key.W:
if self.physics_engine.can_jump():
self.player_sprite.change_y = PLAYER_JUMP_SPEED
elif key == arcade.key.LEFT or key == arcade.key.A:
self.player_sprite.change_x = -PLAYER_MOVEMENT_SPEED
elif key == arcade.key.RIGHT or key == arcade.key.D:
self.player_sprite.change_x = PLAYER_MOVEMENT_SPEED
def on_key_release(self, key, modifiers):
"""Called when the user releases a key. """
if key == arcade.key.LEFT or key == arcade.key.A:
self.player_sprite.change_x = 0
elif key == arcade.key.RIGHT or key == arcade.key.D:
self.player_sprite.change_x = 0
def on_update(self, delta_time):
""" Movement and game logic """
# Move the player with the physics engine
self.physics_engine.update()
# See if we hit any coins
coin_hit_list = arcade.check_for_collision_with_list(self.player_sprite,
self.coin_list)
# Loop through each coin we hit (if any) and remove it
for coin in coin_hit_list:
# Remove the coin
coin.remove_from_sprite_lists()
# Play a sound
arcade.play_sound(self.collect_coin_sound)
# Add one to the score
self.score += 1
# --- Manage Scrolling ---
# Track if we need to change the viewport
changed = False
# Scroll left
left_boundary = self.view_left + LEFT_VIEWPORT_MARGIN
if self.player_sprite.left < left_boundary:
self.view_left -= left_boundary - self.player_sprite.left
changed = True
# Scroll right
right_boundary = self.view_left + SCREEN_WIDTH - RIGHT_VIEWPORT_MARGIN
if self.player_sprite.right > right_boundary:
self.view_left += self.player_sprite.right - right_boundary
changed = True
# Scroll up
top_boundary = self.view_bottom + SCREEN_HEIGHT - TOP_VIEWPORT_MARGIN
if self.player_sprite.top > top_boundary:
self.view_bottom += self.player_sprite.top - top_boundary
changed = True
# Scroll down
bottom_boundary = self.view_bottom + BOTTOM_VIEWPORT_MARGIN
if self.player_sprite.bottom < bottom_boundary:
self.view_bottom -= bottom_boundary - self.player_sprite.bottom
changed = True
if changed:
# Only scroll to integers. Otherwise we end up with pixels that
# don't line up on the screen
self.view_bottom = int(self.view_bottom)
self.view_left = int(self.view_left)
# Do the scrolling
arcade.set_viewport(self.view_left,
SCREEN_WIDTH + self.view_left,
self.view_bottom,
SCREEN_HEIGHT + self.view_bottom)
def main():
""" Main method """
window = MyGame()
window.setup()
arcade.run()
if name == "main":
main()
#YKYG: OSI stands for?
Anonymous Quiz
41%
Open system interpretor
32%
Open system interconnection
18%
Open system integration
9%
Open system internet
Tech news......π₯
Google and Alphabet CEO Sundar Pichai says in a blog post that the company would give $100 million in ad grants to the CDC Foundation, the World Health Organization, and other nonprofits.
Share support β¨
Google and Alphabet CEO Sundar Pichai says in a blog post that the company would give $100 million in ad grants to the CDC Foundation, the World Health Organization, and other nonprofits.
Share support β¨
#YKYG : If it takes 5 minutes to boil one egg How much time take to boil 4 egg?
Anonymous Quiz
9%
7 min
8%
6 min
78%
5 min
6%
9 min