Skip to content

Instantly share code, notes, and snippets.

@Gfox21
Created September 20, 2017 09:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gfox21/02122908f384a4ef2b1768e33f0ef2a1 to your computer and use it in GitHub Desktop.
Save Gfox21/02122908f384a4ef2b1768e33f0ef2a1 to your computer and use it in GitHub Desktop.
I need some help to fix the problems in this project.
-- Projekt17
-- von Gewis
-- Version: 0.0.7 16.9.2017
-- Initialisierungsfunktion
function setup()
-- Voreinstellungen:
displayMode(FULLSCREEN)
-- Klassen aufrufen:
Setup:init()
Localisation:init()
end
-- Diese Funktion wird einmal pro Bild aufgerufen
function draw()
-- Setzt die Hintergrundsfarbe
background(3, 3, 253, 255)
-- Setzt die Textgröße
strokeWidth(5)
fontSize(17)
-- Hier verarbeiten:
Setup:draw()
Localisation:draw()
end
function touched(touch)
Setup:touched(touch)
end
function keyboard(key)
Setup:keyboard(key)
end
Setup = class()
_function Setup:init()
-- Variabeln:
screen = 1
-- Tastatur:
-- x,y,Länge,Breite,Höhe,Tastaturvariante max. 4
k1=keybrd(4,130,14,4,47,2)
k2=keybrd(40,170,11,5,47,2)
k1.size = 70
k2.str = "http://www.ixquick.com"
k2.size = 80
-- Navigation:
Navigation:init()
-- Provinzen:
--prov1 = Province("Small World:Court",500,500)
-- Knöpfe:
button = Button("Documents:Button","Cargo Bot:Dialogue Box",WIDTH/2,HEIGHT/1.5)
button.action = function() Setup:buttonPressed() end
button1 = Button("Documents:Button","Cargo Bot:Dialogue Box",WIDTH/2,HEIGHT/2)
button1.action = function() Setup:button1Pressed() end
button2 = Button("Documents:Button","Cargo Bot:Dialogue Box",WIDTH/2,HEIGHT/1.5)
button2.action = function() Setup:button2Pressed() end
button3 = Button("Documents:Button","Cargo Bot:Dialogue Box",WIDTH/2,HEIGHT/1.5)
button3.action = function() Setup:button3Pressed() end
button4 = Button("Documents:Button","Cargo Bot:Dialogue Box",WIDTH/2,HEIGHT/3)
button4.action = function() Setup:button4Pressed() end
button5 = Button("Documents:Button","Cargo Bot:Dialogue Box",WIDTH/2,HEIGHT/2)
button5.action = function() Setup:button5Pressed() end
button6 = Button("Documents:Button","Cargo Bot:Dialogue Box",WIDTH/2,HEIGHT/1.5)
button6.action = function() Setup:button6Pressed() end
button7 = Button("Documents:Button","Cargo Bot:Dialogue Box",WIDTH/2,HEIGHT/2)
button7.action = function() Setup:button7Pressed() end
button8 = Button("Documents:Button","Cargo Bot:Dialogue Box",WIDTH/4.5,HEIGHT/8.5)
button8.action = function() Setup:button4Pressed() end
button9 = Button("Documents:Button","Cargo Bot:Dialogue Box",WIDTH/2,HEIGHT/3)
button9.action = function() Setup:button9Pressed() end
button10 = Button("Documents:Button","Cargo Bot:Dialogue Box",WIDTH/1.3,HEIGHT/6)
button10.action = function() Setup:button10Pressed() end
button11 = Button("Documents:Button","Cargo Bot:Dialogue Box",WIDTH/4.5,HEIGHT/6)
button11.action = function() Setup:button4Pressed() end
button12 = Button("Documents:Button","Cargo Bot:Dialogue Box",WIDTH/1.3,HEIGHT/8.5)
button12.action = function() Setup:button12Pressed() end
button13 = Button("Documents:Button","Cargo Bot:Dialogue Box",WIDTH/2,HEIGHT/2)
button13.action = function() Setup:button13Pressed() end
button14 = Button("Documents:Button","Cargo Bot:Dialogue Box",WIDTH/3,HEIGHT/4)
button14.action = function() Setup:button14Pressed() end
end
function Setup:draw()
-- Voreinstellungen:
font("ArialRoundedMTBold")
fill(0, 0, 0, 255)
--if k1.value~=nil then
--text(k1.value,800,HEIGHT-50)
--fontSize(17)
--end
if screen == 1 then
textMode(CENTER)
button:draw()
text(start_game,button.pos.x,button.pos.y)
button1:draw()
text(menu_options,button1.pos.x,button1.pos.y)
button9:draw()
text(website,button9.pos.x,button9.pos.y)
elseif screen == 2 then
button2:draw()
text(set_language,button2.pos.x,button2.pos.y)
button4:draw()
text(back_button,button4.pos.x,button4.pos.y)
elseif screen == 3 then
button3:draw()
text(eng_language,button3.pos.x,button3.pos.y)
sprite("Documents:angloamerican",button3.pos.x + 300, button3.pos.y, 130, 80)
button4:draw()
text(back_button,button4.pos.x,button4.pos.y)
button5:draw()
text(deu_language,button5.pos.x,button5.pos.y)
sprite("Documents:astrogerman",button5.pos.x + 300, button5.pos.y, 130, 80)
elseif screen == 4 then
button4:draw()
text(back_button,button4.pos.x,button4.pos.y)
button6:draw()
text(new_game,button6.pos.x,button6.pos.y)
button7:draw()
text(load_game,button7.pos.x,button7.pos.y)
elseif screen == 5 then
background(0, 0, 0, 255)
k1:draw()
button8:draw()
text(back_button,button8.pos.x,button8.pos.y)
button12:draw()
text(start_button,button12.pos.x,button12.pos.y)
fontSize(40)
fill(255, 0, 0, 255)
text(set_savename,500,700)
text(k1.str, 500, 500)
noFill()
fontSize(17)
elseif screen == 6 then
Browser:setup()
Browser:draw()
noStroke()
textMode(CENTER)
k2:draw()
button10:draw()
text(go_button,button10.pos.x,button10.pos.y)
button11:draw()
text(back_button,button11.pos.x,button11.pos.y)
elseif screen == 7 then
save = readLocalData("save", 0)
button4:draw()
text(back_button,button4.pos.x,button4.pos.y)
button13:draw()
text(game_save,button13.pos.x,button13.pos.y+20)
text("" ..save,button13.pos.x,button13.pos.y)
elseif screen == 8 then
Navigation:draw()
--prov1:draw()
button14:draw()
text(back_button,button14.pos.x,button14.pos.y)
end
end
function Setup:buttonPressed()
screen = 4
end
function Setup:button1Pressed()
screen = 2
end
function Setup:button2Pressed()
screen = 3
end
function Setup:button3Pressed()
language = 1
end
function Setup:button4Pressed()
if screen == 2 then
screen = 1
elseif screen == 3 then
screen = 2
elseif screen == 4 then
screen = 1
elseif screen == 5 then
screen = 4
elseif screen == 6 then
screen = 1
elseif screen == 7 then
screen = 4
end
end
function Setup:button5Pressed()
language = 2
end
function Setup:button6Pressed()
screen = 5
end
function Setup:button7Pressed()
screen = 7
end
function Setup:button9Pressed()
screen = 6
end
function Setup:button10Pressed()
Browser:searchSite(pageAdress)
end
function Setup:button11Pressed()
--showKeyboard()
end
function Setup:button12Pressed()
saveLocalData("save", k1.str)
screen = 7
end
function Setup:button13Pressed()
screen = 8
end
function Setup:button14Pressed()
screen = 7
end
function Setup:touched(touch)
if touch.state==BEGAN and screen == 5 then
k1:touched(touch)
elseif touch.state==BEGAN and screen == 6 then
k2:touched(touch)
end
if screen == 1 then
button:touched(touch)
button1:touched(touch)
button9:touched(touch)
elseif screen == 2 then
button2:touched(touch)
button4:touched(touch)
elseif screen == 3 then
button3:touched(touch)
button4:touched(touch)
button5:touched(touch)
elseif screen == 4 then
button4:touched(touch)
button6:touched(touch)
button7:touched(touch)
elseif screen == 5 then
button8:touched(touch)
button11:touched(touch)
button12:touched(touch)
elseif screen == 6 then
button4:touched(touch)
button10:touched(touch)
button11:touched(touch)
elseif screen == 7 then
button4:touched(touch)
button13:touched(touch)
elseif screen == 8 then
--prov1:touched(touch)
Navigation:touched(touch)
button14:touched(touch)
end
end
function Setup:keyboard(key)
end
-- Knopf Klasse
-- von ChrisF
-- modifiziert von Gewis
Button = class()
function Button:init(btnNorm,btnSel,x,y)
self.pos = vec2(x,y)
self.btnNorm = btnNorm
self.btnSel = btnSel
self.selected = false
self.action = nil
self.w,self.h = spriteSize(self.btnNorm)
end
function Button:draw()
if self.selected == true then
sprite(self.btnSel,self.pos.x,self.pos.y,self.w,self.h)
elseif self.selected == false then
sprite(self.btnNorm,self.pos.x,self.pos.y,self.w,self.h)
end
end
function Button:touched(touch)
if touch.state == BEGAN or touch.state == MOVING then
if math.abs(self.pos.x - touch.x) <= (self.w/2)
and math.abs(self.pos.y - touch.y) <= (self.h/2) then
self.selected = true
else
self.selected = false
end
elseif touch.state == ENDED then
if self.selected == true and self.action then
self.action()
end
self.selected = false
end
end
Localisation = class()
-- Lokalisation für unterschiedliche Sprachen
function Localisation:init()
language = 1
start_game = "Start"
menu_options = "Settings"
set_language = "Language"
eng_language = "English"
deu_language = "German"
back_button = "Back"
new_game = "New Save"
load_game = "Load Save"
website = "Website"
go_button = "Go"
edit_button = "Edit"
browser_history = "History:"
error_too_long = "Too long!"
start_button = "Start"
set_savename = "Name your save:"
game_save = "Save:"
pause_button = "Pause"
end
function Localisation:draw()
if language == 1 then
start_game = "Start"
menu_options = "Settings"
set_language = "Language"
eng_language = "English"
deu_language = "German"
back_button = "Back"
new_game = "New Save"
load_game = "Load Save"
website = "Website"
go_button = "Go"
edit_button = "Edit"
browser_history = "History:"
error_too_long = "Too long!"
start_button = "Start"
set_savename = "Name your save:"
game_save = "Save:"
pause_button = "Pause"
elseif language == 2 then
start_game = "Spiel starten"
menu_options = "Einstellungen"
set_language = "Sprache"
eng_language = "Englisch"
deu_language = "Deutsch"
back_button = "Zurück"
new_game = "Neues Spiel"
load_game = "Lade Spiel"
website = "Webseite"
go_button = "Los"
edit_button = "Bearbeiten"
browser_history = "Browserverlauf:"
error_too_long = "Zu lang!"
start_button = "Start"
set_savename = "Benennt den Spielstandt:"
game_save = "Spielstandt:"
pause_button = "Pause"
end
end
keybrd=class()
function keybrd:init(x,y,w,h,size,kb)
self.keys={"ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-/:;()$&@.,?!'<>csbr",
"QWERTYUIOPASDFGHJKLZXCVBNM[]{}#%^*+=_|~<>.,?!'-/()rscb",
"123456789.0-brs",
"0123456789ABCDEFrc"}
self.kb=kb
self.w=w
self.h=h
self.size=size
self.str=""
self.x=x-self.size
self.y=y-self.size
self.caps=false
self.hide=false
self.val=""
self.value=""
end
function keybrd:draw()
pushStyle()
fontSize(self.size/2)
if self.hide then return end
local c=0
for y=self.h,1,-1 do
for x=1,self.w do
c=c+1
fill(255)
rect(x*self.size+self.x,y*self.size+self.y,self.size,self.size)
fill(255,0,0)
self.val=string.sub(self.keys[self.kb],c,c)
local len=string.len(self.keys[self.kb])
if c>=len-3 then
if self.val=="c" then self.val="CAP" end
if self.val=="s" then self.val="SP" end
if self.val=="b" then self.val="BSP" end
if self.val=="r" then self.val="RTN" end
end
if not self.caps then
self.val=string.lower(self.val)
end
text(self.val,x*self.size+self.size/2+self.x,
y*self.size+self.size/2+self.y)
end
end
fill(255)
text(self.str,self.x+2*self.size,self.y+self.h)
popStyle()
end
function keybrd:touched(t)
if self.hide then return end
if t.state==BEGAN then
local tx=math.floor((t.x-self.x)/self.size)
local ty=math.floor((t.y-self.y)/self.size)
local pos=(self.h-ty)*self.w+tx
local len=string.len(self.keys[self.kb])
if tx<1 or tx>self.w or ty<1 or ty>self.h then
return
end
self.val=string.sub(self.keys[self.kb],pos,pos)
if not self.caps then
self.val=string.lower(self.val)
end
if pos>=len-3 then
if self.val=="c" then -- caps
self.caps = not self.caps
return
end
if self.val=="s" then -- space
self.str=self.str.." "
return
end
if self.val=="b" then -- back space
self.str=string.sub(self.str,1,string.len(self.str)-1)
return
end
if self.val=="r" then -- return
self.value=self.str
self.str=""
return
end
end
self.str=self.str..self.val
end
end
-- Navigations Klasse
-- von Dave
-- modifiziert von Gewis
Navigation = class()
function Navigation:init()
displayMode(FULLSCREEN)
dx=WIDTH/2
dy=HEIGHT/2
move=true
end
function Navigation:draw()
background(40, 40, 50)
translate(dx,dy)
fill(255)
ellipse(0,0,100,100)
stroke(255)
strokeWidth(4)
fontSize(30)
for x=-3000,3000,100 do
line(x,-3000,x,3000)
fill(255)
text(x,x,0)
end
for y=-3000,3000,100 do
line(-3000,y,3000,y)
text(y,0,y)
end
end
function Navigation:touched(touch)
if touch.state==BEGAN and move == true then
x1=touch.x
y1=touch.y
elseif touch.state==MOVING and move == true then
dx=dx+touch.x-x1
dy=dy+touch.y-y1
x1=touch.x
y1=touch.y
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment