HT Games
Home  >> Video Games

Build a Simple Virtual Pet Flash Game: "Fluffy" Tutorial (ActionScript 3)

Concept

A minimalist virtual pet: feed, play, clean. Three stats (Hunger, Happiness, Hygiene) decay over time; hit zero → game over.

Tech Stack

  • IDE: Adobe Animate (Flash Pro) or FlashDevelop + Flex SDK.
  • Language: ActionScript 3.0.
  • Target: Flash Player 10+ / AIR Desktop / HTML5 via OpenFL.

Core Classes

// Pet.as
package {
  public class Pet {
    public var hunger:uint = 100;
    public var happiness:uint = 100;
    public var hygiene:uint = 100;
    private var decayTimer:Timer;
    
    public function Pet() {
      decayTimer = new Timer(5000); // 5 sec tick
      decayTimer.addEventListener(TimerEvent.TIMER, decay);
      decayTimer.start();
    }
    
    private function decay(e:TimerEvent):void {
      hunger = Math.max(0, hunger - 2);
      happiness = Math.max(0, happiness - 1);
      hygiene = Math.max(0, hygiene - 1);
      dispatchEvent(new Event("statsChanged"));
    }
    
    public function feed():void {
      hunger = Math.min(100, hunger + 15);
    }
    
    public function play():void {
      happiness = Math.min(100, happiness + 20);
    }
    
    public function clean():void {
      hygiene = Math.min(100, hygiene + 25);
    }
    
    public function isAlive():Boolean {
      return hunger>0 && happiness>0 && hygiene>0;
    }
  }
}

UI Wiring (Document Class)

Main.as → instantiate Pet, add listeners to btnFeed/btnPlay/btnClean, update progress bars on "statsChanged", check isAlive() each tick → GameOver screen.

Polish Checklist

  • Sprite sheets for pet idle/eat/play/poop animations.
  • Sound FX (eat, happy, sad).
  • LocalSharedObject save/load (persist between sessions).
  • Daily login bonus (reset decay timer on new day).

Compile → `.swf` → embed in HTML or wrap with AIR for desktop/mobile. Flash Player EOL? Port to OpenFL/Haxe for native targets.


https://www.htfbw.com © HT Games