“Race Collision” is a one player game in which a truck has to avoid “particles” that appear on the road. By the use of the joystick, the player can guide themselves through the menu system to start the game. The truck is the main element of the game and it can be moved from side to side with the joystick. The road curves randomly from time to time and the player has to be careful to keep the truck within the road boundaries. Particles appear on the screen at random positions and 4 collisions lead to the end of the game.

Dependencies:   ELEC2645_JoystickLCD_LPC1768_2021

lib/Road.cpp

Committer:
alex_20
Date:
2021-03-19
Revision:
3:cbe2dcca5058
Parent:
2:18fd28044860
Child:
4:def20a1665d1

File content as of revision 3:cbe2dcca5058:

#include "Road.h"
#include <vector>

// constructure
Road::Road() {}

void Road::init() {    
    //initialize parameters
    int direction = 0;
    int inclination = 0;
    
    _direction = direction;
    _inclination = inclination;
}

void Road::set_inclination(int inclination) {
    _inclination = inclination; 
    }

void Road::draw(N5110 &lcd, int direction) { 

    if (direction == 0) {
        lcd.drawLine( 0,12,84,12, FILL_BLACK);
        lcd.drawLine(28,12,12,48, FILL_BLACK);
        lcd.drawLine(56,12,72,48, FILL_BLACK);
    }
    
    else {
        lcd.drawLine (0,12,84,12, FILL_BLACK);
        std::vector<Vector2Df> curve_points_1 = lcd.getCurve(12,48,20 + 5 * direction, 30 - abs(direction),28,12);
        std::vector<Vector2Df> curve_points_2 = lcd.getCurve(72,48,64 + 5 * direction, 30 - abs(direction),56,12);
        
        lcd.drawCurve(curve_points_1, 0, 1, TYPE_SOLID);
        lcd.drawCurve(curve_points_2, 0, 1, TYPE_SOLID);
    }
}

    
void Road::draw_warn(N5110 &lcd, int warn_position) {
    const int warn_sign[12][12] = {
        { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
        { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
        { 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1 },
        { 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1 },
        { 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1 },
        { 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1 },
        { 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1 },
        { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
        { 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1 },
        { 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1 },
        { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
        { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
    };
    
    // if ball comes from the left side
    if (warn_position == 0) {
        lcd.drawSprite(0,18,12,12,(int *)warn_sign); 
    }
    
    // if ball comes from the top
    if (warn_position == 1) {
        lcd.drawSprite(36,0,12,12,(int *)warn_sign); 
    }
    
    // if ball comes from the right side
    if (warn_position == 2) {
        lcd.drawSprite(72,18,12,12,(int *)warn_sign); 
    }
}