Pastebin
API
tools
faq
paste
Login
Sign up
Please fix the following errors:
New Paste
Syntax Highlighting
#include "oxygine-framework.h" #include "game.h" #include <functional> #include "helpers/positioning.h" #include <unistd.h> #include <ctime> #include <iostream> using namespace oxygine; //it is our resources //in real project you would have more than one Resources declarations. //It is important on mobile devices with limited memory and you would load/unload them Resources gameResources; MainActor::~MainActor() {} MainActor::MainActor() { srand (time(NULL)); spSprite sky = new Sprite; sky->setResAnim(gameResources.getResAnim("background")); sky->attachTo(this); //create Sprites spSprite sudi = new Sprite(); positioning positions; srand( time( NULL ) ); sudi->setResAnim(gameResources.getResAnim("pudi")); //centered button at screen positions.alignToBottom(sudi); positions.alignToLeft(sudi); //sudi->setPosition(getStage()->getSize().x / 2 - sudi->getSize().x / 2, getStage()->getSize().y - sudi->getSize().y); /*char test[50]; sprintf(test, "%f", getStage()->getSize().x); log::messageln(test);*/ pauseButton = new Button(); pauseButton->setResAnim(gameResources.getResAnim("button")); pauseButton->setPosition(VectorT2<float>(5,5)); resumeButton = new Button(); resumeButton->setResAnim(gameResources.getResAnim("wznow")); resumeButton->setSize(resumeButton->getSize()/2); resumeButton->setPosition(getStage()->getSize()/2 - resumeButton->getSize()/2); resumeButton->setVisible(false); resumeButton->setPriority(1001); //register click handler to button EventCallback cb = CLOSURE(this, &MainActor::pauseButtonClicked); pauseButton->addEventListener(TouchEvent::CLICK, cb); resumeButton->addEventListener(TouchEvent::CLICK, cb); addChild(pauseButton); addChild(resumeButton); //attach pauseButton as child to current actor addChild(sudi); _sudi = sudi; getStage()->addEventListener(TouchEvent::MOVE, CLOSURE(this, &MainActor::mouseHandler)); //create TextField Actor spTextField text = new TextField(); //attach it as child to pauseButton text->attachTo(this); //centered in pauseButton text->setPosition(100, 10); //initialize text style TextStyle style; style.font = gameResources.getResFont("font"); style.color = Color::White; style.vAlign = TextStyle::VALIGN_TOP; style.hAlign = TextStyle::HALIGN_LEFT; style.fontSize = 50; text->setStyle(style); text->setText("0"); addChild(text); _text = text; beginTime = getStage()->getClock()->getTime(); bar = new ProgressBar(); bar->setResAnim(gameResources.getResAnim("button")); bar->setAnchor(Vector2(0.5f, 0.5f)); bar->setPosition(500,500); bar->setProgress(0.0f); bar->setDirection(ProgressBar::dir_90); //bar->setSize(600, 200); this->addChild(bar); dim = new Sprite(); dim->setResAnim(gameResources.getResAnim("dim")); dim->setPosition(0, 0); dim->setVisible(false); addChild(dim); } void MainActor::setPauseMenu(bool status) { dim->setVisible(status); dim->setPriority(1000); resumeButton->setVisible(status); } bool calculateWidth(spActor arg1, spActor arg2) { if(abs(((arg2->getPosition().x+(arg2->getSize().x/2)) - (arg1->getPosition().x+(arg1->getSize().x/2)))) < 100) return true; return false; } bool calculateHeight(spActor arg1, spActor arg2, int distance) { if(((arg2->getPosition().y+(arg2->getSize().y/2)) - (arg1->getPosition().y+(arg1->getSize().y/2))) < distance) return true; return false; } void MainActor::doUpdate(const UpdateState& us) { for (MainActor::units::iterator i = _units.begin(); i != _units.end(); ++i) { spActor unit = *i; if(calculateWidth(unit, _sudi) && calculateHeight(unit, _sudi, 300)) { _sudi->setColumn(1); } if(calculateWidth(unit, _sudi) && calculateHeight(unit, _sudi, 10)) { if(unit->getName() == "jagodowy") { bactive = true; bspeed = speed; this->getClock()->setMultiplier(0.5f); bcounter = 0; silting--; points++; } else if(unit->getName() == "zepsuty") { if(points <= 5) points = 0; else points-=5; silting--; } else if(unit->getName() == "skwarki") { points += 5; silting--; } else if(unit->getName() == "kompot") { silting = 51; } else if(unit->getName() == "ruski") { silting--; points++; } unit->detach(); _units.erase(i); _sudi->setColumn(0); break; } else if(unit->getPosition().y >= getStage()->getSize().y) { unit->detach(); _units.erase(i); if(points > 0) points--; silting--; _sudi->setColumn(0); break; } } bar->setProgress(silting/50.0f); char test[10]; sprintf(test, "Pkt: %d", points); _text->setText(test); double s = (this->getClock()->getTime() - beginTime)/1000.0; if(s>=speed/1000) { beginTime = this->getClock()->getTime(); runSprite(); if(bactive) bcounter++; else counter++; // Wyłącz bonus jak się skończy limit if(bcounter==5) { bactive=false; speed = bspeed; this->getClock()->setMultiplier(1); } // Jeżeli licznik przekroczył granice skoku i prędkość jest większa od 300 to przeskocz if(counter>=jump && speed>500) { speed -= 100; //skok counter = 0; // zeruj licznik if(speed <= 1500) // jump*=1.5; } // Jeżeli bonus nie jest aktywny to losuj szansa 5/100 if(!bactive && rand()%100 <= 4) { switch(rand()%2) { case 0: runSprite(0, speed/1.5f, "jagodowy"); break; case 1: runSprite(0, speed/1.5f, "zepsuty"); break; } } // Kompot if(rand()%200 < 500.0f/silting) { runSprite(speed/2, speed, "kompot"); } // Skwarki if(rand()%100 < 33) { runSprite(speed/2, speed, "skwarki"); } } } void MainActor::pauseButtonClicked(Event* event) { if(!paused) { this->getClock()->pause(); paused=true; } else { this->getClock()->resume(); paused=false; } setPauseMenu(paused); } void MainActor::mouseHandler(Event* event) { TouchEvent* te = safeCast<TouchEvent*>(event); //user clicked to button //log::messageln("button clicked"); Vector2 pos = te->localPosition-_sudi->getSize()/2; if(te->localPosition.x>50 && te->localPosition.x<670 && !paused) _sudi->setPosition(pos.x, _sudi->getPosition().y); //animate button by chaning color //_sudi->setColor(Color::White); //_sudi->addTween(Sprite::TweenColor(Color::Green), 500, 1, true); //animate text by scaling //_text->setScale(1.0f); //_text->addTween(Actor::TweenScale(1.1f), 500, 1, true); //and change text //_text->setText("Clicked!"); //lets create and run sprite with simple animation //runSprite(); } void MainActor::runSprite() { runSprite(0, speed); } void MainActor::runSprite(int delay) { runSprite(delay, speed); } void MainActor::runSprite(int delay, int speed) { runSprite(delay, speed, "ruski"); } void MainActor::runSprite(int delay, int speed, std::string type) { spSprite sprite = new Sprite(); addChild(sprite); int duration = 600;//ms int loops = -1;//infinity loops //animation has 8 columns - frames, check 'res.xml' ResAnim* animation = gameResources.getResAnim(type); //add animation tween to sprite //TweenAnim would change animation frames sprite->addTween(Sprite::TweenAnim(animation), duration, loops); Vector2 destPos = Vector2(rand()%((int)(getStage()->getSize().x-sprite->getWidth())), getStage()->getSize().y+sprite->getHeight()); Vector2 srcPos = Vector2(destPos.x, -sprite->getHeight()); //set sprite initial position sprite->setPosition(srcPos); //add another tween: TweenQueue //TweenQueue is a collection of tweens spTweenQueue tweenQueue = new TweenQueue(); tweenQueue->setDelay(delay); //first, move sprite to dest position tweenQueue->add(Sprite::TweenPosition(destPos), speed, 1); //then fade it out smoothly //tweenQueue->add(Sprite::TweenAlpha(0), 500, 1); sprite->addTween(tweenQueue); sprite->setName(type); sprite->setPriority(10); _units.push_back(sprite); //and remove sprite from tree when tweenQueue is empty //if you don't hold any references to sprite it would be deleted automatically tweenQueue->detachWhenDone(); } //declare spMainActor as intrusive_ptr holder of MainActor typedef oxygine::intrusive_ptr<MainActor> spMainActor; //you could use DECLARE_SMART preprocessor definition it does the same: //DECLARE_SMART(MainActor, spMainActor) void game_preinit() {} //called from main.cpp void game_init() { //load xml file with resources definition gameResources.loadXML("res.xml"); //lets create our client code simple actor //spMainActor was defined above as smart intrusive pointer (read more: http://www.boost.org/doc/libs/1_60_0/libs/smart_ptr/intrusive_ptr.html) spMainActor actor = new MainActor; actor->setClock(new Clock); //and add it to Stage as child getStage()->addChild(actor); } //called each frame from main.cpp void game_update() { } //called each frame from main.cpp void game_destroy() { //free previously loaded resources gameResources.free(); }
Optional Paste Settings
Category:
None
Cryptocurrency
Cybersecurity
Fixit
Food
Gaming
Haiku
Help
History
Housing
Jokes
Legal
Money
Movies
Music
Pets
Photo
Science
Software
Source Code
Spirit
Sports
Travel
TV
Writing
Tags:
Syntax Highlighting:
None
Bash
C
C#
C++
CSS
HTML
JSON
Java
JavaScript
Lua
Markdown (PRO members only)
Objective C
PHP
Perl
Python
Ruby
Swift
4CS
6502 ACME Cross Assembler
6502 Kick Assembler
6502 TASM/64TASS
ABAP
AIMMS
ALGOL 68
APT Sources
ARM
ASM (NASM)
ASP
ActionScript
ActionScript 3
Ada
Apache Log
AppleScript
Arduino
Asymptote
AutoIt
Autohotkey
Avisynth
Awk
BASCOM AVR
BNF
BOO
Bash
Basic4GL
Batch
BibTeX
Blitz Basic
Blitz3D
BlitzMax
BrainFuck
C
C (WinAPI)
C Intermediate Language
C for Macs
C#
C++
C++ (WinAPI)
C++ (with Qt extensions)
C: Loadrunner
CAD DCL
CAD Lisp
CFDG
CMake
COBOL
CSS
Ceylon
ChaiScript
Chapel
Clojure
Clone C
Clone C++
CoffeeScript
ColdFusion
Cuesheet
D
DCL
DCPU-16
DCS
DIV
DOT
Dart
Delphi
Delphi Prism (Oxygene)
Diff
E
ECMAScript
EPC
Easytrieve
Eiffel
Email
Erlang
Euphoria
F#
FO Language
Falcon
Filemaker
Formula One
Fortran
FreeBasic
FreeSWITCH
GAMBAS
GDB
GDScript
Game Maker
Genero
Genie
GetText
Go
Godot GLSL
Groovy
GwBasic
HQ9 Plus
HTML
HTML 5
Haskell
Haxe
HicEst
IDL
INI file
INTERCAL
IO
ISPF Panel Definition
Icon
Inno Script
J
JCL
JSON
Java
Java 5
JavaScript
Julia
KSP (Kontakt Script)
KiXtart
Kotlin
LDIF
LLVM
LOL Code
LScript
Latex
Liberty BASIC
Linden Scripting
Lisp
Loco Basic
Logtalk
Lotus Formulas
Lotus Script
Lua
M68000 Assembler
MIX Assembler
MK-61/52
MPASM
MXML
MagikSF
Make
MapBasic
Markdown (PRO members only)
MatLab
Mercury
MetaPost
Modula 2
Modula 3
Motorola 68000 HiSoft Dev
MySQL
Nagios
NetRexx
Nginx
Nim
NullSoft Installer
OCaml
OCaml Brief
Oberon 2
Objeck Programming Langua
Objective C
Octave
Open Object Rexx
OpenBSD PACKET FILTER
OpenGL Shading
Openoffice BASIC
Oracle 11
Oracle 8
Oz
PARI/GP
PCRE
PHP
PHP Brief
PL/I
PL/SQL
POV-Ray
ParaSail
Pascal
Pawn
Per
Perl
Perl 6
Phix
Pic 16
Pike
Pixel Bender
PostScript
PostgreSQL
PowerBuilder
PowerShell
ProFTPd
Progress
Prolog
Properties
ProvideX
Puppet
PureBasic
PyCon
Python
Python for S60
QBasic
QML
R
RBScript
REBOL
REG
RPM Spec
Racket
Rails
Rexx
Robots
Roff Manpage
Ruby
Ruby Gnuplot
Rust
SAS
SCL
SPARK
SPARQL
SQF
SQL
SSH Config
Scala
Scheme
Scilab
SdlBasic
Smalltalk
Smarty
StandardML
StoneScript
SuperCollider
Swift
SystemVerilog
T-SQL
TCL
TeXgraph
Tera Term
TypeScript
TypoScript
UPC
Unicon
UnrealScript
Urbi
VB.NET
VBScript
VHDL
VIM
Vala
Vedit
VeriLog
Visual Pro Log
VisualBasic
VisualFoxPro
WHOIS
WhiteSpace
Winbatch
XBasic
XML
XPP
Xojo
Xorg Config
YAML
YARA
Z80 Assembler
ZXBasic
autoconf
jQuery
mIRC
newLISP
q/kdb+
thinBasic
Paste Expiration:
Never
Burn after read
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Exposure:
Public
Unlisted
Private
Folder:
(members only)
Password
NEW
Enabled
Disabled
Burn after read
NEW
Paste Name / Title:
Create New Paste
Hello
Guest
Sign Up
or
Login
Sign in with Facebook
Sign in with Twitter
Sign in with Google
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Public Pastes
⭐ Instant Profit Method ⭐ X
JavaScript | 2 sec ago | 0.31 KB
⭐⭐⭐Exchange Exploit T 2⭐⭐⭐
Java | 8 sec ago | 0.06 KB
⭐Swapzone Glitch (Working) 0
JavaScript | 11 sec ago | 0.31 KB
✅ MAKE $5OO IN 15 MIN E
JavaScript | 20 sec ago | 0.31 KB
⭐⭐⭐Make $15OO in 2O minutesV E⭐⭐⭐
Java | 21 sec ago | 0.06 KB
⭐⭐⭐MAKE $500 IN 15 MIN⭐⭐⭐
Java | 36 sec ago | 0.06 KB
⭐Crypto Exchange Profit Method⭐ C
JavaScript | 38 sec ago | 0.31 KB
✅ MAKE $5OO IN 15 MIN 3
JavaScript | 43 sec ago | 0.31 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the
Cookies Policy
.
OK, I Understand
Not a member of Pastebin yet?
Sign Up
, it unlocks many cool features!