GAMEBOX CS 1111 NOVEMBER 2019 GAMEBOX - - PowerPoint PPT Presentation

gamebox
SMART_READER_LITE
LIVE PREVIEW

GAMEBOX CS 1111 NOVEMBER 2019 GAMEBOX - - PowerPoint PPT Presentation

GAMEBOX CS 1111 NOVEMBER 2019 GAMEBOX https://cs1110.cs.virginia.edu/gamebox-summary.html Save gamebox.py into every folder that uses gamebox Gamebox is a simple game library built on top of Pygame It supports Animation


slide-1
SLIDE 1

GAMEBOX

CS 1111 NOVEMBER 2019

slide-2
SLIDE 2

GAMEBOX

  • https://cs1110.cs.virginia.edu/gamebox-summary.html
  • Save gamebox.py into every folder that uses gamebox
  • Gamebox is a simple game library built on top of Pygame
  • It supports
  • Animation
  • Collision Detection
  • Simply physics
  • More
slide-3
SLIDE 3

IMPORT STATEMENTS

  • Always start with:

import pygame import gamebox camera = gamebox.Camera(800, 600) # you can change these # dimensions to change the window size

slide-4
SLIDE 4

CLICKING_EXAMPLE.PY

  • http://cs1110.cs.virginia.edu/files/cs1111_19fa/clicking_example.py
  • Let’s take a look at some of the mechanisms:
slide-5
SLIDE 5

TIME LOOP

  • At the core of gamebox is the passage of time:

gamebox.timer_loop(30, tick)

  • This tells gamebox to call the function “tick” 30 times per second.

def tick(keys):

  • This defines the tick function to take in any pressed keys
slide-6
SLIDE 6

TIME LOOP

if pygame.K_UP in keys:

  • This detects if the “UP” arrow is being hit on the keyboard.
  • List of keys: https://www.pygame.org/docs/ref/key.html

if camera.mouseclick:

  • Detects if the mouse is pressed (could be true several times in a row)

camera.draw(logo)

  • Draws the logo as it’s current stored location

camera.display()

  • Draws everything the camera “drew”
slide-7
SLIDE 7

CAMERA

Point of Origin (0,0) Y increases X increases

slide-8
SLIDE 8

GAMEBOXES

  • A gamebox is a rectangle
  • You can draw images or color the rectangles
  • They can move
  • They support collision detection
  • They can change appearance
  • See 2. gameboxes on http://cs1110.cs.virginia.edu/gamebox-summary.html
slide-9
SLIDE 9

GAMEBOXES MOVEMENT

b1 = gamebox.from_color(50, 100, "red", 20, 40) # x, y, color, width, height b1.move(5, 6) b1.x -= 5 b1.center(50, 100)

slide-10
SLIDE 10

EXAMPLES – SIMPLE ANIMATION

  • Starfield – Simple starfield animation

https://cs1110.cs.virginia.edu/files/cs1111_19fa/starfield.py

  • Gangnam Style – Sprite images

https://cs1110.cs.virginia.edu/files/cs1111_19fa/animation.py

  • Timer

https://cs1110.cs.virginia.edu/files/cs1111_19fa/pygame_demo.py

slide-11
SLIDE 11

COLLISION DETECTION

print(b1.touches(b2))

  • If b1 touches b2, return true

print(b1.bottom_touches(b2))

  • If the bottom of b1 touches b2, return true

b1.move_to_stop_overlapping(b2) b1.move_both_to_stop_overlapping(b2)

slide-12
SLIDE 12

EXAMPLES

  • Arrow-Keys: [movement, images, keyboard controls]

https://cs1110.cs.virginia.edu/files/cs1111_19fa/arrow_keys.py

  • Infinite_jumper: [movement, jumping, collision detection, panning]

https://cs1110.cs.virginia.edu/files/cs1111_19fa/infinite_jumper.py

  • Healthbar: [rudimentary AI, health bar, game_over screen]

https://cs1110.cs.virginia.edu/files/cs1111_19fa/health_bar.py

  • Basic Carry Demo (Carrying an item)

https://cs1110.cs.virginia.edu/files/cs1111_19fa/basic_carry_stuff.py