Skip to content

KevZ1209/CS174A-Tanks

Repository files navigation

CS174A Tanks!

Created by Alyssa Tadeo, Artemis Tran, and Kevin Zhang for UCLA CS174A Spring 2024.

Play now: https://kevz1209.github.io/CS174A-Tanks/

Overview

Tanks! is a recreation of the classic Wii Play "Tanks!" game using the Tiny Graphics library. This game features a user controled a tank via mouse and keyboard to avoid enemy fire, shooting bullets that ricochet off walls, and placing bombs which explode after a duration or can be exploded by a bullet. The goal of the game is to eliminate all enemy tanks without getting hit before the level timer ends, and advance through all possible levels to win the game!

Features

Modeling

IMG_2128

Tanks are modeled using a 3D object mesh made in Blender which separates the body from the turret for isolated animations. Basic Cube, Square, and Sphere models from Tiny Graphics are used for all other objects.

Transformations

Tanks translate and rotate about the game map. Bullets translate in one direction with a given velocity (based on bullet type: Normal, Fast, or User)

Lighting, Shading, and Textures

The map is lit from above to simulate room lighting. Tanks, Bullets, and Bombs are shaded with Phong Shaders to simulate a plastic look as if the models were toys. All other objects such as wood blocks, cork blocks, game banners, dead tank markers, and map holes are shaded with Textured Phong Shaders with graphics designed in Photoshop or textures pulled from the web.

Particles

Smoke from bullets and collisions are generated through particles which have numerous parameters such as opacity, color, lifetime and scale to mimic realistic physics. Each particle is created with subdivision_spheres(1) to improve performance.

Interactivity

  • WASD keys control the translation of the user tank body
  • Using a mousedown event handler, user shoots a bullet towards the cursor position
  • Using a mousemove event handler, the user tank turret rotates to the cursor position and the cursor is replaced with a target
  • E key places a bomb at the user’s current position
  • Enter key starts the game from the initial loading screen

For our cursor-based interactivity, we had to converting screen space coordinates to world space coordinates to create a seamless connection between the user and the game world.

  1. Transform mouse position to normalized device coordinates
  2. Transform position to world space: $$(Projection(ModelView)*Object)^{-1}$$
  3. Find intersection between WS position and ground plane (y = 4.3 in order to avoid clipping with tall map obstacles)

Advanced Features

Game Loop

image1 Every 5 levels, the user gets an extra life!

Physics-based Collision Detection

Collision detection is accomplished by approximating collision boundaries with AABB via hitboxes for Tanks, Bullets, and Obstacles.

  • Tank-Obstacles
  • Tank-Tank
  • Bullet-Obstacles
  • Bullet-Tank
  • Bullet-Bullet
  • Bullet-Bomb

Bullet ricochet is calculated using the formula for light reflections to get a realistic result. $$\vec V_{new}=\vec V - \vec N(2(\vec V \cdot \vec N))$$

Map Generation

Each level map is defined as a text file where each character corresponds to a block type or tank type. Before each level state in the game loop, the schematic is parsed and the locations, textures, and types of each map element is stored in game memory to be used for collision detection.

Element Schematic Encoding
Empty 0
Block (1 height) 1
Cork (1 height) 2
Hole 3
Block (2 height) 4
Cork (2 height) 5
Block (3 height) 6
Cork (3 height) 7
User *
Stationary Enemy (tan) s
Moving Enemy (brown) m
Moving Bomb Enemy (yellow) b
Moving Fast Shooting Enemy (green) f
Moving Fast Reload Enemy (red) r

Intelligence Artificial (IA)

Movement

  • The Tourist: moves in a chosen direction until it hits a wall or randomly changes direction.
  • The Pro Gamer: dodges bullets if it gets too close
  • The Bestie: follows you if close

Shooting

  • Shoots random directions if user not detected.
  • Shoots directly at user upon detection.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages