forked from turanszkij/WickedEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_script.lua
80 lines (60 loc) · 2.18 KB
/
test_script.lua
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
-- Wicked Engine Test Framework lua script
backlog_post("Begin script: test_script.lua");
-- Load a model:
local parent = LoadModel("../Content/models/teapot.wiscene");
LoadModel("../Content/models/cameras.wiscene");
-- Load camera sample script:
dofile("../Content/scripts/camera_animation_repeat.lua");
ToggleCameraAnimation();
-- Load an image:
local sprite = Sprite("../Content/logo_small.png");
sprite.SetParams(ImageParams(100,100,128,128));
-- Set this image as renderable to the active component:
local component = main.GetActivePath();
component.AddSprite(sprite);
-- Start a background task to rotate the model and update the sprite:
runProcess(function()
local velocity = Vector((math.random() * 2 - 1) * 4, (math.random() * 2 - 1) * 4); -- starting velocity for our sprite
local screenW = GetScreenWidth();
local screenH = GetScreenHeight();
local scene = GetScene();
-- This shows how to handle attachments:
-- -- Create parent transform, this will be rotated:
-- local parent = CreateEntity();
-- scene.Component_CreateTransform(parent);
--
-- -- Retrieve teapot base and lid entity IDs:
-- local teapot_base = scene.Entity_FindByName("Base");
-- local teapot_top = scene.Entity_FindByName("Top");
--
-- -- Attach base to parent, lid to base:
-- scene.Component_Attach(teapot_base, parent);
-- scene.Component_Attach(teapot_top, teapot_base);
while(true) do
-- Bounce our sprite across the screen:
local fx = sprite.GetParams();
local pos = fx.GetPos();
local size = fx.GetSize();
-- if it hits a wall, reverse velocity:
if(pos.GetX()+size.GetX() >= screenW) then
velocity.SetX(velocity.GetX() * -1);
end
if(pos.GetY()+size.GetY() >= screenH) then
velocity.SetY(velocity.GetY() * -1);
end
if(pos.GetX() <= 0) then
velocity.SetX(velocity.GetX() * -1);
end
if(pos.GetY() < 0) then
velocity.SetY(velocity.GetY() * -1);
end
pos = vector.Add(pos, velocity);
fx.SetPos(pos);
sprite.SetParams(fx);
-- Rotate teapot by parent transform:
local transform = scene.Component_GetTransform(parent);
transform.Rotate(Vector(0, 0, 0.01));
fixedupdate(); -- wait for new frame
end
end);
backlog_post("Script complete.");