Top Banner

of 24

CSC780 Coincraver Dev Guide

Jun 02, 2018

Download

Documents

Álvaro Méndez
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • 8/10/2019 CSC780 Coincraver Dev Guide

    1/24

    COINCRAVERDEVELOPMENT GUIDE

    CSC 780 under Dr. Puder, San Francisco StateUniversity

  • 8/10/2019 CSC780 Coincraver Dev Guide

    2/24

    Agenda:

    Quick update since last week

    In depth with the Coincraver gameloop 4 classes, and Surface View\

    If time permits: How to handle collisions between the

    objects in Coincraver?

    Conclusion and Questions

  • 8/10/2019 CSC780 Coincraver Dev Guide

    3/24

    Update

    Fixed some UI bugs

    Added a background Image (drawing onto canvas)

    Added birds flying in the sky (looping of birds in sky)

    Polished code Demo app

  • 8/10/2019 CSC780 Coincraver Dev Guide

    4/24

    Gameloop: Android & Java Classes in

    Coincraver

    Android classes:

    PlayGameActivity

    GameViewActivity

    Class PlayerMoveThread (extends thread)

    Defined in GameViewActivity

    Game Java classes:

    GameActivity

    PlayerActivity

  • 8/10/2019 CSC780 Coincraver Dev Guide

    5/24

    Create PlayGameActivity of Coincraver

    Activity

    PlayGameActivity

    Now we have a activity with something like Hello World!..

  • 8/10/2019 CSC780 Coincraver Dev Guide

    6/24

    PlayGameActivityextends Activity implements SensorEventListener

    What is it for?

    Starting Point

    Handles onPause and onResume states

    Defined in onPause() method

  • 8/10/2019 CSC780 Coincraver Dev Guide

    7/24

    Do we need a View for Coincraver?

    Yes, we need a view so that we can house our Coincraver

    Specifically, what we need is a View which allows us to

    continuously draw to a screen and get player input

    Do we have an option? Yes. There is a SurfaceView class

    for this purpose (there is a nice Camera tutorial written by

    Dr. Puder that uses SurfaceView class)

    SurfaceView class is provided by Android SDK

  • 8/10/2019 CSC780 Coincraver Dev Guide

    8/24

    GameviewActivityextends SurfaceView implements SurfaceHolder.Callback

    Provides a dedicated surface to draw on

    Need a view in which we can continuously draw (with the help of

    canvas)

    WHY NOT VIEW???

    Commination b/w Game and UI : SurfaceHolder.CallBack

    ?? When will these be called in our game?

    surfaceChanged()

    surfaceCreated()

    surfaceDestroyed()

    onTouchEvent()

  • 8/10/2019 CSC780 Coincraver Dev Guide

    9/24

    Create GameViewActivity of Coincraver

    Activity

    GameViewActivity

    Now, we have a view that can extend SurfaceView and implement callbacks

  • 8/10/2019 CSC780 Coincraver Dev Guide

    10/24

    Structure will look like this

    SurfaceViewImplements

    SurfaceHolder.Callback

    GameViewActivity

    Callbacks are important:

    1. To know when the surface is created so that we can start our

    Coincraver (do you remember SurfaceCreated( ) callback method in

    Camera tutorial of Dr. Puder, check that out if not)

    2. To know when the surface is being destroyed so that we close our

    Coincraver.

    3. To know when the surface size changes so we can get the updated

    display dimensions.

  • 8/10/2019 CSC780 Coincraver Dev Guide

    11/24

    Why do we need to extend SurfaceView?

    It provides the drawing surface (like a drawing board)

    This surface, then, can be modified with the help of

    Canvas class

    It also allows any other thread to render to the view

    This is required if we want Coincraver to run independent of the

    view UI

  • 8/10/2019 CSC780 Coincraver Dev Guide

    12/24

    PlayerMoveThreadextends thread

    It will be responsible for interfacing our Coincraver game

    (Java) code with Android code Uses the GameActivitysmethods to accomplish this

    Responds to the onTouchEvent() of the surface view

  • 8/10/2019 CSC780 Coincraver Dev Guide

    13/24

    PlayerMoveThreadextends thread

    Some GameActivity game methods

  • 8/10/2019 CSC780 Coincraver Dev Guide

    14/24

    PlayerMoveThreadextends thread

    doTouchEvent in GameViewActivity (SurfaceView)

    doTouchEvent in PlayerMoveThread

  • 8/10/2019 CSC780 Coincraver Dev Guide

    15/24

    Lets focus on the game code now..

    GameActivityIt is responsible for

    1. Managing the game resources

    2. Keeps track of the game state

    (used switch case)3. Handles the game logic

    PlayerActivityIt is responsible for

    1. Drawing the player

    2. Updates the player logic

    3. (collision detection, not yet

    implemented)

  • 8/10/2019 CSC780 Coincraver Dev Guide

    16/24

    Which states do we need to manage?

    All set..go..go

    Game Menu

    Game Over

    Game loop /Play Game

    Start Game

    Player has pressed the

    Start Game button

  • 8/10/2019 CSC780 Coincraver Dev Guide

    17/24

    PlayerActivity will look like this..classPlayerActivity{

    publicPlayerActivity(GameActivity game)

    {

    }

    publicvoidreset()

    {

    }

    publicvoidupdate()

    {

    }

    publicvoiddraw(Canvas canvas)

    {

    }

    }

  • 8/10/2019 CSC780 Coincraver Dev Guide

    18/24

    Setting up the Coincraver game loop..

    PlayerMoveThread will play a major role.

    PlayerMoveThread.run (

    )

    Coincraver

    games gameplay

    state

    GameActivity.run ( )

    AndroidExecutes

    Calls

    Calls

  • 8/10/2019 CSC780 Coincraver Dev Guide

    19/24

    PlayerMoveThread.run ( ) method

  • 8/10/2019 CSC780 Coincraver Dev Guide

    20/24

    GameActivity.run ( ) method

  • 8/10/2019 CSC780 Coincraver Dev Guide

    21/24

    GameActivitys gameplay ( ) method

  • 8/10/2019 CSC780 Coincraver Dev Guide

    22/24

    Where is the input ?

    Input comes from the UI thread from the default view

    GameViewActivity handles touch events and notifies the

    game when a touch occurs

    GameViewActivitys touch event handler:

  • 8/10/2019 CSC780 Coincraver Dev Guide

    23/24

    PlayerMoveThreads touch event handler

  • 8/10/2019 CSC780 Coincraver Dev Guide

    24/24

    Building of the GameActivity class

    Now, try to run Coincraver game loop. So, draw

    something and use timing

    To draw something, we need the screen size. How to get

    it?

    SurfaceView callbacks notify our view of the screens size. We

    need to pass this information in the GameActivity class at the

    runtime. Therefore, setting up the setScreenSize( ) method in

    GameActivity.java: