Skip to content

Instantly share code, notes, and snippets.

@pvcraven
Created April 3, 2020 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pvcraven/25f45b504df43f3fa255c8c4fce78caf to your computer and use it in GitHub Desktop.
Save pvcraven/25f45b504df43f3fa255c8c4fce78caf to your computer and use it in GitHub Desktop.
import random
import arcade
import os
import pyglet
import pyglet.gl as gl
# --- Constants ---
SPRITE_SCALING_PLAYER = 0.5
SPRITE_SCALING_COIN = .25
COIN_COUNT = 50
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
SCREEN_TITLE = "Sprite Collect Coins Example"
class MyGame(arcade.Window):
""" Our custom Window Class"""
def __init__(self):
""" Initializer """
# Call the parent class initializer
super().__init__(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE)
# Variables that will hold sprite lists
self.coin_list = None
# Set up the player info
self.score = 0
arcade.set_background_color(arcade.color.AMAZON)
def setup(self):
""" Set up the game and initialize the variables. """
# Sprite lists
self.coin_list = arcade.SpriteList()
# Create the coins
for i in range(COIN_COUNT):
coin = arcade.Sprite(":resources:images/items/coinGold.png",
SPRITE_SCALING_COIN)
# Position the coin
coin.center_x = random.randrange(SCREEN_WIDTH)
coin.center_y = random.randrange(SCREEN_HEIGHT)
# Add the coin to the lists
self.coin_list.append(coin)
def on_draw(self):
""" Draw everything """
# fb = pyglet.image.Framebuffer()
# texture = pyglet.image.Texture.create(SCREEN_WIDTH, SCREEN_HEIGHT, gl.GL_RGBA)
# fb.attach_texture(texture)
# fb.bind()
# fb.unbind()
arcade.start_render()
self.coin_list.draw()
self.player_list.draw()
# Put the text on the screen.
output = f"Score: {self.score}"
arcade.draw_text(output, 10, 20, arcade.color.WHITE, 14)
def main():
""" Main method """
window = MyGame()
window.setup()
arcade.run()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment