Friday 21 December 2018

Google + Content reposting - June 6 2015


Digital nad Interactive Games 2015 – Term 2, Week 7, Session 2
GameProject1

Tody – Non-Player Class
–    collision detection

Games need some predictability – total randomness doesn't make a game

...

void NPCTwo::moveLeft() {
    velocity.setX(velocity);
}

void NPCTwo::moveRight() {

}

voidNPCTwo::stop() {

}


if (velocity.setX >= 0) {
    velocity.setX(-1 * velocity.setX())l
    velocity.setY(0);
}


else if (velocity.setX() == 0) {
    // should be randomed
    velocity.setX(-3);
}


if (status == 0) {
    stop();
}
else if (status == 1) {
    moveLeft();
}
else {
    moveRight();
}


++idle
if (idle > 1000) {

}


void NPCTwo : Status(int i) {
    status = i;
}


Determine length of time for idle


NPCTwo.h
#pragma once
#include "NonPlayer.h"

class NPCTwo : public NonPlayer
{
public:
    NPCTwo();
    ~NPCTwo();
    void setUp(ID2D1Bitmap*, std::vector<D2D1_RECT_F>);
    void update(GameTime);
    void moveLeft();
    void moveRight();
    void stop();
    int status;
    void setStatus(int i);
    int idle;
};


NPCTwo.cpp
#include "NPCTwo.h"


NPCTwo::NPCTwo()
{
}

void NPCTwo::setUp(ID2D1Bitmap* spriteSheet, std::vector<D2D1_RECT_F> sourceRectangle) {
    // Default window size
    // If not using default, subclass should call setWindowSize()
    windowSize = { 0, 0, 800, 600 };

    this->spriteSheet = spriteSheet;
    this->sourceRectangle = sourceRectangle;

    // Default to Frame 0
    setDrawRectangle(0, 0, sourceRectangle.at(0).right - sourceRectangle.at(0).left, sourceRectangle.at(0).bottom - sourceRectangle.at(0).top);

    currentFrame = 0;
    // maxFrameForAction should be derived from sourceRectangle vector
    //
    maxFrameForAction = 1;
    framePerAction = 10;
    frameCount = 0;

    randomSpeed();
  
    float width = sourceRectangle.at(currentFrame).right -
        sourceRectangle.at(currentFrame).left;
    float height = sourceRectangle.at(currentFrame).bottom -
        sourceRectangle.at(currentFrame).top;

    xLocation = drawRectangle.left + width / 2;
    yLocation = drawRectangle.top + height / 2;

    active = true;
}

NPCTwo::~NPCTwo()
{
}

void NPCTwo::update(GameTime gameTime) {

    float xIntPart;
    float yIntPart;

    if (status == 0) {
        stop();
    }
    else if (status == 1) {
        moveLeft();
    }
    else {
        moveRight();
    }

    modf(static_cast<float>(xLocation + velocity.getX() * static_cast<float>(gameTime.getElapsedTime())), &xIntPart);
    modf(static_cast<float>(yLocation + velocity.getY() * static_cast<float>(gameTime.getElapsedTime())), &yIntPart);
    setLocation(xIntPart, yIntPart);

    bounceLeftRight();
    bounceTopBottom();

    ++idle;
    if (idle > 1000) {
        // Change the status to moving again
    }

    ++frameCount;
    if (frameCount > framePerAction) {
        ++currentFrame;
        if (currentFrame == maxFrameForAction)
            currentFrame = 0;
        frameCount = 0;
    }
  
}

void NPCTwo::moveLeft() {
    if (velocity.getX >= 0) {
        velocity.setX(-1 * velocity.getX());
        velocity.setY(0);
    }
    else if (velocity.getX == 0) {
        // Should be randomed
        velocity.setX(-3);
    }
}

void NPCTwo::moveRight() {
    if (velocity.getX >= 0) {
        velocity.setX(1 * velocity.getX());
        velocity.setY(0);
    }
    else if (velocity.getX == 0) {
        // Should be randomed
        velocity.setX(3);
    }
}

void NPCTwo::stop() {
    velocity.setX(0);
    velocity.setY(0);
}

void NPCTwo::setStatus(int i) {
    status = i;
    idle = 0;
}


Hit testing


http://i483.photobucket.com/albums/rr193/Brenorenz/W15002_zpsquypjrvt.png

Which is on the left?

#cplusplus   #gamedesign   #gameprogramming   #programming   #tafe  





No comments:

Post a Comment