Skip to content

vcpmark/UTowerDefense

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

29 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Motato Towers - Modern WebGL Edition

A dual-mode game featuring both a Motato clone and tower defense, built with a modern WebGL2 engine, actual Motato sprites, and an Entity Component System architecture.

๐ŸŽฎ Two Game Modes

๐Ÿฅ” Motato Mode (Recommended)

A faithful recreation of Motato with:

  • Player-controlled character (WASD movement)
  • Auto-attacking weapons
  • Wave-based survival
  • XP and level progression
  • Real sprites from MotatoWithUnity

๐Ÿ—ผ Tower Defense Mode

Strategic tower placement with:

  • Multiple tower types
  • Hype Burst & Momentum mechanics
  • Special abilities and chain effects
  • Wave modifiers and events

๐Ÿš€ Features

Modern WebGL2 Engine

  • Batch Rendering: Efficient sprite batching for optimal performance
  • WebGL2 Shaders: Custom GLSL shaders for rendering shapes and sprites
  • Fixed Timestep: Deterministic physics with fixed update rate
  • Entity Component System: Flexible and maintainable game architecture
  • Modular Design: Clean separation of concerns with multiple systems

Game Systems

  • Rendering System: WebGL-based rendering with effects and animations
  • Physics System: Movement, velocity, and collision detection
  • Tower System: Automated targeting and shooting mechanics
  • Enemy System: Path-following AI with various enemy types
  • Bullet System: Projectile physics with homing and special effects

Motato-Inspired Mechanics

  • Hype Burst: Build hype from kills and unleash for massive damage boost
  • Momentum Frenzy: Chain kills rapidly to trigger a speed/power frenzy
  • Wave Events: Dynamic modifiers that change gameplay each wave
  • Multiple Tower Types: Basic, Pulse, Frost, Sniper, and Storm towers
  • Special Effects: Chain lightning, splash damage, and slow effects

๐Ÿ“ Project Structure

UTowerDefense/
โ”œโ”€โ”€ index.html                  # Landing page / game mode selector
โ”œโ”€โ”€ motato.html                 # Motato game mode
โ”œโ”€โ”€ go.html                     # Tower defense (original)
โ”œโ”€โ”€ towers.html                 # Tower defense (WebGL2 version)
โ”œโ”€โ”€ assets/
โ”‚   โ””โ”€โ”€ sprites/                # Motato sprites from Unity
โ”‚       โ”œโ”€โ”€ player/             # potato.png, legs.png, highlight.png
โ”‚       โ”œโ”€โ”€ enemies/            # Enemy sprites
โ”‚       โ”œโ”€โ”€ weapons/            # Weapon sprites
โ”‚       โ””โ”€โ”€ bullets/            # Bullet animations
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ renderer/
โ”‚   โ”‚   โ”œโ”€โ”€ WebGLRenderer.js    # WebGL2 rendering engine
โ”‚   โ”‚   โ””โ”€โ”€ TextureLoader.js    # Texture loading and caching
โ”‚   โ”œโ”€โ”€ core/
โ”‚   โ”‚   โ””โ”€โ”€ Engine.js           # Game loop and system management
โ”‚   โ”œโ”€โ”€ ecs/
โ”‚   โ”‚   โ”œโ”€โ”€ Entity.js           # Entity and EntityManager
โ”‚   โ”‚   โ””โ”€โ”€ Components.js       # Component definitions
โ”‚   โ”œโ”€โ”€ systems/
โ”‚   โ”‚   โ”œโ”€โ”€ RenderSystem.js     # Rendering logic
โ”‚   โ”‚   โ””โ”€โ”€ PhysicsSystem.js    # Physics and movement
โ”‚   โ””โ”€โ”€ game/
โ”‚       โ”œโ”€โ”€ Game.js             # Tower defense logic
โ”‚       โ”œโ”€โ”€ MotatoGame.js       # Motato game logic
โ”‚       โ””โ”€โ”€ GameState.js        # Game state management
โ””โ”€โ”€ README.md

๐ŸŽฎ How to Play

Motato Mode (motato.html)

  1. Move: Use WASD or Arrow Keys
  2. Attack: Weapons automatically shoot nearest enemies
  3. Survive: Complete waves to earn money and XP
  4. Level Up: Gain stat boosts every level
  5. Wave Control: Start new waves when ready

Tower Defense Mode (go.html or towers.html)

  1. Select Tower: Click on a tower card
  2. Place: Click on canvas to place tower
  3. Start Wave: Begin the enemy assault
  4. Abilities: Use Hype Burst and momentum
  5. Strategy: Upgrade towers and use chain effects

GitHub Pages Deployment

The game works on GitHub Pages! Access via:

  • Main page: https://[username].github.io/UTowerDefense/
  • Motato: https://[username].github.io/UTowerDefense/motato.html
  • Tower Defense: https://[username].github.io/UTowerDefense/go.html

๐Ÿ—๏ธ Architecture

WebGL Renderer

The WebGLRenderer class provides a modern WebGL2 API for drawing:

  • Circles (filled and outlined)
  • Rectangles
  • Lines
  • Custom shapes with batching

Entity Component System

Entities are composed of components:

  • Transform: Position, rotation, scale
  • Velocity: Movement vector
  • Health: HP and armor
  • Tower: Tower behavior and stats
  • Enemy: Enemy AI and pathfinding
  • Bullet: Projectile behavior

Game Systems

Systems process entities with specific components:

  • PhysicsSystem: Updates positions based on velocity
  • RenderSystem: Draws entities to the canvas
  • Game: Handles tower shooting, enemy movement, collisions

๐Ÿ”ง Technical Details

WebGL2 Features

  • Orthographic projection matrix for 2D rendering
  • Custom vertex and fragment shaders
  • Efficient buffer management
  • Alpha blending for transparency

Performance Optimizations

  • Batch rendering to minimize draw calls
  • Efficient collision detection with spatial partitioning (future)
  • Fixed timestep prevents physics issues
  • Component-based architecture for cache efficiency

Motato Mechanics Integration

Based on the MotatoWithUnity repository analysis:

  • Player-like progression systems
  • Wave-based difficulty scaling
  • Item and stat modifiers
  • Chain and combo mechanics
  • Visual feedback with effects

๐Ÿ› ๏ธ Development

Requirements

  • Modern browser with WebGL2 support
  • ES6 module support
  • Local web server (for development)

Running Locally

# Using Python 3
python -m http.server 8000

# Using Node.js
npx http-server

# Then open http://localhost:8000

Adding New Towers

  1. Define tower stats in Game.getTowerData()
  2. Add tower card to TOWERS array in index.html
  3. Implement special behavior in tower system if needed

Adding New Mechanics

  1. Create new component in Components.js
  2. Add system to process the component
  3. Update game logic in Game.js

๐ŸŽฏ Future Enhancements

Motato Mode

  • Item shop between waves
  • Multiple weapon types
  • Stat modifiers and items
  • More character sprites (different classes)
  • Boss enemies
  • Achievements and unlocks

Tower Defense Mode

  • Tower upgrades UI
  • More tower types
  • Path editor
  • Multiple difficulty levels

Both Modes

  • Save/load game state
  • Sound effects and music
  • Particle system for better effects
  • Mobile touch controls
  • Leaderboards
  • Multiplayer support

๐Ÿ“œ License

This project is open source and available for educational purposes.

๐Ÿ™ Credits

  • Inspired by Motato by Blobfish
  • MotatoWithUnity reference implementation
  • WebGL2 rendering techniques from various sources

Note: This is a modernized version using WebGL2 and ECS architecture. The original game logic has been preserved while the rendering engine has been completely rewritten for better performance and maintainability.

About

UTower Defense Game

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors