Card rotation

This commit is contained in:
Pyrex 2024-02-09 22:17:57 -08:00
parent 6a92341695
commit 3508072c0e
6 changed files with 437 additions and 20 deletions

View File

@ -18,11 +18,13 @@ function board:init(ruleset)
-- wells: -- wells:
-- ...n_suits: wands, cups, swords, pentacles, etc -- ...n_suits: wands, cups, swords, pentacles, etc
local function add_suit(_self,suit) local function add_suit(_self,suit)
add(_self.wells,well:new(_self.ruleset, function(lst,new) local w=well:new(_self.ruleset, function(lst,new)
assert(lst) -- the ace is always present initially assert(lst) -- the ace is always present initially
if (new.suit!=suit) return if (new.suit!=suit) return
return new.suit==suit and new.rank==lst.rank+1 return new.suit==suit and new.rank==lst.rank+1
end)) end)
w.obscured_by_extra_slot=true
add(_self.wells, w)
end end
for suit in all(self.ruleset.deck.suits) do for suit in all(self.ruleset.deck.suits) do
add_suit(self,suit) add_suit(self,suit)
@ -105,13 +107,19 @@ function board:update()
end end
function board:draw() function board:draw()
local extra_slot_full=self.slots[self.ruleset.n_slots+1]:peek()!=nil
for w_ix=1,#self.wells do for w_ix=1,#self.wells do
local w=self.wells[w_ix] local w=self.wells[w_ix]
local l=self.ruleset.layouts:well(w_ix) local l=self.ruleset.layouts:well(w_ix)
local shadowed=nil
if w.obscured_by_extra_slot and extra_slot_full then
shadowed=true
end
for i=1,#w.contents do for i=1,#w.contents do
local x,y=l:place_card(i) local x,y=l:place_card(i)
self.ruleset.deck:draw_card(x,y,w.contents[i]) self.ruleset.deck:draw_card(x,y,w.contents[i],{shadowed=shadowed})
end end
end end
@ -130,7 +138,7 @@ function board:draw()
forall_slots(function(x,y,s_ix,s,l,n) forall_slots(function(x,y,s_ix,s,l,n)
for i=1,n do for i=1,n do
local x,y=l:place_card(i) local x,y=l:place_card(i)
self.ruleset.deck:draw_card(x,y,s.contents[i]) self.ruleset.deck:draw_card(x,y,s.contents[i],{rotate=l.rotated})
end end
end) end)
@ -141,7 +149,7 @@ function board:draw()
forall_slots(function(x,y,s_ix,s,l,n) forall_slots(function(x,y,s_ix,s,l,n)
if hover_slot==s_ix then if hover_slot==s_ix then
local x,y=l:place_card(n+1) local x,y=l:place_card(n+1)
self.cursor:draw_at(x,y) self.cursor:draw_at(l,x,y)
end end
end) end)
end end

View File

@ -61,7 +61,7 @@ function board:_animate_move_card(card,on_end,start_x,start_y,compute_end)
function anim_obj:draw() function anim_obj:draw()
local x=start_x+(end_x-start_x)*progress local x=start_x+(end_x-start_x)*progress
local y=start_y+(end_y-start_y)*progress local y=start_y+(end_y-start_y)*progress
_self.ruleset.deck:draw_card(x,y,card) _self.ruleset.deck:draw_card(x,y,card,{})
end end
self.animator:add(anim_obj) self.animator:add(anim_obj)

View File

