AI Game Maker

Upload assets, prompt AI, play.

Project Assets

Sprites
Sounds

AI Instructions

Copy this text and paste it into your preferred AI (like ChatGPT or Claude) to generate the game code.

Compile Game

Paste the JavaScript code provided by the AI below.

Game preview will appear here

`; } function compileAndPreview() { const userCodeRaw = codeInput.value; if (!userCodeRaw.trim()) { alert("Please paste the JavaScript code first."); return; } // Strip markdown js blocks if the AI included them state.userCode = userCodeRaw.replace(/^```javascript /gm, '').replace(/^```js /gm, '').replace(/```$/gm, ''); const assetsData = getCleanAssetsData(); const htmlString = generateFullHTML(state.userCode, assetsData); // Load into iframe const blob = new Blob([htmlString], { type: 'text/html' }); const url = URL.createObjectURL(blob); gamePreview.src = url; document.getElementById('preview-placeholder').style.display = 'none'; btnDownload.disabled = false; } function downloadGameHTML() { if(!state.userCode) return; const assetsData = getCleanAssetsData(); const htmlString = generateFullHTML(state.userCode, assetsData); const blob = new Blob([htmlString], { type: 'text/html' }); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = 'my_game.html'; document.body.appendChild(a); a.click(); document.body.removeChild(a); URL.revokeObjectURL(url); } /** * Support Form Implementation (Mandatory Requirement) */ function setupSupportForm() { const modal = document.getElementById('support-modal'); const btnOpen = document.getElementById('btn-open-support'); const btnClose = modal.querySelector('.btn-close-modal'); const form = document.getElementById('support-form'); const statusDiv = document.getElementById('support-status'); const submitBtn = form.querySelector('button[type="submit"]'); btnOpen.addEventListener('click', () => modal.classList.add('open')); const closeModal = () => { modal.classList.remove('open'); setTimeout(() => { form.reset(); statusDiv.className = 'form-status'; form.querySelectorAll('.form-group').forEach(g => g.classList.remove('error')); }, 300); }; btnClose.addEventListener('click', closeModal); modal.addEventListener('click', (e) => { if (e.target === modal) closeModal(); }); // Validation on blur const inputs = form.querySelectorAll('input, textarea'); inputs.forEach(input => { input.addEventListener('blur', () => validateField(input)); }); function validateField(field) { const group = field.closest('.form-group'); let isValid = true; if (field.hasAttribute('required') && !field.value.trim()) { isValid = false; } if (field.type === 'email' && field.value.trim()) { const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; if (!emailRegex.test(field.value.trim())) isValid = false; } if (!isValid) { group.classList.add('error'); } else { group.classList.remove('error'); } return isValid; } form.addEventListener('submit', (e) => { e.preventDefault(); let isFormValid = true; inputs.forEach(input => { if (!validateField(input)) isFormValid = false; }); if (!isFormValid) return; const nameVal = document.getElementById('support-name').value.trim(); const emailVal = document.getElementById('support-email').value.trim(); const messageVal = document.getElementById('support-message').value.trim(); submitBtn.disabled = true; submitBtn.textContent = 'Sending...'; statusDiv.className = 'form-status'; fetch('/api/project-email', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ projectId: "289", fields: { "Name": nameVal, "Email": emailVal, "Message": messageVal } }) }) .then(response => { if(response.ok) { statusDiv.textContent = 'Message sent successfully. We will get back to you soon.'; statusDiv.className = 'form-status success'; form.reset(); } else { throw new Error('Failed to send'); } }) .catch(err => { statusDiv.textContent = 'Something went wrong. Please try again later.'; statusDiv.className = 'form-status error'; }) .finally(() => { submitBtn.disabled = false; submitBtn.textContent = 'Send Message'; }); }); } // Start app document.addEventListener('DOMContentLoaded', init);