Compare commits

...

6 Commits

16 changed files with 458 additions and 80 deletions

View File

@@ -1,6 +1,7 @@
{ {
"diagnostics.globals": [ "diagnostics.globals": [
"currentScreen", "currentScreen",
"drawMenu" "drawMenu",
"spielerHand"
] ]
} }

View File

@@ -1,49 +1,196 @@
require "karten" local love = require("love")
require("karten")
spielerHand = {} PlayerHand = {}
dealerHand = {} DealerHand = {}
deck = {} GameState = "playing" -- "playing", "player_won", "dealer_won", "tie"
function loadBlackjack() function LoadBlackjack()
deck = createDeck() DealerHandPosition = {
shuffleDeck(deck) x = love.graphics.getWidth() / 2,
dealInitialCards() y = love.graphics.getHeight() / 4,
}
PlayerHandPosition = {
x = love.graphics.getWidth() / 2,
y = love.graphics.getHeight() / 4 * 2.5,
}
Deck = Karten:createDeck()
Karten:shuffleDeck(Deck)
DealInitialCards()
Cards = love.graphics.newImage("/cards_asset_pack/JustNormalCardsSwitched.png")
end end
function updateBlackjack(dt) function UpdateBlackjack(dt)
-- Hier können zukünftige Updates für Blackjack hinzugefügt werden dt = dt * 1
end end
function drawBlackjack() function DrawBlackjack()
love.graphics.print("Spieler Hand: " .. handValue(spielerHand), 50, 50) local suits = { ["Clubs"] = 0, ["Diamonds"] = 1, ["Spades"] = 2, ["Hearts"] = 3 }
love.graphics.print("Dealer Hand: " .. handValue(dealerHand), 50, 100) local tileWidth = Cards:getWidth() / 13
love.graphics.print("Drücke 'H' für Hit oder 'S' für Stand", 50, 150) local tileHeight = Cards:getHeight() / 4
local scale = 0.5
local drawW, drawH = tileWidth * scale, tileHeight * scale
local spacingX, spacingY = 10, 10
local function drawHandGrid(hand, basePos)
if #hand == 0 then
return
end
local cols = 3
local rows = math.ceil(#hand / cols)
for row = 0, rows - 1 do
local startIdx = row * cols + 1
local endIdx = math.min(startIdx + cols - 1, #hand)
local cardsInRow = endIdx - startIdx + 1
local rowWidth = cardsInRow * drawW + (cardsInRow - 1) * spacingX
local startX = basePos.x - rowWidth / 2
for j = 0, cardsInRow - 1 do
local i = startIdx + j
local card = hand[i]
local tileX = math.min(card.value - 2, 12)
local tileY = suits[card.suit] or 0
local quad = love.graphics.newQuad(
tileX * tileWidth,
tileY * tileHeight,
tileWidth,
tileHeight,
Cards:getDimensions()
)
local x = startX + j * (drawW + spacingX)
local y = basePos.y + row * (drawH + spacingY)
love.graphics.draw(Cards, quad, x, y, 0, scale, scale)
end
end
end
drawHandGrid(PlayerHand, PlayerHandPosition)
love.graphics.print(
GetHandValue(PlayerHand),
PlayerHandPosition.x,
PlayerHandPosition.y + (math.ceil(#PlayerHand / 3) * drawH) + 15
)
drawHandGrid(DealerHand, DealerHandPosition)
love.graphics.print(
GetHandValue(DealerHand),
DealerHandPosition.x,
DealerHandPosition.y + (math.ceil(#DealerHand / 3) * drawH) + 15
)
-- show winner if game is not running
if GameState ~= "playing" then
local message = ""
if GameState == "player_won" then
message = "Player won!"
elseif GameState == "dealer_won" then
message = "Dealer won!"
elseif GameState == "tie" then
message = "Tie!"
end
love.graphics.setColor(1, 1, 0)
love.graphics.print(message, love.graphics.getWidth() / 2 - 100, 100)
love.graphics.setColor(1, 1, 1)
end
end end
function handleBlackjackInput(key)
if key == 'h' then function GetHandValue(hand)
hit(spielerHand) local count = 0
if handValue(spielerHand) > 21 then local aces = 0
love.graphics.print("Spieler hat verloren!", 50, 200) for _, card in pairs(hand) do
end if card.value < 10 then
elseif key == 's' then count = count + card.value
while handValue(dealerHand) < 17 do elseif card.value < 14 then
hit(dealerHand) count = count + 10
end else
if handValue(dealerHand) > 21 then count = count + 11
love.graphics.print("Dealer hat verloren!", 50, 200) aces = aces + 1
elseif handValue(spielerHand) > handValue(dealerHand) then end
love.graphics.print("Spieler gewinnt!", 50, 200) end
else
love.graphics.print("Dealer gewinnt!", 50, 200) ::aceloop::
end if count > 21 and aces > 0 then
end for _ = 1, aces do
count = count - 10
aces = aces - 1
goto aceloop
end
end
return count
end end
function dealInitialCards() function HandleBlackjackInput(key)
for i = 1, 2 do if GameState == "playing" then
hit(spielerHand) if key == "h" then
hit(dealerHand) Karten:hit(PlayerHand)
end CheckWinCondition()
elseif key == "s" then
-- Dealer zieht bis 17 oder höher
while GetHandValue(DealerHand) < 17 do
Karten:hit(DealerHand)
end
CheckWinCondition()
end
end
if key == "r" then
ResetGame()
end
end end
function DealInitialCards()
for _ = 1, 2 do
Karten:hit(PlayerHand)
Karten:hit(DealerHand)
end
end
function CheckWinCondition()
if GameState ~= "playing" then
return
end
local playerValue = GetHandValue(PlayerHand)
local dealerValue = GetHandValue(DealerHand)
if dealerValue < 17 then
return
end
if playerValue > 21 then
GameState = "dealer_won"
return
end
if dealerValue > 21 then
GameState = "player_won"
return
end
if playerValue > dealerValue then
GameState = "player_won"
elseif dealerValue > playerValue then
GameState = "dealer_won"
else
GameState = "tie"
end
end
function ResetGame()
PlayerHand = {}
DealerHand = {}
GameState = "playing"
Deck = Karten:createDeck()
Karten:shuffleDeck(Deck)
DealInitialCards()
end

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

View File

@@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://508ltkqucq7a"
path="res://.godot/imported/CuteCards.png-a691dafeb8615d7c1003502272afbc35.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/CuteCards - asset pack/CuteCards.png"
dest_files=["res://.godot/imported/CuteCards.png-a691dafeb8615d7c1003502272afbc35.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

View File

@@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://dqm1cu22dfech"
path="res://.godot/imported/CuteCards_outline.png-37c08f2c7da86fe4b37b1043f010f835.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/CuteCards - asset pack/CuteCards_outline.png"
dest_files=["res://.godot/imported/CuteCards_outline.png-37c08f2c7da86fe4b37b1043f010f835.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

View File

@@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://buyp5s1dgho3y"
path="res://.godot/imported/PokerChips.png-48cfeaecb5166f271837eaba1eefc640.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/CuteCards - asset pack/PokerChips.png"
dest_files=["res://.godot/imported/PokerChips.png-48cfeaecb5166f271837eaba1eefc640.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

View File

@@ -0,0 +1,34 @@
--- THANK U -----------------
Thank you for downloading this Cute Card Set :) hope you like it and find it usefull
This project it's idependent. But was originaly made as part of a Super Pixel Card Set, comming in the future,
follow me on itch.io to see the updates. @danimaccari -> https://dani-maccari.itch.io/
--- HOW TO USE --------------
The pack contains 60 diferent cards 15 in each row
Each Card is 100x144 pixels
Each row contains one color
Clubs
Diamonds
Spades
Hearts
Contains two joker designs, two fade down cards and two blank cards
There are 15 POKER CHIPS each one 76x76 pixels
--- PIXEL ASSETS -----------
Each Card is 25x36 pixels
Each Chip is 19x19 pixels
--- LICENSE ----------------
This pack is free for personal or comercial use as long as it's atributed to DANI MACCARI.
You are free to edit the sprites as much as you want.
You may not repackage, redistribute or resell the assets, no matter how much they are modified. - This includes NFTs.

View File

@@ -1,3 +1,4 @@
local love = require "love"
function love.conf(t) function love.conf(t)
t.window.width = 350 t.window.width = 350
end end

74
flake.lock generated
View File

@@ -1,9 +1,47 @@
{ {
"nodes": { "nodes": {
"cursor": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
},
"locked": {
"lastModified": 1747112672,
"narHash": "sha256-kUkbIQwb65KiMaxWVTtLmSdgpE/ANFquJ1OLKlZNjZs=",
"owner": "omarcresp",
"repo": "cursor-flake",
"rev": "52061a31dd7fcdfc04e8c4abfeaadf67039324c9",
"type": "github"
},
"original": {
"owner": "omarcresp",
"ref": "main",
"repo": "cursor-flake",
"type": "github"
}
},
"flake-utils": { "flake-utils": {
"inputs": { "inputs": {
"systems": "systems" "systems": "systems"
}, },
"locked": {
"lastModified": 1710146030,
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_2": {
"inputs": {
"systems": "systems_2"
},
"locked": { "locked": {
"lastModified": 1731533236, "lastModified": 1731533236,
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
@@ -19,6 +57,22 @@
} }
}, },
"nixpkgs": { "nixpkgs": {
"locked": {
"lastModified": 1725103162,
"narHash": "sha256-Ym04C5+qovuQDYL/rKWSR+WESseQBbNAe5DsXNx5trY=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "12228ff1752d7b7624a54e9c1af4b222b3c1073b",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_2": {
"locked": { "locked": {
"lastModified": 1753694789, "lastModified": 1753694789,
"narHash": "sha256-cKgvtz6fKuK1Xr5LQW/zOUiAC0oSQoA9nOISB0pJZqM=", "narHash": "sha256-cKgvtz6fKuK1Xr5LQW/zOUiAC0oSQoA9nOISB0pJZqM=",
@@ -36,8 +90,9 @@
}, },
"root": { "root": {
"inputs": { "inputs": {
"flake-utils": "flake-utils", "cursor": "cursor",
"nixpkgs": "nixpkgs" "flake-utils": "flake-utils_2",
"nixpkgs": "nixpkgs_2"
} }
}, },
"systems": { "systems": {
@@ -54,6 +109,21 @@
"repo": "default", "repo": "default",
"type": "github" "type": "github"
} }
},
"systems_2": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
} }
}, },
"root": "root", "root": "root",

View File

@@ -3,12 +3,14 @@
inputs = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils"; flake-utils.url = "github:numtide/flake-utils";
cursor.url = "github:omarcresp/cursor-flake/main";
}; };
outputs = { self, nixpkgs, flake-utils }: outputs = { self, nixpkgs, flake-utils, cursor }:
flake-utils.lib.eachDefaultSystem (system: flake-utils.lib.eachDefaultSystem (system:
let let
pkgs = import nixpkgs { pkgs = import nixpkgs {
inherit system; inherit system;
config.allowUnfree = true;
}; };
in in
{ {
@@ -16,6 +18,7 @@
with pkgs; mkShell rec { with pkgs; mkShell rec {
buildInputs = [ buildInputs = [
love love
cursor.packages.${pkgs.system}.default
]; ];
shellHook = '' shellHook = ''

View File

@@ -1,44 +1,62 @@
karten = {} local love = require("love")
function createDeck() Karten = {}
local deck = {}
local suits = {"Herz", "Karo", "Pik", "Kreuz"} function Karten:createDeck()
local values = {2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 11} -- 10, J, Q, K sind alle 10, A ist 11 local deck = {}
for _, suit in ipairs(suits) do local suits = { "Clubs", "Diamonds", "Spades", "Hearts" }
for _, value in ipairs(values) do local values = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }
table.insert(deck, {suit = suit, value = value}) for _, suit in ipairs(suits) do
end for _, value in ipairs(values) do
end table.insert(deck, { suit = suit, value = value })
return deck end
end
TileMap = love.graphics.newImage("/cards_asset_pack/JustNormalCards.png")
return deck
end end
function shuffleDeck(deck) function Karten:shuffleDeck(deck)
for i = #deck, 2, -1 do for i = #deck, 2, -1 do
local j = love.math.random(i) local j = love.math.random(i)
deck[i], deck[j] = deck[j], deck[i] deck[i], deck[j] = deck[j], deck[i]
end end
end end
function hit(hand) function Karten:hit(hand)
local card = table.remove(deck) if #Deck > 0 then
table.insert(hand, card) local card = table.remove(Deck)
table.insert(hand, card)
return card
end
end end
function handValue(hand)
local value = 0 function Karten:getHandValue(hand)
local aces = 0 local count = 0
for _, card in ipairs(hand) do local aces = 0
value = value + card.value
if card.value == 11 then for _, card in pairs(hand) do
aces = aces + 1 if card.value < 10 then
end count = count + card.value
end elseif card.value < 14 then
while value > 21 and aces > 0 do count = count + 10
value = value - 10 else
aces = aces - 1 count = count + 11
end aces = aces + 1
return value end
end
::aceloop::
if count > 21 and aces > 0 then
for _ = 1, aces do
count = count - 10
aces = aces - 1
goto aceloop
end
end
return count
end end
return karten return Karten

View File

@@ -6,11 +6,12 @@ require "blackjack"
function love.load() function love.load()
love.window.setTitle("Spiele Auswahl") love.window.setTitle("Spiele Auswahl")
currentScreen = "menu" currentScreen = "menu"
love.graphics.setBackgroundColor(0.30 ,0.30 ,0.46, 1)
end end
function love.update(dt) function love.update(dt)
if currentScreen == "blackjack" then if currentScreen == "blackjack" then
updateBlackjack(dt) UpdateBlackjack(dt)
end end
end end
@@ -18,7 +19,7 @@ function love.draw()
if currentScreen == "menu" then if currentScreen == "menu" then
drawMenu() drawMenu()
elseif currentScreen == "blackjack" then elseif currentScreen == "blackjack" then
drawBlackjack() DrawBlackjack()
end end
end end
@@ -26,10 +27,11 @@ function love.keypressed(key)
if currentScreen == "menu" then if currentScreen == "menu" then
if key == '1' then if key == '1' then
currentScreen = "blackjack" currentScreen = "blackjack"
loadBlackjack() LoadBlackjack()
end end
elseif currentScreen == "blackjack" then elseif currentScreen == "blackjack" then
handleBlackjackInput(key) HandleBlackjackInput(key)
DrawBlackjack()
end end
end end