@ -72,7 +72,7 @@ function cursor:grabbed_card()
return nil return nil
end end
function cursor:draw_at(x,y) function cursor:draw_at(l,x,y)
local card=self:grabbed_card() local card=self:grabbed_card()
local acc=self:acceptance_state() local acc=self:acceptance_state()
@ -80,13 +80,34 @@ function cursor:draw_at(x,y)
x+=sin(time()/2)*2+0.5 x+=sin(time()/2)*2+0.5
y+=sin(time()/4)+0.5+1 y+=sin(time()/4)+0.5+1
end end
x=flr(x)
y=flr(y)
local function draw_surround_box(fg)
if (not fg) return
if l.rotated then
rect(x-4,y+6,x+13,y+16,fg)
else
rect(x-1,y-1,x+9,y+16,fg)
end
end
local function draw_overlapping_box(fg)
if (l.obscured) draw_surround_box(fg) return
if l.rotated then
rectfill(x-3,y+7,x+12,y+15,fg)
else
rectfill(x,y,x+8,y+15,fg)
end
end
if card then if card then
local card_fg=self.ruleset.deck:draw_card(x,y,card) local card_fg=self.ruleset.deck:draw_card(x,y,card,{rotate=l.rotated})
local fg=card_fg local fg=card_fg
if (acc==acceptance_state.would_accept) fg=9 if (acc==acceptance_state.would_accept) fg=9
if (fg) rect(x-1,y-1,x+9,y+16,fg) draw_surround_box(fg)
else else
rectfill(x,y,x+8,y+15,9) draw_overlapping_box(9)
end end
end end

View File

@ -1,6 +1,7 @@
layout_mode={ layout_mode={
obscured=0, -- for wells obscured=0, -- for wells
vertical=1, -- for conventional slots vertical=1, -- for conventional slots
rotated=2,
-- todo: sideways -- todo: sideways
} }
@ -9,10 +10,13 @@ function layout:init(x,y,mode)
self.x=x self.x=x
self.y=y self.y=y
self.mode=mode self.mode=mode
if (mode==layout_mode.rotated) self.rotated=true
if (mode!=layout_mode.vertical) self.obscured=true
end end
function layout:place_card(i) function layout:place_card(i)
if (self.mode==layout_mode.obscured) return self.x,self.y if (self.mode==layout_mode.obscured) return self.x,self.y
if (self.mode==layout_mode.rotated) return self.x,self.y
if (self.mode==layout_mode.vertical) return self.x,self.y+(i-1)*6 if (self.mode==layout_mode.vertical) return self.x,self.y+(i-1)*6
assert(false,"unexpected mode: "..self.mode) assert(false,"unexpected mode: "..self.mode)
end end

View File

@ -83,7 +83,14 @@ function ruleset:generate_deck()
if (rank==0 or rank==self.n_arcana-1) deck.instantly_accepted[#deck.cards]=true if (rank==0 or rank==self.n_arcana-1) deck.instantly_accepted[#deck.cards]=true
end end
function deck:draw_card(x,y,c) function deck:draw_card(x,y,c,special)
if special.rotate then
camera(0,-64)
poke(0x5f55,0x00)
else
camera(-x,-y)
end
local meta=deck.cards[c] local meta=deck.cards[c]
local is_extreme=meta.rank==0 or meta.rank==ruleset.n_arcana-1 local is_extreme=meta.rank==0 or meta.rank==ruleset.n_arcana-1
@ -96,8 +103,12 @@ function ruleset:generate_deck()
else else
bg=7 bg=7
end end
if special.shadowed then
if (bg==1) bg=4
if (bg==7) bg=6
end
rectfill(x,y,x+8,y+15,bg) rectfill(0,0,8,15,bg)
if (meta.suit=='p') s,fg=0,4 if (meta.suit=='p') s,fg=0,4
if (meta.suit=='s') s,fg=1,12 if (meta.suit=='s') s,fg=1,12
@ -110,21 +121,38 @@ function ruleset:generate_deck()
local rank=""..meta.rank local rank=""..meta.rank
pal(7,15) pal(7,15)
if (is_extreme) pal(7,1) if (is_extreme) pal(7,1)
print(meta.rank,x+5-#rank*2,y+1,7) print(meta.rank,5-#rank*2,1,7)
spr(5,x,y+8) spr(5,0,8)
pal() pal()
else else
local name=sub(deck.rank_name,meta.rank,meta.rank) local name=sub(deck.rank_name,meta.rank,meta.rank)
local x2=x local x2=0
if (meta.suit=='b') x2+=1 if (meta.suit=='b') x2+=1
rectfill(x,y,x+3,y+6,fg) rectfill(0,0,3,6,fg)
print(name,x2,y+1,bg) print(name,x2,1,bg)
pal(7,fg) pal(7,fg)
spr(s,x+4,y) spr(s,4,0)
spr(15+meta.rank,x,y+8) spr(15+meta.rank,0,8)
pal() pal()
end end
camera()
if special.rotate then
poke(0x5f55,0x60)
mset(0,0,128)
mset(1,0,129)
mset(0,1,144)
mset(1,1,145)
x-=3
y+=7
for sx=0,8 do
for sy=0,15 do
tline(x+sy,y+sx,x+sy,y,(0)/8,sy/8,1/8,0)
end
end
tline()
end
return fg return fg
end end
end end
@ -153,7 +181,7 @@ function ruleset:generate_layouts()
local sx=(i-1)*10 local sx=(i-1)*10
return layout:new(x+sx,18,layout_mode.vertical) return layout:new(x+sx,18,layout_mode.vertical)
end end
if (i==ruleset.n_slots+1) return layout:new(x+width-ruleset.n_suits*5-5,1,layout_mode.obscured) if (i==ruleset.n_slots+1) return layout:new(x+width-ruleset.n_suits*5-5,1,layout_mode.rotated)
assert(false, "unknown slot") assert(false, "unknown slot")
end end
end end

View File

@ -496,3 +496,359 @@
2846 2846
2825 2825
2830 2830
2624
2777
2980
2747
2906
2871
3006
2956
3051
3090
3048
3065
3088
2977
2941
2912
3025
3062
3103
3133
3086
2960
3153
3127
3165
3137
3147
3008
3177
3123
3110
2976
3197
3015
3164
3144
3035
3221
3225
3207
3224
3237
2982
3239
3240
3248
3097
3182
3186
3161
3099
2966
3264
3091
3256
3202
3293
3265
3272
3252
3298
3310
3228
3227
3297
3322
3320
3365
3234
3350
3332
3187
3307
3409
3226
3413
3418
3391
3430
3294
3397
3323
3438
3436
3315
3433
3398
3449
3302
3480
3530
3481
3304
3493
3541
3511
3574
3479
3576
3412
3411
3231
3510
3598
3572
3437
3335
3374
3582
3593
3619
3620
3590
3609
3667
3683
3607
3669
3484
3497
3546
3725
3628
3726
3738
3514
3723
3526
3727
3766
3748
3767
3779
3785
3661
3761
3824
3729
3812
3708
3854
3808
3595
3835
3827
3801
3858
3823
3886
3883
3512
3861
3860
3897
3863
3874
3876
3912
3906
3901
3909
3744
3895
3869
3787
3962
3934
3961
3960
3993
3859
3942
3917
3976
3868
4010
3923
4031
3935
4058
3978
4062
3956
3933
4028
4013
4018
3952
4083
4089
4066
4116
4132
4021
3815
4006
4153
4093
3924
4047
4024
4057
4001
4165
4180
4072
3926
4172
4161
4197
4192
4098
4052
4157
4224
3982
4202
4191
4080
4234
4252
4228
4048
4269
4272
4243
3991
4214
4246
4245
4271
4050
4320
4336
4285
4355
4357
4262
4248
4338
4315
4302
4343
4291
4385
4388
4280
3990
4389
4342
4383
4353
4423
4288
4427
4365
4409
4459
4467
4421
4477
4151
4370
4502
4511
4481
4528
4494
4446
4547
4533
4537
4323
4554
4555
4491
4593
4538
4562
4536
4603
4619
4553
4639
4573
4514
4646
4664
4665
4581
4655
4673
4647
4405
4683
4731
4607
4703
4699
4745
4742
4739
4755
4782
4557
4776
4800
4766
4701
4762
4829
4852
4738
4773
4788
4728
4756
4862
4859
4860
4718
4877
4689
4903
4879
4865
4925
4844
4888
4770
4929
4956
4957
4858
4961
4857
4924
4861
4878
4962
4909
4883
4993
4967
4991
5004
5021
5039
4893
4975
5019
4936
5060
5002
5046
5015