File: delegation.nut

package info (click to toggle)
squirrel3 3.1-8.3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,380 kB
  • sloc: cpp: 12,722; ansic: 917; makefile: 316; python: 40
file content (54 lines) | stat: -rw-r--r-- 915 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54

PEntity <- {
    name="noname"
    pos={x=0,y=0,z=0}
    type="entity"
    //methamethod
    _typeof=function()
    {
        return type;
    }
}

function PEntity::PrintPos()
{
    ::print("x="+pos.x+" y="+pos.y+" z="+pos.z+"\n");
}

function PEntity::new(name,pos)
{
    local newentity=clone ::PEntity;
    if(name)
        newentity.name=name;
    if(pos)
        newentity.pos=pos;
    return newentity;
}

PPlayer <- {
    model="warrior.mdl"
    weapon="fist"
    health=100
    armor=0
    //overrides the parent type
    type="player"
}

function PPlayer::new(name,pos)
{
    local p = clone ::PPlayer;
    local newplayer = ::PEntity.new(name,pos);
    newplayer.setdelegate(p);
    return newplayer;
}

local player=PPlayer.new("godzilla",{x=10,y=20,z=30});

::print("PLAYER NAME"+player.name+"\n");
::print("ENTITY TYPE"+typeof player+"\n");

player.PrintPos();

player.pos.x=123;

player.PrintPos();